Detect garbage near EOF in json_loadf() and json_load_file()
This commit is contained in:
parent
b3e265eb84
commit
ee2d164025
10
src/load.c
10
src/load.c
@ -805,7 +805,17 @@ json_t *json_loadf(FILE *input, json_error_t *error)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
result = parse_json(&lex, error);
|
result = parse_json(&lex, error);
|
||||||
|
if(!result)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
lex_scan(&lex, error);
|
||||||
|
if(lex.token != TOKEN_EOF) {
|
||||||
|
error_set(error, &lex, "end of file expected");
|
||||||
|
json_decref(result);
|
||||||
|
result = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
lex_close(&lex);
|
lex_close(&lex);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
11
test/testdata/invalid
vendored
11
test/testdata/invalid
vendored
@ -182,3 +182,14 @@ aå
|
|||||||
====
|
====
|
||||||
1
|
1
|
||||||
'[' or '{' expected near 'a'
|
'[' or '{' expected near 'a'
|
||||||
|
==== garbage-at-the-end ====
|
||||||
|
[1,2,3]foo
|
||||||
|
====
|
||||||
|
1
|
||||||
|
end of file expected near 'foo'
|
||||||
|
==== garbage-after-newline ====
|
||||||
|
[1,2,3]
|
||||||
|
foo
|
||||||
|
====
|
||||||
|
2
|
||||||
|
end of file expected near 'foo'
|
||||||
|
Loading…
Reference in New Issue
Block a user