Skip to contentSkip to conversation

slirp/tftp.c: fix mode field

PATCH In review Sergei Gavrikov 3 participants 8 messages Jan 10, 2011 – Jan 13, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 slirp/tftp.c: fix mode field

Hi,

According to RFC 1350 http://www.ietf.org/rfc/rfc1350.txt [Page 5]:

The mode field contains the string "netascii", "octet", or "mail" (or any combination of upper and lower case, such as "NETASCII", NetAscii", etc.)

Unfortunately, current implementation of internal TFTP server breaks the requests with the mode fields like "OCTET\0". For example, the RedBoot's TFTP client sends the same (in upper case). So, it is not possible to get internal TFTP working with RedBoot loader. If you do not have doubts about STRCASECMP(3), a patch is provided.

Thanks,
Sergei

---
 slirp/tftp.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
slirp/tftp.c +1 -1
index 55e4692..6ad1da0 100644
@@ -311,7 +311,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
     return;
   }
 
-  if (memcmp(&tp->x.tp_buf[k], "octet\0", 6) != 0) {
+  if (strcasecmp(&tp->x.tp_buf[k], "octet") != 0) {
       tftp_send_error(spt, 4, "Unsupported transfer mode", tp);
       return;
   }
#1 lore raw
Quoted 11 lines · Sergei Gavrikov

According to RFC 1350 http://www.ietf.org/rfc/rfc1350.txt [Page 5]:

The mode field contains the string "netascii", "octet", or "mail" (or any combination of upper and lower case, such as "NETASCII", NetAscii", etc.)

Unfortunately, current implementation of internal TFTP server breaks the requests with the mode fields like "OCTET\0". For example, the RedBoot's TFTP client sends the same (in upper case). So, it is not possible to get internal TFTP working with RedBoot loader. If you do not have doubts about STRCASECMP(3), a patch is provided.

...

slirp/tftp.c static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen) · line 314

Quoted 10 lines
slirp/tftp.c +1 -1
index 55e4692..6ad1da0 100644
@@ -311,7 +311,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
     return;
   }
 
-  if (memcmp(&tp->x.tp_buf[k], "octet\0", 6) != 0) {
+  if (strcasecmp(&tp->x.tp_buf[k], "octet") != 0) {

The above adds a warning, renewed (no warning).

---
 slirp/tftp.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
slirp/tftp.c +1 -1
index 55e4692..a455ad1 100644
@@ -311,7 +311,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
     return;
   }
 
-  if (memcmp(&tp->x.tp_buf[k], "octet\0", 6) != 0) {
+  if (strcasecmp((const char *)&tp->x.tp_buf[k], "octet") != 0) {
       tftp_send_error(spt, 4, "Unsupported transfer mode", tp);
       return;
   }
#2 lore raw

slirp/tftp.c static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen) · line 317

Quoted 13 lines · Sergei Gavrikov
slirp/tftp.c +1 -1
index 55e4692..a455ad1 100644
@@ -311,7 +311,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
     return;
   }
 
-  if (memcmp(&tp->x.tp_buf[k], "octet\0", 6) != 0) {
+  if (strcasecmp((const char *)&tp->x.tp_buf[k], "octet") != 0) {
       tftp_send_error(spt, 4, "Unsupported transfer mode", tp);
       return;
   }

According to RFC 2349 the "tsize" option is also case-insensitive. Want to include a fix for that in this patch?

Stefan

author Acked-by Stefan Hajnoczi
#3 lore raw
Quoted 10 lines · Stefan Hajnoczi
Quoted 8 lines · Sergei Gavrikov
slirp/tftp.c +0 -0
index 55e4692..a455ad1 100644
@@ -311,7 +311,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
     return;
   }
 
Quoted 8 lines

slirp/tftp.c static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen) · line 317

