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:
@@ -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)
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ static void test_post_validation(void)
|
||||
static const struct { const char *body; const char *err; } CASES[] = {
|
||||
{"not json", "invalid json"},
|
||||
{"[1,2]", "invalid json"},
|
||||
{"{\"a\":[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]}", "invalid json"}, /* C1: 20 levels > CJSON_NESTING_LIMIT */
|
||||
{"{\"on\":1}", "invalid on"},
|
||||
{"{\"brightness\":0}", "invalid brightness"},
|
||||
{"{\"brightness\":101}", "invalid brightness"},
|
||||
|
||||
Reference in New Issue
Block a user