diff options
author | Michael Brown <mcb30@ipxe.org> | 2020-02-16 21:25:27 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2020-02-16 21:42:35 +0000 |
commit | 6248ac396aaf9ccff7cda91080305ad2dc08d8cc (patch) | |
tree | 3746bbc5872c4ceeebb9d2020a53a93871e38468 /src/net | |
parent | c625681ca185849d58f2f848de22d6733ff77786 (diff) | |
download | ipxe-6248ac396aaf9ccff7cda91080305ad2dc08d8cc.tar.gz |
[infiniband] Eliminate variable-length stack allocation
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/infiniband/ib_srp.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/net/infiniband/ib_srp.c b/src/net/infiniband/ib_srp.c index cf1ef3bfd..4913f449c 100644 --- a/src/net/infiniband/ib_srp.c +++ b/src/net/infiniband/ib_srp.c @@ -498,14 +498,21 @@ static struct ib_srp_root_path_parser ib_srp_rp_parser[] = { static int ib_srp_parse_root_path ( const char *rp_string, struct ib_srp_root_path *rp ) { struct ib_srp_root_path_parser *parser; - char rp_string_copy[ strlen ( rp_string ) + 1 ]; char *rp_comp[IB_SRP_NUM_RP_COMPONENTS]; - char *rp_string_tmp = rp_string_copy; + char *rp_string_copy; + char *rp_string_tmp; unsigned int i = 0; int rc; + /* Create modifiable copy of root path */ + rp_string_copy = strdup ( rp_string ); + if ( ! rp_string_copy ) { + rc = -ENOMEM; + goto err_strdup; + } + rp_string_tmp = rp_string_copy; + /* Split root path into component parts */ - strcpy ( rp_string_copy, rp_string ); while ( 1 ) { rp_comp[i++] = rp_string_tmp; if ( i == IB_SRP_NUM_RP_COMPONENTS ) @@ -514,7 +521,8 @@ static int ib_srp_parse_root_path ( const char *rp_string, if ( ! *rp_string_tmp ) { DBG ( "IBSRP root path \"%s\" too short\n", rp_string ); - return -EINVAL_RP_TOO_SHORT; + rc = -EINVAL_RP_TOO_SHORT; + goto err_split; } } *(rp_string_tmp++) = '\0'; @@ -527,11 +535,15 @@ static int ib_srp_parse_root_path ( const char *rp_string, DBG ( "IBSRP could not parse \"%s\" in root path " "\"%s\": %s\n", rp_comp[i], rp_string, strerror ( rc ) ); - return rc; + goto err_parse; } } - return 0; + err_parse: + err_split: + free ( rp_string_copy ); + err_strdup: + return rc; } /** |