From 26b6ca9e2e7f4667c9c1e59b3b43f3b41841e015 Mon Sep 17 00:00:00 2001 From: Aravind Ramesh Date: Mon, 29 Jun 2020 10:19:29 +0530 Subject: [PATCH] nvme zns: segmentation fault in cmd "nvme zns zone-mgmt-send" zone_mgmt_send function calls strlen() on a null ptr causing the segmentation fault. Check the pointer instead of len. Signed-off-by: Aravind Ramesh --- plugins/zns/zns.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins/zns/zns.c b/plugins/zns/zns.c index 803887d..dbe9ad7 100644 --- a/plugins/zns/zns.c +++ b/plugins/zns/zns.c @@ -264,15 +264,14 @@ static int zone_mgmt_send(int argc, char **argv, struct command *cmd, struct plu goto close_fd; } - if (cfg.zsa == NVME_ZNS_ZSA_SET_DESC_EXT){ - if(!cfg.data_len){ + if (cfg.zsa == NVME_ZNS_ZSA_SET_DESC_EXT) { + if(!cfg.data_len) { cfg.data_len = get_zdes_bytes(fd, cfg.namespace_id); - if (cfg.data_len == 0){ + if (cfg.data_len == 0) { fprintf(stderr, "Zone Descriptor Extensions are not supported\n"); goto close_fd; - } - else if (cfg.data_len < 0) { + } else if (cfg.data_len < 0) { err = cfg.data_len; goto close_fd; } @@ -296,9 +295,8 @@ static int zone_mgmt_send(int argc, char **argv, struct command *cmd, struct plu perror("read"); goto close_ffd; } - } - else{ - if (strlen(cfg.file) || cfg.data_len){ + } else { + if (cfg.file || cfg.data_len) { fprintf(stderr, "data, data_len only valid with set extended descriptor\n"); err = -EINVAL; -- 2.49.0