cJSON icon indicating copy to clipboard operation
cJSON copied to clipboard

cJSON_Parse has buffer overflow with missing comma

Open brianwyld opened this issue 7 months ago • 7 comments

Using cJSON version 1.7.14 as bundled in the Nordic Semi SDKConnect under Zephyr.

If I try to parse using cJSON_ParseWithLength(tmp_json_buffer, load_len) for a buffer containing JSON missing the comma between items, then depending on where the item is in the overall buffer I either get a parse failure:

[00:00:01.024,841] base: Failed to parse contents of allocdata.json, error is "toto":"hello" }

or a nasty

  • buffer overflow detected *

followed by a zephyr panic and a fatal error/restart.

In the first case, I have

.... } "toto":"hello" }

as the end of my JSON (about 8kB's worth)

In the 2nd case its the first element...

{ "toto":"hello" "o1": { ...

Zephyr main stack size is configred to 64kB;

brianwyld avatar Jul 18 '24 15:07 brianwyld