mirror of https://github.com/ipxe/ipxe.git
[iscsi] Eliminate variable-length stack allocation in URI parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/106/head
parent
e2e29e7ae3
commit
e3ca211071
|
@ -1948,15 +1948,22 @@ const struct setting reverse_password_setting __setting ( SETTING_AUTH_EXTRA,
|
||||||
*/
|
*/
|
||||||
static int iscsi_parse_root_path ( struct iscsi_session *iscsi,
|
static int iscsi_parse_root_path ( struct iscsi_session *iscsi,
|
||||||
const char *root_path ) {
|
const char *root_path ) {
|
||||||
char rp_copy[ strlen ( root_path ) + 1 ];
|
char *rp_copy;
|
||||||
char *rp_comp[NUM_RP_COMPONENTS];
|
char *rp_comp[NUM_RP_COMPONENTS];
|
||||||
char *rp = rp_copy;
|
char *rp;
|
||||||
int skip = 0;
|
int skip = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
/* Create modifiable copy of root path */
|
||||||
|
rp_copy = strdup ( root_path );
|
||||||
|
if ( ! rp_copy ) {
|
||||||
|
rc = -ENOMEM;
|
||||||
|
goto err_strdup;
|
||||||
|
}
|
||||||
|
rp = rp_copy;
|
||||||
|
|
||||||
/* Split root path into component parts */
|
/* Split root path into component parts */
|
||||||
strcpy ( rp_copy, root_path );
|
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
rp_comp[i++] = rp;
|
rp_comp[i++] = rp;
|
||||||
if ( i == NUM_RP_COMPONENTS )
|
if ( i == NUM_RP_COMPONENTS )
|
||||||
|
@ -1965,7 +1972,8 @@ static int iscsi_parse_root_path ( struct iscsi_session *iscsi,
|
||||||
if ( ! *rp ) {
|
if ( ! *rp ) {
|
||||||
DBGC ( iscsi, "iSCSI %p root path \"%s\" "
|
DBGC ( iscsi, "iSCSI %p root path \"%s\" "
|
||||||
"too short\n", iscsi, root_path );
|
"too short\n", iscsi, root_path );
|
||||||
return -EINVAL_ROOT_PATH_TOO_SHORT;
|
rc = -EINVAL_ROOT_PATH_TOO_SHORT;
|
||||||
|
goto err_split;
|
||||||
} else if ( *rp == '[' ) {
|
} else if ( *rp == '[' ) {
|
||||||
skip = 1;
|
skip = 1;
|
||||||
} else if ( *rp == ']' ) {
|
} else if ( *rp == ']' ) {
|
||||||
|
@ -1977,21 +1985,31 @@ static int iscsi_parse_root_path ( struct iscsi_session *iscsi,
|
||||||
|
|
||||||
/* Use root path components to configure iSCSI session */
|
/* Use root path components to configure iSCSI session */
|
||||||
iscsi->target_address = strdup ( rp_comp[RP_SERVERNAME] );
|
iscsi->target_address = strdup ( rp_comp[RP_SERVERNAME] );
|
||||||
if ( ! iscsi->target_address )
|
if ( ! iscsi->target_address ) {
|
||||||
return -ENOMEM;
|
rc = -ENOMEM;
|
||||||
|
goto err_servername;
|
||||||
|
}
|
||||||
iscsi->target_port = strtoul ( rp_comp[RP_PORT], NULL, 10 );
|
iscsi->target_port = strtoul ( rp_comp[RP_PORT], NULL, 10 );
|
||||||
if ( ! iscsi->target_port )
|
if ( ! iscsi->target_port )
|
||||||
iscsi->target_port = ISCSI_PORT;
|
iscsi->target_port = ISCSI_PORT;
|
||||||
if ( ( rc = scsi_parse_lun ( rp_comp[RP_LUN], &iscsi->lun ) ) != 0 ) {
|
if ( ( rc = scsi_parse_lun ( rp_comp[RP_LUN], &iscsi->lun ) ) != 0 ) {
|
||||||
DBGC ( iscsi, "iSCSI %p invalid LUN \"%s\"\n",
|
DBGC ( iscsi, "iSCSI %p invalid LUN \"%s\"\n",
|
||||||
iscsi, rp_comp[RP_LUN] );
|
iscsi, rp_comp[RP_LUN] );
|
||||||
return rc;
|
goto err_lun;
|
||||||
}
|
}
|
||||||
iscsi->target_iqn = strdup ( rp_comp[RP_TARGETNAME] );
|
iscsi->target_iqn = strdup ( rp_comp[RP_TARGETNAME] );
|
||||||
if ( ! iscsi->target_iqn )
|
if ( ! iscsi->target_iqn ) {
|
||||||
return -ENOMEM;
|
rc = -ENOMEM;
|
||||||
|
goto err_targetname;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
err_targetname:
|
||||||
|
err_lun:
|
||||||
|
err_servername:
|
||||||
|
err_split:
|
||||||
|
free ( rp_copy );
|
||||||
|
err_strdup:
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue