Browse Source

[slam] Eliminate variable-length stack allocation

Signed-off-by: Michael Brown <mcb30@ipxe.org>
master
Michael Brown 4 years ago
parent
commit
c5306bcfa5
1 changed files with 19 additions and 5 deletions
  1. 19
    5
      src/net/udp/slam.c

+ 19
- 5
src/net/udp/slam.c View File

656
 static int slam_parse_multicast_address ( struct slam_request *slam,
656
 static int slam_parse_multicast_address ( struct slam_request *slam,
657
 					  const char *path,
657
 					  const char *path,
658
 					  struct sockaddr_in *address ) {
658
 					  struct sockaddr_in *address ) {
659
-	char path_dup[ strlen ( path ) /* no +1 */ ];
659
+	char *path_dup;
660
 	char *sep;
660
 	char *sep;
661
 	char *end;
661
 	char *end;
662
+	int rc;
662
 
663
 
663
 	/* Create temporary copy of path, minus the leading '/' */
664
 	/* Create temporary copy of path, minus the leading '/' */
664
 	assert ( *path == '/' );
665
 	assert ( *path == '/' );
665
-	memcpy ( path_dup, ( path + 1 ) , sizeof ( path_dup ) );
666
+	path_dup = strdup ( path + 1 );
667
+	if ( ! path_dup ) {
668
+		rc = -ENOMEM;
669
+		goto err_strdup;
670
+	}
666
 
671
 
667
 	/* Parse port, if present */
672
 	/* Parse port, if present */
668
 	sep = strchr ( path_dup, ':' );
673
 	sep = strchr ( path_dup, ':' );
672
 		if ( *end != '\0' ) {
677
 		if ( *end != '\0' ) {
673
 			DBGC ( slam, "SLAM %p invalid multicast port "
678
 			DBGC ( slam, "SLAM %p invalid multicast port "
674
 			       "\"%s\"\n", slam, sep );
679
 			       "\"%s\"\n", slam, sep );
675
-			return -EINVAL;
680
+			rc = -EINVAL;
681
+			goto err_port;
676
 		}
682
 		}
677
 	}
683
 	}
678
 
684
 
680
 	if ( inet_aton ( path_dup, &address->sin_addr ) == 0 ) {
686
 	if ( inet_aton ( path_dup, &address->sin_addr ) == 0 ) {
681
 		DBGC ( slam, "SLAM %p invalid multicast address \"%s\"\n",
687
 		DBGC ( slam, "SLAM %p invalid multicast address \"%s\"\n",
682
 		       slam, path_dup );
688
 		       slam, path_dup );
683
-		return -EINVAL;
689
+		rc = -EINVAL;
690
+		goto err_addr;
684
 	}
691
 	}
685
 
692
 
686
-	return 0;
693
+	/* Success */
694
+	rc = 0;
695
+
696
+ err_addr:
697
+ err_port:
698
+	free ( path_dup );
699
+ err_strdup:
700
+	return rc;
687
 }
701
 }
688
 
702
 
689
 /**
703
 /**

Loading…
Cancel
Save