Browse Source

[infiniband] Eliminate variable-length stack allocation

Signed-off-by: Michael Brown <mcb30@ipxe.org>
master
Michael Brown 4 years ago
parent
commit
6248ac396a
1 changed files with 18 additions and 6 deletions
  1. 18
    6
      src/net/infiniband/ib_srp.c

+ 18
- 6
src/net/infiniband/ib_srp.c View File

498
 static int ib_srp_parse_root_path ( const char *rp_string,
498
 static int ib_srp_parse_root_path ( const char *rp_string,
499
 				    struct ib_srp_root_path *rp ) {
499
 				    struct ib_srp_root_path *rp ) {
500
 	struct ib_srp_root_path_parser *parser;
500
 	struct ib_srp_root_path_parser *parser;
501
-	char rp_string_copy[ strlen ( rp_string ) + 1 ];
502
 	char *rp_comp[IB_SRP_NUM_RP_COMPONENTS];
501
 	char *rp_comp[IB_SRP_NUM_RP_COMPONENTS];
503
-	char *rp_string_tmp = rp_string_copy;
502
+	char *rp_string_copy;
503
+	char *rp_string_tmp;
504
 	unsigned int i = 0;
504
 	unsigned int i = 0;
505
 	int rc;
505
 	int rc;
506
 
506
 
507
+	/* Create modifiable copy of root path */
508
+	rp_string_copy = strdup ( rp_string );
509
+	if ( ! rp_string_copy ) {
510
+		rc = -ENOMEM;
511
+		goto err_strdup;
512
+	}
513
+	rp_string_tmp = rp_string_copy;
514
+
507
 	/* Split root path into component parts */
515
 	/* Split root path into component parts */
508
-	strcpy ( rp_string_copy, rp_string );
509
 	while ( 1 ) {
516
 	while ( 1 ) {
510
 		rp_comp[i++] = rp_string_tmp;
517
 		rp_comp[i++] = rp_string_tmp;
511
 		if ( i == IB_SRP_NUM_RP_COMPONENTS )
518
 		if ( i == IB_SRP_NUM_RP_COMPONENTS )
514
 			if ( ! *rp_string_tmp ) {
521
 			if ( ! *rp_string_tmp ) {
515
 				DBG ( "IBSRP root path \"%s\" too short\n",
522
 				DBG ( "IBSRP root path \"%s\" too short\n",
516
 				      rp_string );
523
 				      rp_string );
517
-				return -EINVAL_RP_TOO_SHORT;
524
+				rc = -EINVAL_RP_TOO_SHORT;
525
+				goto err_split;
518
 			}
526
 			}
519
 		}
527
 		}
520
 		*(rp_string_tmp++) = '\0';
528
 		*(rp_string_tmp++) = '\0';
527
 			DBG ( "IBSRP could not parse \"%s\" in root path "
535
 			DBG ( "IBSRP could not parse \"%s\" in root path "
528
 			      "\"%s\": %s\n", rp_comp[i], rp_string,
536
 			      "\"%s\": %s\n", rp_comp[i], rp_string,
529
 			      strerror ( rc ) );
537
 			      strerror ( rc ) );
530
-			return rc;
538
+			goto err_parse;
531
 		}
539
 		}
532
 	}
540
 	}
533
 
541
 
534
-	return 0;
542
+ err_parse:
543
+ err_split:
544
+	free ( rp_string_copy );
545
+ err_strdup:
546
+	return rc;
535
 }
547
 }
536
 
548
 
537
 /**
549
 /**

Loading…
Cancel
Save