Detect garbage near EOF in json_loadf() and json_load_file()
[jansson.git] / src / load.c
index 88cd1f0..25df182 100644 (file)
@@ -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;
 }