Blame SOURCES/0251-net-read-bracketed-ipv6-addrs-and-port-numbers-pjone.patch

f731ee
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f731ee
From: Aaron Miller <aaronmiller@fb.com>
f731ee
Date: Fri, 29 Jul 2016 17:41:38 +0800
f731ee
Subject: [PATCH] net: read bracketed ipv6 addrs and port numbers (pjones
f731ee
 fixup)
f731ee
f731ee
Various bug fixes related to previous patch.
f731ee
f731ee
Signed-off-by: Peter Jones <pjones@redhat.com>
f731ee
---
f731ee
 grub-core/net/http.c |  6 ++++--
f731ee
 grub-core/net/net.c  | 31 +++++++++++++------------------
f731ee
 grub-core/net/tftp.c | 19 ++++++++++++++++---
f731ee
 3 files changed, 33 insertions(+), 23 deletions(-)
f731ee
f731ee
diff --git a/grub-core/net/http.c b/grub-core/net/http.c
f731ee
index 6d99051d345..2b46e4672fc 100644
f731ee
--- a/grub-core/net/http.c
f731ee
+++ b/grub-core/net/http.c
f731ee
@@ -289,7 +289,9 @@ http_receive (grub_net_tcp_socket_t sock __attribute__ ((unused)),
f731ee
 	  nb2 = grub_netbuff_alloc (data->chunk_rem);
f731ee
 	  if (!nb2)
f731ee
 	    return grub_errno;
f731ee
-	  grub_netbuff_put (nb2, data->chunk_rem);
f731ee
+	  err = grub_netbuff_put (nb2, data->chunk_rem);
f731ee
+	  if (err)
f731ee
+	    return grub_errno;
f731ee
 	  grub_memcpy (nb2->data, nb->data, data->chunk_rem);
f731ee
 	  if (file->device->net->packs.count >= 20)
f731ee
 	    {
f731ee
@@ -406,7 +408,7 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial)
f731ee
 		data->filename, server, port ? port : HTTP_PORT);
f731ee
   data->sock = grub_net_tcp_open (server,
f731ee
 				  port ? port : HTTP_PORT, http_receive,
f731ee
-				  http_err, http_err,
f731ee
+				  http_err, NULL,
f731ee
 				  file);
f731ee
   if (!data->sock)
f731ee
     {
f731ee
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
f731ee
index b062f6fd0cd..6b4b10ba444 100644
f731ee
--- a/grub-core/net/net.c
f731ee
+++ b/grub-core/net/net.c
f731ee
@@ -464,10 +464,11 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest)
f731ee
   int word, quaddot = -1;
f731ee
   int bracketed = 0;
f731ee
 
f731ee
-  if (ptr[0] == '[') {
f731ee
-    bracketed = 1;
f731ee
-    ptr++;
f731ee
-  }
f731ee
+  if (ptr[0] == '[')
f731ee
+    {
f731ee
+      bracketed = 1;
f731ee
+      ptr++;
f731ee
+    }
f731ee
 
f731ee
   if (ptr[0] == ':' && ptr[1] != ':')
f731ee
     return 0;
f731ee
@@ -506,9 +507,8 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest)
f731ee
       grub_memset (&newip[quaddot], 0, (7 - word) * sizeof (newip[0]));
f731ee
     }
f731ee
   grub_memcpy (ip, newip, 16);
f731ee
-  if (bracketed && *ptr == ']') {
f731ee
+  if (bracketed && *ptr == ']')
f731ee
     ptr++;
f731ee
-  }
f731ee
   if (rest)
f731ee
     *rest = ptr;
f731ee
   return 1;
f731ee
@@ -1401,7 +1401,7 @@ grub_net_open_real (const char *name)
f731ee
   char* port_start;
f731ee
   /* ipv6 or port specified? */
f731ee
   if ((port_start = grub_strchr (server, ':')))
