Skip to content

fix heap overflow in cupsJSONExportString for non-root nodes - #187

Merged
michaelrsweet merged 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:json-export-subtree
Oct 22, 2026
Merged

michaelrsweet merged 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:json-export-subtree

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

cupsJSONExportString sizes its output in one pass over the tree and writes it in a second pass, but neither pass stops at the node it was given. When that node has a parent, both walks emit a leading ':' or ',', follow its siblings and climb into the ancestors, and only the write pass adds a closing ']' or '}' for each ancestor it climbs through, so the malloc'd string is overrun by one byte per enclosing level. cups-oauth hits this with server-supplied data: get-metadata URI NAME and get-user-id URI NAME export the value of NAME directly when it is an object or array, and the metadata and ID token claims both come from the remote server, so its nesting depth decides how far the write goes. Exporting "a" from {"a":{"b":{"c":{"d":{"e":[1]}}}},"z":2} gives an ASan heap-buffer-overflow WRITE at json.c:476, and even without the overflow the result carries a stray ':' and the following "z" member. Both passes now treat the exported node as the root of the walk, so nothing outside it is visited; output for a root node is unchanged. The new testjson case exports a child object and checks the string; it fails under ASan on master and passes with the fix, and make test is green.

@michaelrsweet michaelrsweet self-assigned this Oct 22, 2026
@michaelrsweet michaelrsweet added the investigating Investigating the issue label Oct 22, 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.

Looks good. In the future, just put the changelog in the description and I'll manually add it. Thanks!

@michaelrsweet michaelrsweet added bug Something isn't working and removed investigating Investigating the issue labels Oct 22, 2026
@michaelrsweet michaelrsweet added this to the Stable milestone Oct 22, 2026
@michaelrsweet
michaelrsweet merged commit bb0ebb5 into OpenPrinting:master Oct 22, 2026
6 checks passed
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