Received: from list by lists.gnu.org with archive (Exim 4.71) id 1XoaoH-0004K6-4e for mharc-grub-devel@gnu.org; Wed, 12 Nov 2014 11:30:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51357) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xoao4-0004Fi-I4 for grub-devel@gnu.org; Wed, 12 Nov 2014 11:30:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xoao3-0006lJ-65 for grub-devel@gnu.org; Wed, 12 Nov 2014 11:30:08 -0500 Received: from gg6-2.genua.de ([2001:a60:f08e:c000::2]:47646 helo=gg.genua.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xoao2-0006Y8-C0 for grub-devel@gnu.org; Wed, 12 Nov 2014 11:30:07 -0500 Received: from gg.genua.de (localhost.genua.de [127.0.0.1]) by gg.genua.de (8.14.8/8.14.8) with ESMTP id sACFuZRZ019469 for ; Wed, 12 Nov 2014 16:56:35 +0100 (CET) Received: (from localhost) by gg.genua.de (MSCAN) id 3/gg.genua.de/smtp-gw/mscan; Wed Nov 12 16:56:35 2014 From: Ilya Bakulin To: grub-devel@gnu.org Subject: [PATCH] GRUB2: Fix http IO handler to report protocol level errors Date: Wed, 12 Nov 2014 16:56:29 +0100 User-Agent: KMail/1.9.10 (enterprise35 0.20130718.c93b994) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart3433164.XxtFPBWxQd"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <201411121656.30120.Ilya_Bakulin@genua.de> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:a60:f08e:c000::2 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Nov 2014 16:30:18 -0000 --nextPart3433164.XxtFPBWxQd Content-Type: multipart/mixed; boundary="Boundary-01=_tM4YUH/hc9JLkFR" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_tM4YUH/hc9JLkFR Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 404 Not Found

Not Found

The requested URL /~ibaku/nonexistent was not found on this server.


Apache/2.2.22 (Debian) Server at xxx.xxx.xxx.xxx Port 80
grub> ----------------------------------------------------------- With the attached patch the behaviour is correct: ----------------------------------------------------------- grub> cat (http)/~ibaku/nonexistent http_receive: error after processing headers error: file `/~ibaku/nonexistent' not found. grub> ----------------------------------------------------------- Please review and merge it if its OK. -- Ilya --Boundary-01=_tM4YUH/hc9JLkFR Content-Type: text/x-diff; charset="iso-8859-15"; name="Fix-http-IO-handler.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="Fix-http-IO-handler.patch" =46rom 1132d2731999721c6a2e74f8ef63f984164d7b86 Mon Sep 17 00:00:00 2001 =46rom: Ilya Bakulin 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 Signed-off-by: Ilya Bakulin =2D-- contrib/grub2/grub-core/net/http.c | 35 ++++++++++++++++++++++++++------= =2D-- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/contrib/grub2/grub-core/net/http.c b/contrib/grub2/grub-core/n= et/http.c index 4684f8b..48779f8 100644 =2D-- a/contrib/grub2/grub-core/net/http.c +++ b/contrib/grub2/grub-core/net/http.c @@ -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; + } + } =20 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 =3D ptr2 + 1; } =20 @@ -410,23 +425,25 @@ http_establish (struct grub_file *file, grub_off_t of= fset, int initial) return err; } =20 =2D for (i =3D 0; !data->headers_recv && i < 100; i++) + for (i =3D 0; !data->err && !data->headers_recv && i < 100; i++) { grub_net_tcp_retransmit (); grub_net_poll_cards (300, &data->headers_recv); } =20 + if (data->err) + { + grub_net_tcp_close (data->sock, GRUB_NET_TCP_ABORT); + char *str =3D data->errmsg; + err =3D grub_error (data->err, "%s", str); + grub_free (str); + data->errmsg =3D 0; + return data->err; + } + if (!data->headers_recv) { grub_net_tcp_close (data->sock, GRUB_NET_TCP_ABORT); =2D if (data->err) =2D { =2D char *str =3D data->errmsg; =2D err =3D grub_error (data->err, "%s", str); =2D grub_free (str); =2D data->errmsg =3D 0; =2D return data->err; =2D } return grub_error (GRUB_ERR_TIMEOUT, N_("time out opening `%s'"), da= ta->filename); } return GRUB_ERR_NONE; =2D-=20 1.7.10.4 --Boundary-01=_tM4YUH/hc9JLkFR-- --nextPart3433164.XxtFPBWxQd Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) iQIcBAABAgAGBQJUY4MtAAoJEHfg8By8ZAOvjR4P/RA7sz60N4s8c6jmaSuqj5/E 9ihCmWHq8iCGqNh0Byc3LnqhNGtS8CtnIh2a56khVR1X4B72v8JMr8KJ4/XA3cdV 3sAljtp1DW5x+MhoSVuJPbgP9cXDfJ3LeShpYzC3TUMWc993xi0fsUXvU2B8nfb8 b1uQNT+WBCukwy6QHwnA9hB7yY1pXr7SdNCxB2MftqxeRTMixWhK6wWHX2AZ+uZO vIx9zkqxwJs8oxtw/5GapUrZidzVQ7xPbpqP9lsm/t6bAH7lKqBJplMtnr4j4WF1 h03upgSVTUWgwnzcIHkjRdwwwwkLV2AFYq1DkkJvT2zNWMOBwkaN+i5eUfjazwF0 MgKAkqDaMEskIN1GMEmZi6W8PF3JXWyt4fKnqFsnfVP+qCoQbyJFKmGDXGfM2CEV s0uozTNhXBv9Hv1QGsB3WFkvdox5+rIqk+2XyXWQCWjEWu0cLhAptvpcitmvt+5v 5u/c6T3bakeQ/wBbuKDD6OdN7kR0UrwMkxzdfbNxoptvLegXeVvS5x3hHK2hbJUT 6fngpFnI1lx2gVRipvp/rjyZkEMWcQNVa/pOrjOcVMpz+JjJPTO6PB0rc88Rj4cw kl41SK9e8My976NGC6Qua3rZrGST3xjJws1t80Bgehbc3v2zOTuiuSe1kh13zrSM lq5wB8u3qOouIlNcT1/Y =YsbD -----END PGP SIGNATURE----- --nextPart3433164.XxtFPBWxQd--