From c0d6eb9d1140f7438ce96c847e11396042e28e45 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Mon, 9 Apr 2018 16:08:14 -0700 Subject: [PATCH] iscsi: Remove all uses of strncpy strncpy is going to be added to the list of banned functions because it does not guarantee strings are null terminated. Change-Id: I5fe2f9e717bb65caf6fa26dca075aa974c7f7173 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/407021 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- lib/iscsi/init_grp.c | 4 ++-- lib/iscsi/portal_grp.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/iscsi/init_grp.c b/lib/iscsi/init_grp.c index c46fb8074..ea72849b0 100644 --- a/lib/iscsi/init_grp.c +++ b/lib/iscsi/init_grp.c @@ -106,7 +106,7 @@ spdk_iscsi_init_grp_add_initiator(struct spdk_iscsi_init_grp *ig, char *name) if (p != NULL) { SPDK_WARNLOG("Please use \"%s\" instead of \"%s\"\n", "ANY", "ALL"); SPDK_WARNLOG("Converting \"%s\" to \"%s\" automatically\n", "ALL", "ANY"); - strncpy(p, "ANY", 3); + memcpy(p, "ANY", 3); } TAILQ_INSERT_TAIL(&ig->initiator_head, iname, tailq); @@ -239,7 +239,7 @@ spdk_iscsi_init_grp_add_netmask(struct spdk_iscsi_init_grp *ig, char *mask) if (p != NULL) { SPDK_WARNLOG("Please use \"%s\" instead of \"%s\"\n", "ANY", "ALL"); SPDK_WARNLOG("Converting \"%s\" to \"%s\" automatically\n", "ALL", "ANY"); - strncpy(p, "ANY", 3); + memcpy(p, "ANY", 3); } TAILQ_INSERT_TAIL(&ig->netmask_head, imask, tailq); diff --git a/lib/iscsi/portal_grp.c b/lib/iscsi/portal_grp.c index 6c6f7fedd..0a09e28b9 100644 --- a/lib/iscsi/portal_grp.c +++ b/lib/iscsi/portal_grp.c @@ -253,7 +253,7 @@ spdk_iscsi_parse_portal(const char *portalstring, struct spdk_iscsi_portal **ip, SPDK_ERRLOG("malloc() failed for host\n"); goto error_out; } - strncpy(host, portalstring, len); + memcpy(host, portalstring, len); host[len] = '\0'; } @@ -288,7 +288,7 @@ spdk_iscsi_parse_portal(const char *portalstring, struct spdk_iscsi_portal **ip, SPDK_ERRLOG("malloc() failed for port\n"); goto error_out; } - strncpy(port, p + 1, len); + memcpy(port, p + 1, len); port[len] = '\0'; } } @@ -308,7 +308,7 @@ spdk_iscsi_parse_portal(const char *portalstring, struct spdk_iscsi_portal **ip, SPDK_ERRLOG("malloc() failed for cpumask\n"); goto error_out; } - strncpy(cpumask, p + 1, len); + memcpy(cpumask, p + 1, len); cpumask[len] = '\0'; } }