mirror of
https://github.com/ipxe/ipxe
synced 2025-12-20 03:55:46 +03:00
[slam] Eliminate variable-length stack allocation
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -656,13 +656,18 @@ static struct interface_descriptor slam_xfer_desc =
|
|||||||
static int slam_parse_multicast_address ( struct slam_request *slam,
|
static int slam_parse_multicast_address ( struct slam_request *slam,
|
||||||
const char *path,
|
const char *path,
|
||||||
struct sockaddr_in *address ) {
|
struct sockaddr_in *address ) {
|
||||||
char path_dup[ strlen ( path ) /* no +1 */ ];
|
char *path_dup;
|
||||||
char *sep;
|
char *sep;
|
||||||
char *end;
|
char *end;
|
||||||
|
int rc;
|
||||||
|
|
||||||
/* Create temporary copy of path, minus the leading '/' */
|
/* Create temporary copy of path, minus the leading '/' */
|
||||||
assert ( *path == '/' );
|
assert ( *path == '/' );
|
||||||
memcpy ( path_dup, ( path + 1 ) , sizeof ( path_dup ) );
|
path_dup = strdup ( path + 1 );
|
||||||
|
if ( ! path_dup ) {
|
||||||
|
rc = -ENOMEM;
|
||||||
|
goto err_strdup;
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse port, if present */
|
/* Parse port, if present */
|
||||||
sep = strchr ( path_dup, ':' );
|
sep = strchr ( path_dup, ':' );
|
||||||
@@ -672,7 +677,8 @@ static int slam_parse_multicast_address ( struct slam_request *slam,
|
|||||||
if ( *end != '\0' ) {
|
if ( *end != '\0' ) {
|
||||||
DBGC ( slam, "SLAM %p invalid multicast port "
|
DBGC ( slam, "SLAM %p invalid multicast port "
|
||||||
"\"%s\"\n", slam, sep );
|
"\"%s\"\n", slam, sep );
|
||||||
return -EINVAL;
|
rc = -EINVAL;
|
||||||
|
goto err_port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -680,10 +686,18 @@ static int slam_parse_multicast_address ( struct slam_request *slam,
|
|||||||
if ( inet_aton ( path_dup, &address->sin_addr ) == 0 ) {
|
if ( inet_aton ( path_dup, &address->sin_addr ) == 0 ) {
|
||||||
DBGC ( slam, "SLAM %p invalid multicast address \"%s\"\n",
|
DBGC ( slam, "SLAM %p invalid multicast address \"%s\"\n",
|
||||||
slam, path_dup );
|
slam, path_dup );
|
||||||
return -EINVAL;
|
rc = -EINVAL;
|
||||||
|
goto err_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
/* Success */
|
||||||
|
rc = 0;
|
||||||
|
|
||||||
|
err_addr:
|
||||||
|
err_port:
|
||||||
|
free ( path_dup );
|
||||||
|
err_strdup:
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user