···11+1.7.18 (May 13, 2024)
22+======
33+Fixes:
44+------
55+* Add NULL check to cJSON_SetValuestring()(CVE-2024-31755), see #839 and #840
66+* Remove non-functional list handling of compiler flags, see #851
77+* Fix heap buffer overflow, see #852
88+* remove misused optimization flag -01, see #854
99+* Set free'd pointers to NULL whenever they are not reassigned immediately after, see #855 and #833
1010+1111+1.7.17 (Dec 26, 2023)
1212+======
1313+Fixes:
1414+------
1515+* Fix null reference in cJSON_SetValuestring(CVE-2023-50472), see #809
1616+* Fix null reference in cJSON_InsertItemInArray(CVE-2023-50471), see #809 and #810
1717+1818+1.7.16 (Jul 5, 2023)
1919+======
2020+Features:
2121+------
2222+* Add an option for ENABLE_CJSON_VERSION_SO in CMakeLists.txt, see #534
2323+* Add cmake_policy to CMakeLists.txt, see #163
2424+* Add cJSON_SetBoolValue, see #639
2525+* Add meson documentation, see #761
2626+2727+Fixes:
2828+------
2929+* Fix memory leak in merge_patch, see #611
3030+* Fix conflicting target names 'uninstall', see #617
3131+* Bump cmake version to 3.0 and use new version syntax, see #587
3232+* Print int without decimal places, see #630
3333+* Fix 'cjson_utils-static' target not exist, see #625
3434+* Add allocate check for replace_item_in_object, see #675
3535+* Fix a null pointer crash in cJSON_ReplaceItemViaPointer, see #726
3636+1371.7.15 (Aug 25, 2021)
238======
339Fixes:
···9696 return (const char*) (global_error.json + global_error.position);
9797}
98989999-CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item)
9999+CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item)
100100{
101101- if (!cJSON_IsString(item))
101101+ if (!cJSON_IsString(item))
102102 {
103103 return NULL;
104104 }
···106106 return item->valuestring;
107107}
108108109109-CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
109109+CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
110110{
111111- if (!cJSON_IsNumber(item))
111111+ if (!cJSON_IsNumber(item))
112112 {
113113 return (double) NAN;
114114 }
···117117}
118118119119/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
120120-#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 15)
120120+#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 18)
121121 #error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
122122#endif
123123···263263 if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL))
264264 {
265265 global_hooks.deallocate(item->valuestring);
266266+ item->valuestring = NULL;
266267 }
267268 if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
268269 {
269270 global_hooks.deallocate(item->string);
271271+ item->string = NULL;
270272 }
271273 global_hooks.deallocate(item);
272274 item = next;
···397399 return object->valuedouble = number;
398400}
399401402402+/* Note: when passing a NULL valuestring, cJSON_SetValuestring treats this as an error and return NULL */
400403CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
401404{
402405 char *copy = NULL;
403406 /* if object's type is not cJSON_String or is cJSON_IsReference, it should not set valuestring */
404404- if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference))
407407+ if ((object == NULL) || !(object->type & cJSON_String) || (object->type & cJSON_IsReference))
408408+ {
409409+ return NULL;
410410+ }
411411+ /* return NULL if the object is corrupted or valuestring is NULL */
412412+ if (object->valuestring == NULL || valuestring == NULL)
405413 {
406414 return NULL;
407415 }
···511519512520 return NULL;
513521 }
514514-522522+515523 memcpy(newbuffer, p->buffer, p->offset + 1);
516524 p->hooks.deallocate(p->buffer);
517525 }
···562570 {
563571 length = sprintf((char*)number_buffer, "null");
564572 }
573573+ else if(d == (double)item->valueint)
574574+ {
575575+ length = sprintf((char*)number_buffer, "%d", item->valueint);
576576+ }
565577 else
566578 {
567579 /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
···884896 if (output != NULL)
885897 {
886898 input_buffer->hooks.deallocate(output);
899899+ output = NULL;
887900 }
888901889902 if (input_pointer != NULL)
···11031116 }
1104111711051118 buffer.content = (const unsigned char*)value;
11061106- buffer.length = buffer_length;
11191119+ buffer.length = buffer_length;
11071120 buffer.offset = 0;
11081121 buffer.hooks = global_hooks;
11091122···1226123912271240 /* free the buffer */
12281241 hooks->deallocate(buffer->buffer);
12421242+ buffer->buffer = NULL;
12291243 }
1230124412311245 return printed;
···12341248 if (buffer->buffer != NULL)
12351249 {
12361250 hooks->deallocate(buffer->buffer);
12511251+ buffer->buffer = NULL;
12371252 }
1238125312391254 if (printed != NULL)
12401255 {
12411256 hooks->deallocate(printed);
12571257+ printed = NULL;
12421258 }
1243125912441260 return NULL;
···12791295 if (!print_value(item, &p))
12801296 {
12811297 global_hooks.deallocate(p.buffer);
12981298+ p.buffer = NULL;
12821299 return NULL;
12831300 }
12841301···16481665 current_item->next = new_item;
16491666 new_item->prev = current_item;
16501667 current_item = new_item;
16681668+ }
16691669+16701670+ if (cannot_access_at_index(input_buffer, 1))
16711671+ {
16721672+ goto fail; /* nothing comes after the comma */
16511673 }
1652167416531675 /* parse the name of the child */
···22602282{
22612283 cJSON *after_inserted = NULL;
2262228422632263- if (which < 0)
22852285+ if (which < 0 || newitem == NULL)
22642286 {
22652287 return false;
22662288 }
···22712293 return add_item_to_array(array, newitem);
22722294 }
2273229522962296+ if (after_inserted != array->child && after_inserted->prev == NULL) {
22972297+ /* return false if after_inserted is a corrupted array item */
22982298+ return false;
22992299+ }
23002300+22742301 newitem->next = after_inserted;
22752302 newitem->prev = after_inserted->prev;
22762303 after_inserted->prev = newitem;
···2287231422882315CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
22892316{
22902290- if ((parent == NULL) || (replacement == NULL) || (item == NULL))
23172317+ if ((parent == NULL) || (parent->child == NULL) || (replacement == NULL) || (item == NULL))
22912318 {
22922319 return false;
22932320 }
···23572384 cJSON_free(replacement->string);
23582385 }
23592386 replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks);
23872387+ if (replacement->string == NULL)
23882388+ {
23892389+ return false;
23902390+ }
23912391+23602392 replacement->type &= ~cJSON_StringIsConst;
2361239323622394 return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement);
···26892721 if (a && a->child) {
26902722 a->child->prev = n;
26912723 }
26922692-27242724+26932725 return a;
26942726}
26952727···31073139CJSON_PUBLIC(void) cJSON_free(void *object)
31083140{
31093141 global_hooks.deallocate(object);
31423142+ object = NULL;
31103143}
+8-1
src/external/cjson/cjson/cJSON.h
···8181/* project version */
8282#define CJSON_VERSION_MAJOR 1
8383#define CJSON_VERSION_MINOR 7
8484-#define CJSON_VERSION_PATCH 15
8484+#define CJSON_VERSION_PATCH 18
85858686#include <stddef.h>
8787···278278#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
279279/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
280280CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
281281+282282+/* If the object is not a boolean type this does nothing and returns cJSON_Invalid else it returns the new type*/
283283+#define cJSON_SetBoolValue(object, boolValue) ( \
284284+ (object != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \
285285+ (object)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \
286286+ cJSON_Invalid\
287287+)
281288282289/* Macro for iterating over an array or object */
283290#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)