Repository navigation
common/wireaddr: validate port range in separate_address_and_port and torport - #9637
bhuvan-somisetty wants to merge 1 commit into
Conversation
Andezion
left a comment
There was a problem hiding this comment.
nice pr, but the same bug still exists in torport= parsing. In common/wireaddr.c at line 675 and common/wireaddr.c at line 703, strtol() is also assigned straight into u16 torservice.port. The port <= 0 check on an unsigned value only catches 0, so autotor:...:/torport=65537 becomes port 1 and torport=-1 becomes 65535
just leaving this for visibility
| u64 p; | ||
| if (!str_to_u64(portcolon + 1, strlen(portcolon + 1), &p)) | ||
| return false; | ||
| if (p == 0 || p > 65535) |
There was a problem hiding this comment.
use UINT16_MAX instead of 65535
There was a problem hiding this comment.
Updated to UINT16_MAX.
324ecb6 to
9dab200
Compare
|
Good catch, thanks! Updated to |
9dab200 to
d540d32
Compare
d540d32 to
51db169
Compare
|
This change makes |
… torport `separate_address_and_port()` and `torport=` parsing in `autotor:` and `statictor:` used `strtol()` and assigned the result directly to `u16` port fields. This caused integer truncation modulo 65536, silently accepting out-of-range ports (>65535), negative ports, and signed ports. Use `str_to_u64()` to parse strict unsigned decimal digits and reject ports equal to 0 or greater than `UINT16_MAX`. Changelog-Fixed: common/wireaddr: reject out-of-range (>65535) and negative ports in separate_address_and_port and torport Fixes: ElementsProject#9636 Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
Head branch was pushed to by a user without write access
51db169 to
5842d47
Compare
|
Good catch, thank you! Updated |
Description
In
common/wireaddr.c,separate_address_and_port()as well astorport=parsing inautotor:andstatictor:parsed port strings withstrtol()and assigned the result directly tou16port fields, causing integer truncation modulo 65536. Consequently:127.0.0.1:65537orautotor:127.0.0.1/torport=65537) were accepted and silently converted to lower ports (e.g. 1).127.0.0.1:-1ortorport=-1were converted to 65535 and accepted.+9735) and space-padded ports were accepted bystrtol.This PR fixes
separate_address_and_port()andtorport=parsing inautotor:/statictor:by:str_to_u64()to enforce strict unsigned decimal digits.UINT16_MAX.common/test/run-ip_port_parsing.candcommon/test/run-wireaddr.ccovering valid boundaries and invalid ports.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