From 61e741efca85edbe6899f2c8c4910b7dc99cc7ef Mon Sep 17 00:00:00 2001 From: GangCao Date: Thu, 27 Sep 2018 18:40:14 -0400 Subject: [PATCH] lib/nvme: add a check for valid namespace id When the NVMe SSD supports multiple namespaces, we allocate the related data structures to hold the namespace related information. Add a check of valid namespace id before accessing the memory structure. Change-Id: I3176099a80f718d9470ee172a040a2ccc353aae9 Signed-off-by: GangCao Reviewed-on: https://review.gerrithub.io/427058 Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Changpeng Liu Reviewed-by: Ben Walker Tested-by: SPDK CI Jenkins --- lib/nvme/nvme_ns.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/nvme/nvme_ns.c b/lib/nvme/nvme_ns.c index 5b7dd7f05..dec032cc5 100644 --- a/lib/nvme/nvme_ns.c +++ b/lib/nvme/nvme_ns.c @@ -142,7 +142,16 @@ spdk_nvme_ns_get_id(struct spdk_nvme_ns *ns) bool spdk_nvme_ns_is_active(struct spdk_nvme_ns *ns) { - const struct spdk_nvme_ns_data *nsdata = _nvme_ns_get_data(ns); + const struct spdk_nvme_ns_data *nsdata = NULL; + + /* + * According to the spec, valid NS has non-zero id. + */ + if (ns->id == 0) { + return false; + } + + nsdata = _nvme_ns_get_data(ns); /* * According to the spec, Identify Namespace will return a zero-filled structure for