Skip to content

Conversation

@domob1812
Copy link
Contributor

Fix #6558. In particular, stop parsing JSON after the first object or array is finished. Check that no other garbage follows, and fail the parser if it does.

Fix bitcoin#6558.  In particular, stop
parsing JSON after the first object or array is finished.  Check that no
other garbage follows, and fail the parser if it does.
@jonasschnelli
Copy link
Contributor

Thanks!

Tested ACK.

@laanwj
Copy link
Member

laanwj commented Aug 20, 2015

utACK. Looks good to me. I remember solving a similar problem in json::spirit shortly ago.

@domob1812
Copy link
Contributor Author

Yeah, I actually noticed this due to an inconsistent behaviour between json_spirit and UniValue. (Note, though, that a different inconsistency remains. While the new behaviour of UniValue is to error out with anything after the first construct, json_spirit just stops parsing and ignores everything that follows.)

@laanwj
Copy link
Member

laanwj commented Aug 21, 2015

json_spirit just stops parsing and ignores everything that follows

Yes, that's what I fixed. I also changed it to error out with trailing garbage. But I didn't notice that UniValue brought back that behavior because the bug (#6226) didn't return: ParseNonRFCJSONValue wraps the value in an array to be able to have top-level numbers and booleans, so it was already non-tolerant of trailing garbage.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd move the definitions of tokenval and consumed here, as they're only used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, they are also used in the loop. That's why I moved them above it. Of course, we could also define them both locally in the loop and then here. Would you prefer that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary. I missed that, then, sorry.

@laanwj laanwj merged commit e938122 into bitcoin:master Aug 24, 2015
laanwj added a commit that referenced this pull request Aug 24, 2015
e938122 Stop parsing JSON after first finished construct. (Daniel Kraft)
@domob1812 domob1812 deleted the json-garbage branch August 25, 2015 05:49
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UniValue should only parse the first JSON construct of a line

3 participants