Skip to content

Guard memcpy against NULL when storing an empty string value#14

Open
SAY-5 wants to merge 1 commit into
mity:masterfrom
SAY-5:fix-empty-key-null-memcpy
Open

Guard memcpy against NULL when storing an empty string value#14
SAY-5 wants to merge 1 commit into
mity:masterfrom
SAY-5:fix-empty-key-null-memcpy

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jul 2, 2026

Copy link
Copy Markdown

Parsing valid JSON with an empty object key (e.g. {"":1}) passes a NULL str with len == 0 into memcpy() in value_init_string_(), which is undefined behavior and gets flagged by UBSan under glibc (the memcpy prototype there is marked nonnull).

The tokenizer delivers the empty key as data == NULL, size == 0, so I guard the copy with if(len > 0) before memcpy. The trailing NUL is still written, so short-string and long-string layouts are unaffected. Added a regression test (bug-issue13) that parses {"":1} and checks the empty key maps to the expected value.

Fixes #13.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
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.

UBSan: null pointer passed to memcpy in value_init_string_() when parsing JSON object with empty string key (e.g. {"":1})

1 participant