XTLS/Xray-core · error

failed to format address:

Error message

failed to format address: 

What it means

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.

Source

Thrown at common/net/find_process_linux.go:50

	case "tcp":
		if net.ParseIP(srcIP).To4() != nil {
			procFile = "/proc/net/tcp"
		} else {
			procFile = "/proc/net/tcp6"
		}
	case "udp":
		if net.ParseIP(srcIP).To4() != nil {
			procFile = "/proc/net/udp"
		} else {
			procFile = "/proc/net/udp6"
		}
	default:
		panic("Unsupported network type for process lookup.")
	}

	targetHexAddr, err := formatLittleEndianString(net.ParseIP(srcIP), Port(srcPort))
	if err != nil {
		return 0, "", "", errors.New("failed to format address: ", err)
	}

	inode, err := findInodeInFile(procFile, targetHexAddr)
	if err != nil {
		return 0, "", "", errors.New("could not search in ", procFile).Base(err)
	}
	if inode == "" {
		return 0, "", "", errors.New("connection for ", srcIP, ":", srcPort, " not found in ", procFile)
	}

	pidStr, err := findPidByInode(inode)
	if err != nil {
		return 0, "", "", errors.New("could not find PID for inode ", inode, ": ", err)
	}
	if pidStr == "" {
		return 0, "", "", errors.New("no process found for inode ", inode)
	}

View on GitHub (pinned to 7d214f8b09)

Solutions

  1. Validate srcIP with net.ParseIP before calling FindProcess and reject nil results
  2. Strip ports and %zone suffixes from the address before passing it
  3. Log the exact srcIP value when the error fires to find which call site sends bad input

Example fix

// before
pid, name, path, err := net.FindProcess(network, srcIP, srcPort, dstIP, dstPort)

// after
if net.ParseIP(srcIP) == nil {
    return errors.New("FindProcess: srcIP is not a valid IP: ", srcIP)
}
pid, name, path, err := net.FindProcess(network, srcIP, srcPort, dstIP, dstPort)
Defensive patterns

Strategy: validation

Validate before calling

if net.ParseIP(srcIP) == nil {
    return errors.New("FindProcess: srcIP is not a valid IP: ", srcIP)
}

Type guard

func isValidIpString(s string) bool { return net.ParseIP(s) != nil }

Prevention

When it happens

Trigger: 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.

Common situations: Call sites forwarding raw proxy-chain metadata where srcIP was never populated; strings containing port or zone identifiers passed as bare IPs.

Related errors


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/e817851775c9cff1. Report an issue: GitHub.