dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0245-Make-grub_strtoul-end-pointer-have-the-right-constif.patch

8631a2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8631a2
From: Peter Jones <pjones@redhat.com>
8631a2
Date: Fri, 19 Oct 2018 13:41:48 -0400
8631a2
Subject: [PATCH] Make grub_strtoul "end" pointer have the right
8631a2
 constification.
8631a2
8631a2
Related: rhbz#1640979
8631a2
Signed-off-by: Peter Jones <pjones@redhat.com>
8631a2
---
8631a2
 grub-core/kern/fs.c                | 2 +-
8631a2
 grub-core/kern/misc.c              | 8 ++++----
8631a2
 grub-core/kern/partition.c         | 2 +-
8631a2
 grub-core/lib/legacy_parse.c       | 2 +-
8631a2
 grub-core/lib/syslinux_parse.c     | 6 +++---
8631a2
 grub-core/loader/i386/xen_fileXX.c | 2 +-
8631a2
 grub-core/net/efi/ip4_config.c     | 2 +-
8631a2
 grub-core/net/efi/ip6_config.c     | 2 +-
8631a2
 grub-core/net/efi/net.c            | 4 ++--
8631a2
 grub-core/net/efi/pxe.c            | 6 +++---
8631a2
 grub-core/net/http.c               | 4 ++--
8631a2
 grub-core/net/net.c                | 8 ++++----
8631a2
 grub-core/net/url.c                | 2 +-
8631a2
 grub-core/script/execute.c         | 6 +++---
8631a2
 grub-core/term/serial.c            | 2 +-
8631a2
 grub-core/term/terminfo.c          | 2 +-
8631a2
 grub-core/tests/strtoull_test.c    | 2 +-
8631a2
 include/grub/misc.h                | 6 +++---
8631a2
 18 files changed, 34 insertions(+), 34 deletions(-)
8631a2
8631a2
diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c
8631a2
index 9085895b6fe..1bd748be83b 100644
8631a2
--- a/grub-core/kern/fs.c
8631a2
+++ b/grub-core/kern/fs.c
8631a2
@@ -134,7 +134,7 @@ struct grub_fs_block
8631a2
 static grub_err_t
8631a2
 grub_fs_blocklist_open (grub_file_t file, const char *name)
8631a2
 {
8631a2
-  char *p = (char *) name;
8631a2
+  const char *p = name;
8631a2
   unsigned num = 0;
8631a2
   unsigned i;
8631a2
   grub_disk_t disk = file->device->disk;
8631a2
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
8631a2
index 5c3899f0e5b..aaae9aa0ab7 100644
8631a2
--- a/grub-core/kern/misc.c
8631a2
+++ b/grub-core/kern/misc.c
8631a2
@@ -383,7 +383,7 @@ grub_isspace (int c)
8631a2
 }
8631a2
 
8631a2
 unsigned long
8631a2
-grub_strtoul (const char *str, char **end, int base)
8631a2
+grub_strtoul (const char *str, const char ** const end, int base)
8631a2
 {
8631a2
   unsigned long long num;
8631a2
 
8631a2
@@ -400,7 +400,7 @@ grub_strtoul (const char *str, char **end, int base)
8631a2
 }
8631a2
 
8631a2
 unsigned long long
