From: HansolChoe Date: Thu, 19 Oct 2023 07:33:01 +0000 (+0900) Subject: tokener_parse_ex_fuzzer: add type checking for parsed object X-Git-Tag: json-c-0.18-20240915~21^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F837%2Fhead;p=thirdparty%2Fjson-c.git tokener_parse_ex_fuzzer: add type checking for parsed object --- diff --git a/fuzz/tokener_parse_ex_fuzzer.cc b/fuzz/tokener_parse_ex_fuzzer.cc index acdc3327..5d07497a 100644 --- a/fuzz/tokener_parse_ex_fuzzer.cc +++ b/fuzz/tokener_parse_ex_fuzzer.cc @@ -8,9 +8,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) json_tokener *tok = json_tokener_new(); json_object *obj = json_tokener_parse_ex(tok, data1, size); - json_object_object_foreach(obj, key, val) { - (void)json_object_get_type(val); - (void)json_object_get_string(val); + if (json_object_is_type(obj, json_type_object)) { + json_object_object_foreach(obj, key, val) { + (void)json_object_get_type(val); + (void)json_object_get_string(val); + } } (void)json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED);