diff --git a/CMakeLists.txt b/CMakeLists.txt index 23b4194..d777537 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,10 @@ set(NL_FW_SOURCES src/sys/nl_app_api.c third_party/cJSON/cJSON.c) +# C1: deeply nested JSON must not overflow the 6 KB HTTP task stack (parse_value recurses). +set_source_files_properties(third_party/cJSON/cJSON.c PROPERTIES + COMPILE_DEFINITIONS "CJSON_NESTING_LIMIT=8") + set(NL_FW ninlight_${NINLIGHT_DEVICE}) add_executable(${NL_FW} ${NL_SDK_BOOT_SOURCES} ${NL_FW_SOURCES} ${NL_SDK_OBJECTS}) set_target_properties(${NL_FW} PROPERTIES SUFFIX ".elf") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a771b37..6b98238 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) diff --git a/test/test_api.c b/test/test_api.c index 794d609..2e6fd05 100644 --- a/test/test_api.c +++ b/test/test_api.c @@ -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"},