8631a2
-grub_strtoull (const char *str, char **end, int base)
8631a2
+grub_strtoull (const char *str, const char ** const end, int base)
8631a2
 {
8631a2
   unsigned long long num = 0;
8631a2
   int found = 0;
8631a2
@@ -901,14 +901,14 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
8631a2
 	{
8631a2
 	  if (fmt[0] == '0')
8631a2
 	    zerofill = '0';
8631a2
-	  format1 = grub_strtoul (fmt, (char **) &fmt, 10);
8631a2
+	  format1 = grub_strtoul (fmt, &fmt, 10);
8631a2
 	}
8631a2
 
8631a2
       if (*fmt == '.')
8631a2
 	fmt++;
8631a2
 
8631a2
       if (grub_isdigit (*fmt))
8631a2
-	format2 = grub_strtoul (fmt, (char **) &fmt, 10);
8631a2
+	format2 = grub_strtoul (fmt, &fmt, 10);
8631a2
 
8631a2
       if (*fmt == '$')
8631a2
 	{
8631a2
diff --git a/grub-core/kern/partition.c b/grub-core/kern/partition.c
8631a2
index e499147cbcb..2c401b866c4 100644
8631a2
--- a/grub-core/kern/partition.c
8631a2
+++ b/grub-core/kern/partition.c
8631a2
@@ -126,7 +126,7 @@ grub_partition_probe (struct grub_disk *disk, const char *str)
8631a2
       while (*ptr && grub_isalpha (*ptr))
8631a2
 	ptr++;
8631a2
       partname_end = ptr; 
8631a2
-      num = grub_strtoul (ptr, (char **) &ptr, 0) - 1;
8631a2
+      num = grub_strtoul (ptr, &ptr, 0) - 1;
8631a2
 
8631a2
       curpart = 0;
8631a2
       /* Use the first partition map type found.  */
8631a2
diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c
8631a2
index ef56150ac77..05719ab2ccb 100644
8631a2
--- a/grub-core/lib/legacy_parse.c
8631a2
+++ b/grub-core/lib/legacy_parse.c
8631a2
@@ -418,7 +418,7 @@ adjust_file (const char *in, grub_size_t len)
8631a2
     }
8631a2
   if (*comma != ',')
8631a2
     return grub_legacy_escape (in, len);
8631a2
-  part = grub_strtoull (comma + 1, (char **) &rest, 0);
8631a2
+  part = grub_strtoull (comma + 1, &rest, 0);
8631a2
   if (rest[0] == ',' && rest[1] >= 'a' && rest[1] <= 'z')
8631a2
     {
8631a2
       subpart = rest[1] - 'a';
8631a2
diff --git a/grub-core/lib/syslinux_parse.c b/grub-core/lib/syslinux_parse.c
8631a2
index 28ba3aef0bb..21ca040ada7 100644
8631a2
--- a/grub-core/lib/syslinux_parse.c
8631a2
+++ b/grub-core/lib/syslinux_parse.c
8631a2
@@ -1058,7 +1058,7 @@ write_entry (struct output_buffer *outbuf,
8631a2
 		if (ptr[0] == 'h' && ptr[1] == 'd')
8631a2
 		  {
8631a2
 		    is_fd = 0;
8631a2
-		    devn = grub_strtoul (ptr + 2, &ptr, 0);
8631a2
+		    devn = grub_strtoul (ptr + 2, (const char **)&ptr, 0);
8631a2
 		    continue;
8631a2
 		  }
8631a2
 		if (grub_strncasecmp (ptr, "file=", 5) == 0)
8631a2
@@ -1082,12 +1082,12 @@ write_entry (struct output_buffer *outbuf,
8631a2
 		if (ptr[0] == 'f' && ptr[1] == 'd')
8631a2
 		  {
8631a2
 		    is_fd = 1;
8631a2
-		    devn = grub_strtoul (ptr + 2, &ptr, 0);
8631a2
+		    devn = grub_strtoul (ptr + 2, (const char **)&ptr, 0);
8631a2
 		    continue;
8631a2
 		  }
8631a2
 		if (grub_isdigit (ptr[0]))
8631a2
 		  {
8631a2
-		    part = grub_strtoul (ptr, &ptr, 0);
8631a2
+		    part = grub_strtoul (ptr, (const char **)&ptr, 0);
8631a2
 		    continue;
8631a2
 		  }
8631a2
 		/* FIXME: isolinux, ntldr, cmldr, *dos, seg, hide
8631a2
diff --git a/grub-core/loader/i386/xen_fileXX.c b/grub-core/loader/i386/xen_fileXX.c
8631a2
index fb66e66fe96..293f1ad5c3e 100644
8631a2
--- a/grub-core/loader/i386/xen_fileXX.c
8631a2
+++ b/grub-core/loader/i386/xen_fileXX.c
8631a2
@@ -25,7 +25,7 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi,
8631a2
 		 grub_off_t off, grub_size_t sz)
8631a2
 {
8631a2
   char *buf;
8631a2
-  char *ptr;
8631a2
+  const char *ptr;
8631a2
   int has_paddr = 0;
8631a2
 
8631a2
   grub_errno = GRUB_ERR_NONE;
8631a2
diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c
8631a2
index b711a5d9457..38e2a04747a 100644
8631a2
--- a/grub-core/net/efi/ip4_config.c
8631a2
+++ b/grub-core/net/efi/ip4_config.c
8631a2
@@ -62,7 +62,7 @@ grub_efi_string_to_ip4_address (const char *val, grub_efi_ipv4_address_t *addres
8631a2
   for (i = 0; i < 4; i++)
8631a2
     {
8631a2
       unsigned long t;
8631a2
-      t = grub_strtoul (ptr, (char **) &ptr, 0);
8631a2
+      t = grub_strtoul (ptr, &ptr, 0);
8631a2
       if (grub_errno)
8631a2
 	{
8631a2
 	  grub_errno = GRUB_ERR_NONE;
8631a2
diff --git a/grub-core/net/efi/ip6_config.c b/grub-core/net/efi/ip6_config.c
8631a2
index 017c4d05bc7..e0e00c23d21 100644
8631a2
--- a/grub-core/net/efi/ip6_config.c
8631a2
+++ b/grub-core/net/efi/ip6_config.c
8631a2
@@ -84,7 +84,7 @@ grub_efi_string_to_ip6_address (const char *val, grub_efi_ipv6_address_t *addres
8631a2
 	  ptr++;
8631a2
 	  continue;
8631a2
 	}
8631a2
-      t = grub_strtoul (ptr, (char **) &ptr, 16);
8631a2
+      t = grub_strtoul (ptr, &ptr, 16);
8631a2
       if (grub_errno)
8631a2
 	{
8631a2
 	  grub_errno = GRUB_ERR_NONE;
8631a2
diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c
8631a2
index f208d1b180c..4c70fc4da2a 100644
8631a2
--- a/grub-core/net/efi/net.c
8631a2
+++ b/grub-core/net/efi/net.c
8631a2
@@ -729,7 +729,7 @@ grub_efi_net_parse_address (const char *address,
8631a2
 	{
8631a2
 	  grub_uint32_t subnet_mask_size;
8631a2
 
8631a2
-	  subnet_mask_size = grub_strtoul (rest + 1, (char **) &rest, 0);
8631a2
+	  subnet_mask_size = grub_strtoul (rest + 1, &rest, 0);
8631a2
 
8631a2
 	  if (!grub_errno && subnet_mask_size <= 32 && *rest == 0)
8631a2
 	    {
8631a2
@@ -758,7 +758,7 @@ grub_efi_net_parse_address (const char *address,
8631a2
 	{
8631a2
 	  grub_efi_uint8_t prefix_length;
8631a2
 
8631a2
-	  prefix_length = grub_strtoul (rest + 1, (char **) &rest, 0);
8631a2
+	  prefix_length = grub_strtoul (rest + 1, &rest, 0);
8631a2
 	  if (!grub_errno && prefix_length <= 128 && *rest == 0)
8631a2
 	    {
8631a2
 	      ip6->prefix_length = prefix_length;
8631a2
diff --git a/grub-core/net/efi/pxe.c b/grub-core/net/efi/pxe.c
8631a2
index 531949cba5c..73e2bb01c1b 100644
8631a2
--- a/grub-core/net/efi/pxe.c
8631a2
+++ b/grub-core/net/efi/pxe.c
8631a2
@@ -187,7 +187,7 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest)
8631a2
 	  ptr++;
8631a2
 	  continue;
8631a2
 	}
8631a2
-      t = grub_strtoul (ptr, (char **) &ptr, 16);
8631a2
+      t = grub_strtoul (ptr, &ptr, 16);
8631a2
       if (grub_errno)
8631a2
 	{
8631a2
 	  grub_errno = GRUB_ERR_NONE;
8631a2
@@ -225,7 +225,7 @@ pxe_open (struct grub_efi_net_device *dev,
8631a2
 	  int type __attribute__((unused)))
8631a2
 {
8631a2
   int i;
8631a2
-  char *p;
8631a2
+  const char *p;
8631a2
   grub_efi_status_t status;
8631a2
   grub_efi_pxe_ip_address_t server_ip;
8631a2
   grub_efi_uint64_t file_size = 0;
8631a2
@@ -313,7 +313,7 @@ pxe_read (struct grub_efi_net_device *dev,
8631a2
 	  grub_size_t len)
8631a2
 {
8631a2
   int i;
8631a2
-  char *p;
8631a2
+  const char *p;
8631a2
   grub_efi_status_t status;
8631a2
   grub_efi_pxe_t *pxe = (prefer_ip6) ? dev->ip6_pxe : dev->ip4_pxe;
8631a2
   grub_efi_uint64_t bufsz = len;
8631a2
diff --git a/grub-core/net/http.c b/grub-core/net/http.c
8631a2
index c9c59690a98..b52b558d631 100644
8631a2
--- a/grub-core/net/http.c
8631a2
+++ b/grub-core/net/http.c
8631a2
@@ -110,7 +110,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len)
8631a2
 	  return GRUB_ERR_NONE;
8631a2
 	}
8631a2
       ptr += sizeof ("HTTP/1.1 ") - 1;
8631a2
-      code = grub_strtoul (ptr, &ptr, 10);
8631a2
+      code = grub_strtoul (ptr, (const char **)&ptr, 10);
8631a2
       if (grub_errno)
8631a2
 	return grub_errno;
8631a2
       switch (code)
8631a2
@@ -137,7 +137,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len)
8631a2
       == 0 && !data->size_recv)
8631a2
     {
8631a2
       ptr += sizeof ("Content-Length: ") - 1;
8631a2
-      file->size = grub_strtoull (ptr, &ptr, 10);
8631a2
+      file->size = grub_strtoull (ptr, (const char **)&ptr, 10);
8631a2
       data->size_recv = 1;
8631a2
       return GRUB_ERR_NONE;
8631a2
     }
8631a2
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
8631a2
index a571ee92efa..a011b940100 100644
8631a2
--- a/grub-core/net/net.c
8631a2
+++ b/grub-core/net/net.c
8631a2
@@ -411,7 +411,7 @@ parse_ip (const char *val, grub_uint32_t *ip, const char **rest)
8631a2
   for (i = 0; i < 4; i++)
8631a2
     {
8631a2
       unsigned long t;
8631a2
-      t = grub_strtoul (ptr, (char **) &ptr, 0);
8631a2
+      t = grub_strtoul (ptr, &ptr, 0);
8631a2
       if (grub_errno)
8631a2
 	{
8631a2
 	  grub_errno = GRUB_ERR_NONE;
8631a2
@@ -465,7 +465,7 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest)
8631a2
 	  ptr++;
8631a2
 	  continue;
8631a2
 	}
8631a2
-      t = grub_strtoul (ptr, (char **) &ptr, 16);
8631a2
+      t = grub_strtoul (ptr, &ptr, 16);
8631a2
       if (grub_errno)
8631a2
 	{
8631a2
 	  grub_errno = GRUB_ERR_NONE;
8631a2
@@ -577,7 +577,7 @@ grub_net_resolve_net_address (const char *name,
8631a2
       addr->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
8631a2
       if (*rest == '/')
8631a2
 	{
8631a2
-	  addr->ipv4.masksize = grub_strtoul (rest + 1, (char **) &rest, 0);
8631a2
+	  addr->ipv4.masksize = grub_strtoul (rest + 1, &rest, 0);
8631a2
 	  if (!grub_errno && *rest == 0)
8631a2
 	    return GRUB_ERR_NONE;
8631a2
 	  grub_errno = GRUB_ERR_NONE;
8631a2
@@ -593,7 +593,7 @@ grub_net_resolve_net_address (const char *name,
8631a2
       addr->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6;
8631a2
       if (*rest == '/')
8631a2
 	{
8631a2
-	  addr->ipv6.masksize = grub_strtoul (rest + 1, (char **) &rest, 0);
8631a2
+	  addr->ipv6.masksize = grub_strtoul (rest + 1, &rest, 0);
8631a2
 	  if (!grub_errno && *rest == 0)
8631a2
 	    return GRUB_ERR_NONE;
8631a2
 	  grub_errno = GRUB_ERR_NONE;
8631a2
diff --git a/grub-core/net/url.c b/grub-core/net/url.c
8631a2
index 146858284cd..d9d2fc9a9dc 100644
8631a2
--- a/grub-core/net/url.c
8631a2
+++ b/grub-core/net/url.c
8631a2
@@ -235,7 +235,7 @@ extract_http_url_info (char *url, int ssl,
8631a2
       c = *port_end;
8631a2
       *port_end = '\0';
8631a2
 
8631a2
-      portul = grub_strtoul (port_off, &separator, 10);
8631a2
+      portul = grub_strtoul (port_off, (const char **)&separator, 10);
8631a2
       *port_end = c;
8631a2
 #ifdef URL_TEST
8631a2
       if (portul == ULONG_MAX && errno == ERANGE)
8631a2
diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
8631a2
index 93965777138..7d327f59d92 100644
8631a2
--- a/grub-core/script/execute.c
8631a2
+++ b/grub-core/script/execute.c
8631a2
@@ -146,7 +146,7 @@ replace_scope (struct grub_script_scope *new_scope)
8631a2
 grub_err_t
8631a2
 grub_script_break (grub_command_t cmd, int argc, char *argv[])
8631a2
 {
8631a2
-  char *p = 0;
8631a2
+  const char *p = NULL;
8631a2
   unsigned long count;
8631a2
 
8631a2
   if (argc == 0)
8631a2
@@ -178,7 +178,7 @@ grub_err_t
8631a2
 grub_script_shift (grub_command_t cmd __attribute__((unused)),
8631a2
 		   int argc, char *argv[])
8631a2
 {
8631a2
-  char *p = 0;
8631a2
+  const char *p = NULL;
8631a2
   unsigned long n = 0;
8631a2
 
8631a2
   if (! scope)
8631a2
@@ -239,7 +239,7 @@ grub_err_t
8631a2
 grub_script_return (grub_command_t cmd __attribute__((unused)),
8631a2
 		    int argc, char *argv[])
8631a2
 {
8631a2
-  char *p;
8631a2
+  const char *p = NULL;
8631a2
   unsigned long n;
8631a2
 
8631a2
   if (! scope || argc > 1)
8631a2
diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c
8631a2
index db80b3ba0fb..f9271b09239 100644
8631a2
--- a/grub-core/term/serial.c
8631a2
+++ b/grub-core/term/serial.c
8631a2
@@ -269,7 +269,7 @@ grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args)
8631a2
 
8631a2
   if (state[OPTION_BASE_CLOCK].set)
8631a2
     {
8631a2
-      char *ptr;
8631a2
+      const char *ptr;
8631a2
       config.base_clock = grub_strtoull (state[OPTION_BASE_CLOCK].arg, &ptr, 0);
8631a2
       if (grub_errno)
8631a2
 	return grub_errno;
8631a2
diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c
8631a2
index 29df35e6d20..537a5c0cb0b 100644
8631a2
--- a/grub-core/term/terminfo.c
8631a2
+++ b/grub-core/term/terminfo.c
8631a2
@@ -737,7 +737,7 @@ grub_cmd_terminfo (grub_extcmd_context_t ctxt, int argc, char **args)
8631a2
 
8631a2
   if (state[OPTION_GEOMETRY].set)
8631a2
     {
8631a2
-      char *ptr = state[OPTION_GEOMETRY].arg;
8631a2
+      const char *ptr = state[OPTION_GEOMETRY].arg;
8631a2
       w = grub_strtoul (ptr, &ptr, 0);
8631a2
       if (grub_errno)
8631a2
 	return grub_errno;
8631a2
diff --git a/grub-core/tests/strtoull_test.c b/grub-core/tests/strtoull_test.c
8631a2
index 7da615ff33e..5488ab26b43 100644
8631a2
--- a/grub-core/tests/strtoull_test.c
8631a2
+++ b/grub-core/tests/strtoull_test.c
8631a2
@@ -25,7 +25,7 @@ static void
8631a2
 strtoull_testcase (const char *input, int base, unsigned long long expected,
8631a2
 		   int num_digits, grub_err_t error)
8631a2
 {
8631a2
-  char *output;
8631a2
+  const char *output;
8631a2
   unsigned long long value;
8631a2
   grub_errno = 0;
8631a2
   value = grub_strtoull(input, &output, base);
8631a2
diff --git a/include/grub/misc.h b/include/grub/misc.h
8631a2
index de9016ab709..1258ec6bbf3 100644
8631a2
--- a/include/grub/misc.h
8631a2
+++ b/include/grub/misc.h
8631a2
@@ -288,11 +288,11 @@ grub_strncasecmp (const char *s1, const char *s2, grub_size_t n)
8631a2
     - (int) grub_tolower ((grub_uint8_t) *s2);
8631a2
 }
8631a2
 
8631a2
-unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, char **end, int base);
8631a2
-unsigned long long EXPORT_FUNC(grub_strtoull) (const char *str, char **end, int base);
8631a2
+unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, const char ** const end, int base);
8631a2
+unsigned long long EXPORT_FUNC(grub_strtoull) (const char *str, const char ** const end, int base);
8631a2
 
8631a2
 static inline long
8631a2
-grub_strtol (const char *str, char **end, int base)
8631a2
+grub_strtol (const char *str, const char ** const end, int base)
8631a2
 {
8631a2
   int negative = 0;
8631a2
   unsigned long long magnitude;