Skip to content

fix: prevent port replacement from corrupting IP addresses#3035

Merged
lidel merged 1 commit intomainfrom
fix/port-replacement-ip-corruption
Feb 20, 2026
Merged

fix: prevent port replacement from corrupting IP addresses#3035
lidel merged 1 commit intomainfrom
fix/port-replacement-ip-corruption

Conversation

@lidel
Copy link
Member

@lidel lidel commented Dec 18, 2025

the naive string replacement in checkPorts() could corrupt multiaddr IP addresses when the port number appeared in the IP portion.

for example, replacing port 0 in /ip4/127.0.0.1/tcp/0 would match the first 0 in 127.0.0.1, producing /ip4/127.5001.0.1/tcp/0.

this caused "invalid ip address" errors on startup when ports were busy.

fix by using /tcp/${port} pattern to match only the port component.

ref: https://discuss.ipfs.tech/t/invalid-ip-address/19925

the naive string replacement in checkPorts() could corrupt multiaddr
IP addresses when the port number appeared in the IP portion.

for example, replacing port `0` in `/ip4/127.0.0.1/tcp/0` would match
the first `0` in `127.0.0.1`, producing `/ip4/127.5001.0.1/tcp/0`.

this caused "invalid ip address" errors on startup when ports were busy.

fix by using `/tcp/${port}` pattern to match only the port component.

ref: https://discuss.ipfs.tech/t/invalid-ip-address/19925
@lidel lidel marked this pull request as ready for review December 18, 2025 06:46
@lidel lidel requested a review from a team as a code owner December 18, 2025 06:46
@lidel
Copy link
Member Author

lidel commented Dec 18, 2025

@lidel lidel self-assigned this Dec 18, 2025
@lidel lidel merged commit efbb2d3 into main Feb 20, 2026
7 checks passed
@lidel lidel deleted the fix/port-replacement-ip-corruption branch February 20, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant