{"record":{"id":"6716dfed6ef645c2","repo":"XTLS/Xray-core","slug":"invalid-source-ip-address","errorCode":null,"errorMessage":"invalid source IP address: ","messagePattern":"invalid source IP address: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/net/find_process_darwin.go","lineNumber":66,"sourceCode":"\tdarwinSocketLocalMatch\n\tdarwinSocketExactMatch\n)\n\nfunc FindProcess(network, srcIP string, srcPort uint16, destIP string, destPort uint16) (PID int, Name string, AbsolutePath string, err error) {\n\tisLocal, err := IsLocal(net.ParseIP(srcIP))\n\tif err != nil {\n\t\treturn 0, \"\", \"\", errors.New(\"failed to determine if address is local: \", err)\n\t}\n\tif !isLocal {\n\t\treturn 0, \"\", \"\", ErrNotLocal\n\t}\n\tif network != \"tcp\" && network != \"udp\" {\n\t\tpanic(\"Unsupported network type for process lookup.\")\n\t}\n\n\tsrcAddr, err := netip.ParseAddr(srcIP)\n\tif err != nil {\n\t\treturn 0, \"\", \"\", errors.New(\"invalid source IP address: \", srcIP)\n\t}\n\tsrcAddr = srcAddr.Unmap()\n\n\tvar dstAddr netip.Addr\n\thasDstAddr := false\n\tif destIP != \"\" && destPort != 0 {\n\t\tdstAddr, err = netip.ParseAddr(destIP)\n\t\tif err != nil {\n\t\t\treturn 0, \"\", \"\", errors.New(\"invalid destination IP address: \", destIP)\n\t\t}\n\t\tdstAddr = dstAddr.Unmap()\n\t\thasDstAddr = true\n\t}\n\n\tprocesses, err := unix.SysctlKinfoProcSlice(\"kern.proc.all\")\n\tif err != nil {\n\t\treturn 0, \"\", \"\", errors.New(\"failed to list processes\").Base(err)\n\t}","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/common/net/find_process_darwin.go#L48-L84","documentation":"On macOS, FindProcess passes srcIP to netip.ParseAddr and it failed to parse (empty string, malformed IPv4/IPv6 text, or a value like 'localhost'). The source address must be a literal IP; hostnames and empty strings are rejected.","triggerScenarios":"Calling FindProcess with srcIP=\"\", srcIP containing a zone/hostname, or an address string with whitespace; also when a caller forwards the host part of an address pair instead of the IP.","commonSituations":"Custom callers extracting the source incorrectly from net.Conn (using addr.String() of a hostname-based Addr, or an uninitialized variable), or tests invoking FindProcess with placeholder strings.","solutions":["Pass the IP extracted from the connection: host, _, err := net.SplitHostPort(conn.RemoteAddr().String()) and verify net.ParseIP(host) != nil.","Skip the call when the source address is missing or not an IP literal.","Trim whitespace/brackets from IPv6 literals before parsing.","Add a unit check that formats srcIP with netip.Addr.String() at the call site."],"exampleFix":"// before\npid, name, path, err := net.FindProcess(\"tcp\", srcHost, srcPort, dstHost, dstPort) // srcHost may be \"localhost\"\n// after\nsrcIP := net.ParseIP(srcHost)\nif srcIP == nil {\n    return fmt.Errorf(\"invalid source IP %q\", srcHost)\n}\npid, name, path, err := net.FindProcess(\"tcp\", srcIP.String(), srcPort, dstIP.String(), dstPort)","handlingStrategy":"validation","validationCode":"func validSourceIP(s string) bool { return net.ParseIP(s) != nil }\n\nif !validSourceIP(srcIP) {\n    return errors.New(\"invalid srcIP, cannot do process lookup\")\n}","typeGuard":"func isParseableIP(s string) bool {\n    if s == \"\" { return false }\n    if _, err := netip.ParseAddr(s); err != nil { return false }\n    return true\n}","tryCatchPattern":"pid, name, path, err := net.FindProcess(network, srcIP, srcPort, destIP, destPort)\nif err != nil && strings.Contains(err.Error(), \"invalid source IP address\") {\n    // caller bug: fix address extraction, do not retry with the same value\n    log.Error(\"process lookup called with bad srcIP %q\", srcIP)\n}","preventionTips":["Extract the host with net.SplitHostPort from conn.RemoteAddr().","Reject hostnames early — FindProcess wants IP literals only.","Unit-test call sites with both IPv4 and IPv6 literals."],"tags":["darwin","macos","validation","process-lookup","xray"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}