From b05a1f61e2fcc4238acea345d94c5abc6dc93b1b Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 29 Sep 2020 16:37:18 +0900 Subject: [PATCH] wgetjson_json_item_scan: fix a NULL dereference I'm not sure if this is the correct fix. wgetjson_json_item_callback seems to expect it to be formatted as "(null)". --- examples/wgetjson/wgetjson_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/wgetjson/wgetjson_main.c b/examples/wgetjson/wgetjson_main.c index 81ccf02fb..99c2ccccb 100644 --- a/examples/wgetjson/wgetjson_main.c +++ b/examples/wgetjson/wgetjson_main.c @@ -260,8 +260,9 @@ static void wgetjson_json_item_scan(cJSON *item, const char *prefix) while (item) { - newprefix = malloc(strlen(prefix) + strlen(item->string) + 2); - sprintf(newprefix, "%s/%s", prefix, item->string); + const char *string = item->string ? item->string : "(null)"; + newprefix = malloc(strlen(prefix) + strlen(string) + 2); + sprintf(newprefix, "%s/%s", prefix, string); dorecurse = wgetjson_json_item_callback(newprefix, item->type, item); if (item->child && dorecurse)