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

Loading…
Cancel
Save