Skip to content

Fix #941: empty strings break msgpack_object_print_buffer() (C) - #942

Merged
redboltz merged 2 commits into
msgpack:c_masterfrom
vmallet:fix_print_buffer_empty_str
Apr 3, 2021
Merged

redboltz merged 2 commits into
msgpack:c_masterfrom
vmallet:fix_print_buffer_empty_str

Conversation

@vmallet

@vmallet vmallet commented Mar 23, 2021

Copy link
Copy Markdown

Don't abort serialization when running into empty strings in msgpack_object_print_buffer().
Added a couple of unit tests to test empty string cases.

vmallet added 2 commits March 23, 2021 13:56
Don't abort serialization when running into empty strings in msgpack_object_print_buffer().
Added a couple of unit tests to test empty string cases.
Use sprintf_s (windows) or snprintf (others) instead of sprintf in unit tests.
@redboltz

redboltz commented Apr 3, 2021

Copy link
Copy Markdown
Contributor

Thank you for sending the PR.
LGTM.

@redboltz
redboltz merged commit 734e47c into msgpack:c_master Apr 3, 2021
@redboltz redboltz added the C label Sep 1, 2021
trestoncuzzort added a commit to trestoncuzzort/dawnr that referenced this pull request Nov 6, 2026
msgpack_object_print_buffer (msgpack-c src/objectc.c at 319ae6ed, branch
c_master) prints a BIN or an EXT object through
msgpack_object_bin_print_buffer, and the MSGPACK_CHECKED_CALL macro takes
a result of 0 as a failure. An object without bytes gives 0 there, so
the function returns 0 after the opening quote. The STR branch has had a
guard for the empty string since 2021; the case checks the same guard on
the BIN and EXT branches.

The harness prints a BIN object or an EXT object of every type, with
zero to two bytes of every value, into every buffer size from 0 to 24,
and compares the result, the text, the bytes after the given size and
the terminator with the text that msgpack_object_print() writes. The
model reads snprintf and isprint as stand-ins in the prelude; the replay
of a counterexample calls the C library.

Suite run of 2026-11-06 with CBMC 6.11.0, in suite-2026-11-06.json: the
original fails with one replayed witness (a BIN object without bytes
into 19 bytes), the proposed change completes on 445 properties, and
contradictory assumptions and an unwinding bound of 1 are vacuous.

cross_check.py is outside the gate. With GCC 13.3 and glibc 2.39 the
stand-ins agree with the C library in 19506 comparisons, and of the
422720025 inputs of the domain the original fails 3184, all of them
objects without bytes, and the proposed change none.

Sources: https://github.com/msgpack/msgpack-c/blob/319ae6edf016327738b707cdb0d222b6091ae9f2/src/objectc.c;
https://github.com/msgpack/msgpack-c/blob/319ae6edf016327738b707cdb0d222b6091ae9f2/include/msgpack/object.h;
msgpack/msgpack-c#942;
C11 7.21.6.5 (snprintf) and 7.4.1.8 (isprint), https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants