From d9f8bf2c85b692b81c5502cc96c6aad1b9d6cfca Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Fri, 8 Aug 2025 00:08:30 -0700 Subject: [PATCH] Return false in Reader::readValue when stack limit is exceeded jsoncpp, as a shared library, should not call `abort` merely because there's an error reading a value. See https://en.cppreference.com/w/c/program/abort, `abort` should only be called to **abnormally** cause the program to exit. Functions inserted by `atexit` are also not called, meaning that the host program may have not cleaned up resources properly. But here, exceeding stack limit isn't a sign of abnormalty. `exit` is not a good substitute either, see the `exit-in-shared-library` from Debian: https://lintian.debian.org/tags/exit-in-shared-library.html Fix #1618 In this case, returning false seems like a better idea. --- src/lib_json/json_reader.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 5b6299906..abe542d6a 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -143,7 +143,12 @@ bool Reader::readValue() { // after calling readValue(). parse() executes one nodes_.push(), so > instead // of >=. if (nodes_.size() > stackLimit_g) +#if JSON_USE_EXCEPTION throwRuntimeError("Exceeded stackLimit in readValue()."); +#else + // throwRuntimeError aborts. Don't abort here. + return false; +#endif Token token; readTokenSkippingComments(token);