Commit f92411c4 authored by Tomasz Zawadzki's avatar Tomasz Zawadzki Committed by Jim Harris
Browse files

lib/nvme_tcp: check destination port before parsing address



nvme_tcp_parse_addr() uses getaddrinfo() to parse the address.
Depending on the system behavior of this function differs.
On FreeBSD the port is verified not to be exceeding 65535
for IPv4, meanwhile Linux does not check it at this point.

test_nvme_tcp_qpair_connect_sock() UT was attempting to
test the code path that is moved in this patch, but
on FreeBSD was encountering failure during getaddrinfo()
with different error code.

This patch moves the destination port check before
parsing addresses to take the same path regardless of
the system used.

Fixes #2936

Change-Id: I271e8c32e07a15dcf0e0ee7e90dd174c96b18858
Signed-off-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17095


Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 97aa2c86
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -1890,6 +1890,13 @@ nvme_tcp_qpair_connect_sock(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpai

	memset(&dst_addr, 0, sizeof(dst_addr));

	port = spdk_strtol(ctrlr->trid.trsvcid, 10);
	if (port <= 0 || port >= INT_MAX) {
		SPDK_ERRLOG("Invalid port: %s\n", ctrlr->trid.trsvcid);
		rc = -1;
		return rc;
	}

	SPDK_DEBUGLOG(nvme, "trsvcid is %s\n", ctrlr->trid.trsvcid);
	rc = nvme_tcp_parse_addr(&dst_addr, family, ctrlr->trid.traddr, ctrlr->trid.trsvcid);
	if (rc != 0) {
@@ -1906,13 +1913,6 @@ nvme_tcp_qpair_connect_sock(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpai
		}
	}

	port = spdk_strtol(ctrlr->trid.trsvcid, 10);
	if (port <= 0 || port >= INT_MAX) {
		SPDK_ERRLOG("Invalid port: %s\n", ctrlr->trid.trsvcid);
		rc = -1;
		return rc;
	}

	sock_impl_name = ctrlr->opts.psk[0] ? "ssl" : NULL;
	SPDK_DEBUGLOG(nvme, "sock_impl_name is %s\n", sock_impl_name);