Skip to content

CborPretty: fix crash in unusal combination of flags - #344

Merged
thiagomacieira merged 1 commit into
intel:mainfrom
thiagomacieira:CborPretty_fix_crash_in_unusal_combination_of_flags
Oct 23, 2026
Merged

thiagomacieira merged 1 commit into
intel:mainfrom
thiagomacieira:CborPretty_fix_crash_in_unusal_combination_of_flags

Conversation

@thiagomacieira

Copy link
Copy Markdown
Member

In resolve_indicator(), if we were resolving indicators for overlong numbers but not for indeterminate length, we could end up calling extract_number_checked() on an indeterminate length, which would then correctly return CborErrorIllegalNumber (because it's not a number). That would cause resolve_indicator() to incorrectly return NULL on something that isn't a real error.

As a result, at least one caller crashed because it dereferenced the result:

        /* recursive type */
        CborValue recursed;
        const char *indicator = get_indicator(it, flags);
        const char *space = *indicator ? " " : indicator;

This wasn't caught before by unit-testing because tst_parser did not test this combination of flags (it was testing the parser, not the pretty-printer). Therefore, I've added an extensive suite for testing the pretty-printer.

In `resolve_indicator()`, if we were resolving indicators for overlong
numbers but not for indeterminate length, we could end up calling
`extract_number_checked()` on an indeterminate length, which would then
correctly return CborErrorIllegalNumber (because it's not a
number). That would cause `resolve_indicator()` to incorrectly return
NULL on something that isn't a real error.

As a result, at least one caller crashed because it dereferenced the result:
```c
        /* recursive type */
        CborValue recursed;
        const char *indicator = get_indicator(it, flags);
        const char *space = *indicator ? " " : indicator;
```

This wasn't caught before by unit-testing because tst_parser did not
test this combination of flags (it was testing the parser, not the
pretty-printer). Therefore, I've added an extensive suite for testing
the pretty-printer.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
@thiagomacieira
thiagomacieira merged commit f20cb2a into intel:main Oct 23, 2026
9 checks passed
@thiagomacieira
thiagomacieira deleted the CborPretty_fix_crash_in_unusal_combination_of_flags branch October 23, 2026 14:52
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.

1 participant