|
|
23d2ea |
From cce5625f26ac5c724710a6416fb5a0bf1bb5449c Mon Sep 17 00:00:00 2001
|
|
|
23d2ea |
From: Peter Jones <pjones@redhat.com>
|
|
|
23d2ea |
Date: Tue, 12 Jul 2016 11:59:39 -0400
|
|
|
23d2ea |
Subject: [PATCH 211/211] Coverity rightly noticed that
|
|
|
23d2ea |
grub_ipv6_get_masksize() was broken.
|
|
|
23d2ea |
|
|
|
23d2ea |
This fixes it with a version that even seems to work.
|
|
|
23d2ea |
|
|
|
23d2ea |
Related: rhbz#1154226
|
|
|
23d2ea |
|
|
|
23d2ea |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
23d2ea |
---
|
|
|
23d2ea |
grub-core/net/net.c | 27 ++++++++++++++++-----------
|
|
|
23d2ea |
include/grub/net.h | 2 +-
|
|
|
23d2ea |
2 files changed, 17 insertions(+), 12 deletions(-)
|
|
|
23d2ea |
|
|
|
23d2ea |
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
|
|
|
23d2ea |
index 19a81bc..36fc0d8 100644
|
|
|
23d2ea |
--- a/grub-core/net/net.c
|
|
|
23d2ea |
+++ b/grub-core/net/net.c
|
|
|
23d2ea |
@@ -970,29 +970,34 @@ grub_net_network_level_interface_register (struct grub_net_network_level_interfa
|
|
|
23d2ea |
}
|
|
|
23d2ea |
|
|
|
23d2ea |
int
|
|
|
23d2ea |
-grub_ipv6_get_masksize(grub_uint8_t *be_mask)
|
|
|
23d2ea |
+grub_ipv6_get_masksize (grub_uint16_t be_mask[8])
|
|
|
23d2ea |
{
|
|
|
23d2ea |
grub_uint8_t *mask;
|
|
|
23d2ea |
grub_uint16_t mask16[8];
|
|
|
23d2ea |
- unsigned int x;
|
|
|
23d2ea |
- int ret = 0;
|
|
|
23d2ea |
+ int x, y;
|
|
|
23d2ea |
+ int ret = 128;
|
|
|
23d2ea |
|
|
|
23d2ea |
- grub_memcpy (mask16, be_mask, sizeof(mask16));
|
|
|
23d2ea |
+ grub_memcpy (mask16, be_mask, sizeof (mask16));
|
|
|
23d2ea |
for (x = 0; x < 8; x++)
|
|
|
23d2ea |
mask16[x] = grub_be_to_cpu16 (mask16[x]);
|
|
|
23d2ea |
|
|
|
23d2ea |
mask = (grub_uint8_t *)mask16;
|
|
|
23d2ea |
|
|
|
23d2ea |
- for (x = 15; x > 0; x--)
|
|
|
23d2ea |
+ for (x = 15; x >= 0; x--)
|
|
|
23d2ea |
{
|
|
|
23d2ea |
grub_uint8_t octet = mask[x];
|
|
|
23d2ea |
- while (octet & 0x80)
|
|
|
23d2ea |
+ if (!octet)
|
|
|
23d2ea |
{
|
|
|
23d2ea |
- ret++;
|
|
|
23d2ea |
- octet <<= 1;
|
|
|
23d2ea |
+ ret -= 8;
|
|
|
23d2ea |
+ continue;
|
|
|
23d2ea |
+ }
|
|
|
23d2ea |
+ for (y = 0; y < 8; y++)
|
|
|
23d2ea |
+ {
|
|
|
23d2ea |
+ if (octet & (1 << y))
|
|
|
23d2ea |
+ break;
|
|
|
23d2ea |
+ else
|
|
|
23d2ea |
+ ret--;
|
|
|
23d2ea |
}
|
|
|
23d2ea |
- if (ret)
|
|
|
23d2ea |
- ret += 8 * (15 - x);
|
|
|
23d2ea |
break;
|
|
|
23d2ea |
}
|
|
|
23d2ea |
|
|
|
23d2ea |
@@ -1009,7 +1014,7 @@ grub_net_add_ipv6_local (struct grub_net_network_level_interface *inter,
|
|
|
23d2ea |
return 0;
|
|
|
23d2ea |
|
|
|
23d2ea |
if (mask == -1)
|
|
|
23d2ea |
- mask = grub_ipv6_get_masksize ((grub_uint8_t *)inter->address.ipv6);
|
|
|
23d2ea |
+ mask = grub_ipv6_get_masksize ((grub_uint16_t *)inter->address.ipv6);
|
|
|
23d2ea |
|
|
|
23d2ea |
if (mask == -1)
|
|
|
23d2ea |
return 0;
|
|
|
23d2ea |
diff --git a/include/grub/net.h b/include/grub/net.h
|
|
|
23d2ea |
index c7b8e2a..bd930f4 100644
|
|
|
23d2ea |
--- a/include/grub/net.h
|
|
|
23d2ea |
+++ b/include/grub/net.h
|
|
|
23d2ea |
@@ -500,7 +500,7 @@ grub_net_configure_by_dhcpv6_ack (const char *name,
|
|
|
23d2ea |
int is_def, char **device, char **path);
|
|
|
23d2ea |
|
|
|
23d2ea |
int
|
|
|
23d2ea |
-grub_ipv6_get_masksize(grub_uint8_t *mask);
|
|
|
23d2ea |
+grub_ipv6_get_masksize(grub_uint16_t *mask);
|
|
|
23d2ea |
|
|
|
23d2ea |
grub_err_t
|
|
|
23d2ea |
grub_net_add_ipv6_local (struct grub_net_network_level_interface *inf,
|
|
|
23d2ea |
--
|
|
|
23d2ea |
2.7.4
|
|
|
23d2ea |
|