f731ee
-  {
f731ee
+    {
f731ee
       char* ipv6_begin;
f731ee
       if((ipv6_begin = grub_strchr (server, '[')))
f731ee
 	{
f731ee
@@ -1473,19 +1473,13 @@ grub_net_open_real (const char *name)
f731ee
 	  {
f731ee
 	    grub_net_t ret = grub_zalloc (sizeof (*ret));
f731ee
 	    if (!ret)
f731ee
-	      return NULL;
f731ee
-	    ret->protocol = proto;
f731ee
-	    if (server)
f731ee
 	      {
f731ee
-		ret->server = grub_strdup (server);
f731ee
-		if (!ret->server)
f731ee
-		  {
f731ee
-		    grub_free (ret);
f731ee
-		    return NULL;
f731ee
-		  }
f731ee
+		grub_free (host);
f731ee
+		return NULL;
f731ee
 	      }
f731ee
-	    else
f731ee
-	      ret->server = NULL;
f731ee
+	    ret->protocol = proto;
f731ee
+	    ret->port = port;
f731ee
+	    ret->server = host;
f731ee
 	    ret->fs = &grub_net_fs;
f731ee
 	    ret->offset = 0;
f731ee
 	    ret->eof = 0;
f731ee
@@ -1516,6 +1510,7 @@ grub_net_open_real (const char *name)
f731ee
   grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("disk `%s' not found"),
f731ee
 	      name);
f731ee
 
f731ee
+  grub_free (host);
f731ee
   return NULL;
f731ee
 }
f731ee
 
f731ee
diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
f731ee
index d13a6c8ed2d..17583cba380 100644
f731ee
--- a/grub-core/net/tftp.c
f731ee
+++ b/grub-core/net/tftp.c
f731ee
@@ -346,7 +346,10 @@ tftp_open (struct grub_file *file, const char *filename)
f731ee
   grub_netbuff_reserve (&nb, 1500);
f731ee
   err = grub_netbuff_push (&nb, sizeof (*tftph));
f731ee
   if (err)
f731ee
-    return err;
f731ee
+    {
f731ee
+      grub_free (data);
f731ee
+      return err;
f731ee
+    }
f731ee
 
f731ee
   tftph = (struct tftphdr *) nb.data;
f731ee
 
f731ee
@@ -384,14 +387,20 @@ tftp_open (struct grub_file *file, const char *filename)
f731ee
 
f731ee
   err = grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen));
f731ee
   if (err)
f731ee
-    return err;
f731ee
+    {
f731ee
+      grub_free (data);
f731ee
+      return err;
f731ee
+    }
f731ee
 
f731ee
   file->not_easily_seekable = 1;
f731ee
   file->data = data;
f731ee
 
f731ee
   data->pq = grub_priority_queue_new (sizeof (struct grub_net_buff *), cmp);
f731ee
   if (!data->pq)
f731ee
-    return grub_errno;
f731ee
+    {
f731ee
+      grub_free (data);
f731ee
+      return grub_errno;
f731ee
+    }
f731ee
 
f731ee
   grub_dprintf("tftp", "resolving address for %s\n", file->device->net->server);
f731ee
   err = grub_net_resolve_address (file->device->net->server, &addr);
f731ee
@@ -402,6 +411,7 @@ tftp_open (struct grub_file *file, const char *filename)
f731ee
 		    (unsigned long long)data->file_size,
f731ee
 		    (unsigned long long)data->block_size);
f731ee
       destroy_pq (data);
f731ee
+      grub_free (data);
f731ee
       return err;
f731ee
     }
f731ee
 
f731ee
@@ -413,6 +423,7 @@ tftp_open (struct grub_file *file, const char *filename)
f731ee
     {
f731ee
       grub_dprintf("tftp", "connection failed\n");
f731ee
       destroy_pq (data);
f731ee
+      grub_free (data);
f731ee
       return grub_errno;
f731ee
     }
f731ee
 
f731ee
@@ -426,6 +437,7 @@ tftp_open (struct grub_file *file, const char *filename)
f731ee
 	{
f731ee
 	  grub_net_udp_close (data->sock);
f731ee
 	  destroy_pq (data);
f731ee
+	  grub_free (data);
f731ee
 	  return err;
f731ee
 	}
f731ee
       grub_net_poll_cards (GRUB_NET_INTERVAL + (i * GRUB_NET_INTERVAL_ADDITION),
f731ee
@@ -442,6 +454,7 @@ tftp_open (struct grub_file *file, const char *filename)
f731ee
     {
f731ee
       grub_net_udp_close (data->sock);
f731ee
       destroy_pq (data);
f731ee
+      grub_free (data);
f731ee
       return grub_errno;
f731ee
     }
f731ee