Skip to content

mask request bytes before ctype calls in client.c#1623

Merged
michaelrsweet merged 1 commit into
OpenPrinting:masterfrom
aizu-m:client-ctype-mask
Jun 21, 2026
Merged

mask request bytes before ctype calls in client.c#1623
michaelrsweet merged 1 commit into
OpenPrinting:masterfrom
aizu-m:client-ctype-mask

Conversation

@aizu-m

@aizu-m aizu-m commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

ASan, modelling a ctype lookup that indexes its 256-entry table by the raw argument:

ctype_demo.c:12: ERROR: AddressSanitizer: BUS, READ memory access
    #0 main ctype_demo.c:12   // table[c] with c == -128

Spotted while reading the request path. The host parsed from the request URI and the If-Modified-Since header value both reach ctype calls on a bare char. char is signed here, so a request byte of 0x80 or above arrives as a negative int, which isdigit/isspace/isalpha must not be given. The rest of this file already masks with & 255 (see lines 2476 and 3755); these four sites were missed. The two tolower calls a bit further down are already safe, since they run only after an isxdigit check on the same byte.

@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.

Note that platforms where "char" is unsigned don't have this issue, which IIRC includes Linux and macOS. However, I am aware of the issue and thought we had already covered all of the calls that mattered, so thanks for the catch!

@michaelrsweet michaelrsweet self-assigned this Jun 21, 2026
@michaelrsweet michaelrsweet added bug Something isn't working platform issue Issue is specific to an OS or desktop labels Jun 21, 2026
@michaelrsweet michaelrsweet added this to the v2.4.x milestone Jun 21, 2026
@michaelrsweet michaelrsweet merged commit 0b3709e into OpenPrinting:master Jun 21, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working platform issue Issue is specific to an OS or desktop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants