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