nvmf:check return value of strdup in spdk_nvmf_subsystem_add_ns_ext()

In spdk_nvmf_subsystem_add_ns_ext(), ns->ptpl_file is set to strdup(),
which may return NULL. We should deal with it.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Change-Id: If95102fe9d6d789b8ba9e846c4d7f4e22e48a93c
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8305
Community-CI: Mellanox Build Bot
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Zhiqiang Liu 2021-06-13 18:59:13 +08:00 committed by Jim Harris
parent e01a3f1c05
commit 242eb6b4c2

View File

@ -1472,14 +1472,14 @@ spdk_nvmf_subsystem_add_ns_ext(struct spdk_nvmf_subsystem *subsystem, const char
rc = nvmf_ns_reservation_restore(ns, &info);
if (rc) {
SPDK_ERRLOG("Subsystem restore reservation failed\n");
subsystem->ns[opts.nsid - 1] = NULL;
spdk_bdev_module_release_bdev(ns->bdev);
spdk_bdev_close(ns->desc);
free(ns);
return 0;
goto err_ns_reservation_restore;
}
}
ns->ptpl_file = strdup(ptpl_file);
if (!ns->ptpl_file) {
SPDK_ERRLOG("Namespace ns->ptpl_file allocation failed\n");
goto err_strdup;
}
}
for (transport = spdk_nvmf_transport_get_first(subsystem->tgt); transport;
@ -1488,13 +1488,7 @@ spdk_nvmf_subsystem_add_ns_ext(struct spdk_nvmf_subsystem *subsystem, const char
rc = transport->ops->subsystem_add_ns(transport, subsystem, ns);
if (rc) {
SPDK_ERRLOG("Namespace attachment is not allowed by %s transport\n", transport->ops->name);
free(ns->ptpl_file);
nvmf_ns_reservation_clear_all_registrants(ns);
subsystem->ns[opts.nsid - 1] = NULL;
spdk_bdev_module_release_bdev(ns->bdev);
spdk_bdev_close(ns->desc);
free(ns);
return 0;
goto err_subsystem_add_ns;
}
}
}
@ -1507,6 +1501,18 @@ spdk_nvmf_subsystem_add_ns_ext(struct spdk_nvmf_subsystem *subsystem, const char
nvmf_subsystem_ns_changed(subsystem, opts.nsid);
return opts.nsid;
err_subsystem_add_ns:
free(ns->ptpl_file);
err_strdup:
nvmf_ns_reservation_clear_all_registrants(ns);
err_ns_reservation_restore:
subsystem->ns[opts.nsid - 1] = NULL;
spdk_bdev_module_release_bdev(ns->bdev);
spdk_bdev_close(ns->desc);
free(ns);
return 0;
}
static uint32_t