Skip to content

Commit 94627af

Browse files
committed
update cjson embedded dependency to 1.7.18
1 parent fca59d4 commit 94627af

File tree

2 files changed

+97
-20
lines changed
  • src/aws-cpp-sdk-core

2 files changed

+97
-20
lines changed

src/aws-cpp-sdk-core/include/aws/core/external/cjson/cJSON.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ then using the CJSON_AS4CPP_API_VISIBILITY flag to "export" the same symbols the
9292
/* project version */
9393
#define CJSON_AS4CPP_VERSION_MAJOR 1
9494
#define CJSON_AS4CPP_VERSION_MINOR 7
95-
#define CJSON_AS4CPP_VERSION_PATCH 14
95+
#define CJSON_AS4CPP_VERSION_PATCH 18
9696

9797
#include <stddef.h>
9898

@@ -148,6 +148,12 @@ typedef int cJSON_AS4CPP_bool;
148148
#define CJSON_AS4CPP_NESTING_LIMIT 1000
149149
#endif
150150

151+
/* Limits the length of circular references can be before cJSON rejects to parse them.
152+
* This is to prevent stack overflows. */
153+
#ifndef CJSON_AS4CPP_CIRCULAR_LIMIT
154+
#define CJSON_AS4CPP_CIRCULAR_LIMIT 10000
155+
#endif
156+
151157
/* returns the version of cJSON as a string */
152158
CJSON_AS4CPP_PUBLIC(const char*) cJSON_AS4CPP_Version(void);
153159

@@ -293,6 +299,13 @@ CJSON_AS4CPP_PUBLIC(double) cJSON_AS4CPP_SetNumberHelper(cJSON *object, double n
293299
/* Change the valuestring of a cJSON_AS4CPP_String object, only takes effect when type of object is cJSON_AS4CPP_String */
294300
CJSON_AS4CPP_PUBLIC(char*) cJSON_AS4CPP_SetValuestring(cJSON *object, const char *valuestring);
295301

302+
/* If the object is not a boolean type this does nothing and returns cJSON_AS4CPP_Invalid else it returns the new type*/
303+
#define cJSON_AS4CPP_SetBoolValue(object, boolValue) ( \
304+
(object != NULL && ((object)->type & (cJSON_AS4CPP_False|cJSON_AS4CPP_True))) ? \
305+
(object)->type=((object)->type &(~(cJSON_AS4CPP_False|cJSON_AS4CPP_True)))|((boolValue)?cJSON_AS4CPP_True:cJSON_AS4CPP_False) : \
306+
cJSON_AS4CPP_Invalid\
307+
)
308+
296309
/* Macro for iterating over an array or object */
297310
#define cJSON_AS4CPP_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
298311

src/aws-cpp-sdk-core/source/external/cjson/cJSON.cpp

Lines changed: 83 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@
7878
#endif
7979

8080
#ifndef NAN
81+
#ifdef _WIN32
82+
#define NAN sqrt(-1.0)
83+
#else
8184
#define NAN 0.0/0.0
8285
#endif
86+
#endif
8387

