Skip to content

printer cbor BUGFIX crash when printing (leaf-)lists nested in a list - #2557

Merged
michalvasko merged 1 commit into
CESNET:develfrom
nokia:fix/cbor-printer-nested-list-crash
Aug 18, 2026
Merged

printer cbor BUGFIX crash when printing (leaf-)lists nested in a list#2557
michalvasko merged 1 commit into
CESNET:develfrom
nokia:fix/cbor-printer-nested-list-crash

Conversation

@manoe

@manoe manoe commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

The CBOR printer kept a single "currently open array" pointer (cborpr_ctx.array) shared across all nesting levels, while tracking the open nodes on a proper stack (cborpr_ctx.open). When a leaf-list or list was nested inside a list, printing the inner array overwrote that pointer and then reset it to NULL, so the enclosing list subsequently pushed into a NULL array, causing a segfault in cbor_array_push().

Replace the single array pointer with a stack (cborpr_ctx.arrays) kept parallel to the open-node stack, add cbor_current_array() to fetch the innermost open array, and update cbor_print_leaf_list()/cbor_print_opaq() and their callers accordingly. The stack is freed on all exit paths of cbor_print_data().

Add a regression test (test_nested_list) covering a leaf-list nested in a list, a list nested in a list, and mixed multi-instance nesting, plus the supporting list-nested node in the cbor-test module.

The CBOR printer kept a single "currently open array" pointer
(cborpr_ctx.array) shared across all nesting levels, while tracking the
open nodes on a proper stack (cborpr_ctx.open). When a leaf-list or list
was nested inside a list, printing the inner array overwrote that pointer
and then reset it to NULL, so the enclosing list subsequently pushed into
a NULL array, causing a segfault in cbor_array_push().

Replace the single array pointer with a stack (cborpr_ctx.arrays) kept
parallel to the open-node stack, add cbor_current_array() to fetch the
innermost open array, and update cbor_print_leaf_list()/cbor_print_opaq()
and their callers accordingly. The stack is freed on all exit paths of
cbor_print_data().

Add a regression test (test_nested_list) covering a leaf-list nested in a
list, a list nested in a list, and mixed multi-instance nesting, plus the
supporting list-nested node in the cbor-test module.

Co-authored-by: Cursor <cursoragent@cursor.com>
@michalvasko

Copy link
Copy Markdown
Member

Thanks, looks fine.

@michalvasko
michalvasko merged commit 317b951 into CESNET:devel Aug 18, 2026
13 checks passed
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