(i)scsi: check strlen before copy

Make sure that we have space for termination char '\0'

Change-Id: Iaebdad3b4278ee322bd78247acc7f0997c3f4b44
Signed-off-by: Ziye Yang <ziye.yang@intel.com>
This commit is contained in:
Ziye Yang 2017-03-24 10:41:27 +08:00 committed by Ben Walker
parent 2abea9da4e
commit ef91841763
2 changed files with 12 additions and 5 deletions

View File

@ -1442,9 +1442,16 @@ spdk_iscsi_op_login_session_normal(struct spdk_iscsi_conn *conn,
memset(conn->target_short_name, 0, MAX_TARGET_NAME);
target_short_name = strstr(target_name, ":");
if (target_short_name != NULL)
strncpy(conn->target_short_name, target_short_name + 1,
MAX_TARGET_NAME);
if (target_short_name != NULL) {
target_short_name++; /* Advance past the ':' */
if (strlen(target_short_name) >= MAX_TARGET_NAME) {
SPDK_ERRLOG("Target Short Name (%s) is more than %u characters\n",
target_short_name, MAX_TARGET_NAME);
return rc;
}
snprintf(conn->target_short_name, MAX_TARGET_NAME, "%s",
target_short_name);
}
pthread_mutex_lock(&g_spdk_iscsi.mutex);
rc = spdk_iscsi_op_login_check_target(conn, rsp_pdu, target_name,

View File

@ -38,13 +38,13 @@ int
spdk_scsi_port_construct(struct spdk_scsi_port *port, uint64_t id, uint16_t index,
const char *name)
{
if (strlen(name) > sizeof(port->name)) {
if (strlen(name) >= sizeof(port->name)) {
SPDK_ERRLOG("port name too long\n");
return -1;
}
port->id = id;
port->index = index;
strncpy(port->name, name, sizeof(port->name));
snprintf(port->name, sizeof(port->name), "%s", name);
return 0;
}