mirror of
https://github.com/json-c/json-c.git
synced 2026-03-30 10:29:06 +08:00
Merge pull request #660 from stoeckmann/arraylist
Validate size arguments in arraylist functions.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user