From 0312e31ed197b3bf1434e8dbb283f0d2374d7457 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 1 Mar 2025 20:34:45 -0800 Subject: [PATCH] net: fix parsing of interfaces on plan9 without associated devices Fixes #72060 Updates #39908 Change-Id: I7d5bda1654753acebc8aa9937d010b41c5722b36 Reviewed-on: https://go-review.googlesource.com/c/go/+/654055 Reviewed-by: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Russ Cox Auto-Submit: Brad Fitzpatrick --- src/net/interface_plan9.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/net/interface_plan9.go b/src/net/interface_plan9.go index 7c44566acf..21d2f95040 100644 --- a/src/net/interface_plan9.go +++ b/src/net/interface_plan9.go @@ -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) -- 2.51.0