lib/iscsi: Use fixed size char array to parse string of portal address and port
Dynamically allocated string is not necessary, and use fixed size char array for simplification instead. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: Iada118fbc81f24d0273269f4980bab28bd9c2c23 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3161 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
92b28effd4
commit
c0d796d7f8
@ -216,13 +216,14 @@ iscsi_portal_close(struct spdk_iscsi_portal *p)
|
|||||||
static int
|
static int
|
||||||
iscsi_parse_portal(const char *portalstring, struct spdk_iscsi_portal **ip)
|
iscsi_parse_portal(const char *portalstring, struct spdk_iscsi_portal **ip)
|
||||||
{
|
{
|
||||||
char *host = NULL, *port = NULL;
|
char host[MAX_PORTAL_ADDR + 1] = {};
|
||||||
int len, rc = -1;
|
char port[MAX_PORTAL_PORT + 1] = {};
|
||||||
|
int len;
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
if (portalstring == NULL) {
|
if (portalstring == NULL) {
|
||||||
SPDK_ERRLOG("portal error\n");
|
SPDK_ERRLOG("portal error\n");
|
||||||
goto error_out;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* IP address */
|
/* IP address */
|
||||||
@ -231,7 +232,7 @@ iscsi_parse_portal(const char *portalstring, struct spdk_iscsi_portal **ip)
|
|||||||
p = strchr(portalstring + 1, ']');
|
p = strchr(portalstring + 1, ']');
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
SPDK_ERRLOG("portal error\n");
|
SPDK_ERRLOG("portal error\n");
|
||||||
goto error_out;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
} else {
|
} else {
|
||||||
@ -243,29 +244,20 @@ iscsi_parse_portal(const char *portalstring, struct spdk_iscsi_portal **ip)
|
|||||||
}
|
}
|
||||||
|
|
||||||
len = p - portalstring;
|
len = p - portalstring;
|
||||||
host = malloc(len + 1);
|
if (len > MAX_PORTAL_ADDR) {
|
||||||
if (host == NULL) {
|
return -EINVAL;
|
||||||
SPDK_ERRLOG("malloc() failed for host\n");
|
|
||||||
goto error_out;
|
|
||||||
}
|
}
|
||||||
memcpy(host, portalstring, len);
|
memcpy(host, portalstring, len);
|
||||||
host[len] = '\0';
|
host[len] = '\0';
|
||||||
|
|
||||||
/* Port number (IPv4 and IPv6 are the same) */
|
/* Port number (IPv4 and IPv6 are the same) */
|
||||||
if (p[0] == '\0') {
|
if (p[0] == '\0') {
|
||||||
port = malloc(PORTNUMSTRLEN);
|
snprintf(port, MAX_PORTAL_PORT, "%d", DEFAULT_PORT);
|
||||||
if (!port) {
|
|
||||||
SPDK_ERRLOG("malloc() failed for port\n");
|
|
||||||
goto error_out;
|
|
||||||
}
|
|
||||||
snprintf(port, PORTNUMSTRLEN, "%d", DEFAULT_PORT);
|
|
||||||
} else {
|
} else {
|
||||||
p++;
|
p++;
|
||||||
len = strlen(p);
|
len = strlen(p);
|
||||||
port = malloc(len + 1);
|
if (len > MAX_PORTAL_PORT) {
|
||||||
if (port == NULL) {
|
return -EINVAL;
|
||||||
SPDK_ERRLOG("malloc() failed for port\n");
|
|
||||||
goto error_out;
|
|
||||||
}
|
}
|
||||||
memcpy(port, p, len);
|
memcpy(port, p, len);
|
||||||
port[len] = '\0';
|
port[len] = '\0';
|
||||||
@ -273,15 +265,10 @@ iscsi_parse_portal(const char *portalstring, struct spdk_iscsi_portal **ip)
|
|||||||
|
|
||||||
*ip = iscsi_portal_create(host, port);
|
*ip = iscsi_portal_create(host, port);
|
||||||
if (!*ip) {
|
if (!*ip) {
|
||||||
goto error_out;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = 0;
|
return 0;
|
||||||
error_out:
|
|
||||||
free(host);
|
|
||||||
free(port);
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct spdk_iscsi_portal_grp *
|
struct spdk_iscsi_portal_grp *
|
||||||
|
Loading…
Reference in New Issue
Block a user