DaveGamble / cJSON

Ultralightweight JSON parser in ANSI C
MIT License
10.83k stars 3.22k forks source link

cJSON_Print does not check CJSON_NESTING_LIMIT. #765

Open cy18 opened 1 year ago

cy18 commented 1 year ago

I'm using cJSON on an Cortex-M4 MCU with a limited stack size. I set the CJSON_NESTING_LIMIT to 10, which works as expected when parsing. However, it seems cJSON_Print does not check CJSON_NESTING_LIMIT and leads a crash of the program.

In the code, I found the struct printbuffer does have a depth parameter. However, it's used just for printing and not checked for CJSON_NESTING_LIMIT. Adding an depth check in to print functions seems quite simple. Is there any reason not doing depth check when printing?