]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[infiniband] Eliminate variable-length stack allocation
authorMichael Brown <mcb30@ipxe.org>
Sun, 16 Feb 2020 21:25:27 +0000 (21:25 +0000)
committerMichael Brown <mcb30@ipxe.org>
Sun, 16 Feb 2020 21:42:35 +0000 (21:42 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/net/infiniband/ib_srp.c

index cf1ef3bfdfac33094f0a1345a483b8a0e711f5ef..4913f449c2c70fb1de9680ee0d53c0f163688654 100644 (file)
@@ -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;
 }
 
 /**