From: Petri Lehtinen Date: Mon, 24 Aug 2009 17:58:59 +0000 (+0300) Subject: Detect garbage near EOF in json_loadf() and json_load_file() X-Git-Tag: v1.0~4 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=jansson.git;a=commitdiff_plain;h=ee2d164025b5090c7cd81ffd8c1e3e07d45e5d31 Detect garbage near EOF in json_loadf() and json_load_file() --- diff --git a/src/load.c b/src/load.c index 88cd1f0..25df182 100644 --- a/src/load.c +++ b/src/load.c @@ -805,7 +805,17 @@ json_t *json_loadf(FILE *input, json_error_t *error) return NULL; 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); return result; } diff --git a/test/testdata/invalid b/test/testdata/invalid index bdca8a5..2887692 100644 --- a/test/testdata/invalid +++ b/test/testdata/invalid @@ -182,3 +182,14 @@ aå ==== 1 '[' 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'