Skip to content

Commit 8d2e01e

Browse files
Merge pull request #179 from tanjiroK-coder/uri-port-truncation
fix port number truncation in httpSeparateURI
2 parents 62650e3 + c41a80a commit 8d2e01e

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎CHANGES.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ v3.0.4 - YYYY-MM-DD
3434
- Fixed some character testing that wasn't safe on platforms with a signed
3535
`char` type (Issue #177)
3636
- Fixed support for mDNSResponder on Windows (Issue #178)
37+
- Fixed `httpSeparateURI` to reject URI port numbers whose value was truncated
38+
when converted to `int`.
3739

3840

3941
v3.0.3 - 2026-08-20

‎cups/http-support.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,21 +938,25 @@ httpSeparateURI(
938938
// See if we have a port number...
939939
if (*uri == ':')
940940
{
941+
long portnum; // Port number
942+
941943
// Yes, collect the port number...
942944
if (!_cups_isdigit(uri[1]))
943945
{
944946
*port = 0;
945947
return (HTTP_URI_STATUS_BAD_PORT);
946948
}
947949

948-
*port = (int)strtol(uri + 1, (char **)&uri, 10);
950+
portnum = strtol(uri + 1, (char **)&uri, 10);
949951

950-
if (*port <= 0 || *port > 65535)
952+
if (portnum <= 0 || portnum > 65535)
951953
{
952954
*port = 0;
953955
return (HTTP_URI_STATUS_BAD_PORT);
954956
}
955957

958+
*port = (int)portnum;
959+
956960
if (*uri != '/' && *uri)
957961
{
958962
*port = 0;

‎cups/testhttp.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ static uri_test_t uri_tests[] = // URI test data
191191
{ HTTP_URI_STATUS_BAD_PORT, "http://127.0.0.1:9999a/index.html",
192192
"http", "", "127.0.0.1", "", 0, 0,
193193
HTTP_URI_CODING_MOST },
194+
{ HTTP_URI_STATUS_BAD_PORT, "http://127.0.0.1:4294967377/index.html",
195+
"http", "", "127.0.0.1", "", 0, 0,
196+
HTTP_URI_CODING_MOST },
194197

195198
// Bad resource
196199
{ HTTP_URI_STATUS_BAD_RESOURCE, "mailto:\r\nbla",

0 commit comments

Comments
 (0)