]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-print: fix 'nvme list -o json' segfault
authorMartin George <marting@netapp.com>
Mon, 21 Feb 2022 10:17:24 +0000 (15:47 +0530)
committerMartin George <marting@netapp.com>
Mon, 21 Feb 2022 10:17:24 +0000 (15:47 +0530)
After the recent upgrade to libnvme, 'nvme list -o json' segfaults
due to incorrect json object type passed here. So fix this by passing
the appropriate json object type and invoking it outside the
nvme_for_each_host loop.

Signed-off-by: Martin George <marting@netapp.com>
nvme-print.c

index bad0da13d10030e2a0297fd65d1727b7d0b9ed48..d1aef1a3c39b1e49b79170c681e7b3dc11b624ed 100644 (file)
@@ -7206,8 +7206,8 @@ static void json_simple_list(nvme_root_t r)
                                json_array_add_value_object(jdevices,
                                                            json_list_item(n));
                }
-               json_object_add_value_object(jroot, "devices", jdevices);
        }
+       json_object_add_value_array(jroot, "devices", jdevices);
        json_print_object(jroot, NULL);
        printf("\n");
        json_free_object(jroot);