Commit 901aafe6 authored by Daniel Verkamp's avatar Daniel Verkamp
Browse files

nvmf_tgt/rpc: check trtype and adrfam for NULL



If the NVMe library trtype and adrfam translation functions are passed
an unknown value, they may return NULL.  This shouldn't normally happen,
since any supported transport type or address family in the NVMe-oF
target should always be supported in the string lookup functions, but
add a fallback anyway to satisfy the static analyzer.

Change-Id: Icadf991d6742a2a759b5793253b71b4eabc763ed
Signed-off-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/383313


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent e55a3c94
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -70,17 +70,27 @@ dump_nvmf_subsystem(struct spdk_json_write_ctx *w, struct nvmf_tgt_subsystem *tg
	for (listener = spdk_nvmf_subsystem_get_first_listener(subsystem); listener != NULL;
	     listener = spdk_nvmf_subsystem_get_next_listener(subsystem, listener)) {
		const struct spdk_nvme_transport_id *trid;
		const char *trtype;
		const char *adrfam;

		trid = spdk_nvmf_listener_get_trid(listener);

		spdk_json_write_object_begin(w);
		trtype = spdk_nvme_transport_id_trtype_str(trid->trtype);
		if (trtype == NULL) {
			trtype = "unknown";
		}
		adrfam = spdk_nvme_transport_id_adrfam_str(trid->adrfam);
		if (adrfam == NULL) {
			adrfam = "unknown";
		}
		/* NOTE: "transport" is kept for compatibility; new code should use "trtype" */
		spdk_json_write_name(w, "transport");
		spdk_json_write_string(w, spdk_nvme_transport_id_trtype_str(trid->trtype));
		spdk_json_write_string(w, trtype);
		spdk_json_write_name(w, "trtype");
		spdk_json_write_string(w, spdk_nvme_transport_id_trtype_str(trid->trtype));
		spdk_json_write_string(w, trtype);
		spdk_json_write_name(w, "adrfam");
		spdk_json_write_string(w, spdk_nvme_transport_id_adrfam_str(trid->adrfam));
		spdk_json_write_string(w, adrfam);
		spdk_json_write_name(w, "traddr");
		spdk_json_write_string(w, trid->traddr);
		spdk_json_write_name(w, "trsvcid");