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