mirror of
https://github.com/json-c/json-c.git
synced 2026-11-05 21:20:16 +08:00
json_parse returned success when input ended while the tokener was
still waiting for more data, and also after read() failures. Finalize the tokener at EOF with the terminating NUL so valid scalar values can complete, while rejecting genuinely truncated input. Also propagate read errors to the caller and add CLI regression tests.
This commit is contained in:
1 parent
a954bda619
commit
0e5a2d43f7
2 files changed
+39
No files matched your search
@@ -143,6 +143,27 @@ static int parseit(int fd, int (*callback)(struct json_object *))
|
||||
json_tokener_free(tok);
|
||||
return 1;
|
||||
}
|
||||
if (json_tokener_get_error(tok) == json_tokener_continue)
|
||||
{
|
||||
obj = json_tokener_parse_ex(tok, "", 1);
|
||||
if (obj != NULL)
|
||||
{
|
||||
int cb_ret = callback(obj);
|
||||
json_object_put(obj);
|
||||
if (cb_ret != 0)
|
||||
{
|
||||
json_tokener_free(tok);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (json_tokener_get_error(tok) != json_tokener_success)
|
||||
{
|
||||
fprintf(stderr, "Failed at offset %lu: unexpected end of data\n",
|
||||
(unsigned long)total_read);
|
||||
json_tokener_free(tok);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
json_tokener_free(tok);
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user