Stop parsing JSON after first finished construct.#6576
Conversation
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.
|
Thanks! Tested ACK. |
|
utACK. Looks good to me. I remember solving a similar problem in json::spirit shortly ago. |
|
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.) |
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: |
There was a problem hiding this comment.
Nit: I'd move the definitions of tokenval and consumed here, as they're only used here.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Not necessary. I missed that, then, sorry.
e938122 Stop parsing JSON after first finished construct. (Daniel Kraft)
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.