Skip to content
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

json_tokener_parse_ex() returns json_tokener_continue on zero-length string #286

Closed
usergoodvery opened this issue Nov 10, 2016 · 3 comments

Comments

@usergoodvery
Copy link

Hi,
The construct below causes indefinite hang where strlen(str)==0, Is this a deliberate design?
do
{
jobj=json_tokener_parse_ex(jtok, str, strlen(str));
}
while ((jerr=json_tokener_get_error(jtok))==json_tokener_continue);

@hawicz
Copy link
Member

hawicz commented Nov 10, 2016

Yes, though indirectly. json_tokener_parse_ex() is meant to be usable to parse a json object across multiple calls, so having nothing to parse yet doesn't mean the next call won't provide some valid json syntax.

That loop looks pretty odd. Even if str wasn't empty, why would you want to keep parsing it? Say you pass in a str that just contains a left curly brace "{". That code will loop, internally creating a whole series of nested objects, until you reach the default depth limit of 32, or if you've adjusted max_depth, until you run out of memory.

@hawicz hawicz closed this as completed Nov 10, 2016
@hawicz hawicz changed the title json_tokener_parse_ex() hangs on zero-length string json_tokener_parse_ex() returns json_tokener_continue on zero-length string Nov 10, 2016
@hawicz
Copy link
Member

hawicz commented Nov 10, 2016

Just to be clear, json_tokener_parse_ex() does not hang. It returns json_tokener_continue, so the loop in the sample code above is essentially an infinite loop.

@usergoodvery
Copy link
Author

Hi,

Thanks for clarifying. I will revisit my implementation in light of the above. For what it is worth, I tend to remember i got stuck on "hanging" as opposed to "spinning". Reason I say that because the way i stumbled across this is when my threads were hanging on to the mutex as they were stuck in the above call when json str was empty (introspected via gdb). I don't recall my cpus going through the roof at the time...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants