Go version

go version go1.24.3 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/k23099/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/k23099/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/qy/n3vgwpdj4mldn4k896109pnh0000gn/T/go-build4022064140=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/k23099/Documents/CYPHONIC/PraseRIB-test/go.mod'
GOMODCACHE='/Users/k23099/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/k23099/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.24.3/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/Users/k23099/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.3/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.3'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

After starting the code below, I ran sudo ifconfig en0 alias 192.168.1.100 255.255.255.0 and sudo ifconfig en0 -alias 192.168.1.10.

package main

import (
    "log"
    "syscall"

    "golang.org/x/net/route"
)

func main() {
    fd, err := syscall.Socket(syscall.AF_ROUTE, syscall.SOCK_RAW, syscall.AF_UNSPEC)
    if err != nil {
        log.Fatalf("socket error: %v", err)
    }
    defer syscall.Close(fd)

    buf := make([]byte, 4096)

    for {
        n, err := syscall.Read(fd, buf)
        if err != nil {
            log.Printf("Read error: %v", err)
            continue
        }

        _, err = route.ParseRIB(route.RIBTypeRoute, buf[:n])
        if err != nil {
            log.Printf("ParseRIB error: %v", err)
        }
    }
}

What did you see happen?

k23099@MacBookAir PraseRIB-test % go run main.go                   
2025/08/03 02:24:25 ParseRIB error: message too short
2025/08/03 02:26:35 ParseRIB error: message too short

What did you expect to see?

Prevent the 'message too short' error.

Comment From: ayuayuyu

Problem Analysis and Solution

The issue is located in the parseAddrs function within the file golang.org/x/net@v0.42.0/route/address.go.

In the code block below, the call to roundup seems to be unnecessary.

// In function parseAddrs
case isInet(int(b[1])) || (isMask(i) && isInet(af)):
    if isInet(int(b[1])) {
        af = int(b[1])
    }
    a, err := parseInetAddr(af, b)
    if err != nil {
        return nil, err
    }
    as[i] = a
    l := roundup(int(b[0])) // This is line 431
    if len(b) < l {
        return nil, errMessageTooShort
    }
    b = b[l:]

The specific line causing the issue is line 431: l := roundup(int(b[0]))

Removing the roundup function call resolves the problem. The reason for its existence in this context is unclear.

Comment From: gabyhelp

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)