Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/value.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ value_init_string_(VALUE* v, const char* str, size_t len)
}
payload[off++] = tmplen & 0x7f;

memcpy(payload + off, str, len);
if(len > 0)
memcpy(payload + off, str, len);
payload[off + len] = '\0';
return 0;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/test-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,26 @@ test_issue3(void)
value_fini(&root);
}

static void
test_issue13(void)
{
static const char input[] = "{\"\":1}";

VALUE root;
VALUE* v;

/* An empty object key must parse without passing a NULL pointer to
* memcpy() while storing the zero-length key string. */
TEST_CHECK(json_dom_parse(input, strlen(input), NULL, 0, &root, NULL) == 0);
TEST_CHECK(value_dict_size(&root) == 1);

v = value_dict_get_(&root, "", 0);
if(TEST_CHECK(v != NULL))
TEST_CHECK(value_int32(v) == 1);

value_fini(&root);
}


TEST_LIST = {
{ "pos-tracking", test_pos_tracking },
Expand Down Expand Up @@ -1548,5 +1568,6 @@ TEST_LIST = {
{ "crazy-double", test_crazy_double },
{ "bug-issue2", test_issue2 },
{ "bug-issue3", test_issue3 },
{ "bug-issue13", test_issue13 },
{ 0 }
};