slirp/tftp.c: fix mode field
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
@@ -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 ; }
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@@ -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
@@ -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 ; }
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@@ -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
Sergei Gavrikov
Acked-by Stefan HajnocziQuoted 10 lines · Stefan Hajnoczi
Quoted 8 lines · Sergei Gavrikov
slirp/tftp.c +0
-0@@ -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
@@ -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;
Stefan Hajnoczi
Reviewed-byQuoted 7 lines · Sergei Gavrikov
It was good to know. If you mean the below I "merge" that in one. Thank you for review.
Sergei
Signed-off-by Sergei Gavrikov <[email protected]>Acked-by Stefan Hajnoczi <[email protected]>
Your new patch looks fine. I prefer:
Stefan
Quoted 7 lines · Stefan Hajnoczi
Quoted 5 lines · Sergei Gavrikov
It was good to know. If you mean the below I "merge" that in one. Thank you for review.
Sergei
Quoted 7 lines
Quoted 2 lines
Signed-off-by Sergei Gavrikov <[email protected]>Acked-by Stefan Hajnoczi <[email protected]>Your new patch looks fine. I prefer:
Reviewed-by Stefan Hajnoczi <[email protected]>Stefan
Excuse, please, that 'Acked-by'. I'm get it. Thank you!
Sergei
PATCH 1/1 slirp: Use strcasecmp() to check tftp mode, tsize
In reply to Stefan HajnocziFrom: 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
@@ -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;
Edgar E. Iglesias
AppliedRe: [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.
Signed-off-by Sergei Gavrikov <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>
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@@ -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;