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

8631a2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8631a2
From: Aaron Miller <aaronmiller@fb.com>
8631a2
Date: Fri, 29 Jul 2016 17:41:38 +0800
8631a2
Subject: [PATCH] net: read bracketed ipv6 addrs and port numbers (pjones
8631a2
 fixup)
8631a2
8631a2
Various bug fixes related to previous patch.
8631a2
8631a2
Signed-off-by: Peter Jones <pjones@redhat.com>
8631a2
---
8631a2
 grub-core/net/http.c |  6 ++++--
8631a2
 grub-core/net/net.c  | 24 ++++++++++++------------
8631a2
 2 files changed, 16 insertions(+), 14 deletions(-)
8631a2
8631a2
diff --git a/grub-core/net/http.c b/grub-core/net/http.c
8631a2
index f182d7b871d..00737c52750 100644
8631a2
--- a/grub-core/net/http.c
8631a2
+++ b/grub-core/net/http.c
8631a2
@@ -289,7 +289,9 @@ http_receive (grub_net_tcp_socket_t sock __attribute__ ((unused)),
8631a2
 	  nb2 = grub_netbuff_alloc (data->chunk_rem);
8631a2
 	  if (!nb2)
8631a2
 	    return grub_errno;
8631a2
-	  grub_netbuff_put (nb2, data->chunk_rem);
8631a2
+	  err = grub_netbuff_put (nb2, data->chunk_rem);
8631a2
+	  if (err)
8631a2
+	    return grub_errno;
8631a2
 	  grub_memcpy (nb2->data, nb->data, data->chunk_rem);
8631a2
 	  if (file->device->net->packs.count >= 20)
8631a2
 	    {
8631a2
@@ -405,7 +407,7 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial)
8631a2
 		data->filename, server, port ? port : HTTP_PORT);
8631a2
   data->sock = grub_net_tcp_open (server,
8631a2
 				  port ? port : HTTP_PORT, http_receive,
8631a2
-				  http_err, http_err,
8631a2
+				  http_err, NULL,
8631a2
 				  file);
8631a2
   if (!data->sock)
8631a2
     {
8631a2
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
8631a2
index 1f887d44b32..a0f4d00f0be 100644
8631a2
--- a/grub-core/net/net.c
8631a2
+++ b/grub-core/net/net.c
8631a2
@@ -441,10 +441,11 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest)
8631a2
   int word, quaddot = -1;
8631a2
   int bracketed = 0;
8631a2
 
8631a2
-  if (ptr[0] == '[') {
8631a2
-    bracketed = 1;
8631a2
-    ptr++;
8631a2
-  }
8631a2
+  if (ptr[0] == '[')
8631a2
+    {
8631a2
+      bracketed = 1;
8631a2
+      ptr++;
8631a2
+    }
8631a2
 
8631a2
   if (ptr[0] == ':' && ptr[1] != ':')
8631a2
     return 0;
8631a2
@@ -483,9 +484,8 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest)
8631a2
       grub_memset (&newip[quaddot], 0, (7 - word) * sizeof (newip[0]));
8631a2
     }
8631a2
   grub_memcpy (ip, newip, 16);
8631a2
-  if (bracketed && *ptr == ']') {
8631a2
+  if (bracketed && *ptr == ']')
8631a2
     ptr++;
8631a2
-  }
8631a2
   if (rest)
8631a2
     *rest = ptr;
8631a2
   return 1;
8631a2
@@ -1389,7 +1389,7 @@ grub_net_open_real (const char *name)
8631a2
   char* port_start;
8631a2
   /* ipv6 or port specified? */
8631a2
   if ((port_start = grub_strchr (server, ':')))
8631a2
-  {
8631a2
+    {
8631a2
       char* ipv6_begin;
8631a2
       if((ipv6_begin = grub_strchr (server, '[')))
8631a2
 	{
8631a2
@@ -1461,14 +1461,13 @@ grub_net_open_real (const char *name)
8631a2
 	  {
8631a2
 	    grub_net_t ret = grub_zalloc (sizeof (*ret));
8631a2
 	    if (!ret)
8631a2
-	      return NULL;
8631a2
-	    ret->protocol = proto;
8631a2
-	    ret->server = grub_strdup (server);
8631a2
-	    if (!ret->server)
8631a2
 	      {
8631a2
-		grub_free (ret);
8631a2
+		grub_free (host);
8631a2
 		return NULL;
8631a2
 	      }
8631a2
+	    ret->protocol = proto;
8631a2
+	    ret->port = port;
8631a2
+	    ret->server = host;
8631a2
 	    ret->fs = &grub_net_fs;
8631a2
 	    return ret;
8631a2
 	  }
8631a2
@@ -1543,6 +1542,7 @@ grub_net_open_real (const char *name)
8631a2
   grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("disk `%s' not found"),
8631a2
 	      name);
8631a2
 
8631a2
+  grub_free (host);
8631a2
   return NULL;
8631a2
 }
8631a2