diff --git a/0160-Make-grub_strtol-end-pointers-have-safer-const-quali.patch b/0160-Make-grub_strtol-end-pointers-have-safer-const-quali.patch new file mode 100644 index 0000000..30c0828 --- /dev/null +++ b/0160-Make-grub_strtol-end-pointers-have-safer-const-quali.patch @@ -0,0 +1,987 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 19 Oct 2018 13:41:48 -0400 +Subject: [PATCH] Make grub_strtol() "end" pointers have safer const + qualifiers. (v2) + +Currently the string functions grub_strtol(), grub_strtoul(), and +grub_strtoull() don't declare the "end" pointer in such a way as to +require the pointer itself or the character array to be immutable to the +implementation, nor does the C standard do so in its similar functions, +though it does require us not to change any of it. + +The typical declarations of these functions follow this pattern: + +long +strtol(const char * restrict nptr, char ** restrict endptr, int base); + +Much of the reason for this is historic, and a discussion of that +follows below, after the explanation of this change. (GRUB currently +does not include the "restrict" qualifiers, and we name the arguments a +bit differently.) + +The implementation is semantically required to treat the character array +as immutable, but such accidental modifications aren't stopped by the +compiler, and the semantics for both the callers and the implementation +of these functions are sometimes also helped by adding that requirement. + +This patch changes these declarations to follow this pattern instead: + +long +strtol(const char * restrict nptr, + const char ** const restrict endptr, + int base); + +This means that if any modification to these functions accidentally +introduces either an errant modification to the underlying character +array, or an accidental assignment to endptr rather than *endptr, the +compiler should generate an error. (The two uses of "restrict" in this +case basically mean strtol() isn't allowed to modify the character array +by going through *endptr, and endptr isn't allowed to point inside the +array.) + +It also means the typical use case changes to: + + char *s = ...; + const char *end; + long l; + + l = strtol(s, &end, 10); + +Or even: + + const char *p = str; + while (p && *p) { + long l = strtol(p, &p, 10); + ... + } + +This fixes 26 places where we discard our attempts at treating the data +safely by doing: + + const char *p = str; + long l; + + l = strtol(p, (char **)&ptr, 10); + +It also adds 5 places where we do: + + char *p = str; + while (p && *p) { + long l = strtol(p, (const char ** const)&p, 10); + ... + /* more calls that need p not to be pointer-to-const */ + } + +While moderately distasteful, this is a better problem to have. + +With one minor exception, I have tested that all of this compiles +without relevant warnings or errors, and that /much/ of it behaves +correctly, with gcc 9 using 'gcc -W -Wall -Wextra'. The one exception +is the changes in grub-core/osdep/aros/hostdisk.c , which I have no idea +how to build. + +Because the C standard defined type-qualifiers in a way that can be +confusing, in the past there's been a slow but fairly regular stream of +churn within our patches, which add and remove the const qualifier in many +of the users of these functions. This change should help avoid that in +the future, and in order to help ensure this, I've added an explanation +in misc.h so that when someone does get a compiler warning about a type +error, they have the fix at hand. + +The reason we don't have "const" in these calls in the standard is +purely anachronistic: C78 (de facto) did not have type qualifiers in the +syntax, and the "const" type qualifier was added for C89 (I think; it +may have been later). strtol() appears to date from 4.3BSD in 1986, +which means it could not be added to those functions in the standard +without breaking compatibility, which is usually avoided. + +The syntax chosen for type qualifiers is what has led to the churn +regarding usage of const, and is especially confusing on string +functions due to the lack of a string type. Quoting from C99, the +syntax is: + + declarator: + pointer[opt] direct-declarator + direct-declarator: + identifier + ( declarator ) + direct-declarator [ type-qualifier-list[opt] assignment-expression[opt] ] + ... + direct-declarator [ type-qualifier-list[opt] * ] + ... + pointer: + * type-qualifier-list[opt] + * type-qualifier-list[opt] pointer + type-qualifier-list: + type-qualifier + type-qualifier-list type-qualifier + ... + type-qualifier: + const + restrict + volatile + +So the examples go like: + +const char foo; // immutable object +const char *foo; // mutable pointer to object +char * const foo; // immutable pointer to mutable object +const char * const foo; // immutable pointer to immutable object +const char const * const foo; // XXX extra const keyword in the middle +const char * const * const foo; // immutable pointer to immutable + // pointer to immutable object +const char ** const foo; // immutable pointer to mutable pointer + // to immutable object + +Making const left-associative for * and right-associative for everything +else may not have been the best choice ever, but here we are, and the +inevitable result is people using trying to use const (as they should!), +putting it at the wrong place, fighting with the compiler for a bit, and +then either removing it or typecasting something in a bad way. I won't +go into describing restrict, but its syntax has exactly the same issue +as with const. + +Anyway, the last example above actually represents the *behavior* that's +required of strtol()-like functions, so that's our choice for the "end" +pointer. + +Signed-off-by: Peter Jones +--- + grub-core/commands/date.c | 3 ++- + grub-core/commands/i386/cmostest.c | 2 +- + grub-core/commands/i386/pc/play.c | 2 +- + grub-core/commands/i386/rdmsr.c | 2 +- + grub-core/commands/i386/wrmsr.c | 2 +- + grub-core/commands/password_pbkdf2.c | 2 +- + grub-core/commands/pcidump.c | 13 ++++++------- + grub-core/commands/regexp.c | 2 +- + grub-core/commands/setpci.c | 21 ++++++++++----------- + grub-core/commands/test.c | 2 +- + grub-core/commands/videoinfo.c | 2 +- + grub-core/disk/diskfilter.c | 3 ++- + grub-core/disk/lvm.c | 9 +++++---- + grub-core/efiemu/pnvram.c | 5 +++-- + grub-core/gfxmenu/gui_circular_progress.c | 2 +- + grub-core/gfxmenu/theme_loader.c | 2 +- + grub-core/kern/fs.c | 2 +- + grub-core/kern/misc.c | 10 ++++++---- + grub-core/kern/partition.c | 2 +- + grub-core/lib/arg.c | 2 +- + grub-core/lib/legacy_parse.c | 2 +- + grub-core/lib/syslinux_parse.c | 6 +++--- + grub-core/loader/i386/bsd.c | 6 +++--- + grub-core/loader/i386/linux.c | 2 +- + grub-core/loader/i386/pc/linux.c | 2 +- + grub-core/loader/i386/xen_fileXX.c | 2 +- + grub-core/mmap/mmap.c | 4 ++-- + grub-core/net/http.c | 4 ++-- + grub-core/net/net.c | 8 ++++---- + grub-core/normal/menu.c | 3 +-- + grub-core/osdep/aros/hostdisk.c | 2 +- + grub-core/osdep/devmapper/hostdisk.c | 2 +- + grub-core/script/execute.c | 6 +++--- + grub-core/term/serial.c | 2 +- + grub-core/term/terminfo.c | 2 +- + grub-core/tests/strtoull_test.c | 2 +- + util/grub-fstest.c | 2 +- + include/grub/misc.h | 24 +++++++++++++++++++++--- + 38 files changed, 96 insertions(+), 75 deletions(-) + +diff --git a/grub-core/commands/date.c b/grub-core/commands/date.c +index 8e1f41f141b..5cb4fafd454 100644 +--- a/grub-core/commands/date.c ++++ b/grub-core/commands/date.c +@@ -59,7 +59,8 @@ grub_cmd_date (grub_command_t cmd __attribute__ ((unused)), + + for (; argc; argc--, args++) + { +- char *p, c; ++ const char *p; ++ char c; + int m1, ofs, n, cur_mask; + + p = args[0]; +diff --git a/grub-core/commands/i386/cmostest.c b/grub-core/commands/i386/cmostest.c +index c839b704dc5..9f6b56a2f0c 100644 +--- a/grub-core/commands/i386/cmostest.c ++++ b/grub-core/commands/i386/cmostest.c +@@ -27,7 +27,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t + parse_args (int argc, char *argv[], int *byte, int *bit) + { +- char *rest; ++ const char *rest; + + if (argc != 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "address required"); +diff --git a/grub-core/commands/i386/pc/play.c b/grub-core/commands/i386/pc/play.c +index c8181310515..a980e46883c 100644 +--- a/grub-core/commands/i386/pc/play.c ++++ b/grub-core/commands/i386/pc/play.c +@@ -132,7 +132,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)), + } + else + { +- char *end; ++ const char *end; + unsigned tempo; + struct note note; + int i; +diff --git a/grub-core/commands/i386/rdmsr.c b/grub-core/commands/i386/rdmsr.c +index 15b9adfca67..46c4346da1b 100644 +--- a/grub-core/commands/i386/rdmsr.c ++++ b/grub-core/commands/i386/rdmsr.c +@@ -44,7 +44,7 @@ grub_cmd_msr_read (grub_extcmd_context_t ctxt, int argc, char **argv) + { + grub_uint32_t manufacturer[3], max_cpuid, a, b, c, features, addr; + grub_uint64_t value; +- char *ptr; ++ const char *ptr; + char buf[sizeof("1122334455667788")]; + + /* +diff --git a/grub-core/commands/i386/wrmsr.c b/grub-core/commands/i386/wrmsr.c +index 9c5e510eb44..fa76f5aed11 100644 +--- a/grub-core/commands/i386/wrmsr.c ++++ b/grub-core/commands/i386/wrmsr.c +@@ -37,7 +37,7 @@ grub_cmd_msr_write (grub_command_t cmd __attribute__ ((unused)), int argc, char + { + grub_uint32_t manufacturer[3], max_cpuid, a, b, c, features, addr; + grub_uint64_t value; +- char *ptr; ++ const char *ptr; + + /* + * The CPUID instruction should be used to determine whether MSRs +diff --git a/grub-core/commands/password_pbkdf2.c b/grub-core/commands/password_pbkdf2.c +index da636e6217a..ab845d25eb3 100644 +--- a/grub-core/commands/password_pbkdf2.c ++++ b/grub-core/commands/password_pbkdf2.c +@@ -86,7 +86,7 @@ grub_cmd_password (grub_command_t cmd __attribute__ ((unused)), + int argc, char **args) + { + grub_err_t err; +- char *ptr, *ptr2; ++ const char *ptr, *ptr2; + grub_uint8_t *ptro; + struct pbkdf2_password *pass; + +diff --git a/grub-core/commands/pcidump.c b/grub-core/commands/pcidump.c +index f99ad4a216f..f72628fce2d 100644 +--- a/grub-core/commands/pcidump.c ++++ b/grub-core/commands/pcidump.c +@@ -95,7 +95,7 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, + if (ctxt->state[0].set) + { + ptr = ctxt->state[0].arg; +- ctx.pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff); ++ ctx.pciid_check_value |= (grub_strtoul (ptr, &ptr, 16) & 0xffff); + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + grub_errno = GRUB_ERR_NONE; +@@ -108,8 +108,7 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, + if (*ptr != ':') + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':'); + ptr++; +- ctx.pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff) +- << 16; ++ ctx.pciid_check_value |= (grub_strtoul (ptr, &ptr, 16) & 0xffff) << 16; + if (grub_errno == GRUB_ERR_BAD_NUMBER) + grub_errno = GRUB_ERR_NONE; + else +@@ -121,10 +120,10 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, + if (ctxt->state[1].set) + { + const char *optr; +- ++ + ptr = ctxt->state[1].arg; + optr = ptr; +- ctx.bus = grub_strtoul (ptr, (char **) &ptr, 16); ++ ctx.bus = grub_strtoul (ptr, &ptr, 16); + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + grub_errno = GRUB_ERR_NONE; +@@ -138,7 +137,7 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':'); + ptr++; + optr = ptr; +- ctx.device = grub_strtoul (ptr, (char **) &ptr, 16); ++ ctx.device = grub_strtoul (ptr, &ptr, 16); + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + grub_errno = GRUB_ERR_NONE; +@@ -149,7 +148,7 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, + if (*ptr == '.') + { + ptr++; +- ctx.function = grub_strtoul (ptr, (char **) &ptr, 16); ++ ctx.function = grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + return grub_errno; + ctx.check_function = 1; +diff --git a/grub-core/commands/regexp.c b/grub-core/commands/regexp.c +index f00b184c81e..7c5c72fe460 100644 +--- a/grub-core/commands/regexp.c ++++ b/grub-core/commands/regexp.c +@@ -64,7 +64,7 @@ set_matches (char **varnames, char *str, grub_size_t nmatches, + { + int i; + char *p; +- char *q; ++ const char * q; + grub_err_t err; + unsigned long j; + +diff --git a/grub-core/commands/setpci.c b/grub-core/commands/setpci.c +index d5bc97d60b2..e966af080a6 100644 +--- a/grub-core/commands/setpci.c ++++ b/grub-core/commands/setpci.c +@@ -169,7 +169,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + if (ctxt->state[0].set) + { + ptr = ctxt->state[0].arg; +- pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff); ++ pciid_check_value |= (grub_strtoul (ptr, &ptr, 16) & 0xffff); + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + grub_errno = GRUB_ERR_NONE; +@@ -182,8 +182,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + if (*ptr != ':') + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':'); + ptr++; +- pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff) +- << 16; ++ pciid_check_value |= (grub_strtoul (ptr, &ptr, 16) & 0xffff) << 16; + if (grub_errno == GRUB_ERR_BAD_NUMBER) + grub_errno = GRUB_ERR_NONE; + else +@@ -197,10 +196,10 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + if (ctxt->state[1].set) + { + const char *optr; +- ++ + ptr = ctxt->state[1].arg; + optr = ptr; +- bus = grub_strtoul (ptr, (char **) &ptr, 16); ++ bus = grub_strtoul (ptr, &ptr, 16); + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + grub_errno = GRUB_ERR_NONE; +@@ -214,7 +213,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':'); + ptr++; + optr = ptr; +- device = grub_strtoul (ptr, (char **) &ptr, 16); ++ device = grub_strtoul (ptr, &ptr, 16); + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + grub_errno = GRUB_ERR_NONE; +@@ -225,7 +224,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + if (*ptr == '.') + { + ptr++; +- function = grub_strtoul (ptr, (char **) &ptr, 16); ++ function = grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + return grub_errno; + check_function = 1; +@@ -253,7 +252,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + if (i == ARRAY_SIZE (pci_registers)) + { + regsize = 0; +- regaddr = grub_strtoul (ptr, (char **) &ptr, 16); ++ regaddr = grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown register"); + } +@@ -270,7 +269,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + if (*ptr == '+') + { + ptr++; +- regaddr += grub_strtoul (ptr, (char **) &ptr, 16); ++ regaddr += grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + return grub_errno; + } +@@ -302,14 +301,14 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + if (*ptr == '=') + { + ptr++; +- regwrite = grub_strtoul (ptr, (char **) &ptr, 16); ++ regwrite = grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + return grub_errno; + write_mask = 0xffffffff; + if (*ptr == ':') + { + ptr++; +- write_mask = grub_strtoul (ptr, (char **) &ptr, 16); ++ write_mask = grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + return grub_errno; + write_mask = 0xffffffff; +diff --git a/grub-core/commands/test.c b/grub-core/commands/test.c +index 4e929e0452e..62d3fb3988f 100644 +--- a/grub-core/commands/test.c ++++ b/grub-core/commands/test.c +@@ -31,7 +31,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); + + /* A simple implementation for signed numbers. */ + static int +-grub_strtosl (char *arg, char **end, int base) ++grub_strtosl (char *arg, const char ** const end, int base) + { + if (arg[0] == '-') + return -grub_strtoul (arg + 1, end, base); +diff --git a/grub-core/commands/videoinfo.c b/grub-core/commands/videoinfo.c +index 4be8107d553..016a4d81835 100644 +--- a/grub-core/commands/videoinfo.c ++++ b/grub-core/commands/videoinfo.c +@@ -136,7 +136,7 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), + ctx.height = ctx.width = ctx.depth = 0; + if (argc) + { +- char *ptr; ++ const char *ptr; + ptr = args[0]; + ctx.width = grub_strtoul (ptr, &ptr, 0); + if (grub_errno) +diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c +index 1a3eb6b8d77..3f264be77d1 100644 +--- a/grub-core/disk/diskfilter.c ++++ b/grub-core/disk/diskfilter.c +@@ -971,7 +971,8 @@ grub_diskfilter_vg_register (struct grub_diskfilter_vg *vg) + for (p = vgp->lvs; p; p = p->next) + { + int cur_num; +- char *num, *end; ++ char *num; ++ const char *end; + if (!p->fullname) + continue; + if (grub_strncmp (p->fullname, lv->fullname, len) != 0) +diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c +index 7b265c780c3..0cbd0dd1629 100644 +--- a/grub-core/disk/lvm.c ++++ b/grub-core/disk/lvm.c +@@ -38,7 +38,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); + at the number. In case STR is not found, *P will be NULL and the + return value will be 0. */ + static grub_uint64_t +-grub_lvm_getvalue (char **p, const char *str) ++grub_lvm_getvalue (const char ** const p, const char *str) + { + *p = grub_strstr (*p, str); + if (! *p) +@@ -63,12 +63,12 @@ grub_lvm_checkvalue (char **p, char *str, char *tmpl) + #endif + + static int +-grub_lvm_check_flag (char *p, const char *str, const char *flag) ++grub_lvm_check_flag (const char *p, const char *str, const char *flag) + { + grub_size_t len_str = grub_strlen (str), len_flag = grub_strlen (flag); + while (1) + { +- char *q; ++ const char *q; + p = grub_strstr (p, str); + if (! p) + return 0; +@@ -105,7 +105,8 @@ grub_lvm_detect (grub_disk_t disk, + char buf[GRUB_LVM_LABEL_SIZE]; + char vg_id[GRUB_LVM_ID_STRLEN+1]; + char pv_id[GRUB_LVM_ID_STRLEN+1]; +- char *metadatabuf, *p, *q, *vgname; ++ char *metadatabuf, *vgname; ++ const char *p, *q; + struct grub_lvm_label_header *lh = (struct grub_lvm_label_header *) buf; + struct grub_lvm_pv_header *pvh; + struct grub_lvm_disk_locn *dlocn; +diff --git a/grub-core/efiemu/pnvram.c b/grub-core/efiemu/pnvram.c +index c5c3d4bd3d5..dd42bc69116 100644 +--- a/grub-core/efiemu/pnvram.c ++++ b/grub-core/efiemu/pnvram.c +@@ -39,7 +39,7 @@ static grub_size_t nvramsize; + + /* Parse signed value */ + static int +-grub_strtosl (const char *arg, char **end, int base) ++grub_strtosl (const char *arg, const char ** const end, int base) + { + if (arg[0] == '-') + return -grub_strtoul (arg + 1, end, base); +@@ -120,7 +120,8 @@ nvram_set (void * data __attribute__ ((unused))) + grub_memset (nvram, 0, nvramsize); + FOR_SORTED_ENV (var) + { +- char *guid, *attr, *name, *varname; ++ const char *guid; ++ char *attr, *name, *varname; + struct efi_variable *efivar; + int len = 0; + int i; +diff --git a/grub-core/gfxmenu/gui_circular_progress.c b/grub-core/gfxmenu/gui_circular_progress.c +index 354dd7b73ee..7578bfbec92 100644 +--- a/grub-core/gfxmenu/gui_circular_progress.c ++++ b/grub-core/gfxmenu/gui_circular_progress.c +@@ -230,7 +230,7 @@ circprog_set_state (void *vself, int visible, int start, + static int + parse_angle (const char *value) + { +- char *ptr; ++ const char *ptr; + int angle; + + angle = grub_strtol (value, &ptr, 10); +diff --git a/grub-core/gfxmenu/theme_loader.c b/grub-core/gfxmenu/theme_loader.c +index d6829bb5e90..eae83086bcc 100644 +--- a/grub-core/gfxmenu/theme_loader.c ++++ b/grub-core/gfxmenu/theme_loader.c +@@ -484,7 +484,7 @@ parse_proportional_spec (const char *value, signed *abs, grub_fixed_signed_t *pr + ptr++; + } + +- num = grub_strtoul (ptr, (char **) &ptr, 0); ++ num = grub_strtoul (ptr, &ptr, 0); + if (grub_errno) + return grub_errno; + if (sig) +diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c +index 2b85f4950bd..88d39360da0 100644 +--- a/grub-core/kern/fs.c ++++ b/grub-core/kern/fs.c +@@ -134,7 +134,7 @@ struct grub_fs_block + static grub_err_t + grub_fs_blocklist_open (grub_file_t file, const char *name) + { +- char *p = (char *) name; ++ const char *p = name; + unsigned num = 0; + unsigned i; + grub_disk_t disk = file->device->disk; +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 5c3899f0e5b..e21dd44c7cf 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -383,7 +383,8 @@ grub_isspace (int c) + } + + unsigned long +-grub_strtoul (const char *str, char **end, int base) ++grub_strtoul (const char * restrict str, const char ** const restrict end, ++ int base) + { + unsigned long long num; + +@@ -400,7 +401,8 @@ grub_strtoul (const char *str, char **end, int base) + } + + unsigned long long +-grub_strtoull (const char *str, char **end, int base) ++grub_strtoull (const char * restrict str, const char ** const restrict end, ++ int base) + { + unsigned long long num = 0; + int found = 0; +@@ -901,14 +903,14 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0, + { + if (fmt[0] == '0') + zerofill = '0'; +- format1 = grub_strtoul (fmt, (char **) &fmt, 10); ++ format1 = grub_strtoul (fmt, &fmt, 10); + } + + if (*fmt == '.') + fmt++; + + if (grub_isdigit (*fmt)) +- format2 = grub_strtoul (fmt, (char **) &fmt, 10); ++ format2 = grub_strtoul (fmt, &fmt, 10); + + if (*fmt == '$') + { +diff --git a/grub-core/kern/partition.c b/grub-core/kern/partition.c +index e499147cbcb..2c401b866c4 100644 +--- a/grub-core/kern/partition.c ++++ b/grub-core/kern/partition.c +@@ -126,7 +126,7 @@ grub_partition_probe (struct grub_disk *disk, const char *str) + while (*ptr && grub_isalpha (*ptr)) + ptr++; + partname_end = ptr; +- num = grub_strtoul (ptr, (char **) &ptr, 0) - 1; ++ num = grub_strtoul (ptr, &ptr, 0) - 1; + + curpart = 0; + /* Use the first partition map type found. */ +diff --git a/grub-core/lib/arg.c b/grub-core/lib/arg.c +index fd7744a6ff6..ccc185017ee 100644 +--- a/grub-core/lib/arg.c ++++ b/grub-core/lib/arg.c +@@ -375,7 +375,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv, + + case ARG_TYPE_INT: + { +- char *tail; ++ const char * tail; + + grub_strtoull (option, &tail, 0); + if (tail == 0 || tail == option || *tail != '\0' || grub_errno) +diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c +index ef56150ac77..05719ab2ccb 100644 +--- a/grub-core/lib/legacy_parse.c ++++ b/grub-core/lib/legacy_parse.c +@@ -418,7 +418,7 @@ adjust_file (const char *in, grub_size_t len) + } + if (*comma != ',') + return grub_legacy_escape (in, len); +- part = grub_strtoull (comma + 1, (char **) &rest, 0); ++ part = grub_strtoull (comma + 1, &rest, 0); + if (rest[0] == ',' && rest[1] >= 'a' && rest[1] <= 'z') + { + subpart = rest[1] - 'a'; +diff --git a/grub-core/lib/syslinux_parse.c b/grub-core/lib/syslinux_parse.c +index 4afa99279a2..de9fda06f52 100644 +--- a/grub-core/lib/syslinux_parse.c ++++ b/grub-core/lib/syslinux_parse.c +@@ -1062,7 +1062,7 @@ write_entry (struct output_buffer *outbuf, + if (ptr[0] == 'h' && ptr[1] == 'd') + { + is_fd = 0; +- devn = grub_strtoul (ptr + 2, &ptr, 0); ++ devn = grub_strtoul (ptr + 2, (const char **)&ptr, 0); + continue; + } + if (grub_strncasecmp (ptr, "file=", 5) == 0) +@@ -1086,12 +1086,12 @@ write_entry (struct output_buffer *outbuf, + if (ptr[0] == 'f' && ptr[1] == 'd') + { + is_fd = 1; +- devn = grub_strtoul (ptr + 2, &ptr, 0); ++ devn = grub_strtoul (ptr + 2, (const char **)&ptr, 0); + continue; + } + if (grub_isdigit (ptr[0])) + { +- part = grub_strtoul (ptr, &ptr, 0); ++ part = grub_strtoul (ptr, (const char **)&ptr, 0); + continue; + } + /* FIXME: isolinux, ntldr, cmldr, *dos, seg, hide +diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c +index 5b9b92d6ba5..50cca304fd0 100644 +--- a/grub-core/loader/i386/bsd.c ++++ b/grub-core/loader/i386/bsd.c +@@ -1616,7 +1616,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "unknown disk type name"); + +- unit = grub_strtoul (arg, (char **) &arg, 10); ++ unit = grub_strtoul (arg, &arg, 10); + if (! (arg && *arg >= 'a' && *arg <= 'z')) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "only device specifications of form " +@@ -1634,7 +1634,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) + if (ctxt->state[OPENBSD_SERIAL_ARG].set) + { + struct grub_openbsd_bootarg_console serial; +- char *ptr; ++ const char *ptr; + unsigned port = 0; + unsigned speed = 9600; + +@@ -1736,7 +1736,7 @@ grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) + if (ctxt->state[NETBSD_SERIAL_ARG].set) + { + struct grub_netbsd_btinfo_serial serial; +- char *ptr; ++ const char *ptr; + + grub_memset (&serial, 0, sizeof (serial)); + grub_strcpy (serial.devname, "com"); +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index 376c726928a..201e6597c6d 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -954,7 +954,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + #endif /* GRUB_MACHINE_PCBIOS */ + if (grub_memcmp (argv[i], "mem=", 4) == 0) + { +- char *val = argv[i] + 4; ++ const char *val = argv[i] + 4; + + linux_mem_size = grub_strtoul (val, &val, 0); + +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index fe3e1d41d09..0bf0e13d647 100644 +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -272,7 +272,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + else if (grub_memcmp (argv[i], "mem=", 4) == 0) + { +- char *val = argv[i] + 4; ++ const char *val = argv[i] + 4; + + linux_mem_size = grub_strtoul (val, &val, 0); + +diff --git a/grub-core/loader/i386/xen_fileXX.c b/grub-core/loader/i386/xen_fileXX.c +index 6329ec01038..27afcaacbce 100644 +--- a/grub-core/loader/i386/xen_fileXX.c ++++ b/grub-core/loader/i386/xen_fileXX.c +@@ -25,7 +25,7 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, + grub_off_t off, grub_size_t sz) + { + char *buf; +- char *ptr; ++ const char *ptr; + int has_paddr = 0; + + grub_errno = GRUB_ERR_NONE; +diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c +index 6a31cbae325..b569cb23b5a 100644 +--- a/grub-core/mmap/mmap.c ++++ b/grub-core/mmap/mmap.c +@@ -423,7 +423,7 @@ static grub_err_t + grub_cmd_badram (grub_command_t cmd __attribute__ ((unused)), + int argc, char **args) + { +- char * str; ++ const char *str; + struct badram_entry entry; + + if (argc != 1) +@@ -465,7 +465,7 @@ static grub_uint64_t + parsemem (const char *str) + { + grub_uint64_t ret; +- char *ptr; ++ const char *ptr; + + ret = grub_strtoul (str, &ptr, 0); + +diff --git a/grub-core/net/http.c b/grub-core/net/http.c +index c9c59690a98..b52b558d631 100644 +--- a/grub-core/net/http.c ++++ b/grub-core/net/http.c +@@ -110,7 +110,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) + return GRUB_ERR_NONE; + } + ptr += sizeof ("HTTP/1.1 ") - 1; +- code = grub_strtoul (ptr, &ptr, 10); ++ code = grub_strtoul (ptr, (const char **)&ptr, 10); + if (grub_errno) + return grub_errno; + switch (code) +@@ -137,7 +137,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) + == 0 && !data->size_recv) + { + ptr += sizeof ("Content-Length: ") - 1; +- file->size = grub_strtoull (ptr, &ptr, 10); ++ file->size = grub_strtoull (ptr, (const char **)&ptr, 10); + data->size_recv = 1; + return GRUB_ERR_NONE; + } +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index 27a0a1d6961..aa56393e1c4 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -411,7 +411,7 @@ parse_ip (const char *val, grub_uint32_t *ip, const char **rest) + for (i = 0; i < 4; i++) + { + unsigned long t; +- t = grub_strtoul (ptr, (char **) &ptr, 0); ++ t = grub_strtoul (ptr, &ptr, 0); + if (grub_errno) + { + grub_errno = GRUB_ERR_NONE; +@@ -465,7 +465,7 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) + ptr++; + continue; + } +- t = grub_strtoul (ptr, (char **) &ptr, 16); ++ t = grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + { + grub_errno = GRUB_ERR_NONE; +@@ -577,7 +577,7 @@ grub_net_resolve_net_address (const char *name, + addr->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + if (*rest == '/') + { +- addr->ipv4.masksize = grub_strtoul (rest + 1, (char **) &rest, 0); ++ addr->ipv4.masksize = grub_strtoul (rest + 1, &rest, 0); + if (!grub_errno && *rest == 0) + return GRUB_ERR_NONE; + grub_errno = GRUB_ERR_NONE; +@@ -593,7 +593,7 @@ grub_net_resolve_net_address (const char *name, + addr->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; + if (*rest == '/') + { +- addr->ipv6.masksize = grub_strtoul (rest + 1, (char **) &rest, 0); ++ addr->ipv6.masksize = grub_strtoul (rest + 1, &rest, 0); + if (!grub_errno && *rest == 0) + return GRUB_ERR_NONE; + grub_errno = GRUB_ERR_NONE; +diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c +index 046a1fb2c84..37d753d8081 100644 +--- a/grub-core/normal/menu.c ++++ b/grub-core/normal/menu.c +@@ -194,8 +194,7 @@ menuentry_eq (const char *id, const char *spec) + static int + get_and_remove_first_entry_number (grub_menu_t menu, const char *name) + { +- const char *val; +- char *tail; ++ const char *val, *tail; + int entry; + int sz = 0; + +diff --git a/grub-core/osdep/aros/hostdisk.c b/grub-core/osdep/aros/hostdisk.c +index 2be654ca3bd..3b2c9de2496 100644 +--- a/grub-core/osdep/aros/hostdisk.c ++++ b/grub-core/osdep/aros/hostdisk.c +@@ -194,7 +194,7 @@ grub_util_fd_open (const char *dev, int flg) + p1 = dev + strlen (dev); + else + { +- unit = grub_strtoul (p1 + 1, (char **) &p2, 16); ++ unit = grub_strtoul (p1 + 1, &p2, 16); + if (p2 && *p2 == '/') + flags = grub_strtoul (p2 + 1, 0, 16); + } +diff --git a/grub-core/osdep/devmapper/hostdisk.c b/grub-core/osdep/devmapper/hostdisk.c +index a697bcb4d8d..a8afc0c9408 100644 +--- a/grub-core/osdep/devmapper/hostdisk.c ++++ b/grub-core/osdep/devmapper/hostdisk.c +@@ -113,7 +113,7 @@ grub_util_get_dm_node_linear_info (dev_t dev, + void *next = NULL; + uint64_t length, start; + char *target, *params; +- char *ptr; ++ const char *ptr; + int major = 0, minor = 0; + int first = 1; + grub_disk_addr_t partstart = 0; +diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c +index ba38b5e8aef..c6d2c365c9a 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -146,7 +146,7 @@ replace_scope (struct grub_script_scope *new_scope) + grub_err_t + grub_script_break (grub_command_t cmd, int argc, char *argv[]) + { +- char *p = 0; ++ const char *p = NULL; + unsigned long count; + + if (argc == 0) +@@ -178,7 +178,7 @@ grub_err_t + grub_script_shift (grub_command_t cmd __attribute__((unused)), + int argc, char *argv[]) + { +- char *p = 0; ++ const char *p = NULL; + unsigned long n = 0; + + if (! scope) +@@ -239,7 +239,7 @@ grub_err_t + grub_script_return (grub_command_t cmd __attribute__((unused)), + int argc, char *argv[]) + { +- char *p; ++ const char *p = NULL; + unsigned long n; + + if (! scope || argc > 1) +diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c +index db80b3ba0fb..f9271b09239 100644 +--- a/grub-core/term/serial.c ++++ b/grub-core/term/serial.c +@@ -269,7 +269,7 @@ grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args) + + if (state[OPTION_BASE_CLOCK].set) + { +- char *ptr; ++ const char *ptr; + config.base_clock = grub_strtoull (state[OPTION_BASE_CLOCK].arg, &ptr, 0); + if (grub_errno) + return grub_errno; +diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c +index 29df35e6d20..537a5c0cb0b 100644 +--- a/grub-core/term/terminfo.c ++++ b/grub-core/term/terminfo.c +@@ -737,7 +737,7 @@ grub_cmd_terminfo (grub_extcmd_context_t ctxt, int argc, char **args) + + if (state[OPTION_GEOMETRY].set) + { +- char *ptr = state[OPTION_GEOMETRY].arg; ++ const char *ptr = state[OPTION_GEOMETRY].arg; + w = grub_strtoul (ptr, &ptr, 0); + if (grub_errno) + return grub_errno; +diff --git a/grub-core/tests/strtoull_test.c b/grub-core/tests/strtoull_test.c +index 7da615ff33e..5488ab26b43 100644 +--- a/grub-core/tests/strtoull_test.c ++++ b/grub-core/tests/strtoull_test.c +@@ -25,7 +25,7 @@ static void + strtoull_testcase (const char *input, int base, unsigned long long expected, + int num_digits, grub_err_t error) + { +- char *output; ++ const char *output; + unsigned long long value; + grub_errno = 0; + value = grub_strtoull(input, &output, base); +diff --git a/util/grub-fstest.c b/util/grub-fstest.c +index 88f9c5d4ad8..39bad1f432f 100644 +--- a/util/grub-fstest.c ++++ b/util/grub-fstest.c +@@ -538,7 +538,7 @@ void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; + static error_t + argp_parser (int key, char *arg, struct argp_state *state) + { +- char *p; ++ const char *p; + + switch (key) + { +diff --git a/include/grub/misc.h b/include/grub/misc.h +index 960097fbd06..998e47e0ccf 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -288,11 +288,29 @@ grub_strncasecmp (const char *s1, const char *s2, grub_size_t n) + - (int) grub_tolower ((grub_uint8_t) *s2); + } + +-unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, char **end, int base); +-unsigned long long EXPORT_FUNC(grub_strtoull) (const char *str, char **end, int base); ++/* ++ * Note that these differ from the C standard's definitions of strtol, ++ * strtoul(), and strtoull() by the addition of two const qualifiers on the end ++ * pointer, which make the declaration match the *semantic* requirements of ++ * their behavior. This means that instead of: ++ * ++ * char *s = "1234 abcd"; ++ * char *end; ++ * unsigned long l; ++ * ++ * l = grub_strtoul(s, &end, 10); ++ * ++ * We must one of: ++ * ++ * const char *end; ++ * ... or ... ++ * l = grub_strtoul(s, (const char ** const)&end, 10); ++ */ ++unsigned long EXPORT_FUNC(grub_strtoul) (const char * restrict str, const char ** const restrict end, int base); ++unsigned long long EXPORT_FUNC(grub_strtoull) (const char * restrict str, const char ** const restrict end, int base); + + static inline long +-grub_strtol (const char *str, char **end, int base) ++grub_strtol (const char * restrict str, const char ** const restrict end, int base) + { + int negative = 0; + unsigned long long magnitude; diff --git a/0160-Make-grub_strtoul-end-pointer-have-the-right-constif.patch b/0160-Make-grub_strtoul-end-pointer-have-the-right-constif.patch deleted file mode 100644 index 234f32a..0000000 --- a/0160-Make-grub_strtoul-end-pointer-have-the-right-constif.patch +++ /dev/null @@ -1,592 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 19 Oct 2018 13:41:48 -0400 -Subject: [PATCH] Make grub_strtoul "end" pointer have the right - constification. - -Related: rhbz#1640979 -Signed-off-by: Peter Jones ---- - grub-core/commands/date.c | 5 +++-- - grub-core/commands/password_pbkdf2.c | 2 +- - grub-core/commands/regexp.c | 2 +- - grub-core/commands/videoinfo.c | 2 +- - grub-core/disk/diskfilter.c | 3 ++- - grub-core/disk/lvm.c | 9 +++++---- - grub-core/kern/fs.c | 2 +- - grub-core/kern/misc.c | 8 ++++---- - grub-core/kern/partition.c | 2 +- - grub-core/lib/arg.c | 2 +- - grub-core/lib/legacy_parse.c | 2 +- - grub-core/lib/syslinux_parse.c | 6 +++--- - grub-core/loader/i386/xen_fileXX.c | 2 +- - grub-core/net/efi/ip4_config.c | 2 +- - grub-core/net/efi/ip6_config.c | 2 +- - grub-core/net/efi/net.c | 4 ++-- - grub-core/net/efi/pxe.c | 6 +++--- - grub-core/net/http.c | 4 ++-- - grub-core/net/net.c | 8 ++++---- - grub-core/net/url.c | 2 +- - grub-core/osdep/devmapper/hostdisk.c | 2 +- - grub-core/script/execute.c | 6 +++--- - grub-core/term/serial.c | 2 +- - grub-core/term/terminfo.c | 2 +- - grub-core/tests/strtoull_test.c | 2 +- - util/grub-fstest.c | 2 +- - include/grub/emu/getroot.h | 4 ++++ - include/grub/emu/misc.h | 3 +++ - include/grub/misc.h | 6 +++--- - 29 files changed, 57 insertions(+), 47 deletions(-) - -diff --git a/grub-core/commands/date.c b/grub-core/commands/date.c -index 8e1f41f141b..0ff0f132c28 100644 ---- a/grub-core/commands/date.c -+++ b/grub-core/commands/date.c -@@ -35,7 +35,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); - - static grub_err_t - grub_cmd_date (grub_command_t cmd __attribute__ ((unused)), -- int argc, char **args) -+ int argc, char ** args) - { - struct grub_datetime datetime; - int limit[6][2] = {{1980, 2079}, {1, 12}, {1, 31}, {0, 23}, {0, 59}, {0, 59}}; -@@ -59,7 +59,8 @@ grub_cmd_date (grub_command_t cmd __attribute__ ((unused)), - - for (; argc; argc--, args++) - { -- char *p, c; -+ const char *p; -+ char c; - int m1, ofs, n, cur_mask; - - p = args[0]; -diff --git a/grub-core/commands/password_pbkdf2.c b/grub-core/commands/password_pbkdf2.c -index da636e6217a..ab845d25eb3 100644 ---- a/grub-core/commands/password_pbkdf2.c -+++ b/grub-core/commands/password_pbkdf2.c -@@ -86,7 +86,7 @@ grub_cmd_password (grub_command_t cmd __attribute__ ((unused)), - int argc, char **args) - { - grub_err_t err; -- char *ptr, *ptr2; -+ const char *ptr, *ptr2; - grub_uint8_t *ptro; - struct pbkdf2_password *pass; - -diff --git a/grub-core/commands/regexp.c b/grub-core/commands/regexp.c -index f00b184c81e..7c5c72fe460 100644 ---- a/grub-core/commands/regexp.c -+++ b/grub-core/commands/regexp.c -@@ -64,7 +64,7 @@ set_matches (char **varnames, char *str, grub_size_t nmatches, - { - int i; - char *p; -- char *q; -+ const char * q; - grub_err_t err; - unsigned long j; - -diff --git a/grub-core/commands/videoinfo.c b/grub-core/commands/videoinfo.c -index 4be8107d553..016a4d81835 100644 ---- a/grub-core/commands/videoinfo.c -+++ b/grub-core/commands/videoinfo.c -@@ -136,7 +136,7 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), - ctx.height = ctx.width = ctx.depth = 0; - if (argc) - { -- char *ptr; -+ const char *ptr; - ptr = args[0]; - ctx.width = grub_strtoul (ptr, &ptr, 0); - if (grub_errno) -diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c -index 1a3eb6b8d77..3f264be77d1 100644 ---- a/grub-core/disk/diskfilter.c -+++ b/grub-core/disk/diskfilter.c -@@ -971,7 +971,8 @@ grub_diskfilter_vg_register (struct grub_diskfilter_vg *vg) - for (p = vgp->lvs; p; p = p->next) - { - int cur_num; -- char *num, *end; -+ char *num; -+ const char *end; - if (!p->fullname) - continue; - if (grub_strncmp (p->fullname, lv->fullname, len) != 0) -diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c -index 7b265c780c3..0cbd0dd1629 100644 ---- a/grub-core/disk/lvm.c -+++ b/grub-core/disk/lvm.c -@@ -38,7 +38,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); - at the number. In case STR is not found, *P will be NULL and the - return value will be 0. */ - static grub_uint64_t --grub_lvm_getvalue (char **p, const char *str) -+grub_lvm_getvalue (const char ** const p, const char *str) - { - *p = grub_strstr (*p, str); - if (! *p) -@@ -63,12 +63,12 @@ grub_lvm_checkvalue (char **p, char *str, char *tmpl) - #endif - - static int --grub_lvm_check_flag (char *p, const char *str, const char *flag) -+grub_lvm_check_flag (const char *p, const char *str, const char *flag) - { - grub_size_t len_str = grub_strlen (str), len_flag = grub_strlen (flag); - while (1) - { -- char *q; -+ const char *q; - p = grub_strstr (p, str); - if (! p) - return 0; -@@ -105,7 +105,8 @@ grub_lvm_detect (grub_disk_t disk, - char buf[GRUB_LVM_LABEL_SIZE]; - char vg_id[GRUB_LVM_ID_STRLEN+1]; - char pv_id[GRUB_LVM_ID_STRLEN+1]; -- char *metadatabuf, *p, *q, *vgname; -+ char *metadatabuf, *vgname; -+ const char *p, *q; - struct grub_lvm_label_header *lh = (struct grub_lvm_label_header *) buf; - struct grub_lvm_pv_header *pvh; - struct grub_lvm_disk_locn *dlocn; -diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c -index 2b85f4950bd..88d39360da0 100644 ---- a/grub-core/kern/fs.c -+++ b/grub-core/kern/fs.c -@@ -134,7 +134,7 @@ struct grub_fs_block - static grub_err_t - grub_fs_blocklist_open (grub_file_t file, const char *name) - { -- char *p = (char *) name; -+ const char *p = name; - unsigned num = 0; - unsigned i; - grub_disk_t disk = file->device->disk; -diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 5c3899f0e5b..aaae9aa0ab7 100644 ---- a/grub-core/kern/misc.c -+++ b/grub-core/kern/misc.c -@@ -383,7 +383,7 @@ grub_isspace (int c) - } - - unsigned long --grub_strtoul (const char *str, char **end, int base) -+grub_strtoul (const char *str, const char ** const end, int base) - { - unsigned long long num; - -@@ -400,7 +400,7 @@ grub_strtoul (const char *str, char **end, int base) - } - - unsigned long long --grub_strtoull (const char *str, char **end, int base) -+grub_strtoull (const char *str, const char ** const end, int base) - { - unsigned long long num = 0; - int found = 0; -@@ -901,14 +901,14 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0, - { - if (fmt[0] == '0') - zerofill = '0'; -- format1 = grub_strtoul (fmt, (char **) &fmt, 10); -+ format1 = grub_strtoul (fmt, &fmt, 10); - } - - if (*fmt == '.') - fmt++; - - if (grub_isdigit (*fmt)) -- format2 = grub_strtoul (fmt, (char **) &fmt, 10); -+ format2 = grub_strtoul (fmt, &fmt, 10); - - if (*fmt == '$') - { -diff --git a/grub-core/kern/partition.c b/grub-core/kern/partition.c -index e499147cbcb..2c401b866c4 100644 ---- a/grub-core/kern/partition.c -+++ b/grub-core/kern/partition.c -@@ -126,7 +126,7 @@ grub_partition_probe (struct grub_disk *disk, const char *str) - while (*ptr && grub_isalpha (*ptr)) - ptr++; - partname_end = ptr; -- num = grub_strtoul (ptr, (char **) &ptr, 0) - 1; -+ num = grub_strtoul (ptr, &ptr, 0) - 1; - - curpart = 0; - /* Use the first partition map type found. */ -diff --git a/grub-core/lib/arg.c b/grub-core/lib/arg.c -index fd7744a6ff6..ccc185017ee 100644 ---- a/grub-core/lib/arg.c -+++ b/grub-core/lib/arg.c -@@ -375,7 +375,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv, - - case ARG_TYPE_INT: - { -- char *tail; -+ const char * tail; - - grub_strtoull (option, &tail, 0); - if (tail == 0 || tail == option || *tail != '\0' || grub_errno) -diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c -index ef56150ac77..05719ab2ccb 100644 ---- a/grub-core/lib/legacy_parse.c -+++ b/grub-core/lib/legacy_parse.c -@@ -418,7 +418,7 @@ adjust_file (const char *in, grub_size_t len) - } - if (*comma != ',') - return grub_legacy_escape (in, len); -- part = grub_strtoull (comma + 1, (char **) &rest, 0); -+ part = grub_strtoull (comma + 1, &rest, 0); - if (rest[0] == ',' && rest[1] >= 'a' && rest[1] <= 'z') - { - subpart = rest[1] - 'a'; -diff --git a/grub-core/lib/syslinux_parse.c b/grub-core/lib/syslinux_parse.c -index 4afa99279a2..de9fda06f52 100644 ---- a/grub-core/lib/syslinux_parse.c -+++ b/grub-core/lib/syslinux_parse.c -@@ -1062,7 +1062,7 @@ write_entry (struct output_buffer *outbuf, - if (ptr[0] == 'h' && ptr[1] == 'd') - { - is_fd = 0; -- devn = grub_strtoul (ptr + 2, &ptr, 0); -+ devn = grub_strtoul (ptr + 2, (const char **)&ptr, 0); - continue; - } - if (grub_strncasecmp (ptr, "file=", 5) == 0) -@@ -1086,12 +1086,12 @@ write_entry (struct output_buffer *outbuf, - if (ptr[0] == 'f' && ptr[1] == 'd') - { - is_fd = 1; -- devn = grub_strtoul (ptr + 2, &ptr, 0); -+ devn = grub_strtoul (ptr + 2, (const char **)&ptr, 0); - continue; - } - if (grub_isdigit (ptr[0])) - { -- part = grub_strtoul (ptr, &ptr, 0); -+ part = grub_strtoul (ptr, (const char **)&ptr, 0); - continue; - } - /* FIXME: isolinux, ntldr, cmldr, *dos, seg, hide -diff --git a/grub-core/loader/i386/xen_fileXX.c b/grub-core/loader/i386/xen_fileXX.c -index 6329ec01038..27afcaacbce 100644 ---- a/grub-core/loader/i386/xen_fileXX.c -+++ b/grub-core/loader/i386/xen_fileXX.c -@@ -25,7 +25,7 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, - grub_off_t off, grub_size_t sz) - { - char *buf; -- char *ptr; -+ const char *ptr; - int has_paddr = 0; - - grub_errno = GRUB_ERR_NONE; -diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c -index b711a5d9457..38e2a04747a 100644 ---- a/grub-core/net/efi/ip4_config.c -+++ b/grub-core/net/efi/ip4_config.c -@@ -62,7 +62,7 @@ grub_efi_string_to_ip4_address (const char *val, grub_efi_ipv4_address_t *addres - for (i = 0; i < 4; i++) - { - unsigned long t; -- t = grub_strtoul (ptr, (char **) &ptr, 0); -+ t = grub_strtoul (ptr, &ptr, 0); - if (grub_errno) - { - grub_errno = GRUB_ERR_NONE; -diff --git a/grub-core/net/efi/ip6_config.c b/grub-core/net/efi/ip6_config.c -index 017c4d05bc7..e0e00c23d21 100644 ---- a/grub-core/net/efi/ip6_config.c -+++ b/grub-core/net/efi/ip6_config.c -@@ -84,7 +84,7 @@ grub_efi_string_to_ip6_address (const char *val, grub_efi_ipv6_address_t *addres - ptr++; - continue; - } -- t = grub_strtoul (ptr, (char **) &ptr, 16); -+ t = grub_strtoul (ptr, &ptr, 16); - if (grub_errno) - { - grub_errno = GRUB_ERR_NONE; -diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c -index 6603cd83edc..cdb8fd111a7 100644 ---- a/grub-core/net/efi/net.c -+++ b/grub-core/net/efi/net.c -@@ -729,7 +729,7 @@ grub_efi_net_parse_address (const char *address, - { - grub_uint32_t subnet_mask_size; - -- subnet_mask_size = grub_strtoul (rest + 1, (char **) &rest, 0); -+ subnet_mask_size = grub_strtoul (rest + 1, &rest, 0); - - if (!grub_errno && subnet_mask_size <= 32 && *rest == 0) - { -@@ -758,7 +758,7 @@ grub_efi_net_parse_address (const char *address, - { - grub_efi_uint8_t prefix_length; - -- prefix_length = grub_strtoul (rest + 1, (char **) &rest, 0); -+ prefix_length = grub_strtoul (rest + 1, &rest, 0); - if (!grub_errno && prefix_length <= 128 && *rest == 0) - { - ip6->prefix_length = prefix_length; -diff --git a/grub-core/net/efi/pxe.c b/grub-core/net/efi/pxe.c -index 531949cba5c..73e2bb01c1b 100644 ---- a/grub-core/net/efi/pxe.c -+++ b/grub-core/net/efi/pxe.c -@@ -187,7 +187,7 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) - ptr++; - continue; - } -- t = grub_strtoul (ptr, (char **) &ptr, 16); -+ t = grub_strtoul (ptr, &ptr, 16); - if (grub_errno) - { - grub_errno = GRUB_ERR_NONE; -@@ -225,7 +225,7 @@ pxe_open (struct grub_efi_net_device *dev, - int type __attribute__((unused))) - { - int i; -- char *p; -+ const char *p; - grub_efi_status_t status; - grub_efi_pxe_ip_address_t server_ip; - grub_efi_uint64_t file_size = 0; -@@ -313,7 +313,7 @@ pxe_read (struct grub_efi_net_device *dev, - grub_size_t len) - { - int i; -- char *p; -+ const char *p; - grub_efi_status_t status; - grub_efi_pxe_t *pxe = (prefer_ip6) ? dev->ip6_pxe : dev->ip4_pxe; - grub_efi_uint64_t bufsz = len; -diff --git a/grub-core/net/http.c b/grub-core/net/http.c -index c9c59690a98..b52b558d631 100644 ---- a/grub-core/net/http.c -+++ b/grub-core/net/http.c -@@ -110,7 +110,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) - return GRUB_ERR_NONE; - } - ptr += sizeof ("HTTP/1.1 ") - 1; -- code = grub_strtoul (ptr, &ptr, 10); -+ code = grub_strtoul (ptr, (const char **)&ptr, 10); - if (grub_errno) - return grub_errno; - switch (code) -@@ -137,7 +137,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) - == 0 && !data->size_recv) - { - ptr += sizeof ("Content-Length: ") - 1; -- file->size = grub_strtoull (ptr, &ptr, 10); -+ file->size = grub_strtoull (ptr, (const char **)&ptr, 10); - data->size_recv = 1; - return GRUB_ERR_NONE; - } -diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index 27a0a1d6961..aa56393e1c4 100644 ---- a/grub-core/net/net.c -+++ b/grub-core/net/net.c -@@ -411,7 +411,7 @@ parse_ip (const char *val, grub_uint32_t *ip, const char **rest) - for (i = 0; i < 4; i++) - { - unsigned long t; -- t = grub_strtoul (ptr, (char **) &ptr, 0); -+ t = grub_strtoul (ptr, &ptr, 0); - if (grub_errno) - { - grub_errno = GRUB_ERR_NONE; -@@ -465,7 +465,7 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) - ptr++; - continue; - } -- t = grub_strtoul (ptr, (char **) &ptr, 16); -+ t = grub_strtoul (ptr, &ptr, 16); - if (grub_errno) - { - grub_errno = GRUB_ERR_NONE; -@@ -577,7 +577,7 @@ grub_net_resolve_net_address (const char *name, - addr->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - if (*rest == '/') - { -- addr->ipv4.masksize = grub_strtoul (rest + 1, (char **) &rest, 0); -+ addr->ipv4.masksize = grub_strtoul (rest + 1, &rest, 0); - if (!grub_errno && *rest == 0) - return GRUB_ERR_NONE; - grub_errno = GRUB_ERR_NONE; -@@ -593,7 +593,7 @@ grub_net_resolve_net_address (const char *name, - addr->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; - if (*rest == '/') - { -- addr->ipv6.masksize = grub_strtoul (rest + 1, (char **) &rest, 0); -+ addr->ipv6.masksize = grub_strtoul (rest + 1, &rest, 0); - if (!grub_errno && *rest == 0) - return GRUB_ERR_NONE; - grub_errno = GRUB_ERR_NONE; -diff --git a/grub-core/net/url.c b/grub-core/net/url.c -index 146858284cd..d9d2fc9a9dc 100644 ---- a/grub-core/net/url.c -+++ b/grub-core/net/url.c -@@ -235,7 +235,7 @@ extract_http_url_info (char *url, int ssl, - c = *port_end; - *port_end = '\0'; - -- portul = grub_strtoul (port_off, &separator, 10); -+ portul = grub_strtoul (port_off, (const char **)&separator, 10); - *port_end = c; - #ifdef URL_TEST - if (portul == ULONG_MAX && errno == ERANGE) -diff --git a/grub-core/osdep/devmapper/hostdisk.c b/grub-core/osdep/devmapper/hostdisk.c -index a697bcb4d8d..a8afc0c9408 100644 ---- a/grub-core/osdep/devmapper/hostdisk.c -+++ b/grub-core/osdep/devmapper/hostdisk.c -@@ -113,7 +113,7 @@ grub_util_get_dm_node_linear_info (dev_t dev, - void *next = NULL; - uint64_t length, start; - char *target, *params; -- char *ptr; -+ const char *ptr; - int major = 0, minor = 0; - int first = 1; - grub_disk_addr_t partstart = 0; -diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c -index ba38b5e8aef..c6d2c365c9a 100644 ---- a/grub-core/script/execute.c -+++ b/grub-core/script/execute.c -@@ -146,7 +146,7 @@ replace_scope (struct grub_script_scope *new_scope) - grub_err_t - grub_script_break (grub_command_t cmd, int argc, char *argv[]) - { -- char *p = 0; -+ const char *p = NULL; - unsigned long count; - - if (argc == 0) -@@ -178,7 +178,7 @@ grub_err_t - grub_script_shift (grub_command_t cmd __attribute__((unused)), - int argc, char *argv[]) - { -- char *p = 0; -+ const char *p = NULL; - unsigned long n = 0; - - if (! scope) -@@ -239,7 +239,7 @@ grub_err_t - grub_script_return (grub_command_t cmd __attribute__((unused)), - int argc, char *argv[]) - { -- char *p; -+ const char *p = NULL; - unsigned long n; - - if (! scope || argc > 1) -diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c -index db80b3ba0fb..f9271b09239 100644 ---- a/grub-core/term/serial.c -+++ b/grub-core/term/serial.c -@@ -269,7 +269,7 @@ grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args) - - if (state[OPTION_BASE_CLOCK].set) - { -- char *ptr; -+ const char *ptr; - config.base_clock = grub_strtoull (state[OPTION_BASE_CLOCK].arg, &ptr, 0); - if (grub_errno) - return grub_errno; -diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c -index 29df35e6d20..537a5c0cb0b 100644 ---- a/grub-core/term/terminfo.c -+++ b/grub-core/term/terminfo.c -@@ -737,7 +737,7 @@ grub_cmd_terminfo (grub_extcmd_context_t ctxt, int argc, char **args) - - if (state[OPTION_GEOMETRY].set) - { -- char *ptr = state[OPTION_GEOMETRY].arg; -+ const char *ptr = state[OPTION_GEOMETRY].arg; - w = grub_strtoul (ptr, &ptr, 0); - if (grub_errno) - return grub_errno; -diff --git a/grub-core/tests/strtoull_test.c b/grub-core/tests/strtoull_test.c -index 7da615ff33e..5488ab26b43 100644 ---- a/grub-core/tests/strtoull_test.c -+++ b/grub-core/tests/strtoull_test.c -@@ -25,7 +25,7 @@ static void - strtoull_testcase (const char *input, int base, unsigned long long expected, - int num_digits, grub_err_t error) - { -- char *output; -+ const char *output; - unsigned long long value; - grub_errno = 0; - value = grub_strtoull(input, &output, base); -diff --git a/util/grub-fstest.c b/util/grub-fstest.c -index 88f9c5d4ad8..39bad1f432f 100644 ---- a/util/grub-fstest.c -+++ b/util/grub-fstest.c -@@ -538,7 +538,7 @@ void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; - static error_t - argp_parser (int key, char *arg, struct argp_state *state) - { -- char *p; -+ const char *p; - - switch (key) - { -diff --git a/include/grub/emu/getroot.h b/include/grub/emu/getroot.h -index 9c642ae3fe3..80b96b972d0 100644 ---- a/include/grub/emu/getroot.h -+++ b/include/grub/emu/getroot.h -@@ -19,6 +19,8 @@ - #ifndef GRUB_UTIL_GETROOT_HEADER - #define GRUB_UTIL_GETROOT_HEADER 1 - -+#define NEED_GRUB_MAKE_SYSTEM_PATH_RELATIVE -+ - #include - #include - -@@ -37,7 +39,9 @@ char *grub_find_device (const char *dir, dev_t dev); - void grub_util_pull_device (const char *osname); - char **grub_guess_root_devices (const char *dir); - int grub_util_get_dev_abstraction (const char *os_dev); -+#ifndef NEED_GRUB_MAKE_SYSTEM_PATH_RELATIVE - char *grub_make_system_path_relative_to_its_root (const char *path); -+#endif - char * - grub_make_system_path_relative_to_its_root_os (const char *path); - char *grub_util_get_grub_dev (const char *os_dev); -diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h -index 5ef4f79e689..8e241c9298a 100644 ---- a/include/grub/emu/misc.h -+++ b/include/grub/emu/misc.h -@@ -41,6 +41,9 @@ void grub_find_zpool_from_dir (const char *dir, - - char *grub_make_system_path_relative_to_its_root (const char *path) - WARN_UNUSED_RESULT; -+#ifdef NEED_GRUB_MAKE_SYSTEM_PATH_RELATIVE -+#undef NEED_GRUB_MAKE_SYSTEM_PATH_RELATIVE -+#endif - int - grub_util_device_is_mapped (const char *dev); - -diff --git a/include/grub/misc.h b/include/grub/misc.h -index 960097fbd06..b7fc9c6a792 100644 ---- a/include/grub/misc.h -+++ b/include/grub/misc.h -@@ -288,11 +288,11 @@ grub_strncasecmp (const char *s1, const char *s2, grub_size_t n) - - (int) grub_tolower ((grub_uint8_t) *s2); - } - --unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, char **end, int base); --unsigned long long EXPORT_FUNC(grub_strtoull) (const char *str, char **end, int base); -+unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, const char ** const end, int base); -+unsigned long long EXPORT_FUNC(grub_strtoull) (const char *str, const char ** const end, int base); - - static inline long --grub_strtol (const char *str, char **end, int base) -+grub_strtol (const char *str, const char ** const end, int base) - { - int negative = 0; - unsigned long long magnitude; diff --git a/0161-Fix-menu-entry-selection-based-on-ID-and-title.patch b/0161-Fix-menu-entry-selection-based-on-ID-and-title.patch index 2105e75..84c1370 100644 --- a/0161-Fix-menu-entry-selection-based-on-ID-and-title.patch +++ b/0161-Fix-menu-entry-selection-based-on-ID-and-title.patch @@ -20,11 +20,11 @@ Signed-off-by: Peter Jones [javierm: fix menu entry selection based on title] Signed-off-by: Javier Martinez Canillas --- - grub-core/normal/menu.c | 143 ++++++++++++++++++++++++------------------------ - 1 file changed, 72 insertions(+), 71 deletions(-) + grub-core/normal/menu.c | 141 ++++++++++++++++++++++++------------------------ + 1 file changed, 71 insertions(+), 70 deletions(-) diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c -index 046a1fb2c84..920b44a8aed 100644 +index 37d753d8081..ea714d27176 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -164,12 +164,12 @@ grub_menu_set_timeout (int timeout) @@ -114,18 +114,15 @@ index 046a1fb2c84..920b44a8aed 100644 /* Get the first entry number from the value of the environment variable NAME, which is a space-separated list of non-negative integers. The entry number which is returned is stripped from the value of NAME. If no entry number -@@ -195,9 +251,8 @@ static int - get_and_remove_first_entry_number (grub_menu_t menu, const char *name) +@@ -196,7 +252,6 @@ get_and_remove_first_entry_number (grub_menu_t menu, const char *name) { - const char *val; -- char *tail; -+ const char *tail; + const char *val, *tail; int entry; - int sz = 0; val = grub_env_get (name); if (! val) -@@ -205,50 +260,24 @@ get_and_remove_first_entry_number (grub_menu_t menu, const char *name) +@@ -204,50 +259,24 @@ get_and_remove_first_entry_number (grub_menu_t menu, const char *name) grub_error_push (); @@ -184,7 +181,7 @@ index 046a1fb2c84..920b44a8aed 100644 } grub_error_pop (); -@@ -525,6 +554,7 @@ static int +@@ -524,6 +553,7 @@ static int get_entry_number (grub_menu_t menu, const char *name) { const char *val; @@ -192,7 +189,7 @@ index 046a1fb2c84..920b44a8aed 100644 int entry; val = grub_env_get (name); -@@ -532,38 +562,9 @@ get_entry_number (grub_menu_t menu, const char *name) +@@ -531,38 +561,9 @@ get_entry_number (grub_menu_t menu, const char *name) return -1; grub_error_push (); diff --git a/0164-Make-it-possible-to-subtract-conditions-from-debug.patch b/0164-Make-it-possible-to-subtract-conditions-from-debug.patch index 24cc724..c281ef6 100644 --- a/0164-Make-it-possible-to-subtract-conditions-from-debug.patch +++ b/0164-Make-it-possible-to-subtract-conditions-from-debug.patch @@ -14,7 +14,7 @@ Signed-off-by: Peter Jones 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index aaae9aa0ab7..f6eaa7b4df8 100644 +index e21dd44c7cf..18a7dbf4cd7 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -163,12 +163,24 @@ int diff --git a/0165-Export-all-variables-from-the-initial-context-when-c.patch b/0165-Export-all-variables-from-the-initial-context-when-c.patch index bd61eff..bfe3165 100644 --- a/0165-Export-all-variables-from-the-initial-context-when-c.patch +++ b/0165-Export-all-variables-from-the-initial-context-when-c.patch @@ -30,10 +30,10 @@ index ee53d4a68e5..87edd254c44 100644 int grub_extractor_level = 0; diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c -index 920b44a8aed..341228f87c9 100644 +index ea714d27176..d4832f17699 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c -@@ -376,8 +376,6 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) +@@ -375,8 +375,6 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) if (ptr && ptr[0] && ptr[1]) grub_env_set ("default", ptr + 1); diff --git a/0168-Don-t-make-grub_strtoull-print-an-error-if-no-conver.patch b/0168-Don-t-make-grub_strtoull-print-an-error-if-no-conver.patch index 0dc6a97..21d242e 100644 --- a/0168-Don-t-make-grub_strtoull-print-an-error-if-no-conver.patch +++ b/0168-Don-t-make-grub_strtoull-print-an-error-if-no-conver.patch @@ -16,10 +16,10 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index f6eaa7b4df8..2477eb609ba 100644 +index 18a7dbf4cd7..87afb43cd55 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c -@@ -473,8 +473,7 @@ grub_strtoull (const char *str, const char ** const end, int base) +@@ -475,8 +475,7 @@ grub_strtoull (const char * restrict str, const char ** const restrict end, if (! found) { diff --git a/0173-Don-t-assume-that-boot-commands-will-only-return-on-.patch b/0173-Don-t-assume-that-boot-commands-will-only-return-on-.patch index 707c1e9..34cff10 100644 --- a/0173-Don-t-assume-that-boot-commands-will-only-return-on-.patch +++ b/0173-Don-t-assume-that-boot-commands-will-only-return-on-.patch @@ -17,10 +17,10 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c -index 341228f87c9..6ef7e2f8e6f 100644 +index d4832f17699..9ea1f411814 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c -@@ -286,7 +286,7 @@ get_and_remove_first_entry_number (grub_menu_t menu, const char *name) +@@ -285,7 +285,7 @@ get_and_remove_first_entry_number (grub_menu_t menu, const char *name) } /* Run a menu entry. */ @@ -29,7 +29,7 @@ index 341228f87c9..6ef7e2f8e6f 100644 grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) { grub_err_t err = GRUB_ERR_NONE; -@@ -386,7 +386,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) +@@ -385,7 +385,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ()) /* Implicit execution of boot, only if something is loaded. */ @@ -38,7 +38,7 @@ index 341228f87c9..6ef7e2f8e6f 100644 if (errs_before != grub_err_printed_errors) grub_wait_after_message (); -@@ -409,6 +409,8 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) +@@ -408,6 +408,8 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) else grub_env_unset ("default"); grub_env_unset ("timeout"); @@ -47,7 +47,7 @@ index 341228f87c9..6ef7e2f8e6f 100644 } /* Execute ENTRY from the menu MENU, falling back to entries specified -@@ -423,10 +425,13 @@ grub_menu_execute_with_fallback (grub_menu_t menu, +@@ -422,10 +424,13 @@ grub_menu_execute_with_fallback (grub_menu_t menu, void *callback_data) { int fallback_entry; @@ -62,7 +62,7 @@ index 341228f87c9..6ef7e2f8e6f 100644 /* Deal with fallback entries. */ while ((fallback_entry = get_and_remove_first_entry_number (menu, "fallback")) -@@ -437,11 +442,9 @@ grub_menu_execute_with_fallback (grub_menu_t menu, +@@ -436,11 +441,9 @@ grub_menu_execute_with_fallback (grub_menu_t menu, entry = grub_menu_get_entry (menu, fallback_entry); callback->notify_fallback (entry, callback_data); diff --git a/0199-efi-http-Export-fw-http-_path-variables-to-make-them.patch b/0199-efi-http-Export-fw-http-_path-variables-to-make-them.patch new file mode 100644 index 0000000..1f85760 --- /dev/null +++ b/0199-efi-http-Export-fw-http-_path-variables-to-make-them.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 5 Mar 2020 16:21:47 +0100 +Subject: [PATCH] efi/http: Export {fw,http}_path variables to make them global + +The fw_path environment variable is used by http_configure() function to +determine the HTTP path that should be used as prefix when using relative +HTTP paths. And this is stored in the http_path environment variable. + +Later, that variable is looked up by grub_efihttp_open() to generate the +complete path to be used in the HTTP request. + +But these variables are not exported, which means that are not global and +so are only found in the initial context. + +This can cause commands like configfile that create a new context to fail +because the fw_path and http_path variables will not be found. + +Resolves: rhbz#1616395 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/kern/main.c | 1 + + grub-core/net/efi/http.c | 1 + + 2 files changed, 2 insertions(+) + +diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c +index dcf48726d54..9bf6a8b231a 100644 +--- a/grub-core/kern/main.c ++++ b/grub-core/kern/main.c +@@ -142,6 +142,7 @@ grub_set_prefix_and_root (void) + if (fw_path) + { + grub_env_set ("fw_path", fw_path); ++ grub_env_export ("fw_path"); + grub_dprintf ("fw_path", "fw_path:\"%s\"\n", fw_path); + grub_free (fw_path); + } +diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c +index de351b2cd03..755b7a6d054 100644 +--- a/grub-core/net/efi/http.c ++++ b/grub-core/net/efi/http.c +@@ -39,6 +39,7 @@ http_configure (struct grub_efi_net_device *dev, int prefer_ip6) + http_path++; + grub_env_unset ("http_path"); + grub_env_set ("http_path", http_path); ++ grub_env_export ("http_path"); + } + } + diff --git a/0200-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch b/0200-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch new file mode 100644 index 0000000..c394549 --- /dev/null +++ b/0200-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch @@ -0,0 +1,114 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 5 Mar 2020 16:21:58 +0100 +Subject: [PATCH] efi/http: Enclose literal IPv6 addresses in square brackets + +According to RFC 2732 (https://www.ietf.org/rfc/rfc2732.txt), literal IPv6 +addresses must be enclosed in square brackets. But GRUB currently does not +do this and is causing HTTP servers to send Bad Request (400) responses. + +For example, the following is the HTTP stream when fetching a config file: + +HEAD /EFI/BOOT/grub.cfg HTTP/1.1 +Host: 2000:dead:beef:a::1 +Accept: */* +User-Agent: UefiHttpBoot/1.0 + +HTTP/1.1 400 Bad Request +Date: Thu, 05 Mar 2020 14:46:02 GMT +Server: Apache/2.4.41 (Fedora) OpenSSL/1.1.1d +Connection: close +Content-Type: text/html; charset=iso-8859-1 + +and after enclosing the IPv6 address the HTTP request is successful: + +HEAD /EFI/BOOT/grub.cfg HTTP/1.1 +Host: [2000:dead:beef:a::1] +Accept: */* +User-Agent: UefiHttpBoot/1.0 + +HTTP/1.1 200 OK +Date: Thu, 05 Mar 2020 14:48:04 GMT +Server: Apache/2.4.41 (Fedora) OpenSSL/1.1.1d +Last-Modified: Thu, 27 Feb 2020 17:45:58 GMT +ETag: "206-59f924b24b1da" +Accept-Ranges: bytes +Content-Length: 518 + +Resolves: rhbz#1732765 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/net/efi/http.c | 37 ++++++++++++++++++++++++++++--------- + 1 file changed, 28 insertions(+), 9 deletions(-) + +diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c +index 755b7a6d054..fc8cb25ae0a 100644 +--- a/grub-core/net/efi/http.c ++++ b/grub-core/net/efi/http.c +@@ -158,13 +158,7 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, + grub_efi_status_t status; + grub_efi_boot_services_t *b = grub_efi_system_table->boot_services; + char *url = NULL; +- +- request_headers[0].field_name = (grub_efi_char8_t *)"Host"; +- request_headers[0].field_value = (grub_efi_char8_t *)server; +- request_headers[1].field_name = (grub_efi_char8_t *)"Accept"; +- request_headers[1].field_value = (grub_efi_char8_t *)"*/*"; +- request_headers[2].field_name = (grub_efi_char8_t *)"User-Agent"; +- request_headers[2].field_value = (grub_efi_char8_t *)"UefiHttpBoot/1.0"; ++ char *hostname = NULL; + + { + grub_efi_ipv6_address_t address; +@@ -174,9 +168,24 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, + const char *protocol = (use_https == 1) ? "https" : "http"; + + if (grub_efi_string_to_ip6_address (server, &address, &rest) && *rest == 0) +- url = grub_xasprintf ("%s://[%s]%s", protocol, server, name); ++ { ++ hostname = grub_xasprintf ("[%s]", server); ++ if (!hostname) ++ return GRUB_ERR_OUT_OF_MEMORY; ++ ++ server = hostname; ++ ++ url = grub_xasprintf ("%s://%s%s", protocol, server, name); ++ if (!url) ++ { ++ grub_free (hostname); ++ return GRUB_ERR_OUT_OF_MEMORY; ++ } ++ } + else +- url = grub_xasprintf ("%s://%s%s", protocol, server, name); ++ { ++ url = grub_xasprintf ("%s://%s%s", protocol, server, name); ++ } + + if (!url) + { +@@ -199,6 +208,13 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, + request_data.url = ucs2_url; + } + ++ request_headers[0].field_name = (grub_efi_char8_t *)"Host"; ++ request_headers[0].field_value = (grub_efi_char8_t *)server; ++ request_headers[1].field_name = (grub_efi_char8_t *)"Accept"; ++ request_headers[1].field_value = (grub_efi_char8_t *)"*/*"; ++ request_headers[2].field_name = (grub_efi_char8_t *)"User-Agent"; ++ request_headers[2].field_value = (grub_efi_char8_t *)"UefiHttpBoot/1.0"; ++ + request_data.method = (headeronly > 0) ? GRUB_EFI_HTTPMETHODHEAD : GRUB_EFI_HTTPMETHODGET; + + request_message.data.request = &request_data; +@@ -228,6 +244,9 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, + + status = efi_call_2 (http->request, http, &request_token); + ++ if (hostname) ++ grub_free (hostname); ++ + if (status != GRUB_EFI_SUCCESS) + { + efi_call_1 (b->close_event, request_token.event); diff --git a/0201-efi-net-Allow-to-specify-a-port-number-in-addresses.patch b/0201-efi-net-Allow-to-specify-a-port-number-in-addresses.patch new file mode 100644 index 0000000..209aed8 --- /dev/null +++ b/0201-efi-net-Allow-to-specify-a-port-number-in-addresses.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 9 Mar 2020 15:29:45 +0100 +Subject: [PATCH] efi/net: Allow to specify a port number in addresses + +The grub_efi_net_parse_address() function is not covering the case where a +port number is specified in an IPv4 or IPv6 address, so will fail to parse +the network address. + +For most cases the issue is harmless, because the function is only used to +match an address with a network interface and if fails the default is used. + +But still is a bug that has to be fixed and it causes error messages to be +printed like the following: + +error: net/efi/net.c:782:unrecognised network address '192.168.122.1:8080' + +error: net/efi/net.c:781:unrecognised network address '[2000:dead:beef:a::1]:8080' + +Resolves: rhbz#1732765 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/net/efi/net.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c +index 6603cd83edc..84573937b18 100644 +--- a/grub-core/net/efi/net.c ++++ b/grub-core/net/efi/net.c +@@ -742,7 +742,7 @@ grub_efi_net_parse_address (const char *address, + return GRUB_ERR_NONE; + } + } +- else if (*rest == 0) ++ else if (*rest == 0 || *rest == ':') + { + grub_uint32_t subnet_mask = 0xffffffffU; + grub_memcpy (ip4->subnet_mask, &subnet_mask, sizeof (ip4->subnet_mask)); +@@ -768,7 +768,7 @@ grub_efi_net_parse_address (const char *address, + return GRUB_ERR_NONE; + } + } +- else if (*rest == 0) ++ else if (*rest == 0 || *rest == ':') + { + ip6->prefix_length = 128; + ip6->is_anycast = 0; diff --git a/0202-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch b/0202-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch new file mode 100644 index 0000000..f92dee4 --- /dev/null +++ b/0202-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 9 Mar 2020 15:30:05 +0100 +Subject: [PATCH] efi/ip4_config: Improve check to detect literal IPv6 + addresses + +The grub_efi_string_to_ip4_address() function wrongly assumes that an IPv6 +address is an IPv4 address, because it doesn't take into account the case +of a caller passing an IPv6 address as a string. + +This leads to the grub_efi_net_parse_address() function to fail and print +the following error message: + +error: net/efi/net.c:785:unrecognised network address '2000:dead:beef:a::1' + +Resolves: rhbz#1732765 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/net/efi/ip4_config.c | 13 ++++++++++++- + 1 file changed, 12 insertions(+), 1 deletion(-) + +diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c +index b711a5d9457..313c818b184 100644 +--- a/grub-core/net/efi/ip4_config.c ++++ b/grub-core/net/efi/ip4_config.c +@@ -56,9 +56,20 @@ int + grub_efi_string_to_ip4_address (const char *val, grub_efi_ipv4_address_t *address, const char **rest) + { + grub_uint32_t newip = 0; +- int i; ++ int i, ncolon = 0; + const char *ptr = val; + ++ /* Check that is not an IPv6 address */ ++ for (i = 0; i < grub_strlen(ptr); i++) ++ { ++ if (ptr[i] == '[' && i == 0) ++ return 0; ++ ++ if (ptr[i] == ':') ++ if (i == 0 || ++ncolon == 2) ++ return 0; ++ } ++ + for (i = 0; i < 4; i++) + { + unsigned long t; diff --git a/0203-efi-net-Print-a-debug-message-if-parsing-the-address.patch b/0203-efi-net-Print-a-debug-message-if-parsing-the-address.patch new file mode 100644 index 0000000..33d8f88 --- /dev/null +++ b/0203-efi-net-Print-a-debug-message-if-parsing-the-address.patch @@ -0,0 +1,68 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 10 Mar 2020 11:23:49 +0100 +Subject: [PATCH] efi/net: Print a debug message if parsing the address fails + +Currently if parsing the address fails an error message is printed. But in +most cases this isn't a fatal error since the grub_efi_net_parse_address() +function is only used to match an address with a network interface to use. + +And if this fails, the default interface is used which is good enough for +most cases. So instead of printing an error that would pollute the console +just print a debug message if the address is not parsed correctly. + +A user can enable debug messages for the efinet driver to have information +about the failure and the fact that the default interface is being used. + +Related: rhbz#1732765 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/net/efi/net.c | 18 +++++++++++------- + 1 file changed, 11 insertions(+), 7 deletions(-) + +diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c +index 84573937b18..a3f0535d43c 100644 +--- a/grub-core/net/efi/net.c ++++ b/grub-core/net/efi/net.c +@@ -778,9 +778,9 @@ grub_efi_net_parse_address (const char *address, + } + } + +- return grub_error (GRUB_ERR_NET_BAD_ADDRESS, +- N_("unrecognised network address `%s'"), +- address); ++ grub_dprintf ("efinet", "unrecognised network address '%s'\n", address); ++ ++ return GRUB_ERR_NET_BAD_ADDRESS; + } + + static grub_efi_net_interface_t * +@@ -795,10 +795,7 @@ match_route (const char *server) + err = grub_efi_net_parse_address (server, &ip4, &ip6, &is_ip6, 0); + + if (err) +- { +- grub_print_error (); + return NULL; +- } + + if (is_ip6) + { +@@ -1233,8 +1230,15 @@ grub_net_open_real (const char *name __attribute__ ((unused))) + /*FIXME: Use DNS translate name to address */ + net_interface = match_route (server); + ++ if (!net_interface && net_default_interface) ++ { ++ net_interface = net_default_interface; ++ grub_dprintf ("efinet", "interface lookup failed, using default '%s'\n", ++ net_interface->name); ++ } ++ + /*XXX: should we check device with default gateway ? */ +- if (!net_interface && !(net_interface = net_default_interface)) ++ if (!net_interface) + { + grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("disk `%s' no route found"), + name); diff --git a/0204-blscfg-return-NULL-instead-of-a-zero-length-array-in.patch b/0204-blscfg-return-NULL-instead-of-a-zero-length-array-in.patch new file mode 100644 index 0000000..fa35f65 --- /dev/null +++ b/0204-blscfg-return-NULL-instead-of-a-zero-length-array-in.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 16 Mar 2020 13:51:45 +0100 +Subject: [PATCH] blscfg: return NULL instead of a zero-length array in + bls_make_list() + +The bls_make_list() function returns a list of all the values for a given +key and if there is none a NULL pointer should be returned. But currently +is returnin a zero-length array instead. + +This makes the callers to wrongly assume that there are values for a key +and populate wrong menu entries. For example menu entries are populated +with an initrd command even if there is no initrd fiel in the BLS file. + +Resolves: rhbz#1806022 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/blscfg.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 24e35a40f24..9263a5c1a02 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -600,6 +600,12 @@ static char **bls_make_list (struct bls_entry *entry, const char *key, int *num) + list[nlist] = NULL; + } + ++ if (!nlist) ++ { ++ grub_free (list); ++ return NULL; ++ } ++ + if (num) + *num = nlist; + diff --git a/grub.patches b/grub.patches index 369b648..483aa8b 100644 --- a/grub.patches +++ b/grub.patches @@ -157,7 +157,7 @@ Patch0156: 0156-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch Patch0157: 0157-Fix-getroot.c-s-trampolines.patch Patch0158: 0158-Do-not-allow-stack-trampolines-anywhere.patch Patch0159: 0159-Reimplement-boot_counter.patch -Patch0160: 0160-Make-grub_strtoul-end-pointer-have-the-right-constif.patch +Patch0160: 0160-Make-grub_strtol-end-pointers-have-safer-const-quali.patch Patch0161: 0161-Fix-menu-entry-selection-based-on-ID-and-title.patch Patch0162: 0162-Make-the-menu-entry-users-option-argument-to-be-opti.patch Patch0163: 0163-Add-efi-export-env-and-efi-load-env-commands.patch @@ -196,3 +196,9 @@ Patch0195: 0195-RISC-V-Add-__clzdi2-symbol.patch Patch0196: 0196-grub-install-Define-default-platform-for-RISC-V.patch Patch0197: 0197-blscfg-Always-use-the-root-variable-to-search-for-BL.patch Patch0198: 0198-bootstrap.conf-Force-autogen.sh-to-use-python3.patch +Patch0199: 0199-efi-http-Export-fw-http-_path-variables-to-make-them.patch +Patch0200: 0200-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch +Patch0201: 0201-efi-net-Allow-to-specify-a-port-number-in-addresses.patch +Patch0202: 0202-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch +Patch0203: 0203-efi-net-Print-a-debug-message-if-parsing-the-address.patch +Patch0204: 0204-blscfg-return-NULL-instead-of-a-zero-length-array-in.patch diff --git a/grub2.spec b/grub2.spec index d01388a..a353222 100644 --- a/grub2.spec +++ b/grub2.spec @@ -9,7 +9,7 @@ Name: grub2 Epoch: 1 Version: 2.04 -Release: 9%{?dist} +Release: 10%{?dist} Summary: Bootloader with support for Linux, Multiboot and more License: GPLv3+ URL: http://www.gnu.org/software/grub/ @@ -338,8 +338,6 @@ rm -r /boot/grub2.tmp/ || : %files common -f grub.lang %dir %{_libdir}/grub/ %dir %{_datarootdir}/grub/ -%dir %{_datarootdir}/grub/themes/ -%exclude %{_datarootdir}/grub/themes/* %attr(0700,root,root) %dir %{_sysconfdir}/grub.d %{_prefix}/lib/kernel/install.d/20-grub.install %{_prefix}/lib/kernel/install.d/99-grub-mkconfig.install @@ -348,7 +346,6 @@ rm -r /boot/grub2.tmp/ || : %dir /boot/%{name} %dir /boot/%{name}/themes/ %dir /boot/%{name}/themes/system -%exclude /boot/%{name}/themes/system/* %attr(0700,root,root) %dir /boot/grub2 %exclude /boot/grub2/* %dir %attr(0700,root,root) %{efi_esp_dir} @@ -512,6 +509,10 @@ rm -r /boot/grub2.tmp/ || : %endif %changelog +* Tue Mar 17 2020 Javier Martinez Canillas - 2.04-10 +- Fix for entries having an empty initrd command and HTTP boot issues + Resolves: rhbz#1806022 + * Thu Jan 16 2020 Javier Martinez Canillas - 2.04-9 - Add riscv64 support to grub.macros and RISC-V build fixes (davidlt) - blscfg: Always use the root variable to search for BLS snippets