Skip to content

fix off-by-one write copying snmp supply names#1604

Closed
aizu-m wants to merge 1 commit into
OpenPrinting:masterfrom
aizu-m:snmp-supply-name-bounds
Closed

fix off-by-one write copying snmp supply names#1604
aizu-m wants to merge 1 commit into
OpenPrinting:masterfrom
aizu-m:snmp-supply-name-bounds

Conversation

@aizu-m

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

Copy link
Copy Markdown
Contributor

Checking the SNMP backend supply parser. The unknown-charset branch in backend_walk_cb carries a comment that the copy is safe because both buffers are CUPS_SNMP_MAX_STRING long. They are not:

object_value.string.bytes[CUPS_SNMP_MAX_STRING + 1]   // source, 1025
supplies[i - 1].name[CUPS_SNMP_MAX_STRING]            // dest, 1024

asn1_get_string can fill the source with 1024 non-nul bytes. A printer that reports an unknown character set and a 1024-byte prtMarkerSuppliesDescription then makes the loop copy 1024 chars and write the terminating nul one past name. Reproduced the exact loop with a canary:

ORIGINAL: nul written at name[1024] (slots 0..1023) -> out of bounds, color[0] 0x23 -> 0x00
FIXED   : nul written at name[1023] -> in bounds, color[0] 0x23

The other charset branches pass sizeof(supplies[0].name) and stay inside the buffer. Bounding the loop the same way keeps the nul in range.

The unknown character set branch in backend_walk_cb copies prtMarkerSuppliesDescription into supplies[i-1].name until the source nul. object_value.string.bytes is CUPS_SNMP_MAX_STRING + 1 bytes while name is CUPS_SNMP_MAX_STRING, so a 1024-byte description writes the terminating nul one past name. Bound the copy like the other charset branches do.

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

We should just change the supply level name buffer to be size+1 as well.

@michaelrsweet michaelrsweet self-assigned this Jun 9, 2026
@michaelrsweet michaelrsweet added the bug Something isn't working label Jun 9, 2026
@michaelrsweet michaelrsweet added this to the v2.4.x milestone Jun 9, 2026
@michaelrsweet

Copy link
Copy Markdown
Member

[master 69dd78d] Increase supply name buffer by 1 byte (Issue #1604)

[2.4.x 483d780] Increase supply name buffer by 1 byte (Issue #1604)

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants