Blame SOURCES/0210-Coverity-rightly-noticed-that-grub_ipv6_get_masksize.patch

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