File: fix-debian-buildd-failures-on-nil-network-interface.patch

package info (click to toggle)
golang-github-astroprofundis-sysinfo 0.0~git20240112.ed54df1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 212 kB
  • sloc: asm: 21; makefile: 3
file content (48 lines) | stat: -rw-r--r-- 1,817 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
From: =?utf-8?b?T3R0byBLZWvDpGzDpGluZW4=?= <otto@debian.org>
Date: Mon, 25 Aug 2025 18:40:22 +0000
Subject: Handle nil interface from net.InterfaceByName

This package built and all post-build Go tests passed fully on all local builds,
Salsa CI and on Launchpad on all architectures. However, on Debian buildd it
failed randomly, apparently as the `net.InterfaceByName` function returned a nil
interface if the specified network interface is not found or available,
manifesting as a `SIGSEGV` in the `getNetworkInfo` function. Seems that if an
error occurs (indicating `inet` is nil), the `ip_addrs` slice and `mtu` variable
are initialized to their zero values, preventing the subsequent nil pointer
dereference and ensuring the code handles unavailable interfaces gracefully.

Attempt to handle this error returned by `net.InterfaceByName` to avoid tests
failing.
---
 network.go | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/network.go b/network.go
index 34e78b0..370dfee 100644
--- a/network.go
+++ b/network.go
@@ -153,8 +153,13 @@ func (si *SysInfo) getNetworkInfo() {
 		supp := getSupported(link.Name())
 
 		// get IP Address(es) of interface
-		inet, _ := net.InterfaceByName(link.Name())
-		ip_addrs, _ := getIPAddrByInterface(inet)
+		inet, err := net.InterfaceByName(link.Name())
+		var ip_addrs []string
+		var mtu int
+		if err == nil {
+			ip_addrs, _ = getIPAddrByInterface(inet)
+			mtu = inet.MTU
+		}
 
 		speed := readIfaceSpeed(path.Join(fullpath, "speed"))
 		if speed == 0 {
@@ -167,7 +172,7 @@ func (si *SysInfo) getNetworkInfo() {
 			IPAddress:  ip_addrs,
 			Port:       getPortType(supp),
 			Speed:      speed,
-			MTU:        inet.MTU,
+			MTU:        mtu,
 		}
 
 		if driver, err := os.Readlink(path.Join(fullpath, "device", "driver")); err == nil {