]> Cypherpunks repositories - gostls13.git/commitdiff
net: fix parsing of interfaces on plan9 without associated devices
authorBrad Fitzpatrick <bradfitz@golang.org>
Sun, 2 Mar 2025 04:34:45 +0000 (20:34 -0800)
committerGopher Robot <gobot@golang.org>
Mon, 3 Mar 2025 16:07:04 +0000 (08:07 -0800)
Fixes #72060
Updates #39908

Change-Id: I7d5bda1654753acebc8aa9937d010b41c5722b36
Reviewed-on: https://go-review.googlesource.com/c/go/+/654055
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Auto-Submit: Brad Fitzpatrick <bradfitz@golang.org>

src/net/interface_plan9.go

index 7c44566acf0165d44727470512e177164450c3b8..21d2f95040175a65d6d83327de85112a736a9136 100644 (file)
@@ -57,6 +57,17 @@ func readInterface(i int) (*Interface, error) {
        }
 
        fields := getFields(line)
+
+       // If the interface has no device file then we see two spaces between "device" and
+       // "maxtu" and and getFields treats the two spaces as one delimiter.
+       // Insert a gap for the missing device name.
+       // See https://go.dev/issue/72060.
+       if stringslite.HasPrefix(line, "device  maxtu ") {
+               fields = append(fields, "")
+               copy(fields[2:], fields[1:])
+               fields[1] = ""
+       }
+
        if len(fields) < 4 {
                return nil, errors.New("invalid interface status file: " + ifcstat)
        }
@@ -163,7 +174,7 @@ func interfaceAddrTable(ifi *Interface) ([]Addr, error) {
                for line, ok := statusf.readLine(); ok; line, ok = statusf.readLine() {
                        fields := getFields(line)
                        if len(fields) < 1 {
-                               return nil, errors.New("cannot parse IP address for interface: " + status)
+                               continue
                        }
                        addr := fields[0]
                        ip := ParseIP(addr)