mirror of
https://github.com/DaveGamble/cJSON.git
synced 2026-08-22 08:29:52 +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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (output_buffer->depth >= CJSON_NESTING_LIMIT)
|
||||||
|
{
|
||||||
|
return false; /* nesting is too deep */
|
||||||
|
}
|
||||||
|
|
||||||
/* Compose the output array. */
|
/* Compose the output array. */
|
||||||
/* opening square bracket */
|
/* opening square bracket */
|
||||||
output_pointer = ensure(output_buffer, 1);
|
output_pointer = ensure(output_buffer, 1);
|
||||||
@@ -1778,6 +1783,11 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (output_buffer->depth >= CJSON_NESTING_LIMIT)
|
||||||
|
{
|
||||||
|
return false; /* nesting is too deep */
|
||||||
|
}
|
||||||
|
|
||||||
/* Compose the output: */
|
/* Compose the output: */
|
||||||
length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */
|
length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */
|
||||||
output_pointer = ensure(output_buffer, length + 1);
|
output_pointer = ensure(output_buffer, length + 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user