Skip to content

driverless: stop converting non-digit bytes to port numbers - #813

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix-driverless-convert-to-port-non-digit-pr
Nov 21, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix-driverless-convert-to-port-non-digit-pr

Conversation

@ManasBagul23

Copy link
Copy Markdown
Contributor

Summary

convert_to_port() in utils/driverless.c builds a port number by walking every byte of its input with no check that the byte is actually a digit:

for (int i = 0; i < strlen(a); i++)
  port = port*10 + (a[i] - '0');

Its only caller passes the "port" field parsed out of ippfind's tab-separated output for a discovered IPP/IPPS service on the LAN - network-sourced data, not something this process controls. A malformed or hostile mDNS/DNS-SD response whose port field contains anything other than ASCII digits (truncated, garbled, or deliberately malicious) turns into effectively arbitrary signed-integer arithmetic instead of a real port number, which then gets used to build the printer's connection URI via httpAssembleURIf().

Fix

Added an isdigit() check and stop at the first non-digit byte (or the end of the string), matching the common "parse as many digits as are actually there" convention. A well-formed numeric port string behaves identically; a malformed one now stops cleanly instead of folding garbage bytes into the result.

Test plan

  • Verified with a standalone comparison: a valid "631" produces the same result both ways; a string with a non-digit byte spliced into otherwise-numeric content produces a large nonsensical number under the old logic and the correct leading digits under the new one.
  • CI

convert_to_port() builds a port number by walking every byte of its
input and computing port*10 + (a[i] - '0'), with no check that a[i]
is actually a digit:

    for (int i = 0; i < strlen(a); i++)
      port = port*10 + (a[i] - '0');

Its only caller passes the "port" field parsed out of ippfind's
tab-separated output for a discovered IPP/IPPS service on the LAN --
network-sourced data, not something this process controls. A
malformed or hostile mDNS/DNS-SD response whose port field contains
anything other than ASCII digits (truncated, garbled, or deliberately
malicious) turns into effectively arbitrary signed-integer arithmetic
instead of a real port number, which then gets used to build the
printer's connection URI via httpAssembleURIf().

Added an isdigit() check and stop at the first non-digit byte (or the
end of the string), matching the common "parse as many digits as are
actually there" convention. A well-formed numeric port string
behaves identically; a malformed one now stops cleanly instead of
folding garbage bytes into the result.
Copilot AI balanced review requested due to automatic review settings November 21, 2026 18:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@tillkamppeter
tillkamppeter merged commit 2728f98 into OpenPrinting:master Nov 21, 2026
10 of 11 checks passed
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.

3 participants