diff options
author | Hans Rosenfeld <hans.rosenfeld@joyent.com> | 2017-07-20 17:15:19 +0200 |
---|---|---|
committer | Hans Rosenfeld <hans.rosenfeld@joyent.com> | 2017-09-12 16:59:24 +0200 |
commit | e7e9ed12e28c345b730aae97b62991a1b640fc7c (patch) | |
tree | c09d1574bedc9c193784d12415580230270f090c | |
parent | 1e167260e7cd91e04759854b0ae61b36cd47a218 (diff) | |
download | illumos-joyent-e7e9ed12e28c345b730aae97b62991a1b640fc7c.tar.gz |
8481 nvmeadm: nvme_dskname() string handling is buggy
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Yuri Pankov <yuripv@gmx.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r-- | usr/src/cmd/nvmeadm/nvmeadm.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/usr/src/cmd/nvmeadm/nvmeadm.c b/usr/src/cmd/nvmeadm/nvmeadm.c index de1d3e0171..00931bf77e 100644 --- a/usr/src/cmd/nvmeadm/nvmeadm.c +++ b/usr/src/cmd/nvmeadm/nvmeadm.c @@ -432,21 +432,29 @@ nvme_dskname(const nvme_process_arg_t *npa) path = di_dim_path_dev(dim, di_driver_name(child), di_instance(child), "c"); - if (path != NULL) { - path[strlen(path) - 2] = '\0'; - path = strrchr(path, '/') + 1; - if (path != NULL) { - path = strdup(path); - if (path == NULL) - err(-1, "nvme_dskname"); - } - } + /* + * Error out if we didn't get a path, or if it's too short for + * the following operations to be safe. + */ + if (path == NULL || strlen(path) < 2) + goto fail; + + /* Chop off 's0' and get everything past the last '/' */ + path[strlen(path) - 2] = '\0'; + path = strrchr(path, '/'); + if (path == NULL) + goto fail; + path++; break; } di_dim_fini(dim); + return (path); + +fail: + err(-1, "nvme_dskname"); } static int |