8488
typedef struct {
8589
const unsigned char *json;
@@ -120,7 +124,7 @@ CJSON_AS4CPP_PUBLIC(double) cJSON_AS4CPP_GetNumberValue(const cJSON * const item
120124
}
121125

122126
/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
123-
#if (CJSON_AS4CPP_VERSION_MAJOR != 1) || (CJSON_AS4CPP_VERSION_MINOR != 7) || (CJSON_AS4CPP_VERSION_PATCH != 14)
127+
#if (CJSON_AS4CPP_VERSION_MAJOR != 1) || (CJSON_AS4CPP_VERSION_MINOR != 7) || (CJSON_AS4CPP_VERSION_PATCH != 18)
124128
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
125129
#endif
126130

@@ -266,10 +270,12 @@ CJSON_AS4CPP_PUBLIC(void) cJSON_AS4CPP_Delete(cJSON *item)
266270
if (!(item->type & cJSON_AS4CPP_IsReference) && (item->valuestring != NULL))
267271
{
268272
global_hooks.deallocate(item->valuestring);
273+
item->valuestring = NULL;
269274
}
270275
if (!(item->type & cJSON_AS4CPP_StringIsConst) && (item->string != NULL))
271276
{
272277
global_hooks.deallocate(item->string);
278+
item->string = NULL;
273279
}
274280
global_hooks.deallocate(item);
275281
item = next;
@@ -411,17 +417,34 @@ CJSON_AS4CPP_PUBLIC(double) cJSON_AS4CPP_SetNumberHelper(cJSON *object, double n
411417
return object->valuedouble = number;
412418
}
413419

420+
/* Note: when passing a NULL valuestring, cJSON_AS4CPP_SetValuestring treats this as an error and return NULL */
414421
CJSON_AS4CPP_PUBLIC(char*) cJSON_AS4CPP_SetValuestring(cJSON *object, const char *valuestring)
415422
{
416423
char *copy = NULL;
424+
size_t v1_len;
425+
size_t v2_len;
417426
/* if object's type is not cJSON_AS4CPP_String or is cJSON_AS4CPP_IsReference, it should not set valuestring */
418-
if (!(object->type & cJSON_AS4CPP_String) || (object->type & cJSON_AS4CPP_IsReference))
427+
if ((object == NULL) || !(object->type & cJSON_AS4CPP_String) || (object->type & cJSON_AS4CPP_IsReference))
419428
{
420429
return NULL;
421430
}
422-
if (strlen(valuestring) <= strlen(object->valuestring))
431+
/* return NULL if the object is corrupted or valuestring is NULL */
432+
if (object->valuestring == NULL || valuestring == NULL)
423433
{
424-
memcpy(object->valuestring, valuestring, strlen(valuestring) + sizeof(""));
434+
return NULL;
435+
}
436+
437+
v1_len = strlen(valuestring);
438+
v2_len = strlen(object->valuestring);
439+
440+
if (v1_len <= v2_len)
441+
{
442+
/* strcpy does not handle overlapping string: [X1, X2] [Y1, Y2] => X2 < Y1 or Y2 < X1 */
443+
if (!( valuestring + v1_len < object->valuestring || object->valuestring + v2_len < valuestring ))
444+
{
445+
return NULL;
446+
}
447+
strcpy(object->valuestring, valuestring);
425448
return object->valuestring;
426449
}
427450
copy = (char*) cJSON_AS4CPP_strdup((const unsigned char*)valuestring, &global_hooks);
@@ -525,10 +548,8 @@ static unsigned char* ensure(printbuffer * const p, size_t needed)
525548

526549
return NULL;
527550
}
528-
if (newbuffer)
529-
{
530-
memcpy(newbuffer, p->buffer, p->offset + 1);
531-
}
551+
552+
memcpy(newbuffer, p->buffer, p->offset + 1);
532553
p->hooks.deallocate(p->buffer);
533554
}
534555
p->length = newsize;
@@ -905,6 +926,7 @@ static cJSON_AS4CPP_bool parse_string(cJSON * const item, parse_buffer * const i
905926
if (output != NULL)
906927
{
907928
input_buffer->hooks.deallocate(output);
929+
output = NULL;
908930
}
909931

910932
if (input_pointer != NULL)
@@ -1185,7 +1207,6 @@ CJSON_AS4CPP_PUBLIC(cJSON *) cJSON_AS4CPP_ParseWithLengthOpts(const char *value,
11851207
{
11861208
*return_parse_end = (const char*)local_error.json + local_error.position;
11871209
}
1188-
11891210
/* NOTE: disabled due to thread safety (see note at the top of this file).
11901211
global_error = local_error;
11911212
*/
@@ -1253,6 +1274,7 @@ static unsigned char *print(const cJSON * const item, cJSON_AS4CPP_bool format,
12531274

12541275
/* free the buffer */
12551276
hooks->deallocate(buffer->buffer);
1277+
buffer->buffer = NULL;
12561278
}
12571279

12581280
return printed;
@@ -1261,11 +1283,13 @@ static unsigned char *print(const cJSON * const item, cJSON_AS4CPP_bool format,
12611283
if (buffer->buffer != NULL)
12621284
{
12631285
hooks->deallocate(buffer->buffer);
1286+
buffer->buffer = NULL;
12641287
}
12651288

12661289
if (printed != NULL)
12671290
{
12681291
hooks->deallocate(printed);
1292+
printed = NULL;
12691293
}
12701294

12711295
return NULL;
@@ -1306,6 +1330,7 @@ CJSON_AS4CPP_PUBLIC(char *) cJSON_AS4CPP_PrintBuffered(const cJSON *item, int pr
13061330
if (!print_value(item, &p))
13071331
{
13081332
global_hooks.deallocate(p.buffer);
1333+
p.buffer = NULL;
13091334
return NULL;
13101335
}
13111336

@@ -1677,6 +1702,11 @@ static cJSON_AS4CPP_bool parse_object(cJSON * const item, parse_buffer * const i
16771702
current_item = new_item;
16781703
}
16791704

1705+
if (cannot_access_at_index(input_buffer, 1))
1706+
{
1707+
goto fail; /* nothing comes after the comma */
1708+
}
1709+
16801710
/* parse the name of the child */
16811711
input_buffer->offset++;
16821712
buffer_skip_whitespace(input_buffer);
@@ -2209,7 +2239,7 @@ CJSON_AS4CPP_PUBLIC(cJSON*) cJSON_AS4CPP_AddArrayToObject(cJSON * const object,
22092239

22102240
CJSON_AS4CPP_PUBLIC(cJSON *) cJSON_AS4CPP_DetachItemViaPointer(cJSON *parent, cJSON * const item)
22112241
{
2212-
if ((parent == NULL) || (item == NULL))
2242+
if ((parent == NULL) || (item == NULL) || (item != parent->child && item->prev == NULL))
22132243
{
22142244
return NULL;
22152245
}
@@ -2287,7 +2317,7 @@ CJSON_AS4CPP_PUBLIC(cJSON_AS4CPP_bool) cJSON_AS4CPP_InsertItemInArray(cJSON *arr
22872317
{
22882318
cJSON *after_inserted = NULL;
22892319

2290-
if (which < 0)
2320+
if (which < 0 || newitem == NULL)
22912321
{
22922322
return false;
22932323
}
@@ -2298,6 +2328,11 @@ CJSON_AS4CPP_PUBLIC(cJSON_AS4CPP_bool) cJSON_AS4CPP_InsertItemInArray(cJSON *arr
22982328
return add_item_to_array(array, newitem);
22992329
}
23002330

2331+
if (after_inserted != array->child && after_inserted->prev == NULL) {
2332+
/* return false if after_inserted is a corrupted array item */
2333+
return false;
2334+
}
2335+
23012336
newitem->next = after_inserted;
23022337
newitem->prev = after_inserted->prev;
23032338
after_inserted->prev = newitem;
@@ -2314,7 +2349,7 @@ CJSON_AS4CPP_PUBLIC(cJSON_AS4CPP_bool) cJSON_AS4CPP_InsertItemInArray(cJSON *arr
23142349

23152350
CJSON_AS4CPP_PUBLIC(cJSON_AS4CPP_bool) cJSON_AS4CPP_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
23162351
{
2317-
if ((parent == NULL) || (replacement == NULL) || (item == NULL))
2352+
if ((parent == NULL) || (parent->child == NULL) || (replacement == NULL) || (item == NULL))
23182353
{
23192354
return false;
23202355
}
@@ -2384,6 +2419,11 @@ static cJSON_AS4CPP_bool replace_item_in_object(cJSON *object, const char *strin
23842419
cJSON_AS4CPP_free(replacement->string);
23852420
}
23862421
replacement->string = (char*)cJSON_AS4CPP_strdup((const unsigned char*)string, &global_hooks);
2422+
if (replacement->string == NULL)
2423+
{
2424+
return false;
2425+
}
2426+
23872427
replacement->type &= ~cJSON_AS4CPP_StringIsConst;
23882428

23892429
return cJSON_AS4CPP_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement);
@@ -2608,6 +2648,7 @@ CJSON_AS4CPP_PUBLIC(cJSON *) cJSON_AS4CPP_CreateIntArray(const int *numbers, int
26082648
}
26092649

26102650
a = cJSON_AS4CPP_CreateArray();
2651+
26112652
for(i = 0; a && (i < (size_t)count); i++)
26122653
{
26132654
n = cJSON_AS4CPP_CreateNumber(numbers[i]);
@@ -2626,7 +2667,10 @@ CJSON_AS4CPP_PUBLIC(cJSON *) cJSON_AS4CPP_CreateIntArray(const int *numbers, int
26262667
}
26272668
p = n;
26282669
}
2629-
a->child->prev = n;
2670+
2671+
if (a && a->child) {
2672+
a->child->prev = n;
2673+
}
26302674

26312675
return a;
26322676
}
@@ -2663,7 +2707,10 @@ CJSON_AS4CPP_PUBLIC(cJSON *) cJSON_AS4CPP_CreateFloatArray(const float *numbers,
26632707
}
26642708
p = n;
26652709
}
2666-
a->child->prev = n;
2710+
2711+
if (a && a->child) {
2712+
a->child->prev = n;
2713+
}
26672714

26682715
return a;
26692716
}
@@ -2682,7 +2729,7 @@ CJSON_AS4CPP_PUBLIC(cJSON *) cJSON_AS4CPP_CreateDoubleArray(const double *number
26822729

26832730
a = cJSON_AS4CPP_CreateArray();
26842731

2685-
for(i = 0;a && (i < (size_t)count); i++)
2732+
for(i = 0; a && (i < (size_t)count); i++)
26862733
{
26872734
n = cJSON_AS4CPP_CreateNumber(numbers[i]);
26882735
if(!n)
@@ -2700,7 +2747,10 @@ CJSON_AS4CPP_PUBLIC(cJSON *) cJSON_AS4CPP_CreateDoubleArray(const double *number
27002747
}
27012748
p = n;
27022749
}
2703-
a->child->prev = n;
2750+
2751+
if (a && a->child) {
2752+
a->child->prev = n;
2753+
}
27042754

27052755
return a;
27062756
}
@@ -2737,13 +2787,23 @@ CJSON_AS4CPP_PUBLIC(cJSON *) cJSON_AS4CPP_CreateStringArray(const char *const *s
27372787
}
27382788
p = n;
27392789
}
2740-
a->child->prev = n;
2790+
2791+
if (a && a->child) {
2792+
a->child->prev = n;
2793+
}
27412794

27422795
return a;
27432796
}
27442797

27452798
/* Duplication */
2799+
cJSON * cJSON_AS4CPP_Duplicate_rec(const cJSON *item, size_t depth, cJSON_AS4CPP_bool recurse);
2800+
27462801
CJSON_AS4CPP_PUBLIC(cJSON *) cJSON_AS4CPP_Duplicate(const cJSON *item, cJSON_AS4CPP_bool recurse)
2802+
{
2803+
return cJSON_AS4CPP_Duplicate_rec(item, 0, recurse );
2804+
}
2805+
2806+
cJSON * cJSON_AS4CPP_Duplicate_rec(const cJSON *item, size_t depth, cJSON_AS4CPP_bool recurse)
27472807
{
27482808
cJSON *newitem = NULL;
27492809
cJSON *child = NULL;
@@ -2790,7 +2850,10 @@ CJSON_AS4CPP_PUBLIC(cJSON *) cJSON_AS4CPP_Duplicate(const cJSON *item, cJSON_AS4
27902850
child = item->child;
27912851
while (child != NULL)
27922852
{
2793-
newchild = cJSON_AS4CPP_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */
2853+
if(depth >= CJSON_AS4CPP_CIRCULAR_LIMIT) {
2854+
goto fail;
2855+
}
2856+
newchild = cJSON_AS4CPP_Duplicate_rec(child, depth + 1, true); /* Duplicate (with recurse) each item in the ->next chain */
27942857
if (!newchild)
27952858
{
27962859
goto fail;
@@ -3025,7 +3088,7 @@ CJSON_AS4CPP_PUBLIC(cJSON_AS4CPP_bool) cJSON_AS4CPP_IsRaw(const cJSON * const it
30253088

30263089
CJSON_AS4CPP_PUBLIC(cJSON_AS4CPP_bool) cJSON_AS4CPP_Compare(const cJSON * const a, const cJSON * const b, const cJSON_AS4CPP_bool case_sensitive)
30273090
{
3028-
if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_AS4CPP_IsInvalid(a))
3091+
if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)))
30293092
{
30303093
return false;
30313094
}
@@ -3156,4 +3219,5 @@ CJSON_AS4CPP_PUBLIC(void *) cJSON_AS4CPP_malloc(size_t size)
31563219
CJSON_AS4CPP_PUBLIC(void) cJSON_AS4CPP_free(void *object)
31573220
{
31583221
global_hooks.deallocate(object);
3222+
object = NULL;
31593223
}

0 commit comments

Comments
 (0)