{"record":{"id":"4b9a392b832bd9f1","repo":"valyala/fasthttp","slug":"unexpected-convert-net-interface-index-int-to-uint","errorCode":null,"errorMessage":"unexpected convert net interface index int to uint32: %w","messagePattern":"unexpected convert net interface index int to uint32: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tcplisten/tcplisten.go","lineNumber":162,"sourceCode":"\n\tswitch network {\n\tcase \"tcp4\":\n\t\tvar sa4 unix.SockaddrInet4\n\t\tsa4.Port = tcpAddr.Port\n\t\tcopy(sa4.Addr[:], tcpAddr.IP.To4())\n\t\treturn &sa4, unix.AF_INET, nil\n\tcase \"tcp6\":\n\t\tvar sa6 unix.SockaddrInet6\n\t\tsa6.Port = tcpAddr.Port\n\t\tcopy(sa6.Addr[:], tcpAddr.IP.To16())\n\t\tif tcpAddr.Zone != \"\" {\n\t\t\tifi, err := net.InterfaceByName(tcpAddr.Zone)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, -1, err\n\t\t\t}\n\t\t\tsa6.ZoneId, err = safeIntToUint32(ifi.Index)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, -1, fmt.Errorf(\"unexpected convert net interface index int to uint32: %w\", err)\n\t\t\t}\n\t\t}\n\t\treturn &sa6, unix.AF_INET6, nil\n\tcase \"tcp\":\n\t\tvar sa6 unix.SockaddrInet6\n\t\tsa6.Port = tcpAddr.Port\n\t\tif tcpAddr.IP == nil {\n\t\t\ttcpAddr.IP = net.IPv4(0, 0, 0, 0)\n\t\t}\n\t\tcopy(sa6.Addr[:], tcpAddr.IP.To16())\n\t\tif tcpAddr.Zone != \"\" {\n\t\t\tifi, err := net.InterfaceByName(tcpAddr.Zone)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, -1, err\n\t\t\t}\n\t\t\tsa6.ZoneId, err = safeIntToUint32(ifi.Index)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, -1, fmt.Errorf(\"unexpected convert net interface index int to uint32: %w\", err)","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/tcplisten/tcplisten.go#L144-L180","documentation":"When parsing a tcp6 address that includes a numeric zone (e.g. \"[fe80::1%eth0]:8080\" resolved via net.InterfaceByName), getSockaddr must convert the interface index (int) to the uint32 ZoneId field of unix.SockaddrInet6. safeIntToUint32 rejects out-of-range values, and the library wraps that failure with this message.","triggerScenarios":"NewListener with network \"tcp6\" (or an address whose zone resolution path reaches this branch) where net.InterfaceByName returns an interface whose Index is negative or exceeds uint32 range — practically only possible with corrupt/mock netstate or an integer overflow scenario.","commonSituations":"Extremely rare in practice; seen with mocked net.Interface implementations in tests, corrupted /sys/class/net state, or on exotic platforms where interface indexes are not bounded by uint32.","solutions":["Inspect the wrapped %w error from safeIntToUint32","Verify the interface named in the address Zone exists and has a sane index (ip link show)","Remove the zone from the address if listening on a global-scope address","Update the library/golang.org/x/sys if running an unusual platform"],"exampleFix":"// before\nln, err := tcplisten.NewListener(cfg, \"tcp6\", \"[fe80::1%weird0]:8080\") // bad zone/index\n// after\nifi, _ := net.InterfaceByName(\"eth0\") // validate zone first\nln, err := tcplisten.NewListener(cfg, \"tcp6\", fmt.Sprintf(\"[fe80::1%%%s]:8080\", ifi.Name))","handlingStrategy":"validation","validationCode":"func validV6Zone(addr string) bool {\n    host, _, err := net.SplitHostPort(addr)\n    if err != nil { return false }\n    if i := strings.LastIndexByte(host, '%'); i >= 0 {\n        ifi, err := net.InterfaceByName(host[i+1:])\n        return err == nil && ifi.Index > 0 && uint64(ifi.Index) <= math.MaxUint32\n    }\n    return true\n}","typeGuard":null,"tryCatchPattern":"ln, err := tcplisten.NewListener(cfg, \"tcp6\", addr)\nif err != nil && strings.Contains(err.Error(), \"interface index\") {\n    return fmt.Errorf(\"bad ipv6 zone in %q: %w\", addr, err)\n}","preventionTips":["Resolve and validate the zone interface index before building link-local listener addresses","Prefer global-scope addresses without zones for listeners","Validate interface names against `ip link` output in deployment scripts"],"tags":["network","ipv6","zone-id","integer-overflow"],"backgroundTag":"interface-index-out-of-range","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}