Repository navigation
common/wireaddr: validate port range in separate_address_and_port - #9637
Open
bhuvan-somisetty wants to merge 1 commit into
Open
bhuvan-somisetty wants to merge 1 commit into
bhuvan-somisetty wants to merge 1 commit into
Conversation
`separate_address_and_port()` used `strtol()` and assigned the result directly to `*port` (type `u16`), which truncated numbers modulo 65536. As a result, out-of-range ports like `127.0.0.1:65537` and `127.0.0.1:75271` were accepted and truncated to ports 1 and 9735, negative ports like `-1` were accepted as 65535, and signed or space-padded ports were accepted. Use `str_to_u64()` to parse strict unsigned decimal digits and reject ports equal to 0 or greater than 65535. Changelog-Fixed: common/wireaddr: reject out-of-range (>65535) and negative ports in separate_address_and_port Fixes: ElementsProject#9636 Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In
common/wireaddr.c,separate_address_and_port()parsed the port suffix withstrtol()and assigned the result directly to*port(typeu16), causing integer truncation modulo 65536. Consequently:127.0.0.1:65537or127.0.0.1:75271) were accepted and silently converted to lower ports (1 and 9735).127.0.0.1:-1were converted to 65535 and accepted.+9735) and space-padded ports were accepted bystrtol.This PR fixes
separate_address_and_port()by parsing port strings withstr_to_u64()to enforce strict unsigned decimal digits and rejecting ports that are 0 or greater than 65535. Unit tests covering valid boundaries and invalid ports have been added tocommon/test/run-ip_port_parsing.c.Fixes #9636.
Checklist
Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:
tools/lightning-downgradeSigned-off-by: bhuvan-somisetty somisettybhuvan5@gmail.com