You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by je...@apache.org on 2020/09/30 06:22:28 UTC

[incubator-nuttx-apps] 03/04: wgetjson_json_item_scan: fix a NULL dereference

This is an automated email from the ASF dual-hosted git repository.

jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit b05a1f61e2fcc4238acea345d94c5abc6dc93b1b
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Tue Sep 29 16:37:18 2020 +0900

    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 81ccf02..99c2ccc 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)