]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: fix segfault in nvme telemetry-log error handling
authorMartin George <marting@netapp.com>
Tue, 1 Mar 2022 11:52:36 +0000 (17:22 +0530)
committerMartin George <marting@netapp.com>
Tue, 1 Mar 2022 11:52:36 +0000 (17:22 +0530)
After the upgrade to libnvme, the nvme telemetry-log command
segfaults for error scenarios as shown below:

NVMe status: Invalid Log Page: The log page indicated is invalid(0x4009)
Failed to acquire telemetry log 16393!
Segmentation fault (core dumped)

Freeing the telemetry log page header for error scenarios is already
handled in the libnvme. So avoid freeing this again here, which led to
this segfault.

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

diff --git a/nvme.c b/nvme.c
index 5e9e5cdadea63d907a9891a622904308a9e7b441..d707c18df418bcbc091cdf1dd59bbece3bfb04c6 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -482,7 +482,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *cmd,
                fprintf(stderr, "Failed to open output file %s: %s!\n",
                                cfg.file_name, strerror(errno));
                err = output;
-               goto free_mem;
+               goto close_fd;
        }
 
        if (cfg.ctrl_init)
@@ -526,10 +526,10 @@ static int get_telemetry_log(int argc, char **argv, struct command *cmd,
                return -1;
        }
 
+       free(log);
+
 close_output:
        close(output);
-free_mem:
-       free(log);
 close_fd:
        close(fd);
 ret: