]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
net/http: Do not tear down socket if it's already been torn down
authorDaniel Axtens <dja@axtens.net>
Tue, 1 Mar 2022 12:14:15 +0000 (23:14 +1100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 7 Jun 2022 14:39:33 +0000 (16:39 +0200)
It's possible for data->sock to get torn down in tcp error handling.
If we unconditionally tear it down again we will end up doing writes
to an offset of the NULL pointer when we go to tear it down again.

Detect if it has been torn down and don't do it again.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/net/http.c

index 8d6c62c76b83b6462ad665d424dd6e69ab86b3c3..f8d7bf0cd466cab43e2dd079e28d0c6421a0cb10 100644 (file)
@@ -445,7 +445,7 @@ 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->sock && !data->headers_recv && i < 100; i++)
     {
       grub_net_tcp_retransmit ();
       grub_net_poll_cards (300, &data->headers_recv);
@@ -453,7 +453,8 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial)
 
   if (!data->headers_recv)
     {
-      grub_net_tcp_close (data->sock, GRUB_NET_TCP_ABORT);
+      if (data->sock)
+        grub_net_tcp_close (data->sock, GRUB_NET_TCP_ABORT);
       if (data->err)
        {
          char *str = data->errmsg;