http module is not checking correctly HTTP headers
PATCH 1/1 http module is not checking correctly HTTP headers
According to https://www.ietf.org/rfc/rfc2616.txt 4.2, header names shall be case insensitive and we are now forced to read headers like Content-Length capitalized.
The problem with that is when a HTTP server responds with a content-length header in lowercase GRUB gets stuck because HTTP module doesn't know the length of the transmision and the call never ends. I've been able to reproduce it and after ignoring the text case it worked perfectly.
Here is it my patch proposal:
grub-core/net/http.c +0 -0
@@ -130,7 +130,7 @@ parse_line (grub_file_t file, http_data_t data,
char *ptr, grub_size_t len)
data->first_line_recv = 1;
return GRUB_ERR_NONE;
}
- if (grub_memcmp (ptr, "Content-Length: ", sizeof ("Content-Length: ") - 1)
+ if (grub_strncasecmp (ptr, "Content-Length: ", grub_strlen
("Content-Length: ") )
== 0 && !data->size_recv)
{
ptr += sizeof ("Content-Length: ") - 1;
@@ -138,8 +138,8 @@ parse_line (grub_file_t file, http_data_t data,
char *ptr, grub_size_t len)
data->size_recv = 1;
return GRUB_ERR_NONE;
}- if (grub_memcmp (ptr, "Transfer-Encoding: chunked",
- sizeof ("Transfer-Encoding: chunked") - 1) == 0)
+ if (grub_strncasecmp (ptr, "Transfer-Encoding: chunked",
+ grub_strlen ("Transfer-Encoding: chunked") ) == 0)
{
data->chunked = 1;
return GRUB_ERR_NONE;Quoted 17 lines · On Wed, 12 Jan 2022 23:54:58 +0100 Javier Moragon <[email protected]> wrote:
According to https://www.ietf.org/rfc/rfc2616.txt 4.2, header names shall be case insensitive and we are now forced to read headers like
Content-Lengthcapitalized.The problem with that is when a HTTP server responds with a
content-lengthheader in lowercase GRUB gets stuck because HTTP module doesn't know the length of the transmision and the call never ends. I've been able to reproduce it and after ignoring the text case it worked perfectly.Here is it my patch proposal:
grub-core/net/http.c +0
-0
grub-core/net/http.c parse_line (grub_file_t file, http_data_t data, · line 135
Quoted 7 lines
grub-core/net/http.c +1
-1@@ -130,7 +130,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) data->first_line_recv = 1;return GRUB_ERR_NONE ; } -if (grub_memcmp (ptr,"Content-Length: " ,sizeof ("Content-Length: " ) -1 ) +if (grub_strncasecmp (ptr,"Content-Length: " ,grub_strlen ("Content-Length: ") )
I don't think there should be a new line here. And why change to grub_strlen? Now the length is calculated everytime at runtime instead of once at compile time.
grub-core/net/http.c parse_line (grub_file_t file, http_data_t data, · line 143
Quoted 12 lines
grub-core/net/http.c +0
-0== 0 && !data->size_recv){ ptr += sizeof ("Content-Length: ") - 1;grub-core/net/http.c +2
-2@@ -138,8 +138,8 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) data->size_recv = 1;return GRUB_ERR_NONE ; } -if (grub_memcmp (ptr,"Transfer-Encoding: chunked" , -sizeof ("Transfer-Encoding: chunked" ) -1 ) ==0 ) +if (grub_strncasecmp (ptr,"Transfer-Encoding: chunked" , +grub_strlen ("Transfer-Encoding: chunked" ) ) ==0 )
Ditto on the grub_strlen. I also don't like the original indentation of this line and think that it should align with "ptr".
Quoted 3 lines
grub-core/net/http.c +0
-0{ data->chunked =1 ;return GRUB_ERR_NONE;
Otherwise, it seems like good patch.
Glenn
I'm sorry, it's my first time using a mailing list for publishing patches so I sent you the message directly instead of to grub-devel and my mail client wrapped the patch lines. I attached the patch Instead of pasting the diff, I hope this time the lines don't get wrapped.
Quoted 49 lines · Glenn Washburn
Quoted 17 lines · On Wed, 12 Jan 2022 23:54:58 +0100 Javier Moragon <[email protected]> wrote:
According to https://www.ietf.org/rfc/rfc2616.txt 4.2, header names shall be case insensitive and we are now forced to read headers like
Content-Lengthcapitalized.The problem with that is when a HTTP server responds with a
content-lengthheader in lowercase GRUB gets stuck because HTTP module doesn't know the length of the transmision and the call never ends. I've been able to reproduce it and after ignoring the text case it worked perfectly.Here is it my patch proposal:
grub-core/net/http.c +0
-0grub-core/net/http.c parse_line (grub_file_t file, http_data_t data, · line 135
Quoted 7 lines
grub-core/net/http.c +1
-1@@ -130,7 +130,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) data->first_line_recv = 1;return GRUB_ERR_NONE ; } -if (grub_memcmp (ptr,"Content-Length: " ,sizeof ("Content-Length: " ) -1 ) +if (grub_strncasecmp (ptr,"Content-Length: " ,grub_strlen ("Content-Length: ") )I don't think there should be a new line here. And why change to
grub_strlen? Now the length is calculated everytime at runtime instead of once at compile time.grub-core/net/http.c parse_line (grub_file_t file, http_data_t data, · line 143
Quoted 12 lines
grub-core/net/http.c +0
-0== 0 && !data->size_recv){ ptr += sizeof ("Content-Length: ") - 1;grub-core/net/http.c +2
-2@@ -138,8 +138,8 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) data->size_recv = 1;return GRUB_ERR_NONE ; } -if (grub_memcmp (ptr,"Transfer-Encoding: chunked" , -sizeof ("Transfer-Encoding: chunked" ) -1 ) ==0 ) +if (grub_strncasecmp (ptr,"Transfer-Encoding: chunked" , +grub_strlen ("Transfer-Encoding: chunked" ) ) ==0 )Ditto on the
grub_strlen. I also don't like the original indentation of this line and think that it should align with "ptr".
Quoted 8 lines
Quoted 3 lines
grub-core/net/http.c +0
-0{ data->chunked =1 ;return GRUB_ERR_NONE;Otherwise, it seems like good patch.
Glenn
grub-core/net/http.c +3 -3
@@ -130,7 +130,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) data->first_line_recv =1 ;return GRUB_ERR_NONE ; } -if (grub_memcmp (ptr,"Content-Length: " ,sizeof ("Content-Length: " ) -1 ) +if (grub_strncasecmp (ptr,"Content-Length: " ,sizeof ("Content-Length: " ) -1 ) ==0 && !data->size_recv) { ptr +=sizeof ("Content-Length: " ) -1 ;
@@ -138,8 +138,8 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) data->size_recv =1 ;return GRUB_ERR_NONE ; } -if (grub_memcmp (ptr,"Transfer-Encoding: chunked" , -sizeof ("Transfer-Encoding: chunked" ) -1 ) ==0 ) +if (grub_strncasecmp (ptr,"Transfer-Encoding: chunked" , +sizeof ("Transfer-Encoding: chunked" ) -1 ) ==0 ) { data->chunked =1 ;return GRUB_ERR_NONE ;
PATCH 1/1 http module is not checking correctly HTTP headers
From: Javier Moragon <[email protected]>
I applied the last suggestion in this patch and I've finally realized how to use git send-email.
I'm sorry for the unnecesary mails and I hope for next contributions I won't make the same mistakes, Thank you!
--- grub-core/net/http.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
grub-core/net/http.c +3 -3
@@ -130,7 +130,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) data->first_line_recv =1 ;return GRUB_ERR_NONE ; } -if (grub_memcmp (ptr,"Content-Length: " ,sizeof ("Content-Length: " ) -1 ) +if (grub_strncasecmp (ptr,"Content-Length: " ,sizeof ("Content-Length: " ) -1 ) ==0 && !data->size_recv) { ptr +=sizeof ("Content-Length: " ) -1 ;
@@ -138,8 +138,8 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) data->size_recv =1 ;return GRUB_ERR_NONE ; } -if (grub_memcmp (ptr,"Transfer-Encoding: chunked" , -sizeof ("Transfer-Encoding: chunked" ) -1 ) ==0 ) +if (grub_strncasecmp (ptr,"Transfer-Encoding: chunked" , +sizeof ("Transfer-Encoding: chunked" ) -1 ) ==0 ) { data->chunked =1 ;return GRUB_ERR_NONE ;
Signature · 1 line
2.32.0
Quoted 7 lines · On Fri, 14 Jan 2022 00:05:59 +0100 Jamo <[email protected]> wrote:
From: Javier Moragon <[email protected]>
I applied the last suggestion in this patch and I've finally realized how to use git send-email.
I'm sorry for the unnecesary mails and I hope for next contributions I won't make the same mistakes, Thank you!
No worries, we all had to learn at some point. There are still a couple issues. One is that this space is for the commit message. For instance, based on your first email it might be:
According to https://www.ietf.org/rfc/rfc2616.txt 4.2, header names shall be case insensitive and we are now forced to read headers like Content-Length capitalized.
The problem with that is when a HTTP server responds with a content-length header in lowercase GRUB gets stuck because HTTP module doesn't know the length of the transmision and the call never ends.
Another issue is that when you update a patch, you should update its version number. See the "-v" option in git-format-patch. Also, the list convention is to start a new thread when submitting an updated patch. So no need to do have an "In-Reply-To" header on the next update.
Quoted 2 lines
---
If you want to have some text that will not get recorded in the commit, like the text after your email above, you can put that here.
Quoted 17 lines
grub-core/net/http.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)grub-core/net/http.c +1
-1@@ -130,7 +130,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) data->first_line_recv =1 ;return GRUB_ERR_NONE ; } -if (grub_memcmp (ptr,"Content-Length: " ,sizeof ("Content-Length: " ) -1 ) +if (grub_strncasecmp (ptr,"Content-Length: " ,sizeof ("Content-Length: " ) -1 ) ==0 && !data->size_recv) { ptr +=sizeof ("Content-Length: " ) -1 ;
grub-core/net/http.c parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) · line 142
Quoted 7 lines
grub-core/net/http.c +2
-2@@ -138,8 +138,8 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) data->size_recv =1 ;return GRUB_ERR_NONE ; } -if (grub_memcmp (ptr,"Transfer-Encoding: chunked" , -sizeof ("Transfer-Encoding: chunked" ) -1 ) ==0 ) +if (grub_strncasecmp (ptr,"Transfer-Encoding: chunked" , +sizeof ("Transfer-Encoding: chunked" ) -1 ) ==0 )
Almost there. The code style guidelines for this project use a TAB character for every 8 spaces. It looks like you used all spaces to do the indent.
grub-core/net/http.c parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) · line 145
Quoted 3 lines
grub-core/net/http.c +0
-0{ data->chunked =1 ;return GRUB_ERR_NONE ;
Glenn
Quoted 5 lines · On Thu, 13 Jan 2022 23:14:54 +0100 Javier Moragon <[email protected]> wrote:
I'm sorry, it's my first time using a mailing list for publishing patches so I sent you the message directly instead of to grub-devel and my mail client wrapped the patch lines. I attached the patch Instead of pasting the diff, I hope this time the lines don't get wrapped.
Its okay, I had a few hiccups my first several times sending patches to the list. Sending the patch as an attachment does fix the line wrapping issue, but it creates another one. Its makes it more difficult for reviewers to review it. This list is accustomed to having the patch sent inline (in the text of the email). The advantage of this is that reviewers get to comment inline on specific lines of the patch (like I did for your original patch). Most people use git-format-patch and git-send for creating and sending patches to the list.
Also, I've noticed that you changed the indentation of the second change of this latest patch. Could you please create a new patch with the indention exactly as it was? Your editor is probably changing the indentation with out you realizing it. To be clear, the "sizeof" should be preceeded by a string of 2 tabs followed by 2 spaces.
Glenn
Quoted 60 lines
Quoted 57 lines · Glenn Washburn
Quoted 17 lines · On Wed, 12 Jan 2022 23:54:58 +0100 Javier Moragon <[email protected]> wrote:
According to https://www.ietf.org/rfc/rfc2616.txt 4.2, header names shall be case insensitive and we are now forced to read headers like
Content-Lengthcapitalized.The problem with that is when a HTTP server responds with a
content-lengthheader in lowercase GRUB gets stuck because HTTP module doesn't know the length of the transmision and the call never ends. I've been able to reproduce it and after ignoring the text case it worked perfectly.Here is it my patch proposal:
grub-core/net/http.c +0
-0grub-core/net/http.c parse_line (grub_file_t file, http_data_t data, · line 135
Quoted 7 lines
grub-core/net/http.c +1
-1@@ -130,7 +130,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) data->first_line_recv = 1;return GRUB_ERR_NONE ; } -if (grub_memcmp (ptr,"Content-Length: " ,sizeof ("Content-Length: " ) -1 ) +if (grub_strncasecmp (ptr,"Content-Length: " ,grub_strlen ("Content-Length: ") )I don't think there should be a new line here. And why change to
grub_strlen? Now the length is calculated everytime at runtime instead of once at compile time.grub-core/net/http.c parse_line (grub_file_t file, http_data_t data, · line 143
Quoted 12 lines
grub-core/net/http.c +0
-0== 0 && !data->size_recv){ ptr += sizeof ("Content-Length: ") - 1;grub-core/net/http.c +2
-2@@ -138,8 +138,8 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) data->size_recv = 1;return GRUB_ERR_NONE ; } -if (grub_memcmp (ptr,"Transfer-Encoding: chunked" , -sizeof ("Transfer-Encoding: chunked" ) -1 ) ==0 ) +if (grub_strncasecmp (ptr,"Transfer-Encoding: chunked" , +grub_strlen ("Transfer-Encoding: chunked" ) ) ==0 )Ditto on the
grub_strlen. I also don't like the original indentation of this line and think that it should align with "ptr".Quoted 3 lines
grub-core/net/http.c +0
-0{ data->chunked =1 ;return GRUB_ERR_NONE;Otherwise, it seems like good patch.
Glenn