-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limit nesting of json commands #2326
Conversation
Jenkins Build SummaryBuilt from this commit Built at 20180116 - 21:32:39 Test Results
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Only comment is maybe set the maximum nesting depth as a constexpr
at the top of the file.
src/ripple/json/impl/json_reader.cpp
Outdated
@@ -29,6 +29,8 @@ namespace Json | |||
// Implementation of class Reader | |||
// //////////////////////////////// | |||
|
|||
constexpr unsigned nest_limit = 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a point of reference, the code that converts JSON to STObjects/STArrays limits recursion (objects containing objects or arrays and on down) to 64: https://github.com/ripple/rippled/blob/develop/src/ripple/protocol/impl/STParsedJSON.cpp#L693. Not suggesting any change here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might worth making a public static member that can be referenced externally, like a unit test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such a unit test would get pretty ugly. Not sure it is worth it.
src/ripple/json/impl/json_reader.cpp
Outdated
@@ -141,7 +143,7 @@ Reader::readValue(unsigned depth) | |||
{ | |||
Token token; | |||
skipCommentTokens ( token ); | |||
if (++depth >= 1000) | |||
if (++depth >= nest_limit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be if (depth > nest_limit)
?
depth
is already incremented by the readObject
and readArray
functions before readValue
is called. Incrementing here seems to incorrectly double how many nests we think there are. With following json {"obj":{"obj":{"obj":{"obj":{"obj":{"obj":{"obj":{"obj":{"obj":{"obj":{}}}}}}}}}}}
depth reaches a value of 20 instead of 10.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<slaps forehead>
Thanks! Fixing...
@HowardHinnant I extended https://github.com/miguelportilla/rippled/commits/nest_test |
@miguelportilla Nice! Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
26fe5a4
to
29544a8
Compare
Rebased to 0.90.0-b3 |
Incorporated in 0.90.0-b4 as 0ec66b3. |
No description provided.