Browse Source

[tftp] Eliminate unnecessary variable-length stack allocation

Eliminate an unnecessary variable-length stack allocation and memory
copy by allowing TFTP option processors to modify the option string
in-place.

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

+ 6
- 11
src/net/udp/tftp.c View File

@@ -545,8 +545,7 @@ static void tftp_timer_expired ( struct retry_timer *timer, int fail ) {
545 545
  * @v value		Option value
546 546
  * @ret rc		Return status code
547 547
  */
548
-static int tftp_process_blksize ( struct tftp_request *tftp,
549
-				  const char *value ) {
548
+static int tftp_process_blksize ( struct tftp_request *tftp, char *value ) {
550 549
 	char *end;
551 550
 
552 551
 	tftp->blksize = strtoul ( value, &end, 10 );
@@ -567,8 +566,7 @@ static int tftp_process_blksize ( struct tftp_request *tftp,
567 566
  * @v value		Option value
568 567
  * @ret rc		Return status code
569 568
  */
570
-static int tftp_process_tsize ( struct tftp_request *tftp,
571
-				const char *value ) {
569
+static int tftp_process_tsize ( struct tftp_request *tftp, char *value ) {
572 570
 	char *end;
573 571
 
574 572
 	tftp->tsize = strtoul ( value, &end, 10 );
@@ -589,13 +587,11 @@ static int tftp_process_tsize ( struct tftp_request *tftp,
589 587
  * @v value		Option value
590 588
  * @ret rc		Return status code
591 589
  */
592
-static int tftp_process_multicast ( struct tftp_request *tftp,
593
-				    const char *value ) {
590
+static int tftp_process_multicast ( struct tftp_request *tftp, char *value ) {
594 591
 	union {
595 592
 		struct sockaddr sa;
596 593
 		struct sockaddr_in sin;
597 594
 	} socket;
598
-	char buf[ strlen ( value ) + 1 ];
599 595
 	char *addr;
600 596
 	char *port;
601 597
 	char *port_end;
@@ -604,8 +600,7 @@ static int tftp_process_multicast ( struct tftp_request *tftp,
604 600
 	int rc;
605 601
 
606 602
 	/* Split value into "addr,port,mc" fields */
607
-	memcpy ( buf, value, sizeof ( buf ) );
608
-	addr = buf;
603
+	addr = value;
609 604
 	port = strchr ( addr, ',' );
610 605
 	if ( ! port ) {
611 606
 		DBGC ( tftp, "TFTP %p multicast missing port,mc\n", tftp );
@@ -662,7 +657,7 @@ struct tftp_option {
662 657
 	 * @v value	Option value
663 658
 	 * @ret rc	Return status code
664 659
 	 */
665
-	int ( * process ) ( struct tftp_request *tftp, const char *value );
660
+	int ( * process ) ( struct tftp_request *tftp, char *value );
666 661
 };
667 662
 
668 663
 /** Recognised TFTP options */
@@ -682,7 +677,7 @@ static struct tftp_option tftp_options[] = {
682 677
  * @ret rc		Return status code
683 678
  */
684 679
 static int tftp_process_option ( struct tftp_request *tftp,
685
-				 const char *name, const char *value ) {
680
+				 const char *name, char *value ) {
686 681
 	struct tftp_option *option;
687 682
 
688 683
 	for ( option = tftp_options ; option->name ; option++ ) {

Loading…
Cancel
Save