Repository navigation
driverless: stop converting non-digit bytes to port numbers - #813
Merged
tillkamppeter merged 1 commit intoNov 21, 2026
Conversation
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.
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.
Summary
convert_to_port()inutils/driverless.cbuilds a port number by walking every byte of its input with no check that the byte is actually a digit: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 viahttpAssembleURIf().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
"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.