-
Notifications
You must be signed in to change notification settings - Fork 906
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
common/json.c: Check that JSMN result is well-formed. #3761
common/json.c: Check that JSMN result is well-formed. #3761
Conversation
Probably deserves some kind of test though. |
3b8b422
to
3141935
Compare
Modified the |
3141935
to
469a2eb
Compare
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.
Nice fix, just three tiny comments/clarifications needed.
Am I correct in assuming this is O(n)
despite the recursive calls, since we advance the pointers by the parsed amounts in the recursive calls?
Yes, it should be. |
Ah, no, no. Deeply-nested objects/arrays would trigger the function being called over sub-ranges of an earlier call, so it does not achieve O(nd) where d is the nestedness of objects. Personally I think correctness is more important, we can always rewrite it faster later. |
469a2eb
to
0cf663b
Compare
Sorry, completely rewrote the code to be O(n) on the number of tokens validated, and requiring O(d) stack space (d being nestedness of objects/arrays in the JSON input). |
xref: https://lists.ozlabs.org/pipermail/c-lightning/2020-June/000188.html Changelog-Fixed: Reject some bad JSON at parsing.
0cf663b
to
f3438c2
Compare
Renamed the validation function to |
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.
Ack f3438c2
Nice work. Yes, I hit a similar issue previously, but that one was fixed upstream. Good to validate generally for this reason. |
xref: https://lists.ozlabs.org/pipermail/c-lightning/2020-June/000188.html