fix: cJSON-Verschachtelung begrenzen

C1: Ein POST an /api/v1/device/state mit tief verschachteltem JSON (z.B.
20 Ebenen "[[[[...") lässt cJSONs rekursiven Parser den 6-KB-Stack des
HTTP-Tasks überlaufen - CJSON_NESTING_LIMIT war mit 1000 viel zu hoch und
FreeRTOS' Stack-Overflow-Checking ist aus. Begrenzt auf 8 Ebenen, sowohl
für die Firmware (third_party/cJSON/cJSON.c) als auch für die
Host-Tests (nl_cjson), damit beide dasselbe Verhalten zeigen.

Test: test_post_validation deckt jetzt einen Body mit 20 verschachtelten
Arrays ab (400 "invalid json").
This commit is contained in:
Michael Sauer
2026-09-11 23:50:45 +02:00
parent de49647f9d
commit 89c764514a
3 changed files with 7 additions and 0 deletions
+2
View File
@@ -15,6 +15,8 @@ enable_testing()
# cJSON is third-party code: build it without -Werror.
add_library(nl_cjson STATIC ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/cJSON/cJSON.c)
target_include_directories(nl_cjson PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/cJSON)
# C1: match the firmware's nesting limit so host tests exercise the same behaviour.
target_compile_definitions(nl_cjson PUBLIC CJSON_NESTING_LIMIT=8)
set(NL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../src)