Skip to content

mask signed char in ctype calls in http_create and _cupsEncodeOption - #177

Closed
tanjiroK-coder wants to merge 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:ctype-signed-char-mask
Closed

tanjiroK-coder wants to merge 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:ctype-signed-char-mask

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

http_create decides whether a hostname is a bare IPv6 literal by testing its first four bytes with isxdigit, and _cupsEncodeOption decides whether an integer/enum option value is numeric by testing its first byte with isdigit, both handing a plain char straight to the ctype function. The hostname is the connection target and the option value is whatever the caller is encoding, so either leading byte can be >= 0x80; where char is signed that is a negative int, and passing anything other than EOF or an unsigned char value to a ctype function is undefined behaviour, and an out-of-bounds classification-table read on libc builds whose table isn't padded for negative indices. I hit it reading the two sites next to code that already masks the same way, e.g. isspace(*end & 255) earlier in http.c and isxdigit(src[1] & 255) in http-support.c. The fix adds the & 255 mask the rest of the library already uses, so the result is unchanged on common libc and defined everywhere.

Assisted-by: Claude Code:claude-opus-4-8

both passed a plain `char` to `isxdigit`/`isdigit`; mask with `& 255` like the rest of the code so a byte >= 0x80 isn't sign-extended to a negative int.
@michaelrsweet michaelrsweet self-assigned this Oct 13, 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.

I think I want to update the _cups_isXXX functions to include _cups_isxdigit and _cups_isdigit so we can eliminate the masking completely.

@michaelrsweet michaelrsweet added bug Something isn't working priority-low labels Oct 13, 2026
@michaelrsweet michaelrsweet added this to the Stable milestone Oct 13, 2026
michaelrsweet added a commit that referenced this pull request Oct 13, 2026
@michaelrsweet

Copy link
Copy Markdown
Member

[master 318b6b8] Replace all usage of ctype macros with internal versions to avoid signed char issues (Issue #177)

@tanjiroK-coder

Copy link
Copy Markdown
Contributor Author

thanks — the internal _cups_is* functions are a cleaner fix than masking at each call site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority-low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants