Skip to content

Commit 85f4e17

Browse files
committed
Better default depth
1 parent 1145943 commit 85f4e17

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ set(JSONEXPR_USE_STD_EXPECTED OFF CACHE BOOL "Use std::expected (requires C++
2929
set(JSONEXPR_USE_STD_FROM_CHARS ON CACHE BOOL "Use std::from_chars (requires C++17). Else, use streams.")
3030

3131
# Configurable parameters
32-
set(JSONEXPR_MAX_AST_DEPTH 32 CACHE STRING "Maximum depth of the parsed AST (0=infinite)")
32+
set(JSONEXPR_MAX_PARSER_DEPTH 128 CACHE STRING "Maximum depth of the parser (0=infinite)")
3333

3434
# Development options.
3535
set(JSONEXPR_DEV OFF CACHE BOOL "Enable warnings in compilation.")

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ first_non_null(1, 1+'abc') -> 1 (second argument was invalid, but no error si
330330

331331
# Security
332332

333-
All operations allowed in the language are meant to be safe, in the sense that they should not make the host process abort or behave in an unspecified manner (e.g., through out-of-bounds read or writes, use-after-free, incorrect type accesses, read of uninitialized memory, etc.). This is tested by running the test suite with sanitizers, and by fuzzing.
333+
All operations allowed in the language are meant to be safe, in the sense that they should not make the host process abort or behave in an unspecified manner (e.g., through out-of-bounds read or writes, use-after-free, incorrect type accesses, read of uninitialized memory, etc.). This is tested by running the test suite with sanitizers, and by fuzzing. The underlying JSON library is also battle-tested.
334334

335-
Furthermore, the parser has a fixed maximum recursion depth to prevent stack overflows. This depth is set to 32 by default, and can be changed with the CMake option `JSONEXPR_MAX_AST_DEPTH`.
335+
Furthermore, the parser has a fixed maximum recursion depth to prevent stack overflows. This depth can be changed with the CMake/compilation option `JSONEXPR_MAX_AST_DEPTH`.
336336

337337
Despite the above, the library is not 100% risk-free. In particular, the following is currently unsafe:
338338
- integer overflow and underflow in evaluated expression

libjsonexpr/include/jsonexpr/config.hpp.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@
4343

4444
#cmakedefine01 JSONEXPR_FUZZ
4545

46-
#define JSONEXPR_MAX_AST_DEPTH ${JSONEXPR_MAX_AST_DEPTH}
46+
#define JSONEXPR_MAX_PARSER_DEPTH ${JSONEXPR_MAX_PARSER_DEPTH}
4747

4848
#endif

libjsonexpr/src/parse.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ struct depth_counter {
7070

7171
#define CHECK_MAX_DEPTH \
7272
do { \
73-
if (depth.depth == JSONEXPR_MAX_AST_DEPTH) { \
73+
if (depth.depth == JSONEXPR_MAX_PARSER_DEPTH) { \
7474
if (tokens.empty()) { \
75-
return unexpected( \
76-
abort_parse("max depth of AST reached; increase JSONEXPR_MAX_AST_DEPTH")); \
75+
return unexpected(abort_parse( \
76+
"max depth of parser reached; increase JSONEXPR_MAX_PARSER_DEPTH")); \
7777
} else { \
7878
return unexpected(abort_parse( \
79-
tokens.front(), "max depth of AST reached; increase JSONEXPR_MAX_AST_DEPTH")); \
79+
tokens.front(), \
80+
"max depth of parser reached; increase JSONEXPR_MAX_PARSER_DEPTH")); \
8081
} \
8182
} \
8283
} while (0)

0 commit comments

Comments
 (0)