GRUB2: Fix http IO handler to report protocol level errors
PATCH 1/1 GRUB2: Fix http IO handler to report protocol level errors
Hi list,
we have found that GRUB2 doesn't respect HTTP error codes when trying to load the files via HTTP.
-----------------------------------------------------------
grub> cat (http)/~ibaku/nonexistent
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /~ibaku/nonexistent was not found on this server.</p> <hr>
<address>Apache/2.2.22 (Debian) Server at xxx.xxx.xxx.xxx Port 80</address> </body></html>
grub>
-----------------------------------------------------------
With the attached patch the behaviour is correct:
-----------------------------------------------------------
grub> cat (http)/~ibaku/nonexistenthttp_receive: error after processing headers
error: file `/~ibaku/nonexistent' not found.
grub>
-----------------------------------------------------------
Please review and merge it if its OK.
--
Ilya
From 1132d2731999721c6a2e74f8ef63f984164d7b86 Mon Sep 17 00:00:00 2001
From: Ilya Bakulin <[email protected]>
Date: Wed, 12 Nov 2014 16:30:19 +0100
Subject: [PATCH] GRUB2: Fix http IO handler to report protocol level errors
Although the code that processes the HTTP headers is able to detect "file not found" and other types of HTTP-level errors, GRUB doesn't check if there was an error and loads the server's error page as a file instead.
Change-Id: I94ab517d3f465765cb11b5f71c6423bf381887f1
--- contrib/grub2/grub-core/net/http.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
contrib/grub2/grub-core/net/http.c +26 -9
@@ -226,6 +226,14 @@ http_receive (grub_net_tcp_socket_t sock __attribute__ ((unused)),grub_netbuff_free (nb);return err; } + +if (data->err) { +grub_printf ("%s: Data error after processing headers\n" , __func__); +grub_net_tcp_close (data->sock,GRUB_NET_TCP_ABORT ); +grub_netbuff_free (nb); +return GRUB_ERR_IO ; + } + } while (ptr < (char *) nb->tail && (!data->headers_recv
@@ -254,6 +262,13 @@ http_receive (grub_net_tcp_socket_t sock __attribute__ ((unused)),grub_netbuff_free (nb);return err; } +if (data->err) { +grub_printf ("%s: error after processing headers\n" , __func__); +grub_net_tcp_close (data->sock,GRUB_NET_TCP_ABORT ); +grub_netbuff_free (nb); +return GRUB_ERR_IO ; + } + ptr = ptr2 +1 ; }
@@ -410,23 +425,25 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial)return err; } -for (i =0 ; !data->headers_recv && i <100 ; i++) +for (i =0 ; !data->err && !data->headers_recv && i <100 ; i++) {grub_net_tcp_retransmit ();grub_net_poll_cards (300 , &data->headers_recv); } +if (data->err) + { +grub_net_tcp_close (data->sock,GRUB_NET_TCP_ABORT ); +char *str = data->errmsg; + err =grub_error (data->err,"%s" , str); +grub_free (str); + data->errmsg =0 ; +return data->err; + } +if (!data->headers_recv) {grub_net_tcp_close (data->sock,GRUB_NET_TCP_ABORT ); -if (data->err) - { -char *str = data->errmsg; - err =grub_error (data->err,"%s" , str); -grub_free (str); - data->errmsg =0 ; -return data->err; - }return grub_error (GRUB_ERR_TIMEOUT ,N_ ("time out opening `%s'" ), data->filename); }return GRUB_ERR_NONE ;
Signature · 1 line
1.7.10.4