Skip to content

Fix Buffer overflow in cupsSideChannelSNMPGet() - #1719 - #1720

Closed
PavlNekrasov wants to merge 1 commit into
OpenPrinting:masterfrom
PavlNekrasov:fix-tainted-int-overflow-sidechannel-snmp
Closed

PavlNekrasov wants to merge 1 commit into
OpenPrinting:masterfrom
PavlNekrasov:fix-tainted-int-overflow-sidechannel-snmp

Conversation

@PavlNekrasov

Copy link
Copy Markdown

fixed #1719

Solution: Located the OID terminator with memchr() within the received length in both functions and rejected a response without one as CUPS_SC_STATUS_BAD_MESSAGE.

Signed-off-by: p.nekrasov@fobos-nt.ru
Signed-off-by: Timofei Fedotov sovtouch@altlinux.org

@michaelrsweet michaelrsweet self-assigned this Sep 24, 2026
@michaelrsweet michaelrsweet added the investigating Investigating the issue label Sep 24, 2026
@michaelrsweet

Copy link
Copy Markdown
Member

In the future, please combine bug report and PR into a single PR with the full explanation of the bug. Doing both just gives both of us extra work.

@michaelrsweet

Copy link
Copy Markdown
Member

Also, please start signing your commits...

Problem:
cupsSideChannelSNMPGet() takes the OID length from strlen() without checking that the nul terminator is inside the bytes the backend actually sent, so strlen() runs into the uninitialised tail of the buffer, real_datalen goes negative and memcpy() gets (size_t)real_datalen as its size. cupsSideChannelSNMPWalk() has the same flaw, and its guard against it measures sizeof() a char pointer instead of the buffer, so it only fires below 8 bytes.
Solution: Located the OID terminator with memchr() within the received length in both functions and rejected a response without one as CUPS_SC_STATUS_BAD_MESSAGE.
Signed-off-by: p.nekrasov@fobos-nt.ru
Signed-off-by: Timofei Fedotov sovtouch@altlinux.org
@PavlNekrasov
PavlNekrasov force-pushed the fix-tainted-int-overflow-sidechannel-snmp branch from c784ad3 to a69f054 Compare September 25, 2026 12:44
@PavlNekrasov

Copy link
Copy Markdown
Author

The commit has now been signed and forced-pushed.

@michaelrsweet

Copy link
Copy Markdown
Member

OK, so I am still having trouble accepting this PR.

The maximum buffer length in cups/sidechannel.c is 64k+4 bytes: command byte, status byte, two length bytes (to allow data up to 65535 bytes), and 65536 bytes to allow for a 65535-byte string + nul.

The data buffer in backend/network.c is 65536 bytes - 65535 bytes + nul.

So the only issue here is that we aren't ensuring that the byte after the first nul in the response is part of the message/buffer. Using memchr doesn't actually help here, but what we want to know is that we actually have a value.

@michaelrsweet

Copy link
Copy Markdown
Member

[master ee5658d] Add checks for an OID that is 64k or larger in size (Issue #1719)

[2.4.x 7e0ab3d] Add checks for an OID that is 64k or larger in size (Issue #1719)

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

Labels

investigating Investigating the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Buffer overflow in cupsSideChannelSNMPGet()

2 participants