Skip to content

fix off-by-one buffer overflow in copy_hex_string - #1674

Merged
michaelrsweet merged 1 commit into
OpenPrinting:masterfrom
aizu-m:ipptool-hex-string-off-by-one
Aug 20, 2026
Merged

fix off-by-one buffer overflow in copy_hex_string#1674
michaelrsweet merged 1 commit into
OpenPrinting:masterfrom
aizu-m:ipptool-hex-string-off-by-one

Conversation

@aizu-m

@aizu-m aizu-m commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Was checking the octetString paths in with_value against an IPP server I control. ASan tripped when the server returned a value whose length was exactly sizeof(temp):

tools/ipptool.c:1134: heap-buffer-overflow WRITE of size 1
    #0 copy_hex_string  tools/ipptool.c:1134
    #1 with_value       tools/ipptool.c:7686

copy_hex_string clamps the copy length with > where it wants >=. When an all-printable octetString is exactly bufsize bytes the clamp is skipped, so memcpy fills the whole buffer and buffer[datalen] writes the terminating NUL one byte past the end. Both call sites pass a 1024-byte temp[], so a response attribute of 1024 printable bytes is enough. The over-length case (> bufsize) already truncates to bufsize - 1; the exact-fit case just fell through the gap.

Signed-off-by: Aizal Khan <aizumusheer2@gmail.com>
@michaelrsweet michaelrsweet self-assigned this Aug 20, 2026
@michaelrsweet michaelrsweet added the enhancement New feature or request label Aug 20, 2026
@michaelrsweet michaelrsweet added this to the v2.5 milestone Aug 20, 2026
@michaelrsweet

Copy link
Copy Markdown
Member

Since octetString values are limited to 1023 bytes and the output buffer in ipptool is 1024 bytes, this isn't an issue in practice but the fix does address the correctness of the code going forward...

@michaelrsweet
michaelrsweet merged commit 9650f00 into OpenPrinting:master Aug 20, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants