Skip to content

fix port number truncation in httpSeparateURI - #179

Merged
michaelrsweet merged 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:uri-port-truncation
Oct 15, 2026
Merged

michaelrsweet merged 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:uri-port-truncation

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

httpSeparateURI collects the port portion of a URI with *port = (int)strtol(uri + 1, ...), so the range check that follows runs on the already-truncated int. On 64-bit platforms a numeric port of 2^32+N truncates to N, and a URI such as ipp://host:4294967953/ipp/print comes back as HTTP_URI_STATUS_OK with port 657 instead of HTTP_URI_STATUS_BAD_PORT, while http://127.0.0.1:99999/ is rejected as expected. URIs that land here are often remote input, for example printer-uri-supported values from an IPP printer or endpoint URLs from OAuth server metadata, so this parser and a strict RFC 3986 parser disagree about the same string. Keeping the strtol result in a long and checking the range before narrowing restores the rejection for out-of-range values of any size. Added a testhttp case under the bad-port entries that returns OK with port 81 before the change and BAD_PORT after; make test still passes with a 100% score.

@michaelrsweet michaelrsweet self-assigned this Oct 15, 2026
@michaelrsweet michaelrsweet added the investigating Investigating the issue label Oct 15, 2026

@michaelrsweet michaelrsweet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@michaelrsweet michaelrsweet added enhancement New feature or request and removed investigating Investigating the issue labels Oct 15, 2026
@michaelrsweet michaelrsweet added this to the Stable milestone Oct 15, 2026
@michaelrsweet
michaelrsweet merged commit 8d2e01e into OpenPrinting:master Oct 15, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants