summaryrefslogtreecommitdiffstats
path: root/src/net/udp/tftp.c
diff options
context:
space:
mode:
authorMichael Brown2020-02-16 21:08:20 +0100
committerMichael Brown2020-02-16 21:08:20 +0100
commitc625681ca185849d58f2f848de22d6733ff77786 (patch)
tree175d0bf52da75145f8c96a15e623321c2f537cf0 /src/net/udp/tftp.c
parent[travis] Ensure that most recent tag is always available (diff)
downloadipxe-c625681ca185849d58f2f848de22d6733ff77786.tar.gz
ipxe-c625681ca185849d58f2f848de22d6733ff77786.tar.xz
ipxe-c625681ca185849d58f2f848de22d6733ff77786.zip
[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>
Diffstat (limited to 'src/net/udp/tftp.c')
-rw-r--r--src/net/udp/tftp.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/src/net/udp/tftp.c b/src/net/udp/tftp.c
index 6ce27497..a0dac1ec 100644
--- a/src/net/udp/tftp.c
+++ b/src/net/udp/tftp.c
@@ -545,8 +545,7 @@ static void tftp_timer_expired ( struct retry_timer *timer, int fail ) {
* @v value Option value
* @ret rc Return status code
*/
-static int tftp_process_blksize ( struct tftp_request *tftp,
- const char *value ) {
+static int tftp_process_blksize ( struct tftp_request *tftp, char *value ) {
char *end;
tftp->blksize = strtoul ( value, &end, 10 );
@@ -567,8 +566,7 @@ static int tftp_process_blksize ( struct tftp_request *tftp,
* @v value Option value
* @ret rc Return status code
*/
-static int tftp_process_tsize ( struct tftp_request *tftp,
- const char *value ) {
+static int tftp_process_tsize ( struct tftp_request *tftp, char *value ) {
char *end;
tftp->tsize = strtoul ( value, &end, 10 );
@@ -589,13 +587,11 @@ static int tftp_process_tsize ( struct tftp_request *tftp,
* @v value Option value
* @ret rc Return status code
*/
-static int tftp_process_multicast ( struct tftp_request *tftp,
- const char *value ) {
+static int tftp_process_multicast ( struct tftp_request *tftp, char *value ) {
union {
struct sockaddr sa;
struct sockaddr_in sin;
} socket;
- char buf[ strlen ( value ) + 1 ];
char *addr;
char *port;
char *port_end;
@@ -604,8 +600,7 @@ static int tftp_process_multicast ( struct tftp_request *tftp,
int rc;
/* Split value into "addr,port,mc" fields */
- memcpy ( buf, value, sizeof ( buf ) );
- addr = buf;
+ addr = value;
port = strchr ( addr, ',' );
if ( ! port ) {
DBGC ( tftp, "TFTP %p multicast missing port,mc\n", tftp );
@@ -662,7 +657,7 @@ struct tftp_option {
* @v value Option value
* @ret rc Return status code
*/
- int ( * process ) ( struct tftp_request *tftp, const char *value );
+ int ( * process ) ( struct tftp_request *tftp, char *value );
};
/** Recognised TFTP options */
@@ -682,7 +677,7 @@ static struct tftp_option tftp_options[] = {
* @ret rc Return status code
*/
static int tftp_process_option ( struct tftp_request *tftp,
- const char *name, const char *value ) {
+ const char *name, char *value ) {
struct tftp_option *option;
for ( option = tftp_options ; option->name ; option++ ) {