a5bd9f6
From 401a7131f31017fc73138d0e8c72ab92332b72c6 Mon Sep 17 00:00:00 2001
a5bd9f6
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
a5bd9f6
Date: Fri, 12 Apr 2013 20:17:53 +0200
a5bd9f6
Subject: [PATCH 290/364] 	* grub-core/net/http.c: Fix bad free.
a5bd9f6
a5bd9f6
---
a5bd9f6
 ChangeLog            |  4 ++++
a5bd9f6
 grub-core/net/http.c | 15 ++++++++++++---
a5bd9f6
 2 files changed, 16 insertions(+), 3 deletions(-)
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index ced68cc..79563b8 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,5 +1,9 @@
a5bd9f6
 2013-04-12  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
 
a5bd9f6
+	* grub-core/net/http.c: Fix bad free.
a5bd9f6
+
a5bd9f6
+2013-04-12  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
+
a5bd9f6
 	* grub-core/net/drivers/ieee1275/ofnet.c: Don't attempt to send more
a5bd9f6
 	than buffer size.
a5bd9f6
 
a5bd9f6
diff --git a/grub-core/net/http.c b/grub-core/net/http.c
a5bd9f6
index a7542d1..4684f8b 100644
a5bd9f6
--- a/grub-core/net/http.c
a5bd9f6
+++ b/grub-core/net/http.c
a5bd9f6
@@ -157,9 +157,10 @@ http_err (grub_net_tcp_socket_t sock __attribute__ ((unused)),
a5bd9f6
 
a5bd9f6
   if (data->sock)
a5bd9f6
     grub_net_tcp_close (data->sock, GRUB_NET_TCP_ABORT);
a5bd9f6
+  data->sock = 0;
a5bd9f6
   if (data->current_line)
a5bd9f6
     grub_free (data->current_line);
a5bd9f6
-  grub_free (data);
a5bd9f6
+  data->current_line = 0;
a5bd9f6
   file->device->net->eof = 1;
a5bd9f6
   file->device->net->stall = 1;
a5bd9f6
   if (file->size == GRUB_FILE_SIZE_UNKNOWN)
a5bd9f6
@@ -175,6 +176,12 @@ http_receive (grub_net_tcp_socket_t sock __attribute__ ((unused)),
a5bd9f6
   http_data_t data = file->data;
a5bd9f6
   grub_err_t err;
a5bd9f6
 
a5bd9f6
+  if (!data->sock)
a5bd9f6
+    {
a5bd9f6
+      grub_netbuff_free (nb);
a5bd9f6
+      return GRUB_ERR_NONE;
a5bd9f6
+    }
a5bd9f6
+
a5bd9f6
   while (1)
a5bd9f6
     {
a5bd9f6
       char *ptr = (char *) nb->data;
a5bd9f6
@@ -432,7 +439,8 @@ http_seek (struct grub_file *file, grub_off_t off)
a5bd9f6
   grub_err_t err;
a5bd9f6
   old_data = file->data;
a5bd9f6
   /* FIXME: Reuse socket?  */
a5bd9f6
-  grub_net_tcp_close (old_data->sock, GRUB_NET_TCP_ABORT);
a5bd9f6
+  if (old_data->sock)
a5bd9f6
+    grub_net_tcp_close (old_data->sock, GRUB_NET_TCP_ABORT);
a5bd9f6
   old_data->sock = 0;
a5bd9f6
 
a5bd9f6
   while (file->device->net->packs.first)
a5bd9f6
@@ -529,7 +537,8 @@ http_packets_pulled (struct grub_file *file)
a5bd9f6
 
a5bd9f6
   if (!file->device->net->eof)
a5bd9f6
     file->device->net->stall = 0;
a5bd9f6
-  grub_net_tcp_unstall (data->sock);
a5bd9f6
+  if (data && data->sock)
a5bd9f6
+    grub_net_tcp_unstall (data->sock);
a5bd9f6
   return 0;
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
-- 
a5bd9f6
1.8.1.4
a5bd9f6