nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0257-net-http-Do-not-tear-down-socket-if-it-s-already-bee.patch

e28c09
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
e28c09
From: Daniel Axtens <dja@axtens.net>
e28c09
Date: Tue, 1 Mar 2022 23:14:15 +1100
e28c09
Subject: [PATCH] net/http: Do not tear down socket if it's already been torn
e28c09
 down
e28c09
e28c09
It's possible for data->sock to get torn down in tcp error handling.
e28c09
If we unconditionally tear it down again we will end up doing writes
e28c09
to an offset of the NULL pointer when we go to tear it down again.
e28c09
e28c09
Detect if it has been torn down and don't do it again.
e28c09
e28c09
Signed-off-by: Daniel Axtens <dja@axtens.net>
e28c09
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
e28c09
(cherry picked from commit ec233d3ecf995293304de443579aab5c46c49e85)
e28c09
(cherry picked from commit d39cf87ed701b9f0900daed7f672e07994d37ce8)
e28c09
---
e28c09
 grub-core/net/http.c | 5 +++--
e28c09
 1 file changed, 3 insertions(+), 2 deletions(-)
e28c09
e28c09
diff --git a/grub-core/net/http.c b/grub-core/net/http.c
e28c09
index 7f878b5615..19cb8768e3 100644
e28c09
--- a/grub-core/net/http.c
e28c09
+++ b/grub-core/net/http.c
e28c09
@@ -427,7 +427,7 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial)
e28c09
       return err;
e28c09
     }
e28c09
 
e28c09
-  for (i = 0; !data->headers_recv && i < 100; i++)
e28c09
+  for (i = 0; data->sock && !data->headers_recv && i < 100; i++)
e28c09
     {
e28c09
       grub_net_tcp_retransmit ();
e28c09
       grub_net_poll_cards (300, &data->headers_recv);
e28c09
@@ -435,7 +435,8 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial)
e28c09
 
e28c09
   if (!data->headers_recv)
e28c09
     {
e28c09
-      grub_net_tcp_close (data->sock, GRUB_NET_TCP_ABORT);
e28c09
+      if (data->sock)
e28c09
+        grub_net_tcp_close (data->sock, GRUB_NET_TCP_ABORT);
e28c09
       if (data->err)
e28c09
 	{
e28c09
 	  char *str = data->errmsg;