@@ -352,6 +352,19 @@ static void cjson_functions_should_not_crash_with_null_pointers(void)
352
352
{
353
353
char buffer [10 ];
354
354
cJSON * item = cJSON_CreateString ("item" );
355
+ cJSON * array = cJSON_CreateArray ();
356
+ cJSON * item1 = cJSON_CreateString ("item1" );
357
+ cJSON * item2 = cJSON_CreateString ("corrupted array item3" );
358
+ cJSON * corruptedString = cJSON_CreateString ("corrupted" );
359
+ struct cJSON * originalPrev ;
360
+
361
+ add_item_to_array (array , item1 );
362
+ add_item_to_array (array , item2 );
363
+
364
+ originalPrev = item2 -> prev ;
365
+ item2 -> prev = NULL ;
366
+ free (corruptedString -> valuestring );
367
+ corruptedString -> valuestring = NULL ;
355
368
356
369
cJSON_InitHooks (NULL );
357
370
TEST_ASSERT_NULL (cJSON_Parse (NULL ));
@@ -411,6 +424,8 @@ static void cjson_functions_should_not_crash_with_null_pointers(void)
411
424
cJSON_DeleteItemFromObject (item , NULL );
412
425
cJSON_DeleteItemFromObjectCaseSensitive (NULL , "item" );
413
426
cJSON_DeleteItemFromObjectCaseSensitive (item , NULL );
427
+ TEST_ASSERT_FALSE (cJSON_InsertItemInArray (array , 0 , NULL ));
428
+ TEST_ASSERT_FALSE (cJSON_InsertItemInArray (array , 1 , item ));
414
429
TEST_ASSERT_FALSE (cJSON_InsertItemInArray (NULL , 0 , item ));
415
430
TEST_ASSERT_FALSE (cJSON_InsertItemInArray (item , 0 , NULL ));
416
431
TEST_ASSERT_FALSE (cJSON_ReplaceItemViaPointer (NULL , item , item ));
@@ -427,10 +442,16 @@ static void cjson_functions_should_not_crash_with_null_pointers(void)
427
442
TEST_ASSERT_NULL (cJSON_Duplicate (NULL , true));
428
443
TEST_ASSERT_FALSE (cJSON_Compare (item , NULL , false));
429
444
TEST_ASSERT_FALSE (cJSON_Compare (NULL , item , false));
445
+ TEST_ASSERT_NULL (cJSON_SetValuestring (NULL , "test" ));
446
+ TEST_ASSERT_NULL (cJSON_SetValuestring (corruptedString , "test" ));
430
447
cJSON_Minify (NULL );
431
448
/* skipped because it is only used via a macro that checks for NULL */
432
449
/* cJSON_SetNumberHelper(NULL, 0); */
433
450
451
+ /* restore corrupted item2 to delete it */
452
+ item2 -> prev = originalPrev ;
453
+ cJSON_Delete (corruptedString );
454
+ cJSON_Delete (array );
434
455
cJSON_Delete (item );
435
456
}
436
457
0 commit comments