Skip to content

Commit a7e6a5e

Browse files
committed
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.
1 parent ca98c98 commit a7e6a5e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/lib_json/json_reader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ bool Reader::readValue() {
143143
// after calling readValue(). parse() executes one nodes_.push(), so > instead
144144
// of >=.
145145
if (nodes_.size() > stackLimit_g)
146+
#if JSON_USE_EXCEPTION
146147
throwRuntimeError("Exceeded stackLimit in readValue().");
148+
#else
149+
return false;
150+
#endif
147151

148152
Token token;
149153
readTokenSkippingComments(token);

0 commit comments

Comments
 (0)