Commit 6e540558 authored by Marcin Spiewak's avatar Marcin Spiewak Committed by Jim Harris
Browse files

bdev_nvme: trid initialization and NULL terminated trid->subnqn



The patch is created to	address	issues discovered by Coverity
scan.
The struct spdk_nvme_transport_id trid was declared, but not
initialized. In spdk_nvme_transport_id_compare() function
the trid.trstring was used if the transport was specified as
SPDK_NVME_TRANSPORT_CUSTOM, which may lead to undesired effects
as it was not initialized in this place. Now it will point to
empty string.
It was also possible that trid->subnqn was not NULL-terminated,
which was wrong. Now it is corrected.

Change-Id: I750f58a7ae39ab3179cc2e793cd8059bdacd234d
Signed-off-by: default avatarMarcin Spiewak <marcin.spiewak@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/18143


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
parent 401d3c53
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -5580,7 +5580,12 @@ build_trid_from_log_page_entry(struct spdk_nvme_transport_id *trid,
	trid->adrfam = entry->adrfam;
	memcpy(trid->traddr, entry->traddr, sizeof(entry->traddr));
	memcpy(trid->trsvcid, entry->trsvcid, sizeof(entry->trsvcid));
	memcpy(trid->subnqn, entry->subnqn, sizeof(trid->subnqn));
	/* Because the source buffer (entry->subnqn) is longer than trid->subnqn, and
	 * before call to this function trid->subnqn is zeroed out, we need
	 * to copy sizeof(trid->subnqn) minus one byte to make sure the last character
	 * remains 0. Then we can shorten the string (replace ' ' with 0) if required
	 */
	memcpy(trid->subnqn, entry->subnqn, sizeof(trid->subnqn) - 1);

	/* We want the traddr, trsvcid and subnqn fields to be NULL-terminated.
	 * But the log page entries typically pad them with spaces, not zeroes.
@@ -5636,7 +5641,7 @@ remove_discovery_entry(struct nvme_ctrlr *nvme_ctrlr)
{
	struct discovery_ctx *d_ctx;
	struct nvme_path_id *path_id;
	struct spdk_nvme_transport_id trid;
	struct spdk_nvme_transport_id trid = {};
	struct discovery_entry_ctx *entry_ctx, *tmp;

	path_id = TAILQ_FIRST(&nvme_ctrlr->trids);
@@ -5665,7 +5670,7 @@ discovery_remove_controllers(struct discovery_ctx *ctx)
	struct spdk_nvmf_discovery_log_page *log_page = ctx->log_page;
	struct discovery_entry_ctx *entry_ctx, *tmp;
	struct spdk_nvmf_discovery_log_page_entry *new_entry, *old_entry;
	struct spdk_nvme_transport_id old_trid;
	struct spdk_nvme_transport_id old_trid = {};
	uint64_t numrec, i;
	bool found;