Quoted 5 lines
slirp/tftp.c +1 -1
-  if (memcmp(&tp->x.tp_buf[k], "octet\0", 6) != 0) {
+  if (strcasecmp((const char *)&tp->x.tp_buf[k], "octet") != 0) {
       tftp_send_error(spt, 4, "Unsupported transfer mode", tp);
       return;
   }

According to RFC 2349 the "tsize" option is also case-insensitive. Want to include a fix for that in this patch?

It was good to know. If you mean the below I "merge" that in one. Thank you for review.

Sergei

----

 slirp/tftp.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
slirp/tftp.c +2 -2
index 55e4692..1821648 100644
@@ -311,7 +311,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
     return;
   }
 
-  if (memcmp(&tp->x.tp_buf[k], "octet\0", 6) != 0) {
+  if (strcasecmp((const char *)&tp->x.tp_buf[k], "octet") != 0) {
       tftp_send_error(spt, 4, "Unsupported transfer mode", tp);
       return;
   }
@@ -351,7 +351,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
       value = (const char *)&tp->x.tp_buf[k];
       k += strlen(value) + 1;
 
-      if (strcmp(key, "tsize") == 0) {
+      if (strcasecmp(key, "tsize") == 0) {
 	  int tsize = atoi(value);
 	  struct stat stat_p;
 
#6 lore raw

PATCH 1/1 slirp: Use strcasecmp() to check tftp mode, tsize

In reply to Stefan Hajnoczi

From: Sergei Gavrikov <[email protected]>

According to RFC 1350 (TFTP Revision 2) the mode field can contain any combination of upper and lower case; also RFC 2349 propagates that the transfer size option ("tsize") is case in-sensitive too.

Current implementation of embedded TFTP server missed that what does mess some TFTP clients. Fixed by using STRCASECMP(3) in the required places.

---
 slirp/tftp.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
slirp/tftp.c +2 -2
index 55e4692..1821648 100644
@@ -311,7 +311,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
     return;
   }
 
-  if (memcmp(&tp->x.tp_buf[k], "octet\0", 6) != 0) {
+  if (strcasecmp((const char *)&tp->x.tp_buf[k], "octet") != 0) {
       tftp_send_error(spt, 4, "Unsupported transfer mode", tp);
       return;
   }
@@ -351,7 +351,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
       value = (const char *)&tp->x.tp_buf[k];
       k += strlen(value) + 1;
 
-      if (strcmp(key, "tsize") == 0) {
+      if (strcasecmp(key, "tsize") == 0) {
 	  int tsize = atoi(value);
 	  struct stat stat_p;
 
#7 lore raw

Re: [Qemu-devel] [PATCHv1] slirp: Use strcasecmp() to check tftp mode, tsize

Quoted 6 lines · Sergei Gavrikov

From: Sergei Gavrikov <[email protected]>

According to RFC 1350 (TFTP Revision 2) the mode field can contain any combination of upper and lower case; also RFC 2349 propagates that the transfer size option ("tsize") is case in-sensitive too.

Quoted 6 lines

Current implementation of embedded TFTP server missed that what does mess some TFTP clients. Fixed by using STRCASECMP(3) in the required places.

I've applied this, thanks both of you.

Cheers

Quoted 27 lines
---
 slirp/tftp.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
slirp/tftp.c +2 -2
index 55e4692..1821648 100644
@@ -311,7 +311,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
     return;
   }
 
-  if (memcmp(&tp->x.tp_buf[k], "octet\0", 6) != 0) {
+  if (strcasecmp((const char *)&tp->x.tp_buf[k], "octet") != 0) {
       tftp_send_error(spt, 4, "Unsupported transfer mode", tp);
       return;
   }
@@ -351,7 +351,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
       value = (const char *)&tp->x.tp_buf[k];
       k += strlen(value) + 1;
 
-      if (strcmp(key, "tsize") == 0) {
+      if (strcasecmp(key, "tsize") == 0) {
 	  int tsize = atoi(value);
 	  struct stat stat_p;