Commit 242eb6b4 authored by Zhiqiang Liu's avatar Zhiqiang Liu Committed by Jim Harris
Browse files

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: default avatarZhiqiang 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: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent e01a3f1c
Loading
Loading
Loading
Loading
+18 −12
Original line number Diff line number Diff line
@@ -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