Skip to content

consume %c argument in cupsFormatStringv when buffer is full - #201

Closed
tanjiroK-coder wants to merge 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:formatstring-c-arg-sync
Closed

tanjiroK-coder wants to merge 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:formatstring-c-arg-sync

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

Dropped %c argument in cupsFormatStringv

When the output buffer is already full, the %c case returns without calling va_arg, so every later conversion reads one argument too early; a %c followed by %s or %p then treats a non-pointer value as a pointer and dereferences it. cupsFormatString/cupsFormatStringv are public, so any caller that puts %c before another conversion with runtime data long enough to fill the buffer is affected.

Reproduced under AddressSanitizer with cupsFormatString(buf, 2, "X%c%s", 'A', "hello"), which faults with a read at address 0x41 in string.c. The new cups/teststring.c checks that the returned length does not depend on the output buffer size; it fails before this change and passes after.

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

This change is far too intrusive. Will push a simpler change and without another unit test for this edge case.

michaelrsweet added a commit that referenced this pull request Oct 29, 2026
@tanjiroK-coder

Copy link
Copy Markdown
Contributor Author

thanks, 416b035 keeps it a lot smaller than mine did. closing this one.

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.

2 participants