Skip to content

Commit

Permalink
Fix heap buffer overflow
Browse files Browse the repository at this point in the history
Fixes #800
  • Loading branch information
sbvoxel committed May 6, 2024
1 parent 9108285 commit 80183a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 1660,11 @@ static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_bu
current_item = new_item;
}

if (input_buffer->offset 1 >= input_buffer->length)
{
goto fail; /* nothing comes after the comma */
}

/* parse the name of the child */
input_buffer->offset ;
buffer_skip_whitespace(input_buffer);
Expand Down
2 changes: 1 addition & 1 deletion tests/parse_examples.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 266,7 @@ static void test15_should_not_heap_buffer_overflow(void)
size_t len = strlen(json_string);
cJSON *json = NULL;

char *exact_size_heap = malloc(len);
char *exact_size_heap = (char*)malloc(len);
TEST_ASSERT_NOT_NULL(exact_size_heap);

memcpy(exact_size_heap, json_string, len);
Expand Down

0 comments on commit 80183a0

Please sign in to comment.