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