Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 826cd6f

Browse files
sbvoxelAlanscut
authored andcommitted
Add test for heap buffer overflow
From DaveGamble#800
1 parent 98f9eb0 commit 826cd6f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎tests/parse_examples.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,33 @@ static void test14_should_not_be_parsed(void)
250250
}
251251
}
252252

253+
/* Address Sanitizer */
254+
static void test15_should_not_heap_buffer_overflow(void)
255+
{
256+
const char *strings[] = {
257+
"{\"1\":1,",
258+
"{\"1\":1, ",
259+
};
260+
261+
size_t i;
262+
263+
for (i = 0; i < sizeof(strings) / sizeof(strings[0]); i+=1)
264+
{
265+
const char *json_string = strings[i];
266+
size_t len = strlen(json_string);
267+
cJSON *json = NULL;
268+
269+
char *exact_size_heap = (char*)malloc(len);
270+
TEST_ASSERT_NOT_NULL(exact_size_heap);
271+
272+
memcpy(exact_size_heap, json_string, len);
273+
json = cJSON_ParseWithLength(exact_size_heap, len);
274+
275+
cJSON_Delete(json);
276+
free(exact_size_heap);
277+
}
278+
}
279+
253280
int CJSON_CDECL main(void)
254281
{
255282
UNITY_BEGIN();
@@ -267,5 +294,6 @@ int CJSON_CDECL main(void)
267294
RUN_TEST(test12_should_not_be_parsed);
268295
RUN_TEST(test13_should_be_parsed_without_null_termination);
269296
RUN_TEST(test14_should_not_be_parsed);
297+
RUN_TEST(test15_should_not_heap_buffer_overflow);
270298
return UNITY_END();
271299
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /