From ba4b2ec96e62163be6c8115e0580cf7dcd7df268 Mon Sep 17 00:00:00 2001 From: Eyal Ben David Date: Thu, 20 Sep 2018 13:14:32 +0300 Subject: [PATCH] attach-ns : fix segfault for ctrl list wrong input --- nvme.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nvme.c b/nvme.c index 970fc0bd..253bc9e0 100644 --- a/nvme.c +++ b/nvme.c @@ -1072,7 +1072,7 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s __u16 ctrlist[2048]; const char *namespace_id = "namespace to attach"; - const char *cont = "optional comma-sep controllers list"; + const char *cont = "optional comma-sep controller id list"; struct config { char *cntlist; @@ -1102,6 +1102,14 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s num = argconfig_parse_comma_sep_array(cfg.cntlist, list, 2047); + + if (num == -1) { + fprintf(stderr, "%s: controller id list is required\n", + cmd->name); + err = EINVAL; + goto close_fd; + } + for (i = 0; i < num; i++) ctrlist[i] = (uint16_t)list[i]; -- 2.50.1