Fix: add depth check to prevent stack overflow in cJSON_Print (#984)

This commit is contained in:
liloler
2026-02-25 15:40:05 +08:00
committed by GitHub
parent a29814f285
commit 5cc0e39f42
+10
View File
@@ -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);