mirror of
https://github.com/json-c/json-c.git
synced 2026-11-05 21:20:16 +08:00
Merge pull request #968 from 1234binpig/master
json_parse: report incomplete and failed input
This commit is contained in:
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;
|
||||
|
||||
@@ -18,4 +18,22 @@ TESTNAME="${TESTNAME%.test}"
|
||||
( cat file1.dat ; cat file2.dat ) | run_output_test -o "${TESTNAME}" --exit 1 ../apps/json_parse -u -N -n -
|
||||
_err=$?
|
||||
|
||||
printf '{' | "${top_builddir}/../apps/json_parse" -N -n - > /dev/null 2>&1
|
||||
if test $? -eq 0; then
|
||||
echo "ERROR: json_parse accepted incomplete input" 1>&2
|
||||
_err=1
|
||||
fi
|
||||
|
||||
printf '123' | "${top_builddir}/../apps/json_parse" -N -n - > /dev/null 2>&1
|
||||
if test $? -ne 0; then
|
||||
echo "ERROR: json_parse rejected valid EOF-terminated scalar input" 1>&2
|
||||
_err=1
|
||||
fi
|
||||
|
||||
"${top_builddir}/../apps/json_parse" -N -n - <&- > /dev/null 2>&1
|
||||
if test $? -eq 0; then
|
||||
echo "ERROR: json_parse returned success after read failure" 1>&2
|
||||
_err=1
|
||||
fi
|
||||
|
||||
exit $_err
|
||||
Reference in new issue
Block a user