mirror of
https://github.com/DaveGamble/cJSON.git
synced 2026-06-05 21:04:39 +00:00
Fix: add depth check to prevent stack overflow in cJSON_Print (#984)
This commit is contained in:
@@ -1598,6 +1598,11 @@ static cJSON_bool print_array(const cJSON * const item, printbuffer * const outp
|
||||
return false;
|
||||
}
|
||||
|
||||
if (output_buffer->depth >= CJSON_NESTING_LIMIT)
|
||||
{
|
||||
return false; /* nesting is too deep */
|
||||
}
|
||||
|
||||
/* Compose the output array. */
|
||||
/* opening square bracket */
|
||||
output_pointer = ensure(output_buffer, 1);
|
||||
@@ -1778,6 +1783,11 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out
|
||||
return false;
|
||||
}
|
||||
|
||||
if (output_buffer->depth >= CJSON_NESTING_LIMIT)
|
||||
{
|
||||
return false; /* nesting is too deep */
|
||||
}
|
||||
|
||||
/* Compose the output: */
|
||||
length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */
|
||||
output_pointer = ensure(output_buffer, length + 1);
|
||||
|
||||
Reference in New Issue
Block a user