{"record":{"id":"e817851775c9cff1","repo":"XTLS/Xray-core","slug":"failed-to-format-address","errorCode":null,"errorMessage":"failed to format address: ","messagePattern":"failed to format address: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/net/find_process_linux.go","lineNumber":50,"sourceCode":"\tcase \"tcp\":\n\t\tif net.ParseIP(srcIP).To4() != nil {\n\t\t\tprocFile = \"/proc/net/tcp\"\n\t\t} else {\n\t\t\tprocFile = \"/proc/net/tcp6\"\n\t\t}\n\tcase \"udp\":\n\t\tif net.ParseIP(srcIP).To4() != nil {\n\t\t\tprocFile = \"/proc/net/udp\"\n\t\t} else {\n\t\t\tprocFile = \"/proc/net/udp6\"\n\t\t}\n\tdefault:\n\t\tpanic(\"Unsupported network type for process lookup.\")\n\t}\n\n\ttargetHexAddr, err := formatLittleEndianString(net.ParseIP(srcIP), Port(srcPort))\n\tif err != nil {\n\t\treturn 0, \"\", \"\", errors.New(\"failed to format address: \", err)\n\t}\n\n\tinode, err := findInodeInFile(procFile, targetHexAddr)\n\tif err != nil {\n\t\treturn 0, \"\", \"\", errors.New(\"could not search in \", procFile).Base(err)\n\t}\n\tif inode == \"\" {\n\t\treturn 0, \"\", \"\", errors.New(\"connection for \", srcIP, \":\", srcPort, \" not found in \", procFile)\n\t}\n\n\tpidStr, err := findPidByInode(inode)\n\tif err != nil {\n\t\treturn 0, \"\", \"\", errors.New(\"could not find PID for inode \", inode, \": \", err)\n\t}\n\tif pidStr == \"\" {\n\t\treturn 0, \"\", \"\", errors.New(\"no process found for inode \", inode)\n\t}\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/common/net/find_process_linux.go#L32-L68","documentation":"Linux FindProcess converts srcIP:srcPort into the little-endian hexadecimal form used by /proc/net/tcp{,6} via formatLittleEndianString, and that failed. In practice this only fails when net.ParseIP(srcIP) returned nil (invalid IP string), because To4()/To16() on nil yield nil ipBytes.","triggerScenarios":"Passing an empty or malformed srcIP ('', 'example.com', '1.2.3.4:80', an address with a zone) so net.ParseIP returns nil; the nil IP then fails the ipBytes == nil check in formatLittleEndianString.","commonSituations":"Call sites forwarding raw proxy-chain metadata where srcIP was never populated; strings containing port or zone identifiers passed as bare IPs.","solutions":["Validate srcIP with net.ParseIP before calling FindProcess and reject nil results","Strip ports and %zone suffixes from the address before passing it","Log the exact srcIP value when the error fires to find which call site sends bad input"],"exampleFix":"// before\npid, name, path, err := net.FindProcess(network, srcIP, srcPort, dstIP, dstPort)\n\n// after\nif net.ParseIP(srcIP) == nil {\n    return errors.New(\"FindProcess: srcIP is not a valid IP: \", srcIP)\n}\npid, name, path, err := net.FindProcess(network, srcIP, srcPort, dstIP, dstPort)","handlingStrategy":"validation","validationCode":"if net.ParseIP(srcIP) == nil {\n    return errors.New(\"FindProcess: srcIP is not a valid IP: \", srcIP)\n}","typeGuard":"func isValidIpString(s string) bool { return net.ParseIP(s) != nil }","tryCatchPattern":null,"preventionTips":["Never pass hostnames, CIDRs, or address:port strings as srcIP","Validate at the system boundary where the address enters, not at the lookup call site"],"tags":["linux","process-lookup","input-validation","ip-parsing"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}