Merge pull request #660 from stoeckmann/arraylist

Validate size arguments in arraylist functions.
This commit is contained in:
Eric Hawicz
2020-08-24 09:51:18 -04:00
committed by GitHub
2 changed files with 26 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
#include <assert.h>
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -307,6 +308,27 @@ int main(int argc, char **argv)
}
printf("my_object.to_string()=%s\n", json_object_to_json_string(my_object));
json_object_put(my_array);
my_array = json_object_new_array_ext(INT_MIN + 1);
if (my_array != NULL)
{
printf("ERROR: able to allocate an array of negative size!\n");
fflush(stdout);
json_object_put(my_array);
my_array = NULL;
}
#if SIZEOF_SIZE_T == SIZEOF_INT
my_array = json_object_new_array_ext(INT_MAX / 2 + 2);
if (my_array != NULL)
{
printf("ERROR: able to allocate an array of insufficient size!\n");
fflush(stdout);
json_object_put(my_array);
my_array = NULL;
}
#endif
json_object_put(my_string);
json_object_put(my_int);
json_object_put(my_null);