diff --git a/0001-Revert-templates-Fix-user-facing-typo-with-an-incorr.patch b/0001-Revert-templates-Fix-user-facing-typo-with-an-incorr.patch new file mode 100644 index 0000000000000000000000000000000000000000..fcc78251bdddae408b96d354061a322d4721d694 --- /dev/null +++ b/0001-Revert-templates-Fix-user-facing-typo-with-an-incorr.patch @@ -0,0 +1,24 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Fri, 11 Jun 2021 12:10:45 +0200 +Subject: [PATCH] Revert "templates: Fix user-facing typo with an incorrect use + of "it's"" + +This reverts commit 722737630889607c3b5761f1f5a48f1674cd2821. +--- + util/grub.d/30_os-prober.in | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in +index 5984e92d291..94622481284 100644 +--- a/util/grub.d/30_os-prober.in ++++ b/util/grub.d/30_os-prober.in +@@ -36,7 +36,7 @@ if ! command -v os-prober > /dev/null || ! command -v linux-boot-prober > /dev/n + exit 0 + fi + +-grub_warn "$(gettext_printf "os-prober will be executed to detect other bootable partitions.\nIts output will be used to detect bootable binaries on them and create new boot entries.")" ++grub_warn "$(gettext_printf "os-prober will be executed to detect other bootable partitions.\nIt's output will be used to detect bootable binaries on them and create new boot entries.")" + + OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`" + if [ -z "${OSPROBED}" ] ; then diff --git a/0002-Revert-templates-Properly-disable-the-os-prober-by-d.patch b/0002-Revert-templates-Properly-disable-the-os-prober-by-d.patch new file mode 100644 index 0000000000000000000000000000000000000000..4187765fb6bd501b572e08283f95550b6989a6af --- /dev/null +++ b/0002-Revert-templates-Properly-disable-the-os-prober-by-d.patch @@ -0,0 +1,71 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Fri, 11 Jun 2021 12:10:54 +0200 +Subject: [PATCH] Revert "templates: Properly disable the os-prober by default" + +This reverts commit 54e0a1bbf1e9106901a557195bb35e5e20fb3925. +--- + util/grub-mkconfig.in | 5 +---- + util/grub.d/30_os-prober.in | 8 ++++---- + 2 files changed, 5 insertions(+), 8 deletions(-) + +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index f8cbb8d7a2b..d3e879b8e5c 100644 +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -140,9 +140,6 @@ GRUB_DEVICE_PARTUUID="`${grub_probe} --device ${GRUB_DEVICE} --target=partuuid 2 + GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`" + GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true + +-# Disable os-prober by default due to security reasons. +-GRUB_DISABLE_OS_PROBER="true" +- + # Filesystem for the device containing our userland. Used for stuff like + # choosing Hurd filesystem module. + GRUB_FS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2> /dev/null || echo unknown`" +@@ -204,7 +201,6 @@ export GRUB_DEVICE \ + GRUB_DEVICE_PARTUUID \ + GRUB_DEVICE_BOOT \ + GRUB_DEVICE_BOOT_UUID \ +- GRUB_DISABLE_OS_PROBER \ + GRUB_FS \ + GRUB_FONT \ + GRUB_PRELOAD_MODULES \ +@@ -246,6 +242,7 @@ export GRUB_DEFAULT \ + GRUB_BACKGROUND \ + GRUB_THEME \ + GRUB_GFXPAYLOAD_LINUX \ ++ GRUB_DISABLE_OS_PROBER \ + GRUB_INIT_TUNE \ + GRUB_SAVEDEFAULT \ + GRUB_ENABLE_CRYPTODISK \ +diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in +index 94622481284..80685b15f4d 100644 +--- a/util/grub.d/30_os-prober.in ++++ b/util/grub.d/30_os-prober.in +@@ -26,8 +26,8 @@ export TEXTDOMAINDIR="@localedir@" + + . "$pkgdatadir/grub-mkconfig_lib" + +-if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then +- grub_warn "$(gettext_printf "os-prober will not be executed to detect other bootable partitions.\nSystems on them will not be added to the GRUB boot configuration.\nCheck GRUB_DISABLE_OS_PROBER documentation entry.")" ++if [ "x${GRUB_DISABLE_OS_PROBER}" = "xfalse" ]; then ++ gettext_printf "os-prober will not be executed to detect other bootable partitions.\nSystems on them will not be added to the GRUB boot configuration.\nCheck GRUB_DISABLE_OS_PROBER documentation entry.\n" + exit 0 + fi + +@@ -36,12 +36,12 @@ if ! command -v os-prober > /dev/null || ! command -v linux-boot-prober > /dev/n + exit 0 + fi + +-grub_warn "$(gettext_printf "os-prober will be executed to detect other bootable partitions.\nIt's output will be used to detect bootable binaries on them and create new boot entries.")" +- + OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`" + if [ -z "${OSPROBED}" ] ; then + # empty os-prober output, nothing doing + exit 0 ++else ++ grub_warn "$(gettext_printf "os-prober was executed to detect other bootable partitions.\nIt's output will be used to detect bootable binaries on them and create new boot entries.")" + fi + + osx_entry() { diff --git a/0003-Revert-templates-Disable-the-os-prober-by-default.patch b/0003-Revert-templates-Disable-the-os-prober-by-default.patch new file mode 100644 index 0000000000000000000000000000000000000000..68cacfca1bead3a89fecede8564df9c71cb49f7b --- /dev/null +++ b/0003-Revert-templates-Disable-the-os-prober-by-default.patch @@ -0,0 +1,70 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Fri, 11 Jun 2021 12:10:58 +0200 +Subject: [PATCH] Revert "templates: Disable the os-prober by default" + +This reverts commit e346414725a70e5c74ee87ca14e580c66f517666. +--- + docs/grub.texi | 18 ++++++++---------- + util/grub.d/30_os-prober.in | 5 +---- + 2 files changed, 9 insertions(+), 14 deletions(-) + +diff --git a/docs/grub.texi b/docs/grub.texi +index f8b4b3b21a7..69f08d289f9 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -1519,13 +1519,10 @@ boot sequence. If you have problems, set this option to @samp{text} and + GRUB will tell Linux to boot in normal text mode. + + @item GRUB_DISABLE_OS_PROBER +-The @command{grub-mkconfig} has a feature to use the external +-@command{os-prober} program to discover other operating systems installed on +-the same machine and generate appropriate menu entries for them. It is disabled +-by default since automatic and silent execution of @command{os-prober}, and +-creating boot entries based on that data, is a potential attack vector. Set +-this option to @samp{false} to enable this feature in the +-@command{grub-mkconfig} command. ++Normally, @command{grub-mkconfig} will try to use the external ++@command{os-prober} program, if installed, to discover other operating ++systems installed on the same system and generate appropriate menu entries ++for them. Set this option to @samp{true} to disable this. + + @item GRUB_OS_PROBER_SKIP_LIST + List of space-separated FS UUIDs of filesystems to be ignored from os-prober +@@ -1853,9 +1850,10 @@ than zero; otherwise 0. + @section Multi-boot manual config + + Currently autogenerating config files for multi-boot environments depends on +-os-prober and has several shortcomings. Due to that it is disabled by default. +-It is advised to use the power of GRUB syntax and do it yourself. A possible +-configuration is detailed here, feel free to adjust to your needs. ++os-prober and has several shortcomings. While fixing it is scheduled for the ++next release, meanwhile you can make use of the power of GRUB syntax and do it ++yourself. A possible configuration is detailed here, feel free to adjust to your ++needs. + + First create a separate GRUB partition, big enough to hold GRUB. Some of the + following entries show how to load OS installer images from this same partition, +diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in +index 80685b15f4d..1b91c102f35 100644 +--- a/util/grub.d/30_os-prober.in ++++ b/util/grub.d/30_os-prober.in +@@ -26,8 +26,7 @@ export TEXTDOMAINDIR="@localedir@" + + . "$pkgdatadir/grub-mkconfig_lib" + +-if [ "x${GRUB_DISABLE_OS_PROBER}" = "xfalse" ]; then +- gettext_printf "os-prober will not be executed to detect other bootable partitions.\nSystems on them will not be added to the GRUB boot configuration.\nCheck GRUB_DISABLE_OS_PROBER documentation entry.\n" ++if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then + exit 0 + fi + +@@ -40,8 +39,6 @@ OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`" + if [ -z "${OSPROBED}" ] ; then + # empty os-prober output, nothing doing + exit 0 +-else +- grub_warn "$(gettext_printf "os-prober was executed to detect other bootable partitions.\nIt's output will be used to detect bootable binaries on them and create new boot entries.")" + fi + + osx_entry() { diff --git a/0001-Add-support-for-Linux-EFI-stub-loading.patch b/0004-Add-support-for-Linux-EFI-stub-loading.patch similarity index 92% rename from 0001-Add-support-for-Linux-EFI-stub-loading.patch rename to 0004-Add-support-for-Linux-EFI-stub-loading.patch index e839b15b9ebc9ab91a1eb8c1b7ebef68b26927de..73d231a266b93cd52db2c667279f01c3559f764a 100644 --- a/0001-Add-support-for-Linux-EFI-stub-loading.patch +++ b/0004-Add-support-for-Linux-EFI-stub-loading.patch @@ -1,7 +1,7 @@ -From a66a5e1ff5e4ad4df490754bfe41839a43cad1d5 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Matthew Garrett -Date: Fri, 5 Jul 2019 18:36:44 +0200 -Subject: [PATCH 001/220] Add support for Linux EFI stub loading. +Date: Tue, 10 Jul 2012 11:58:52 -0400 +Subject: [PATCH] Add support for Linux EFI stub loading. Also: @@ -29,25 +29,25 @@ moves the check into grub_dl_load_file. grub-core/kern/dl.c | 21 +++ grub-core/kern/efi/efi.c | 28 ++++ grub-core/kern/efi/mm.c | 32 ++++ - grub-core/loader/arm64/linux.c | 112 +++++++------ + grub-core/loader/arm64/linux.c | 118 +++++++------- grub-core/loader/arm64/xen_boot.c | 1 - grub-core/loader/efi/linux.c | 70 ++++++++ grub-core/loader/i386/efi/linux.c | 335 ++++++++++++++++++++++++++++++++++++++ grub-core/loader/i386/pc/linux.c | 10 +- include/grub/arm/linux.h | 9 + - include/grub/arm64/linux.h | 10 ++ + include/grub/arm64/linux.h | 9 + include/grub/efi/efi.h | 7 +- include/grub/efi/linux.h | 31 ++++ - 13 files changed, 616 insertions(+), 66 deletions(-) + 13 files changed, 618 insertions(+), 69 deletions(-) create mode 100644 grub-core/loader/efi/linux.c create mode 100644 grub-core/loader/i386/efi/linux.c create mode 100644 include/grub/efi/linux.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 474a63e..581d9df 100644 +index 8022e1c0a79..45d3edaa4dc 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -1709,13 +1709,6 @@ module = { +@@ -1734,13 +1734,6 @@ module = { enable = i386_pc; }; @@ -61,7 +61,7 @@ index 474a63e..581d9df 100644 module = { name = ntldr; i386_pc = loader/i386/pc/ntldr.c; -@@ -1771,7 +1764,9 @@ module = { +@@ -1796,7 +1789,9 @@ module = { module = { name = linux; @@ -72,7 +72,7 @@ index 474a63e..581d9df 100644 i386_xen_pvh = loader/i386/linux.c; xen = loader/i386/xen.c; i386_pc = lib/i386/pc/vesa_modes_table.c; -@@ -1786,9 +1781,14 @@ module = { +@@ -1811,9 +1806,14 @@ module = { arm64 = loader/arm64/linux.c; riscv32 = loader/riscv/linux.c; riscv64 = loader/riscv/linux.c; @@ -88,7 +88,7 @@ index 474a63e..581d9df 100644 module = { diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index 48eb5e7..896bebf 100644 +index 48f8a79073d..b7149370950 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -38,6 +38,14 @@ @@ -106,7 +106,7 @@ index 48eb5e7..896bebf 100644 #pragma GCC diagnostic ignored "-Wcast-align" -@@ -686,6 +694,19 @@ grub_dl_load_file (const char *filename) +@@ -695,6 +703,19 @@ grub_dl_load_file (const char *filename) void *core = 0; grub_dl_t mod = 0; @@ -127,11 +127,11 @@ index 48eb5e7..896bebf 100644 file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE); diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index 6e1ceb9..a0faa40 100644 +index 8cff7be0289..35b8f670602 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c -@@ -273,6 +273,34 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, - return NULL; +@@ -286,6 +286,34 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, + return grub_efi_get_variable_with_attributes (var, guid, datasize_out, data_out, NULL); } +grub_efi_boolean_t @@ -166,7 +166,7 @@ index 6e1ceb9..a0faa40 100644 /* Search the mods section from the PE32/PE32+ image. This code uses diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c -index b02fab1..a9e3710 100644 +index 9838fb2f50d..f6aef0ef649 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -113,6 +113,38 @@ grub_efi_drop_alloc (grub_efi_physical_address_t address, @@ -209,7 +209,7 @@ index b02fab1..a9e3710 100644 void * grub_efi_allocate_pages_real (grub_efi_physical_address_t address, diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c -index ef3e9f9..a312c66 100644 +index ef3e9f9444c..a312c668685 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c @@ -29,6 +29,7 @@ @@ -238,41 +238,20 @@ index ef3e9f9..a312c66 100644 void *fdt; -@@ -102,6 +105,25 @@ finalize_params_linux (void) +@@ -102,79 +105,70 @@ finalize_params_linux (void) if (grub_fdt_install() != GRUB_ERR_NONE) goto failure; -+ grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n", -+ fdt); -+ -+ /* Convert command line to UCS-2 */ -+ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); -+ if (!loaded_image) -+ goto failure; -+ -+ loaded_image->load_options_size = len = -+ (grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t); -+ loaded_image->load_options = -+ grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); -+ if (!loaded_image->load_options) -+ return grub_error(GRUB_ERR_BAD_OS, "failed to create kernel parameters"); -+ -+ loaded_image->load_options_size = -+ 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, -+ (grub_uint8_t *) linux_args, len, NULL); -+ - return GRUB_ERR_NONE; - - failure: -@@ -109,72 +131,44 @@ failure: - return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); - } - +- return GRUB_ERR_NONE; +- +-failure: +- grub_fdt_unload(); +- return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); +-} +- -grub_err_t -grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) -+static void -+free_params (void) - { +-{ - grub_efi_memory_mapped_device_path_t *mempath; - grub_efi_handle_t image_handle; - grub_efi_boot_services_t *b; @@ -290,8 +269,7 @@ index ef3e9f9..a312c66 100644 - mempath[0].memory_type = GRUB_EFI_LOADER_DATA; - mempath[0].start_address = addr; - mempath[0].end_address = addr + size; -+ grub_efi_loaded_image_t *loaded_image = NULL; - +- - mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE; - mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; - mempath[1].header.length = sizeof (grub_efi_device_path_t); @@ -302,6 +280,50 @@ index ef3e9f9..a312c66 100644 - (void *) addr, size, &image_handle); - if (status != GRUB_EFI_SUCCESS) - return grub_error (GRUB_ERR_BAD_OS, "cannot load image"); +- +- grub_dprintf ("linux", "linux command line: '%s'\n", args); ++ grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n", ++ fdt); + + /* Convert command line to UCS-2 */ +- loaded_image = grub_efi_get_loaded_image (image_handle); ++ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); ++ if (!loaded_image) ++ goto failure; ++ + loaded_image->load_options_size = len = +- (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t); ++ (grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t); + loaded_image->load_options = + grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); + if (!loaded_image->load_options) +- return grub_errno; ++ return grub_error(GRUB_ERR_BAD_OS, "failed to create kernel parameters"); + + loaded_image->load_options_size = + 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, +- (grub_uint8_t *) args, len, NULL); ++ (grub_uint8_t *) linux_args, len, NULL); + +- grub_dprintf ("linux", "starting image %p\n", image_handle); +- status = b->start_image (image_handle, 0, NULL); ++ return GRUB_ERR_NONE; + +- /* When successful, not reached */ +- b->unload_image (image_handle); +- grub_efi_free_pages ((grub_addr_t) loaded_image->load_options, +- GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); ++failure: ++ grub_fdt_unload(); ++ return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); ++} + +- return grub_errno; ++static void ++free_params (void) ++{ ++ grub_efi_loaded_image_t *loaded_image = NULL; ++ + loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); + if (loaded_image) + { @@ -312,39 +334,20 @@ index ef3e9f9..a312c66 100644 + loaded_image->load_options_size = 0; + } +} - -- grub_dprintf ("linux", "linux command line: '%s'\n", args); ++ +grub_err_t +grub_arch_efi_linux_boot_image (grub_addr_t addr, char *args) +{ + grub_err_t retval; - -- /* Convert command line to UCS-2 */ -- loaded_image = grub_efi_get_loaded_image (image_handle); -- loaded_image->load_options_size = len = -- (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t); -- loaded_image->load_options = -- grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); -- if (!loaded_image->load_options) ++ + retval = finalize_params_linux (); + if (retval != GRUB_ERR_NONE) - return grub_errno; - -- loaded_image->load_options_size = -- 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, -- (grub_uint8_t *) args, len, NULL); -- -- grub_dprintf ("linux", "starting image %p\n", image_handle); -- status = b->start_image (image_handle, 0, NULL); ++ return grub_errno; ++ + grub_dprintf ("linux", "linux command line: '%s'\n", args); - -- /* When successful, not reached */ -- b->unload_image (image_handle); -- grub_efi_free_pages ((grub_addr_t) loaded_image->load_options, -- GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); ++ + retval = grub_efi_linux_boot ((char *)addr, handover_offset, (void *)addr); - -- return grub_errno; ++ + /* Never reached... */ + free_params(); + return retval; @@ -387,7 +390,7 @@ index ef3e9f9..a312c66 100644 linux_args = grub_malloc (cmdline_size); if (!linux_args) diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c -index 22cc25e..d9b7a9b 100644 +index 22cc25eccd9..d9b7a9ba400 100644 --- a/grub-core/loader/arm64/xen_boot.c +++ b/grub-core/loader/arm64/xen_boot.c @@ -266,7 +266,6 @@ xen_boot (void) @@ -400,7 +403,7 @@ index 22cc25e..d9b7a9b 100644 diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c new file mode 100644 -index 0000000..c24202a +index 00000000000..c24202a5dd1 --- /dev/null +++ b/grub-core/loader/efi/linux.c @@ -0,0 +1,70 @@ @@ -476,7 +479,7 @@ index 0000000..c24202a +#pragma GCC diagnostic pop diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c new file mode 100644 -index 0000000..bb2616a +index 00000000000..bb2616a8092 --- /dev/null +++ b/grub-core/loader/i386/efi/linux.c @@ -0,0 +1,335 @@ @@ -816,10 +819,10 @@ index 0000000..bb2616a + grub_unregister_command (cmd_initrdefi); +} diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c -index 47ea294..eea25ea 100644 +index 2a299520160..8be4c3b3f48 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c -@@ -470,14 +470,20 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), +@@ -474,14 +474,20 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), return grub_errno; } @@ -841,7 +844,7 @@ index 47ea294..eea25ea 100644 grub_register_command ("initrd16", grub_cmd_initrd, 0, N_("Load initrd.")); my_mod = mod; -@@ -486,5 +492,7 @@ GRUB_MOD_INIT(linux16) +@@ -490,5 +496,7 @@ GRUB_MOD_INIT(linux16) GRUB_MOD_FINI(linux16) { grub_unregister_command (cmd_linux); @@ -850,7 +853,7 @@ index 47ea294..eea25ea 100644 + grub_unregister_command (cmd_initrd16); } diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h -index 2e98a66..775297d 100644 +index bcd5a7eb186..b582f67f661 100644 --- a/include/grub/arm/linux.h +++ b/include/grub/arm/linux.h @@ -20,6 +20,7 @@ @@ -880,19 +883,18 @@ index 2e98a66..775297d 100644 #if defined GRUB_MACHINE_UBOOT diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h -index 4269adc..a3be9dd 100644 +index 7e22b4ab699..ea030312df3 100644 --- a/include/grub/arm64/linux.h +++ b/include/grub/arm64/linux.h -@@ -19,6 +19,8 @@ +@@ -19,6 +19,7 @@ #ifndef GRUB_ARM64_LINUX_HEADER #define GRUB_ARM64_LINUX_HEADER 1 +#include -+ - #define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */ + #include - /* From linux/Documentation/arm64/booting.txt */ -@@ -36,9 +38,17 @@ struct linux_arm64_kernel_header + #define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */ +@@ -38,9 +39,17 @@ struct linux_arm64_kernel_header grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ }; @@ -911,7 +913,7 @@ index 4269adc..a3be9dd 100644 #endif /* ! GRUB_ARM64_LINUX_HEADER */ diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h -index e90e00d..6840bfe 100644 +index 83d958f9945..6295df85f3f 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -47,6 +47,9 @@ EXPORT_FUNC(grub_efi_allocate_fixed) (grub_efi_physical_address_t address, @@ -924,7 +926,7 @@ index e90e00d..6840bfe 100644 void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address, grub_efi_uintn_t pages); grub_efi_uintn_t EXPORT_FUNC(grub_efi_find_mmap_size) (void); -@@ -82,6 +85,7 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var, +@@ -88,6 +91,7 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var, const grub_efi_guid_t *guid, void *data, grub_size_t datasize); @@ -932,7 +934,7 @@ index e90e00d..6840bfe 100644 int EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1, const grub_efi_device_path_t *dp2); -@@ -95,8 +99,7 @@ void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); +@@ -101,8 +105,7 @@ void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *); #include grub_err_t grub_arch_efi_linux_check_image(struct linux_arch_kernel_header *lh); @@ -944,7 +946,7 @@ index e90e00d..6840bfe 100644 grub_addr_t grub_efi_modules_addr (void); diff --git a/include/grub/efi/linux.h b/include/grub/efi/linux.h new file mode 100644 -index 0000000..d9ede36 +index 00000000000..d9ede36773b --- /dev/null +++ b/include/grub/efi/linux.h @@ -0,0 +1,31 @@ @@ -979,6 +981,3 @@ index 0000000..d9ede36 + void *kernel_param); + +#endif /* ! GRUB_EFI_LINUX_HEADER */ --- -1.8.3.1 - diff --git a/0002-Rework-linux-command.patch b/0005-Rework-linux-command.patch similarity index 66% rename from 0002-Rework-linux-command.patch rename to 0005-Rework-linux-command.patch index 07ee4c4dee4392baec0ceebd55913ab69b97b9ee..9954dd0a61c6f3dcbb997241ac69e293bf3f0138 100644 --- a/0002-Rework-linux-command.patch +++ b/0005-Rework-linux-command.patch @@ -1,20 +1,22 @@ -From 6dd706679d6a784317929140bdc7bb11c90ab622 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Matthew Garrett -Date: Fri, 5 Jul 2019 20:54:51 +0200 -Subject: [PATCH 002/220] Rework linux command +Date: Sun, 9 Aug 2015 16:12:39 -0700 +Subject: [PATCH] Rework linux command We want a single buffer that contains the entire kernel image in order to perform a TPM measurement. Allocate one and copy the entire kernel into it before pulling out the individual blocks later on. + +Signed-off-by: Matthew Garrett --- - grub-core/loader/i386/linux.c | 36 +++++++++++++++++++++++------------- - 1 file changed, 23 insertions(+), 13 deletions(-) + grub-core/loader/i386/linux.c | 35 +++++++++++++++++++++++------------ + 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c -index d0501e2..b255c95 100644 +index 9f74a96b19a..dccf3bb3005 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c -@@ -641,13 +641,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -649,13 +649,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), { grub_file_t file = 0; struct linux_i386_kernel_header lh; @@ -31,7 +33,7 @@ index d0501e2..b255c95 100644 grub_dl_ref (my_mod); -@@ -661,7 +663,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -669,7 +671,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (! file) goto fail; @@ -48,7 +50,7 @@ index d0501e2..b255c95 100644 { if (!grub_errno) grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), -@@ -669,6 +679,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -677,6 +687,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } @@ -58,32 +60,25 @@ index d0501e2..b255c95 100644 if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55)) { grub_error (GRUB_ERR_BAD_OS, "invalid magic number"); -@@ -760,6 +773,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - preferred_address)) - goto fail; - -+ - grub_memset (&linux_params, 0, sizeof (linux_params)); - grub_memcpy (&linux_params.setup_sects, &lh.setup_sects, sizeof (lh) - 0x1F1); - -@@ -782,13 +796,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -784,13 +797,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* We've already read lh so there is no need to read it second time. */ len -= sizeof(lh); -- if (grub_file_read (file, (char *) &linux_params + sizeof (lh), len) != len) -- { +- if ((len > 0) && +- (grub_file_read (file, (char *) &linux_params + sizeof (lh), len) != len)) ++ linux_params_ptr = (void *)&linux_params; ++ if (len > 0) + { - if (!grub_errno) - grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), - argv[0]); - goto fail; -- } -+ linux_params_ptr = (void *)&linux_params; -+ grub_memcpy (linux_params_ptr + sizeof (lh), kernel + kernel_offset, len); -+ kernel_offset += len; - - linux_params.type_of_loader = GRUB_LINUX_BOOT_LOADER_TYPE; ++ grub_memcpy (linux_params_ptr + sizeof (lh), kernel + kernel_offset, len); ++ kernel_offset += len; + } -@@ -847,7 +857,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + linux_params.code32_start = prot_mode_target + lh.code32_start - GRUB_LINUX_BZIMAGE_ADDR; +@@ -853,7 +864,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* The other parameters are filled when booting. */ @@ -92,7 +87,7 @@ index d0501e2..b255c95 100644 grub_dprintf ("linux", "bzImage, setup=0x%x, size=0x%x\n", (unsigned) real_size, (unsigned) prot_size); -@@ -1001,9 +1011,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -1007,9 +1018,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), } len = prot_file_size; @@ -103,7 +98,7 @@ index d0501e2..b255c95 100644 if (grub_errno == GRUB_ERR_NONE) { -@@ -1014,6 +1022,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -1020,6 +1029,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), fail: @@ -112,6 +107,3 @@ index d0501e2..b255c95 100644 if (file) grub_file_close (file); --- -1.8.3.1 - diff --git a/0003-Rework-linux16-command.patch b/0006-Rework-linux16-command.patch similarity index 81% rename from 0003-Rework-linux16-command.patch rename to 0006-Rework-linux16-command.patch index 287343aac512128d3d2ab0e08b5fbaaf472082fa..2c2d6f0ba6ccf41ad7df6f9e96fa054d3535baad 100644 --- a/0003-Rework-linux16-command.patch +++ b/0006-Rework-linux16-command.patch @@ -1,20 +1,22 @@ -From 84d1fbf3d3a427c168b57f83e8e29a7ae22e7192 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Matthew Garrett -Date: Fri, 5 Jul 2019 21:12:00 +0200 -Subject: [PATCH 003/220] Rework linux16 command +Date: Sun, 9 Aug 2015 16:20:58 -0700 +Subject: [PATCH] Rework linux16 command We want a single buffer that contains the entire kernel image in order to perform a TPM measurement. Allocate one and copy the entire kernel int it before pulling out the individual blocks later on. + +Signed-off-by: Matthew Garrett --- grub-core/loader/i386/pc/linux.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c -index eea25ea..73fb91e 100644 +index 8be4c3b3f48..4b1750e360e 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c -@@ -123,13 +123,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -124,13 +124,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_file_t file = 0; struct linux_i386_kernel_header lh; grub_uint8_t setup_sects; @@ -30,7 +32,7 @@ index eea25ea..73fb91e 100644 grub_dl_ref (my_mod); -@@ -143,7 +144,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -144,7 +145,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (! file) goto fail; @@ -47,7 +49,7 @@ index eea25ea..73fb91e 100644 { if (!grub_errno) grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), -@@ -151,6 +160,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -152,6 +161,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } @@ -57,7 +59,7 @@ index eea25ea..73fb91e 100644 if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55)) { grub_error (GRUB_ERR_BAD_OS, "invalid magic number"); -@@ -314,13 +326,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -320,13 +332,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_memmove (grub_linux_real_chunk, &lh, sizeof (lh)); len = real_size + GRUB_DISK_SECTOR_SIZE - sizeof (lh); @@ -74,7 +76,7 @@ index eea25ea..73fb91e 100644 if (lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE) || grub_le_to_cpu16 (lh.version) < 0x0200) -@@ -358,9 +366,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -364,9 +372,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), } len = grub_linux16_prot_size; @@ -86,7 +88,7 @@ index eea25ea..73fb91e 100644 if (grub_errno == GRUB_ERR_NONE) { -@@ -370,6 +377,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -376,6 +383,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), fail: @@ -95,6 +97,3 @@ index eea25ea..73fb91e 100644 if (file) grub_file_close (file); --- -1.8.3.1 - diff --git a/0004-Add-secureboot-support-on-efi-chainloader.patch b/0007-Add-secureboot-support-on-efi-chainloader.patch similarity index 96% rename from 0004-Add-secureboot-support-on-efi-chainloader.patch rename to 0007-Add-secureboot-support-on-efi-chainloader.patch index b1d0a33d3887261f99649a68b022ebecc6cfef34..6826cce1e3986691913aa31ce63dc5fec2a24e73 100644 --- a/0004-Add-secureboot-support-on-efi-chainloader.patch +++ b/0007-Add-secureboot-support-on-efi-chainloader.patch @@ -1,7 +1,7 @@ -From 703e2ddcf768f52f46d02a59627b91280822c293 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Raymund Will Date: Mon, 8 Jul 2019 11:55:18 +0200 -Subject: [PATCH 004/220] Add secureboot support on efi chainloader +Subject: [PATCH] Add secureboot support on efi chainloader Expand the chainloader to be able to verify the image by means of shim lock protocol. The PE/COFF image is loaded and relocated by the @@ -164,21 +164,36 @@ following branches: Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1347291 Signed-off-by: Laszlo Ersek + +Also: + +commit cc06f149fbd2d8c1da1e83173d21629ba97e0d92 +Author: Raymund Will + +chainloader: Define machine types for RISC-V + +The commit "Add secureboot support on efi chainloader" didn't add machine +types for RISC-V, so this patch adds them. + +Note, that grub-core/loader/riscv/linux.c is skipped because Linux is not +supported yet. This patch might need a new revision once that's the case. + +Signed-off-by: David Abdurachmanov --- grub-core/kern/efi/efi.c | 14 +- grub-core/loader/arm64/linux.c | 4 +- - grub-core/loader/efi/chainloader.c | 817 +++++++++++++++++++++++++++++++++---- + grub-core/loader/efi/chainloader.c | 820 +++++++++++++++++++++++++++++++++---- grub-core/loader/efi/linux.c | 25 +- grub-core/loader/i386/efi/linux.c | 17 +- include/grub/efi/linux.h | 2 +- include/grub/efi/pe32.h | 52 ++- - 7 files changed, 840 insertions(+), 91 deletions(-) + 7 files changed, 844 insertions(+), 90 deletions(-) diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index a0faa40..3487b06 100644 +index 35b8f670602..4a2259aa1c7 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c -@@ -283,14 +283,20 @@ grub_efi_secure_boot (void) +@@ -296,14 +296,20 @@ grub_efi_secure_boot (void) grub_efi_boolean_t ret = 0; secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize); @@ -204,7 +219,7 @@ index a0faa40..3487b06 100644 if (*secure_boot && !*setup_mode) ret = 1; diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c -index a312c66..04994d5 100644 +index a312c668685..04994d5c67d 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c @@ -284,6 +284,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), @@ -226,7 +241,7 @@ index a312c66..04994d5 100644 grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]); goto fail; diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index cd92ea3..ef87b06 100644 +index 2bd80f4db3d..e6a8d4ad0e9 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -32,6 +32,8 @@ @@ -261,15 +276,7 @@ index cd92ea3..ef87b06 100644 grub_dl_unref (my_mod); return GRUB_ERR_NONE; -@@ -179,7 +187,6 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) - /* Fill the file path for the directory. */ - d = (grub_efi_device_path_t *) ((char *) file_path - + ((char *) d - (char *) dp)); -- grub_efi_print_device_path (d); - copy_file_path ((grub_efi_file_path_device_path_t *) d, - dir_start, dir_end - dir_start); - -@@ -197,20 +204,690 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) +@@ -213,20 +221,694 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) return file_path; } @@ -384,6 +391,10 @@ index cd92ea3..ef87b06 100644 + GRUB_PE32_MACHINE_I386; +#elif defined(__ia64__) + GRUB_PE32_MACHINE_IA64; ++#elif defined(__riscv) && (__riscv_xlen == 32) ++ GRUB_PE32_MACHINE_RISCV32; ++#elif defined(__riscv) && (__riscv_xlen == 64) ++ GRUB_PE32_MACHINE_RISCV64; +#else +#error this architecture is not supported by grub2 +#endif @@ -963,7 +974,7 @@ index cd92ea3..ef87b06 100644 if (argc == 0) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); -@@ -222,15 +899,45 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), +@@ -238,15 +920,45 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), address = 0; image_handle = 0; file_path = 0; @@ -1011,7 +1022,7 @@ index cd92ea3..ef87b06 100644 if (! dev) goto fail; -@@ -267,17 +974,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), +@@ -283,17 +995,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), if (! file_path) goto fail; @@ -1032,7 +1043,7 @@ index cd92ea3..ef87b06 100644 status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ANY_PAGES, GRUB_EFI_LOADER_CODE, -@@ -291,7 +995,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), +@@ -307,7 +1016,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), } boot_image = (void *) ((grub_addr_t) address); @@ -1041,7 +1052,7 @@ index cd92ea3..ef87b06 100644 { if (grub_errno == GRUB_ERR_NONE) grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), -@@ -301,7 +1005,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), +@@ -317,7 +1026,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), } #if defined (__i386__) || defined (__x86_64__) @@ -1050,12 +1061,12 @@ index cd92ea3..ef87b06 100644 { struct grub_macho_fat_header *head = boot_image; if (head->magic -@@ -310,6 +1014,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), +@@ -326,6 +1035,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), grub_uint32_t i; struct grub_macho_fat_arch *archs = (struct grub_macho_fat_arch *) (head + 1); + -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + { + grub_error (GRUB_ERR_BAD_OS, + "MACHO binaries are forbidden with Secure Boot"); @@ -1065,7 +1076,7 @@ index cd92ea3..ef87b06 100644 for (i = 0; i < grub_cpu_to_le32 (head->nfat_arch); i++) { if (GRUB_MACHO_CPUTYPE_IS_HOST_CURRENT (archs[i].cputype)) -@@ -324,79 +1036,39 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), +@@ -340,79 +1057,39 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), > ~grub_cpu_to_le32 (archs[i].size) || grub_cpu_to_le32 (archs[i].offset) + grub_cpu_to_le32 (archs[i].size) @@ -1097,27 +1108,27 @@ index cd92ea3..ef87b06 100644 - grub_error (GRUB_ERR_BAD_OS, "cannot load image"); - - goto fail; -- } ++ grub_file_close (file); ++ grub_device_close (dev); ++ grub_loader_set (grub_secureboot_chainloader_boot, ++ grub_secureboot_chainloader_unload, 0); ++ return 0; + } - - /* LoadImage does not set a device handler when the image is - loaded from memory, so it is necessary to set it explicitly here. - This is a mess. */ - loaded_image = grub_efi_get_loaded_image (image_handle); - if (! loaded_image) -- { ++ else if (rc == 0) + { - grub_error (GRUB_ERR_BAD_OS, "no loaded image available"); - goto fail; -+ grub_file_close (file); -+ grub_device_close (dev); -+ grub_loader_set (grub_secureboot_chainloader_boot, -+ grub_secureboot_chainloader_unload, 0); -+ return 0; - } +- } - loaded_image->device_handle = dev_handle; - - if (argc > 1) -+ else if (rc == 0) - { +- { - int i, len; - grub_efi_char16_t *p16; - @@ -1128,7 +1139,11 @@ index cd92ea3..ef87b06 100644 - cmdline = p16 = grub_malloc (len); - if (! cmdline) - goto fail; -- ++ grub_load_and_start_image(boot_image); ++ grub_file_close (file); ++ grub_device_close (dev); ++ grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0); + - for (i = 1; i < argc; i++) - { - char *p8; @@ -1140,11 +1155,7 @@ index cd92ea3..ef87b06 100644 - *(p16++) = ' '; - } - *(--p16) = 0; -+ grub_load_and_start_image(boot_image); -+ grub_file_close (file); -+ grub_device_close (dev); -+ grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0); - +- - loaded_image->load_options = cmdline; - loaded_image->load_options_size = len; + return 0; @@ -1162,7 +1173,7 @@ index cd92ea3..ef87b06 100644 if (dev) grub_device_close (dev); -@@ -408,6 +1080,9 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), +@@ -424,6 +1101,9 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), if (address) efi_call_2 (b->free_pages, address, pages); @@ -1173,7 +1184,7 @@ index cd92ea3..ef87b06 100644 return grub_errno; diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c -index c24202a..c8ecce6 100644 +index c24202a5dd1..c8ecce6dfd0 100644 --- a/grub-core/loader/efi/linux.c +++ b/grub-core/loader/efi/linux.c @@ -33,21 +33,34 @@ struct grub_efi_shim_lock @@ -1197,7 +1208,9 @@ index c24202a..c8ecce6 100644 + grub_dprintf ("secureboot", "shim not available\n"); + return 0; + } -+ + +- if (shim_lock->verify(data, size) == GRUB_EFI_SUCCESS) +- return 1; + grub_dprintf ("secureboot", "Asking shim to verify kernel signature\n"); + status = shim_lock->verify (data, size); + grub_dprintf ("secureboot", "shim_lock->verify(): %ld\n", (long int)status); @@ -1207,18 +1220,16 @@ index c24202a..c8ecce6 100644 + return 1; + } -- if (shim_lock->verify(data, size) == GRUB_EFI_SUCCESS) -- return 1; +- return 0; + grub_dprintf ("secureboot", "Kernel signature verification failed (0x%lx)\n", + (unsigned long) status); - -- return 0; ++ + return -1; } #pragma GCC diagnostic push diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index bb2616a..6b24cbb 100644 +index bb2616a8092..6b24cbb9483 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -117,6 +117,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), @@ -1286,7 +1297,7 @@ index bb2616a..6b24cbb 100644 grub_file_close (file); diff --git a/include/grub/efi/linux.h b/include/grub/efi/linux.h -index d9ede36..0033d93 100644 +index d9ede36773b..0033d9305a9 100644 --- a/include/grub/efi/linux.h +++ b/include/grub/efi/linux.h @@ -22,7 +22,7 @@ @@ -1299,7 +1310,7 @@ index d9ede36..0033d93 100644 grub_err_t EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset, diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h -index 0ed8781..a43adf2 100644 +index 0ed8781f037..a43adf27464 100644 --- a/include/grub/efi/pe32.h +++ b/include/grub/efi/pe32.h @@ -223,7 +223,11 @@ struct grub_pe64_optional_header @@ -1388,6 +1399,3 @@ index 0ed8781..a43adf2 100644 struct grub_pe32_fixup_block { grub_uint32_t page_rva; --- -1.8.3.1 - diff --git a/0005-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch b/0008-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch similarity index 53% rename from 0005-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch rename to 0008-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch index d553562320898bceb960410e335995a3a8f727c0..030c71c9599a53ceb786186ee5ebe932649ed837 100644 --- a/0005-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch +++ b/0008-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch @@ -1,132 +1,102 @@ -From a5d1b0391c2875677f3d7a6d762b3fadaa3ecf85 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 6 Oct 2015 16:09:25 -0400 -Subject: [PATCH 005/220] Make any of the loaders that link in efi mode honor - secure boot. +Subject: [PATCH] Make any of the loaders that link in efi mode honor secure + boot. And in this case "honor" means "even if somebody does link this in, they won't register commands if SB is enabled." Signed-off-by: Peter Jones --- - grub-core/Makefile.am | 1 + - grub-core/Makefile.core.def | 1 + - grub-core/commands/iorw.c | 7 +++++ - grub-core/commands/memrw.c | 7 +++++ - grub-core/kern/dl.c | 1 + - grub-core/kern/efi/efi.c | 34 -------------------- - grub-core/kern/efi/sb.c | 64 ++++++++++++++++++++++++++++++++++++++ - grub-core/loader/efi/appleloader.c | 7 +++++ + grub-core/commands/iorw.c | 7 +++++++ + grub-core/commands/memrw.c | 7 +++++++ + grub-core/kern/dl.c | 3 ++- + grub-core/kern/efi/efi.c | 34 ---------------------------------- + grub-core/loader/efi/appleloader.c | 7 +++++++ grub-core/loader/efi/chainloader.c | 1 + - grub-core/loader/i386/bsd.c | 7 +++++ - grub-core/loader/i386/linux.c | 7 +++++ - grub-core/loader/i386/pc/linux.c | 7 +++++ - grub-core/loader/multiboot.c | 7 +++++ - grub-core/loader/xnu.c | 7 +++++ + grub-core/loader/i386/bsd.c | 7 +++++++ + grub-core/loader/i386/linux.c | 7 +++++++ + grub-core/loader/i386/pc/linux.c | 7 +++++++ + grub-core/loader/multiboot.c | 7 +++++++ + grub-core/loader/xnu.c | 7 +++++++ include/grub/efi/efi.h | 1 - - include/grub/efi/sb.h | 29 +++++++++++++++++ include/grub/ia64/linux.h | 0 include/grub/mips/linux.h | 0 include/grub/powerpc/linux.h | 0 include/grub/sparc64/linux.h | 0 - 20 files changed, 153 insertions(+), 35 deletions(-) - create mode 100644 grub-core/kern/efi/sb.c - create mode 100644 include/grub/efi/sb.h + 16 files changed, 59 insertions(+), 36 deletions(-) create mode 100644 include/grub/ia64/linux.h create mode 100644 include/grub/mips/linux.h create mode 100644 include/grub/powerpc/linux.h create mode 100644 include/grub/sparc64/linux.h -diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am -index 3ea8e7f..c6ba5b2 100644 ---- a/grub-core/Makefile.am -+++ b/grub-core/Makefile.am -@@ -71,6 +71,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/command.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/device.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/disk.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/dl.h -+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/sb.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env_private.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/err.h -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 581d9df..eb1088f 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -207,6 +207,7 @@ kernel = { - i386_multiboot = kern/i386/pc/acpi.c; - i386_coreboot = kern/acpi.c; - i386_multiboot = kern/acpi.c; -+ common = kern/efi/sb.c; - - x86 = kern/i386/tsc.c; - x86 = kern/i386/tsc_pit.c; diff --git a/grub-core/commands/iorw.c b/grub-core/commands/iorw.c -index a0c164e..41a7f3f 100644 +index 584baec8f91..7b2999b14b5 100644 --- a/grub-core/commands/iorw.c +++ b/grub-core/commands/iorw.c -@@ -23,6 +23,7 @@ - #include +@@ -24,6 +24,7 @@ #include #include + #include +#include GRUB_MOD_LICENSE ("GPLv3+"); -@@ -118,6 +119,9 @@ grub_cmd_write (grub_command_t cmd, int argc, char **argv) +@@ -119,6 +120,9 @@ grub_cmd_write (grub_command_t cmd, int argc, char **argv) GRUB_MOD_INIT(memrw) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + cmd_read_byte = grub_register_extcmd ("inb", grub_cmd_read, 0, N_("PORT"), N_("Read 8-bit value from PORT."), -@@ -146,6 +150,9 @@ GRUB_MOD_INIT(memrw) +@@ -147,6 +151,9 @@ GRUB_MOD_INIT(memrw) GRUB_MOD_FINI(memrw) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + grub_unregister_extcmd (cmd_read_byte); grub_unregister_extcmd (cmd_read_word); grub_unregister_extcmd (cmd_read_dword); diff --git a/grub-core/commands/memrw.c b/grub-core/commands/memrw.c -index 98769ea..088cbe9 100644 +index d401a6db0ef..39cf3a06dbd 100644 --- a/grub-core/commands/memrw.c +++ b/grub-core/commands/memrw.c -@@ -22,6 +22,7 @@ - #include +@@ -23,6 +23,7 @@ #include #include + #include +#include GRUB_MOD_LICENSE ("GPLv3+"); -@@ -120,6 +121,9 @@ grub_cmd_write (grub_command_t cmd, int argc, char **argv) +@@ -121,6 +122,9 @@ grub_cmd_write (grub_command_t cmd, int argc, char **argv) GRUB_MOD_INIT(memrw) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + cmd_read_byte = grub_register_extcmd ("read_byte", grub_cmd_read, 0, N_("ADDR"), N_("Read 8-bit value from ADDR."), -@@ -148,6 +152,9 @@ GRUB_MOD_INIT(memrw) +@@ -149,6 +153,9 @@ GRUB_MOD_INIT(memrw) GRUB_MOD_FINI(memrw) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + grub_unregister_extcmd (cmd_read_byte); grub_unregister_extcmd (cmd_read_word); grub_unregister_extcmd (cmd_read_dword); diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index 896bebf..d7718d2 100644 +index b7149370950..7afb9e6f724 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -32,6 +32,7 @@ @@ -137,12 +107,21 @@ index 896bebf..d7718d2 100644 /* Platforms where modules are in a readonly area of memory. */ #if defined(GRUB_MACHINE_QEMU) +@@ -704,7 +705,7 @@ grub_dl_load_file (const char *filename) + grub_dl_t mod = 0; + + #ifdef GRUB_MACHINE_EFI +- if (grub_efi_secure_boot ()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + { + #if 0 + /* This is an error, but grub2-mkconfig still generates a pile of diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index 3487b06..6e1ceb9 100644 +index 4a2259aa1c7..8cff7be0289 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c -@@ -273,40 +273,6 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, - return NULL; +@@ -286,40 +286,6 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, + return grub_efi_get_variable_with_attributes (var, guid, datasize_out, data_out, NULL); } -grub_efi_boolean_t @@ -182,78 +161,8 @@ index 3487b06..6e1ceb9 100644 #pragma GCC diagnostic ignored "-Wcast-align" /* Search the mods section from the PE32/PE32+ image. This code uses -diff --git a/grub-core/kern/efi/sb.c b/grub-core/kern/efi/sb.c -new file mode 100644 -index 0000000..d74778b ---- /dev/null -+++ b/grub-core/kern/efi/sb.c -@@ -0,0 +1,64 @@ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2014 Free Software Foundation, Inc. -+ * -+ * GRUB is free software: you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation, either version 3 of the License, or -+ * (at your option) any later version. -+ * -+ * GRUB is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with GRUB. If not, see . -+ */ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+int -+grub_efi_secure_boot (void) -+{ -+#ifdef GRUB_MACHINE_EFI -+ grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID; -+ grub_size_t datasize; -+ char *secure_boot = NULL; -+ char *setup_mode = NULL; -+ grub_efi_boolean_t ret = 0; -+ -+ secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize); -+ if (datasize != 1 || !secure_boot) -+ { -+ grub_dprintf ("secureboot", "No SecureBoot variable\n"); -+ goto out; -+ } -+ grub_dprintf ("secureboot", "SecureBoot: %d\n", *secure_boot); -+ -+ setup_mode = grub_efi_get_variable("SetupMode", &efi_var_guid, &datasize); -+ if (datasize != 1 || !setup_mode) -+ { -+ grub_dprintf ("secureboot", "No SetupMode variable\n"); -+ goto out; -+ } -+ grub_dprintf ("secureboot", "SetupMode: %d\n", *setup_mode); -+ -+ if (*secure_boot && !*setup_mode) -+ ret = 1; -+ -+ out: -+ grub_free (secure_boot); -+ grub_free (setup_mode); -+ return ret; -+#else -+ return 0; -+#endif -+} diff --git a/grub-core/loader/efi/appleloader.c b/grub-core/loader/efi/appleloader.c -index 74888c4..69c2a10 100644 +index 74888c463ba..585f2b57385 100644 --- a/grub-core/loader/efi/appleloader.c +++ b/grub-core/loader/efi/appleloader.c @@ -24,6 +24,7 @@ @@ -268,7 +177,7 @@ index 74888c4..69c2a10 100644 GRUB_MOD_INIT(appleloader) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + cmd = grub_register_command ("appleloader", grub_cmd_appleloader, @@ -278,13 +187,13 @@ index 74888c4..69c2a10 100644 GRUB_MOD_FINI(appleloader) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + grub_unregister_command (cmd); } diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index ef87b06..5aa3a5d 100644 +index e6a8d4ad0e9..07c4937898d 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -34,6 +34,7 @@ @@ -296,10 +205,10 @@ index ef87b06..5aa3a5d 100644 #include #include diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c -index 3730ed3..5b9b92d 100644 +index 5f3290ce17b..54befc26626 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c -@@ -39,6 +39,7 @@ +@@ -40,6 +40,7 @@ #ifdef GRUB_MACHINE_PCBIOS #include #endif @@ -307,92 +216,92 @@ index 3730ed3..5b9b92d 100644 GRUB_MOD_LICENSE ("GPLv3+"); -@@ -2130,6 +2131,9 @@ static grub_command_t cmd_netbsd_module_elf, cmd_openbsd_ramdisk; +@@ -2137,6 +2138,9 @@ static grub_command_t cmd_netbsd_module_elf, cmd_openbsd_ramdisk; GRUB_MOD_INIT (bsd) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + /* Net and OpenBSD kernels are often compressed. */ grub_dl_load ("gzio"); -@@ -2169,6 +2173,9 @@ GRUB_MOD_INIT (bsd) +@@ -2176,6 +2180,9 @@ GRUB_MOD_INIT (bsd) GRUB_MOD_FINI (bsd) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + grub_unregister_extcmd (cmd_freebsd); grub_unregister_extcmd (cmd_openbsd); grub_unregister_extcmd (cmd_netbsd); diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c -index b255c95..376c726 100644 +index dccf3bb3005..4aeb0e4b9a6 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c -@@ -36,6 +36,7 @@ - #include +@@ -37,6 +37,7 @@ #include #include + #include +#include GRUB_MOD_LICENSE ("GPLv3+"); -@@ -1131,6 +1132,9 @@ static grub_command_t cmd_linux, cmd_initrd; +@@ -1138,6 +1139,9 @@ static grub_command_t cmd_linux, cmd_initrd; GRUB_MOD_INIT(linux) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, N_("Load Linux.")); cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, -@@ -1140,6 +1144,9 @@ GRUB_MOD_INIT(linux) +@@ -1147,6 +1151,9 @@ GRUB_MOD_INIT(linux) GRUB_MOD_FINI(linux) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + grub_unregister_command (cmd_linux); grub_unregister_command (cmd_initrd); } diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c -index 73fb91e..fe3e1d4 100644 +index 4b1750e360e..e3fa1221e81 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c -@@ -35,6 +35,7 @@ - #include +@@ -36,6 +36,7 @@ #include #include + #include +#include GRUB_MOD_LICENSE ("GPLv3+"); -@@ -483,6 +484,9 @@ static grub_command_t cmd_linux, cmd_linux16, cmd_initrd, cmd_initrd16; +@@ -487,6 +488,9 @@ static grub_command_t cmd_linux, cmd_linux16, cmd_initrd, cmd_initrd16; GRUB_MOD_INIT(linux16) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, N_("Load Linux.")); -@@ -500,6 +504,9 @@ GRUB_MOD_INIT(linux16) +@@ -504,6 +508,9 @@ GRUB_MOD_INIT(linux16) GRUB_MOD_FINI(linux16) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + grub_unregister_command (cmd_linux); grub_unregister_command (cmd_linux16); grub_unregister_command (cmd_initrd); diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c -index 4a98d70..3e6ad16 100644 +index facb13f3d36..47e481f4576 100644 --- a/grub-core/loader/multiboot.c +++ b/grub-core/loader/multiboot.c @@ -50,6 +50,7 @@ @@ -407,7 +316,7 @@ index 4a98d70..3e6ad16 100644 GRUB_MOD_INIT(multiboot) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + cmd_multiboot = @@ -417,49 +326,49 @@ index 4a98d70..3e6ad16 100644 GRUB_MOD_FINI(multiboot) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + grub_unregister_command (cmd_multiboot); grub_unregister_command (cmd_module); } diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c -index 7f74d1d..e0f47e7 100644 +index 1c0cf6a430a..baa54e652ab 100644 --- a/grub-core/loader/xnu.c +++ b/grub-core/loader/xnu.c -@@ -34,6 +34,7 @@ - #include +@@ -35,6 +35,7 @@ #include #include + #include +#include GRUB_MOD_LICENSE ("GPLv3+"); -@@ -1478,6 +1479,9 @@ static grub_extcmd_t cmd_splash; +@@ -1497,6 +1498,9 @@ static grub_extcmd_t cmd_splash; GRUB_MOD_INIT(xnu) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + cmd_kernel = grub_register_command ("xnu_kernel", grub_cmd_xnu_kernel, 0, N_("Load XNU image.")); cmd_kernel64 = grub_register_command ("xnu_kernel64", grub_cmd_xnu_kernel64, -@@ -1518,6 +1522,9 @@ GRUB_MOD_INIT(xnu) +@@ -1540,6 +1544,9 @@ GRUB_MOD_INIT(xnu) GRUB_MOD_FINI(xnu) { -+ if (grub_efi_secure_boot()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + return; + #ifndef GRUB_MACHINE_EMU grub_unregister_command (cmd_resume); #endif diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h -index 6840bfe..090c862 100644 +index 6295df85f3f..585fa6662b6 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h -@@ -85,7 +85,6 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var, +@@ -91,7 +91,6 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var, const grub_efi_guid_t *guid, void *data, grub_size_t datasize); @@ -467,53 +376,15 @@ index 6840bfe..090c862 100644 int EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1, const grub_efi_device_path_t *dp2); -diff --git a/include/grub/efi/sb.h b/include/grub/efi/sb.h -new file mode 100644 -index 0000000..9629fbb ---- /dev/null -+++ b/include/grub/efi/sb.h -@@ -0,0 +1,29 @@ -+/* sb.h - declare functions for EFI Secure Boot support */ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. -+ * -+ * GRUB is free software: you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation, either version 3 of the License, or -+ * (at your option) any later version. -+ * -+ * GRUB is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with GRUB. If not, see . -+ */ -+ -+#ifndef GRUB_EFI_SB_HEADER -+#define GRUB_EFI_SB_HEADER 1 -+ -+#include -+#include -+ -+/* Functions. */ -+int EXPORT_FUNC (grub_efi_secure_boot) (void); -+ -+#endif /* ! GRUB_EFI_SB_HEADER */ diff --git a/include/grub/ia64/linux.h b/include/grub/ia64/linux.h new file mode 100644 -index 0000000..e69de29 +index 00000000000..e69de29bb2d diff --git a/include/grub/mips/linux.h b/include/grub/mips/linux.h new file mode 100644 -index 0000000..e69de29 +index 00000000000..e69de29bb2d diff --git a/include/grub/powerpc/linux.h b/include/grub/powerpc/linux.h new file mode 100644 -index 0000000..e69de29 +index 00000000000..e69de29bb2d diff --git a/include/grub/sparc64/linux.h b/include/grub/sparc64/linux.h new file mode 100644 -index 0000000..e69de29 --- -1.8.3.1 - +index 00000000000..e69de29bb2d diff --git a/0006-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch b/0009-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch similarity index 94% rename from 0006-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch rename to 0009-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch index ba6eae35950a0bc52c65c12c01fc90e73420df76..f3aae38990761f1ebbfbf16e0d2c98b73cdf185f 100644 --- a/0006-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch +++ b/0009-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch @@ -1,19 +1,19 @@ -From 6290701c8bd7183fef478afd5c27053bf9691639 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 8 Jul 2019 12:32:37 +0200 -Subject: [PATCH 006/220] Handle multi-arch (64-on-32) boot in linuxefi loader. +Subject: [PATCH] Handle multi-arch (64-on-32) boot in linuxefi loader. Allow booting 64-bit kernels on 32-bit EFI on x86. Signed-off-by: Peter Jones --- - grub-core/loader/efi/linux.c | 9 ++- - grub-core/loader/i386/efi/linux.c | 114 ++++++++++++++++++++++++++------------ + grub-core/loader/efi/linux.c | 9 +++- + grub-core/loader/i386/efi/linux.c | 110 ++++++++++++++++++++++++++------------ include/grub/i386/linux.h | 7 ++- - 3 files changed, 91 insertions(+), 39 deletions(-) + 3 files changed, 89 insertions(+), 37 deletions(-) diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c -index c8ecce6..0622dfa 100644 +index c8ecce6dfd0..0622dfa48d4 100644 --- a/grub-core/loader/efi/linux.c +++ b/grub-core/loader/efi/linux.c @@ -69,12 +69,17 @@ grub_linuxefi_secure_validate (void *data, grub_uint32_t size) @@ -37,7 +37,7 @@ index c8ecce6..0622dfa 100644 return GRUB_ERR_BUG; diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 6b24cbb..3017d0f 100644 +index 6b24cbb9483..3017d0f3e52 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -44,14 +44,10 @@ static char *linux_cmdline; @@ -95,16 +95,14 @@ index 6b24cbb..3017d0f 100644 } - grub_dprintf ("linux", "params = %lx\n", (unsigned long) params); -- ++ grub_dprintf ("linux", "params = %p\n", params); + - grub_memset (params, 0, 16384); -- ++ grub_memset (params, 0, sizeof(*params)); + - grub_memcpy (&lh, kernel, sizeof (lh)); - - if (lh.boot_flag != grub_cpu_to_le16 (0xaa55)) -+ grub_dprintf ("linux", "params = %p\n", params); -+ -+ grub_memset (params, 0, sizeof(*params)); -+ + setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201); + grub_dprintf ("linux", "copying %lu bytes from %p to %p\n", + MIN((grub_size_t)0x202+setup_header_end_offset, @@ -218,15 +216,15 @@ index 6b24cbb..3017d0f 100644 loaded=1; + grub_dprintf ("linux", "setting lh->code32_start to %p\n", kernel_mem); + lh->code32_start = (grub_uint32_t)(grub_addr_t) kernel_mem; -+ -+ grub_memcpy (kernel_mem, (char *)kernel + start, filelen - start); - lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem; - grub_memcpy (params, &lh, 2 * 512); -+ grub_dprintf ("linux", "setting lh->type_of_loader\n"); -+ lh->type_of_loader = 0x6; ++ grub_memcpy (kernel_mem, (char *)kernel + start, filelen - start); - params->type_of_loader = 0x21; ++ grub_dprintf ("linux", "setting lh->type_of_loader\n"); ++ lh->type_of_loader = 0x6; ++ + grub_dprintf ("linux", "setting lh->ext_loader_{type,ver}\n"); + params->ext_loader_type = 0; + params->ext_loader_ver = 2; @@ -247,10 +245,10 @@ index 6b24cbb..3017d0f 100644 if (kernel_mem && !loaded) grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h -index ce30e7f..a093679 100644 +index eddf9251d9a..25ef52c04eb 100644 --- a/include/grub/i386/linux.h +++ b/include/grub/i386/linux.h -@@ -136,7 +136,12 @@ struct linux_i386_kernel_header +@@ -138,7 +138,12 @@ struct linux_i386_kernel_header grub_uint32_t kernel_alignment; grub_uint8_t relocatable; grub_uint8_t min_alignment; @@ -264,6 +262,3 @@ index ce30e7f..a093679 100644 grub_uint32_t cmdline_size; grub_uint32_t hardware_subarch; grub_uint64_t hardware_subarch_data; --- -1.8.3.1 - diff --git a/0007-re-write-.gitignore.patch b/0010-re-write-.gitignore.patch similarity index 49% rename from 0007-re-write-.gitignore.patch rename to 0010-re-write-.gitignore.patch index 7e3c6b1f4e3f70bf5433e62518d9505491373eb8..74cb0dae950ba4bd29c6e61f4f72de2dc25fb1f9 100644 --- a/0007-re-write-.gitignore.patch +++ b/0010-re-write-.gitignore.patch @@ -1,17 +1,17 @@ -From 22e9b5b6f0e2031bc68d1c3cb0e8e1f33cc68c93 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 8 Jul 2019 12:55:29 +0200 -Subject: [PATCH 007/220] re-write .gitignore +Subject: [PATCH] re-write .gitignore --- - .gitignore | 366 +++++++++++++++----------------------- - docs/.gitignore | 5 + - grub-core/.gitignore | 16 ++ + .gitignore | 152 ++++++++++++++++++++++++++++++++++++++ + docs/.gitignore | 5 ++ + grub-core/.gitignore | 16 ++++ grub-core/lib/.gitignore | 1 + include/grub/gcrypt/.gitignore | 2 + - po/.gitignore | 5 + + po/.gitignore | 5 ++ util/bash-completion.d/.gitignore | 2 + - 7 files changed, 171 insertions(+), 226 deletions(-) + 7 files changed, 183 insertions(+) create mode 100644 docs/.gitignore create mode 100644 grub-core/.gitignore create mode 100644 grub-core/lib/.gitignore @@ -20,10 +20,14 @@ Subject: [PATCH 007/220] re-write .gitignore create mode 100644 util/bash-completion.d/.gitignore diff --git a/.gitignore b/.gitignore -index 819cd18..b45a633 100644 +index f6a1bd05175..594d0134d33 100644 --- a/.gitignore +++ b/.gitignore -@@ -1,237 +1,151 @@ +@@ -275,3 +275,155 @@ widthspec.bin + /xfs_test + /xzcompress_test + /zfs_test ++======= +# things ./autogen.sh will create +/Makefile.utilgcry.def +/ABOUT-NLS @@ -36,45 +40,7 @@ index 819cd18..b45a633 100644 +/Makefile + +# things very common editors create that we never want - *~ --00_header --10_* --20_linux_xen --30_os-prober --40_custom --41_custom --*.1 --*.8 --ABOUT-NLS --aclocal.m4 --ahci_test --ascii.bitmaps --ascii.h --autom4te.cache --build-aux --build-grub-gen-asciih --build-grub-gen-widthspec --build-grub-mkfont --cdboot_test --cmp_test --config.cache --config.guess --config.h --config-util.h --config-util.h.in --config.log --config.status --config.sub --configure --core_compress_test --DISTLIST --docs/*.info --docs/stamp-vti --docs/version.texi --ehci_test --example_grub_script_test --example_scripted_test --example_unit_test ++*~ +.*.sw? +*.patch + @@ -87,207 +53,22 @@ index 819cd18..b45a633 100644 +*.a +*.am +*.efi - *.exec --*.exec.exe --fddboot_test --genkernsyms.sh --gensymlist.sh --gentrigtables --gentrigtables.exe --gettext_strings_test --/gnulib --grub-bin2h --/grub-bios-setup --/grub-bios-setup.exe --grub_cmd_date --grub_cmd_echo --grub_cmd_regexp --grub_cmd_set_date --grub_cmd_sleep --/grub-editenv --/grub-editenv.exe --grub-emu --grub-emu-lite --grub-emu.exe --grub-emu-lite.exe --grub_emu_init.c --grub_emu_init.h --/grub-file --/grub-file.exe --grub-fstest --grub-fstest.exe --grub_fstest_init.c --grub_fstest_init.h --grub_func_test --grub-install --grub-install.exe --grub-kbdcomp --/grub-macbless --/grub-macbless.exe --grub-macho2img --/grub-menulst2cfg --/grub-menulst2cfg.exe --/grub-mk* --grub-mount --/grub-ofpathname --/grub-ofpathname.exe --grub-core/build-grub-pe2elf.exe --/grub-probe --/grub-probe.exe --grub_probe_init.c --grub_probe_init.h --/grub-reboot --grub_script_blanklines --grub_script_blockarg --grub_script_break --grub-script-check --grub-script-check.exe --grub_script_check_init.c --grub_script_check_init.h --grub_script_comments --grub_script_continue --grub_script_dollar --grub_script_echo1 --grub_script_echo_keywords --grub_script_escape_comma --grub_script_eval --grub_script_expansion --grub_script_final_semicolon --grub_script_for1 --grub_script_functions --grub_script_gettext --grub_script_if --grub_script_leading_whitespace --grub_script_no_commands --grub_script_not --grub_script_return --grub_script_setparams --grub_script_shift --grub_script_strcmp --grub_script_test --grub_script_vars1 --grub_script_while1 --grub_script.tab.c --grub_script.tab.h --grub_script.yy.c --grub_script.yy.h --grub-set-default --grub_setup_init.c --grub_setup_init.h --grub-shell --grub-shell-tester --grub-sparc64-setup --grub-sparc64-setup.exe --/grub-syslinux2cfg --/grub-syslinux2cfg.exe --gzcompress_test --hddboot_test --help_test --*.img - *.image --*.image.exe --include/grub/cpu --include/grub/machine --INSTALL.grub --install-sh --lib/libgcrypt-grub --libgrub_a_init.c --*.log ++*.exec ++*.image +*.img +*.info - *.lst --lzocompress_test - *.marker --Makefile - /m4 - *.mod --mod-*.c --missing --netboot_test ++*.lst ++*.marker ++/m4 ++*.mod +*.module - *.o --*.a --ohci_test --partmap_test --pata_test - *.pf2 --*.pp --po/*.mo --po/grub.pot --po/Makefile.in.in --po/Makevars --po/Makevars.template --po/POTFILES --po/Rules-quot --po/stamp-po --printf_test --priority_queue_unit_test --pseries_test --stamp-h --stamp-h1 --stamp-h.in --symlist.c --symlist.h --trigtables.c --*.trs --uhci_test --update-grub_lib --unidata.c --xzcompress_test --Makefile.in --GPATH --GRTAGS --GSYMS --GTAGS --compile --depcomp --mdate-sh --texinfo.tex --grub-core/lib/libgcrypt-grub --.deps --.deps-util --.deps-core ++*.o ++*.pf2 +*.yy.[ch] +.deps/ +.deps-core/ +.deps-util/ - .dirstamp --Makefile.util.am --contrib --grub-core/bootinfo.txt --grub-core/Makefile.core.am --grub-core/Makefile.gcry.def --grub-core/contrib --grub-core/gdb_grub --grub-core/genmod.sh --grub-core/gensyminfo.sh --grub-core/gmodule.pl --grub-core/grub.chrp --grub-core/modinfo.sh --grub-core/*.module --grub-core/*.module.exe --grub-core/*.pp --grub-core/kernel.img.bin --util/bash-completion.d/grub --grub-core/lib/gnulib --grub-core/rs_decoder.h --widthspec.bin --widthspec.h --docs/stamp-1 --docs/version-dev.texi --Makefile.utilgcry.def --po/*.po --po/*.gmo --po/LINGUAS --po/remove-potcdate.sed --include/grub/gcrypt/gcrypt.h --include/grub/gcrypt/g10lib.h --po/POTFILES.in --po/POTFILES-shell.in --/grub-glue-efi --/grub-render-label --/grub-glue-efi.exe --/grub-render-label.exe ++.dirstamp + +# next are things you get if you do ./configure in the topdir (for e.g. +# "make dist" invocation. @@ -320,10 +101,7 @@ index 819cd18..b45a633 100644 +/build-grub-gen-widthspec +/build-grub-mkfont +/config-util.h.in - /garbage-gen --/garbage-gen.exe --/grub-fs-tester --grub-core/build-grub-module-verifier ++/garbage-gen +/grub*-bios-setup +/grub*-bios-setup.8 +/grub*-editenv @@ -403,7 +181,7 @@ index 819cd18..b45a633 100644 +/widthspec.h diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 -index 0000000..e1d849e +index 00000000000..e1d849ef95b --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1,5 @@ @@ -414,7 +192,7 @@ index 0000000..e1d849e +/version*.texi diff --git a/grub-core/.gitignore b/grub-core/.gitignore new file mode 100644 -index 0000000..2acce28 +index 00000000000..2acce281159 --- /dev/null +++ b/grub-core/.gitignore @@ -0,0 +1,16 @@ @@ -436,14 +214,14 @@ index 0000000..2acce28 +/trigtables.c diff --git a/grub-core/lib/.gitignore b/grub-core/lib/.gitignore new file mode 100644 -index 0000000..6815459 +index 00000000000..68154591404 --- /dev/null +++ b/grub-core/lib/.gitignore @@ -0,0 +1 @@ +/libgcrypt-grub/ diff --git a/include/grub/gcrypt/.gitignore b/include/grub/gcrypt/.gitignore new file mode 100644 -index 0000000..8fbf564 +index 00000000000..8fbf5646246 --- /dev/null +++ b/include/grub/gcrypt/.gitignore @@ -0,0 +1,2 @@ @@ -451,7 +229,7 @@ index 0000000..8fbf564 +gcrypt.h diff --git a/po/.gitignore b/po/.gitignore new file mode 100644 -index 0000000..f507e77 +index 00000000000..f507e7741e3 --- /dev/null +++ b/po/.gitignore @@ -0,0 +1,5 @@ @@ -462,12 +240,9 @@ index 0000000..f507e77 +/stamp-po diff --git a/util/bash-completion.d/.gitignore b/util/bash-completion.d/.gitignore new file mode 100644 -index 0000000..6813a52 +index 00000000000..6813a527ad3 --- /dev/null +++ b/util/bash-completion.d/.gitignore @@ -0,0 +1,2 @@ +Makefile +grub --- -1.8.3.1 - diff --git a/0011-Honor-a-symlink-when-generating-configuration-by-gru.patch b/0011-Honor-a-symlink-when-generating-configuration-by-gru.patch deleted file mode 100644 index 473aeb18c794b4fc821808cfe0431caded31c201..0000000000000000000000000000000000000000 --- a/0011-Honor-a-symlink-when-generating-configuration-by-gru.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 100f123a544bc54034cf61646f03f988fc876435 Mon Sep 17 00:00:00 2001 -From: Marcel Kolaja -Date: Tue, 21 Jan 2014 10:57:08 -0500 -Subject: [PATCH 011/220] Honor a symlink when generating configuration by - grub2-mkconfig - -Honor a symlink when generating configuration by grub2-mkconfig, so that -the -o option follows it rather than overwriting it with a regular file. ---- - util/grub-mkconfig.in | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index 9f477ff..523d4e0 100644 ---- a/util/grub-mkconfig.in -+++ b/util/grub-mkconfig.in -@@ -287,7 +287,8 @@ and /etc/grub.d/* files or please file a bug report with - exit 1 - else - # none of the children aborted with error, install the new grub.cfg -- mv -f ${grub_cfg}.new ${grub_cfg} -+ cat ${grub_cfg}.new > ${grub_cfg} -+ rm -f ${grub_cfg}.new - fi - fi - --- -1.8.3.1 - diff --git a/0008-IBM-client-architecture-CAS-reboot-support.patch b/0011-IBM-client-architecture-CAS-reboot-support.patch similarity index 88% rename from 0008-IBM-client-architecture-CAS-reboot-support.patch rename to 0011-IBM-client-architecture-CAS-reboot-support.patch index 6bf74105c9ab01053783133d4266980454e51314..431a443b46db46845bbe2aff100f6f5e7cccfc10 100644 --- a/0008-IBM-client-architecture-CAS-reboot-support.patch +++ b/0011-IBM-client-architecture-CAS-reboot-support.patch @@ -1,22 +1,26 @@ -From 3b4c970a7123c3c29415f41bebee761524597b25 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Paulo Flabiano Smorigo Date: Thu, 20 Sep 2012 18:07:39 -0300 -Subject: [PATCH 008/220] IBM client architecture (CAS) reboot support +Subject: [PATCH] IBM client architecture (CAS) reboot support This is an implementation of IBM client architecture (CAS) reboot for GRUB. There are cases where the POWER firmware must reboot in order to support specific features requested by a kernel. The kernel calls -ibm,client-architecture-support and it may either return or reboot with the new -feature set. eg: +ibm,client-architecture-support and it may either return or reboot with +the new feature set. eg: Calling ibm,client-architecture-support.../ Elapsed time since release of system processors: 70959 mins 50 secs Welcome to GRUB! -Instead of return to the GRUB menu, it will check if the flag for CAS reboot is -set. If so, grub will automatically boot the last booted kernel using the same -parameters +Instead of return to the GRUB menu, it will check if the flag for CAS +reboot is set. If so, grub will automatically boot the last booted +kernel using the same parameters + +Signed-off-by: Paulo Flabiano Smorigo +[rharwood@redhat.com: commit message rewrap] +Signed-off-by: Robbie Harwood --- grub-core/kern/ieee1275/openfw.c | 63 ++++++++++++++++++++++++++++++++++++++++ grub-core/normal/main.c | 19 ++++++++++++ @@ -25,7 +29,7 @@ parameters 4 files changed, 91 insertions(+) diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c -index 4d493ab..3a6689a 100644 +index 4d493ab7661..3a6689abb11 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -591,3 +591,66 @@ grub_ieee1275_get_boot_dev (void) @@ -96,10 +100,10 @@ index 4d493ab..3a6689a 100644 + return 0; +} diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index 1b03dfd..222e239 100644 +index c4ebe9e22ad..70614de1565 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c -@@ -33,6 +33,9 @@ +@@ -34,6 +34,9 @@ #include #include #include @@ -109,7 +113,7 @@ index 1b03dfd..222e239 100644 GRUB_MOD_LICENSE ("GPLv3+"); -@@ -275,6 +278,22 @@ grub_normal_execute (const char *config, int nested, int batch) +@@ -276,6 +279,22 @@ grub_normal_execute (const char *config, int nested, int batch) { menu = read_config_file (config); @@ -133,7 +137,7 @@ index 1b03dfd..222e239 100644 grub_errno = GRUB_ERR_NONE; } diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c -index ee299fd..0d05d6b 100644 +index 25158407dd8..ad80399246a 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -28,6 +28,9 @@ @@ -146,7 +150,7 @@ index ee299fd..0d05d6b 100644 /* Max digits for a char is 3 (0xFF is 255), similarly for an int it is sizeof (int) * 3, and one extra for a possible -ve sign. */ -@@ -878,6 +881,10 @@ grub_script_execute_sourcecode (const char *source) +@@ -883,6 +886,10 @@ grub_script_execute_sourcecode (const char *source) grub_err_t ret = 0; struct grub_script *parsed_script; @@ -158,7 +162,7 @@ index ee299fd..0d05d6b 100644 { char *line; diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h -index 73e2f46..0a59960 100644 +index 73e2f464475..0a599607f31 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -254,6 +254,8 @@ int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *ali @@ -170,6 +174,3 @@ index 73e2f46..0a59960 100644 char *EXPORT_FUNC(grub_ieee1275_get_boot_dev) (void); --- -1.8.3.1 - diff --git a/0009-for-ppc-reset-console-display-attr-when-clear-screen.patch b/0012-for-ppc-reset-console-display-attr-when-clear-screen.patch similarity index 79% rename from 0009-for-ppc-reset-console-display-attr-when-clear-screen.patch rename to 0012-for-ppc-reset-console-display-attr-when-clear-screen.patch index 9a6ca8e721f5763879871d9366050ba9c2b102c6..c8ccc7e22eb7d6d76fb845064d34c9161d62c081 100644 --- a/0009-for-ppc-reset-console-display-attr-when-clear-screen.patch +++ b/0012-for-ppc-reset-console-display-attr-when-clear-screen.patch @@ -1,7 +1,7 @@ -From 8213eaa16384c332659e2655a7f5f01d09d5b27d Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Paulo Flabiano Smorigo Date: Wed, 24 Apr 2013 10:51:48 -0300 -Subject: [PATCH 009/220] for ppc, reset console display attr when clear screen +Subject: [PATCH] for ppc, reset console display attr when clear screen v2: Also use \x0c instead of a literal ^L to make future patches less awkward. @@ -10,12 +10,14 @@ This should fix this bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=908519 Signed-off-by: Peter Jones +Signed-off-by: Paulo Flabiano Smorigo +Signed-off-by: Robbie Harwood --- grub-core/term/terminfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c -index d317efa..29df35e 100644 +index 85ecf06b4df..05c88dcf49e 100644 --- a/grub-core/term/terminfo.c +++ b/grub-core/term/terminfo.c @@ -151,7 +151,7 @@ grub_terminfo_set_current (struct grub_term_output *term, @@ -27,6 +29,3 @@ index d317efa..29df35e 100644 data->reverse_video_on = grub_strdup ("\e[7m"); data->reverse_video_off = grub_strdup ("\e[m"); if (grub_strcmp ("ieee1275", str) == 0) --- -1.8.3.1 - diff --git a/0010-Disable-GRUB-video-support-for-IBM-power-machines.patch b/0013-Disable-GRUB-video-support-for-IBM-power-machines.patch similarity index 84% rename from 0010-Disable-GRUB-video-support-for-IBM-power-machines.patch rename to 0013-Disable-GRUB-video-support-for-IBM-power-machines.patch index 83d7c486f4a21efee70614eaf7282e42af601bed..e8aa3678c386011b42e82c429c2a16af07930c4a 100644 --- a/0010-Disable-GRUB-video-support-for-IBM-power-machines.patch +++ b/0013-Disable-GRUB-video-support-for-IBM-power-machines.patch @@ -1,10 +1,13 @@ -From 0a3d7e634bfa38143cdbe1c53aae681ea4432547 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Paulo Flabiano Smorigo Date: Tue, 11 Jun 2013 15:14:05 -0300 -Subject: [PATCH 010/220] Disable GRUB video support for IBM power machines +Subject: [PATCH] Disable GRUB video support for IBM power machines Should fix the problem in bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=973205 + +Signed-off-by: Paulo Flabiano Smorigo +Signed-off-by: Robbie Harwood --- grub-core/kern/ieee1275/cmain.c | 5 ++++- grub-core/video/ieee1275.c | 9 ++++++--- @@ -12,7 +15,7 @@ https://bugzilla.redhat.com/show_bug.cgi?id=973205 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/grub-core/kern/ieee1275/cmain.c b/grub-core/kern/ieee1275/cmain.c -index 20cbbd7..04df9d2 100644 +index 20cbbd761ec..04df9d2c667 100644 --- a/grub-core/kern/ieee1275/cmain.c +++ b/grub-core/kern/ieee1275/cmain.c @@ -90,7 +90,10 @@ grub_ieee1275_find_options (void) @@ -28,7 +31,7 @@ index 20cbbd7..04df9d2 100644 /* Old Macs have no key repeat, newer ones have fully working one. The ones inbetween when repeated key generates an escaoe sequence diff --git a/grub-core/video/ieee1275.c b/grub-core/video/ieee1275.c -index 17a3dbb..b8e4b3f 100644 +index 17a3dbbb575..b8e4b3feb32 100644 --- a/grub-core/video/ieee1275.c +++ b/grub-core/video/ieee1275.c @@ -352,9 +352,12 @@ static struct grub_video_adapter grub_video_ieee1275_adapter = @@ -48,7 +51,7 @@ index 17a3dbb..b8e4b3f 100644 GRUB_MOD_FINI(ieee1275_fb) diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h -index 0a59960..b5a1d49 100644 +index 0a599607f31..b5a1d49bbc3 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -148,6 +148,8 @@ enum grub_ieee1275_flag @@ -60,6 +63,3 @@ index 0a59960..b5a1d49 100644 }; extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag); --- -1.8.3.1 - diff --git a/0013-Update-to-minilzo-2.08.patch b/0013-Update-to-minilzo-2.08.patch deleted file mode 100644 index 9d2759754a88736bfa5a890a4a4034f7550a7311..0000000000000000000000000000000000000000 --- a/0013-Update-to-minilzo-2.08.patch +++ /dev/null @@ -1,8790 +0,0 @@ -From f2619e8e299f13ea8ade1ee9f69334f2c1c71219 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 4 Dec 2014 15:36:09 -0500 -Subject: [PATCH 013/220] Update to minilzo-2.08 - -This fixes CVE-2014-4607 - lzo: lzo1x_decompress_safe() integer overflow - -Signed-off-by: Peter Jones ---- - grub-core/lib/minilzo/lzoconf.h | 216 ++- - grub-core/lib/minilzo/lzodefs.h | 2450 +++++++++++++++++------- - grub-core/lib/minilzo/minilzo.c | 3953 +++++++++++++++++++++++++++------------ - grub-core/lib/minilzo/minilzo.h | 21 +- - 4 files changed, 4630 insertions(+), 2010 deletions(-) - -diff --git a/grub-core/lib/minilzo/lzoconf.h b/grub-core/lib/minilzo/lzoconf.h -index 1d0fe14..61be29c 100644 ---- a/grub-core/lib/minilzo/lzoconf.h -+++ b/grub-core/lib/minilzo/lzoconf.h -@@ -2,22 +2,7 @@ - - This file is part of the LZO real-time data compression library. - -- Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer -+ Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer - All Rights Reserved. - - The LZO library is free software; you can redistribute it and/or -@@ -44,9 +29,9 @@ - #ifndef __LZOCONF_H_INCLUDED - #define __LZOCONF_H_INCLUDED 1 - --#define LZO_VERSION 0x2050 --#define LZO_VERSION_STRING "2.05" --#define LZO_VERSION_DATE "Apr 23 2011" -+#define LZO_VERSION 0x2080 -+#define LZO_VERSION_STRING "2.08" -+#define LZO_VERSION_DATE "Jun 29 2014" - - /* internal Autoconf configuration file - only used when building LZO */ - #if defined(LZO_HAVE_CONFIG_H) -@@ -63,7 +48,7 @@ - #if !defined(CHAR_BIT) || (CHAR_BIT != 8) - # error "invalid CHAR_BIT" - #endif --#if !defined(UCHAR_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX) -+#if !defined(UCHAR_MAX) || !defined(USHRT_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX) - # error "check your compiler installation" - #endif - #if (USHRT_MAX < 1) || (UINT_MAX < 1) || (ULONG_MAX < 1) -@@ -85,14 +70,6 @@ extern "C" { - // some core defines - ************************************************************************/ - --#if !defined(LZO_UINT32_C) --# if (UINT_MAX < LZO_0xffffffffL) --# define LZO_UINT32_C(c) c ## UL --# else --# define LZO_UINT32_C(c) ((c) + 0U) --# endif --#endif -- - /* memory checkers */ - #if !defined(__LZO_CHECKER) - # if defined(__BOUNDS_CHECKING_ON) -@@ -111,28 +88,31 @@ extern "C" { - // integral and pointer types - ************************************************************************/ - --/* lzo_uint should match size_t */ -+/* lzo_uint must match size_t */ - #if !defined(LZO_UINT_MAX) --# if defined(LZO_ABI_LLP64) /* WIN64 */ --# if defined(LZO_OS_WIN64) -+# if (LZO_ABI_LLP64) -+# if (LZO_OS_WIN64) - typedef unsigned __int64 lzo_uint; - typedef __int64 lzo_int; - # else -- typedef unsigned long long lzo_uint; -- typedef long long lzo_int; -+ typedef lzo_ullong_t lzo_uint; -+ typedef lzo_llong_t lzo_int; - # endif -+# define LZO_SIZEOF_LZO_UINT 8 - # define LZO_UINT_MAX 0xffffffffffffffffull - # define LZO_INT_MAX 9223372036854775807LL - # define LZO_INT_MIN (-1LL - LZO_INT_MAX) --# elif defined(LZO_ABI_IP32L64) /* MIPS R5900 */ -+# elif (LZO_ABI_IP32L64) /* MIPS R5900 */ - typedef unsigned int lzo_uint; - typedef int lzo_int; -+# define LZO_SIZEOF_LZO_UINT LZO_SIZEOF_INT - # define LZO_UINT_MAX UINT_MAX - # define LZO_INT_MAX INT_MAX - # define LZO_INT_MIN INT_MIN - # elif (ULONG_MAX >= LZO_0xffffffffL) - typedef unsigned long lzo_uint; - typedef long lzo_int; -+# define LZO_SIZEOF_LZO_UINT LZO_SIZEOF_LONG - # define LZO_UINT_MAX ULONG_MAX - # define LZO_INT_MAX LONG_MAX - # define LZO_INT_MIN LONG_MIN -@@ -141,63 +121,22 @@ extern "C" { - # endif - #endif - --/* Integral types with 32 bits or more. */ --#if !defined(LZO_UINT32_MAX) --# if (UINT_MAX >= LZO_0xffffffffL) -- typedef unsigned int lzo_uint32; -- typedef int lzo_int32; --# define LZO_UINT32_MAX UINT_MAX --# define LZO_INT32_MAX INT_MAX --# define LZO_INT32_MIN INT_MIN --# elif (ULONG_MAX >= LZO_0xffffffffL) -- typedef unsigned long lzo_uint32; -- typedef long lzo_int32; --# define LZO_UINT32_MAX ULONG_MAX --# define LZO_INT32_MAX LONG_MAX --# define LZO_INT32_MIN LONG_MIN --# else --# error "lzo_uint32" --# endif --#endif -- --/* Integral types with exactly 64 bits. */ --#if !defined(LZO_UINT64_MAX) --# if (LZO_UINT_MAX >= LZO_0xffffffffL) --# if ((((LZO_UINT_MAX) >> 31) >> 31) == 3) --# define lzo_uint64 lzo_uint --# define lzo_int64 lzo_int --# define LZO_UINT64_MAX LZO_UINT_MAX --# define LZO_INT64_MAX LZO_INT_MAX --# define LZO_INT64_MIN LZO_INT_MIN --# endif --# elif (ULONG_MAX >= LZO_0xffffffffL) --# if ((((ULONG_MAX) >> 31) >> 31) == 3) -- typedef unsigned long lzo_uint64; -- typedef long lzo_int64; --# define LZO_UINT64_MAX ULONG_MAX --# define LZO_INT64_MAX LONG_MAX --# define LZO_INT64_MIN LONG_MIN --# endif --# endif --#endif -- --/* The larger type of lzo_uint and lzo_uint32. */ --#if (LZO_UINT_MAX >= LZO_UINT32_MAX) -+/* The larger type of lzo_uint and lzo_uint32_t. */ -+#if (LZO_SIZEOF_LZO_UINT >= 4) - # define lzo_xint lzo_uint - #else --# define lzo_xint lzo_uint32 -+# define lzo_xint lzo_uint32_t - #endif - --/* Memory model that allows to access memory at offsets of lzo_uint. */ --#if !defined(__LZO_MMODEL) --# if (LZO_UINT_MAX <= UINT_MAX) --# define __LZO_MMODEL /*empty*/ --# elif defined(LZO_HAVE_MM_HUGE_PTR) --# define __LZO_MMODEL_HUGE 1 --# define __LZO_MMODEL __huge --# else --# define __LZO_MMODEL /*empty*/ --# endif -+typedef int lzo_bool; -+ -+/* sanity checks */ -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == LZO_SIZEOF_LZO_UINT) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_xint) >= sizeof(lzo_uint)) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_xint) >= sizeof(lzo_uint32_t)) -+ -+#ifndef __LZO_MMODEL -+#define __LZO_MMODEL /*empty*/ - #endif - - /* no typedef here because of const-pointer issues */ -@@ -206,21 +145,52 @@ extern "C" { - #define lzo_voidp void __LZO_MMODEL * - #define lzo_shortp short __LZO_MMODEL * - #define lzo_ushortp unsigned short __LZO_MMODEL * --#define lzo_uint32p lzo_uint32 __LZO_MMODEL * --#define lzo_int32p lzo_int32 __LZO_MMODEL * --#if defined(LZO_UINT64_MAX) --#define lzo_uint64p lzo_uint64 __LZO_MMODEL * --#define lzo_int64p lzo_int64 __LZO_MMODEL * --#endif --#define lzo_uintp lzo_uint __LZO_MMODEL * - #define lzo_intp lzo_int __LZO_MMODEL * -+#define lzo_uintp lzo_uint __LZO_MMODEL * - #define lzo_xintp lzo_xint __LZO_MMODEL * - #define lzo_voidpp lzo_voidp __LZO_MMODEL * - #define lzo_bytepp lzo_bytep __LZO_MMODEL * --/* deprecated - use 'lzo_bytep' instead of 'lzo_byte *' */ --#define lzo_byte unsigned char __LZO_MMODEL - --typedef int lzo_bool; -+#define lzo_int8_tp lzo_int8_t __LZO_MMODEL * -+#define lzo_uint8_tp lzo_uint8_t __LZO_MMODEL * -+#define lzo_int16_tp lzo_int16_t __LZO_MMODEL * -+#define lzo_uint16_tp lzo_uint16_t __LZO_MMODEL * -+#define lzo_int32_tp lzo_int32_t __LZO_MMODEL * -+#define lzo_uint32_tp lzo_uint32_t __LZO_MMODEL * -+#if defined(lzo_int64_t) -+#define lzo_int64_tp lzo_int64_t __LZO_MMODEL * -+#define lzo_uint64_tp lzo_uint64_t __LZO_MMODEL * -+#endif -+ -+/* Older LZO versions used to support ancient systems and memory models -+ * like 16-bit MSDOS with __huge pointers and Cray PVP, but these -+ * obsolete configurations are not supported any longer. -+ */ -+#if defined(__LZO_MMODEL_HUGE) -+#error "__LZO_MMODEL_HUGE is unsupported" -+#endif -+#if (LZO_MM_PVP) -+#error "LZO_MM_PVP is unsupported" -+#endif -+#if (LZO_SIZEOF_INT < 4) -+#error "LZO_SIZEOF_INT < 4 is unsupported" -+#endif -+#if (__LZO_UINTPTR_T_IS_POINTER) -+#error "__LZO_UINTPTR_T_IS_POINTER is unsupported" -+#endif -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) >= 4) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) >= 4) -+/* Strange configurations where sizeof(lzo_uint) != sizeof(size_t) should -+ * work but have not received much testing lately, so be strict here. -+ */ -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(size_t)) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(ptrdiff_t)) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(lzo_uintptr_t)) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(void *) == sizeof(lzo_uintptr_t)) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(char *) == sizeof(lzo_uintptr_t)) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long *) == sizeof(lzo_uintptr_t)) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(void *) == sizeof(lzo_voidp)) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(char *) == sizeof(lzo_bytep)) - - - /*********************************************************************** -@@ -315,7 +285,7 @@ struct lzo_callback_t - /* a progress indicator callback function (set to 0 to disable) */ - lzo_progress_func_t nprogress; - -- /* NOTE: the first parameter "self" of the nalloc/nfree/nprogress -+ /* INFO: the first parameter "self" of the nalloc/nfree/nprogress - * callbacks points back to this struct, so you are free to store - * some extra info in the following variables. */ - lzo_voidp user1; -@@ -343,6 +313,9 @@ struct lzo_callback_t - #define LZO_E_INPUT_NOT_CONSUMED (-8) - #define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [not used right now] */ - #define LZO_E_INVALID_ARGUMENT (-10) -+#define LZO_E_INVALID_ALIGNMENT (-11) /* pointer argument is not properly aligned */ -+#define LZO_E_OUTPUT_NOT_CONSUMED (-12) -+#define LZO_E_INTERNAL_ERROR (-99) - - - #ifndef lzo_sizeof_dict_t -@@ -356,7 +329,7 @@ struct lzo_callback_t - * compiler's view of various types are consistent. - */ - #define lzo_init() __lzo_init_v2(LZO_VERSION,(int)sizeof(short),(int)sizeof(int),\ -- (int)sizeof(long),(int)sizeof(lzo_uint32),(int)sizeof(lzo_uint),\ -+ (int)sizeof(long),(int)sizeof(lzo_uint32_t),(int)sizeof(lzo_uint),\ - (int)lzo_sizeof_dict_t,(int)sizeof(char *),(int)sizeof(lzo_voidp),\ - (int)sizeof(lzo_callback_t)) - LZO_EXTERN(int) __lzo_init_v2(unsigned,int,int,int,int,int,int,int,int,int); -@@ -379,18 +352,22 @@ LZO_EXTERN(lzo_voidp) - lzo_memset(lzo_voidp buf, int c, lzo_uint len); - - /* checksum functions */ --LZO_EXTERN(lzo_uint32) -- lzo_adler32(lzo_uint32 c, const lzo_bytep buf, lzo_uint len); --LZO_EXTERN(lzo_uint32) -- lzo_crc32(lzo_uint32 c, const lzo_bytep buf, lzo_uint len); --LZO_EXTERN(const lzo_uint32p) -+LZO_EXTERN(lzo_uint32_t) -+ lzo_adler32(lzo_uint32_t c, const lzo_bytep buf, lzo_uint len); -+LZO_EXTERN(lzo_uint32_t) -+ lzo_crc32(lzo_uint32_t c, const lzo_bytep buf, lzo_uint len); -+LZO_EXTERN(const lzo_uint32_tp) - lzo_get_crc32_table(void); - - /* misc. */ - LZO_EXTERN(int) _lzo_config_check(void); --typedef union { lzo_bytep p; lzo_uint u; } __lzo_pu_u; --typedef union { lzo_bytep p; lzo_uint32 u32; } __lzo_pu32_u; --typedef union { void *vp; lzo_bytep bp; lzo_uint u; lzo_uint32 u32; unsigned long l; } lzo_align_t; -+typedef union { -+ lzo_voidp a00; lzo_bytep a01; lzo_uint a02; lzo_xint a03; lzo_uintptr_t a04; -+ void *a05; unsigned char *a06; unsigned long a07; size_t a08; ptrdiff_t a09; -+#if defined(lzo_int64_t) -+ lzo_uint64_t a10; -+#endif -+} lzo_align_t; - - /* align a char pointer on a boundary that is a multiple of 'size' */ - LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp p, lzo_uint size); -@@ -399,9 +376,30 @@ LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp p, lzo_uint size); - - - /*********************************************************************** --// deprecated macros - only for backward compatibility with LZO v1.xx -+// deprecated macros - only for backward compatibility - ************************************************************************/ - -+/* deprecated - use 'lzo_bytep' instead of 'lzo_byte *' */ -+#define lzo_byte unsigned char -+/* deprecated type names */ -+#define lzo_int32 lzo_int32_t -+#define lzo_uint32 lzo_uint32_t -+#define lzo_int32p lzo_int32_t __LZO_MMODEL * -+#define lzo_uint32p lzo_uint32_t __LZO_MMODEL * -+#define LZO_INT32_MAX LZO_INT32_C(2147483647) -+#define LZO_UINT32_MAX LZO_UINT32_C(4294967295) -+#if defined(lzo_int64_t) -+#define lzo_int64 lzo_int64_t -+#define lzo_uint64 lzo_uint64_t -+#define lzo_int64p lzo_int64_t __LZO_MMODEL * -+#define lzo_uint64p lzo_uint64_t __LZO_MMODEL * -+#define LZO_INT64_MAX LZO_INT64_C(9223372036854775807) -+#define LZO_UINT64_MAX LZO_UINT64_C(18446744073709551615) -+#endif -+/* deprecated types */ -+typedef union { lzo_bytep a; lzo_uint b; } __lzo_pu_u; -+typedef union { lzo_bytep a; lzo_uint32_t b; } __lzo_pu32_u; -+ - #if defined(LZO_CFG_COMPAT) - - #define __LZOCONF_H 1 -@@ -443,4 +441,4 @@ LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp p, lzo_uint size); - #endif /* already included */ - - --/* vim:set ts=4 et: */ -+/* vim:set ts=4 sw=4 et: */ -diff --git a/grub-core/lib/minilzo/lzodefs.h b/grub-core/lib/minilzo/lzodefs.h -index 0e40e33..f4ae948 100644 ---- a/grub-core/lib/minilzo/lzodefs.h -+++ b/grub-core/lib/minilzo/lzodefs.h -@@ -2,22 +2,7 @@ - - This file is part of the LZO real-time data compression library. - -- Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer -+ Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer - All Rights Reserved. - - The LZO library is free software; you can redistribute it and/or -@@ -47,12 +32,6 @@ - #if defined(__CYGWIN32__) && !defined(__CYGWIN__) - # define __CYGWIN__ __CYGWIN32__ - #endif --#if defined(__IBMCPP__) && !defined(__IBMC__) --# define __IBMC__ __IBMCPP__ --#endif --#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER) --# define __INTEL_COMPILER __ICL --#endif - #if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE) - # define _ALL_SOURCE 1 - #endif -@@ -61,19 +40,30 @@ - # define __LONG_MAX__ 9223372036854775807L - # endif - #endif --#if defined(__INTEL_COMPILER) && defined(__linux__) -+#if !defined(LZO_CFG_NO_DISABLE_WUNDEF) -+#if defined(__ARMCC_VERSION) -+# pragma diag_suppress 193 -+#elif defined(__clang__) && defined(__clang_minor__) -+# pragma clang diagnostic ignored "-Wundef" -+#elif defined(__INTEL_COMPILER) - # pragma warning(disable: 193) --#endif --#if defined(__KEIL__) && defined(__C166__) --# pragma warning disable = 322 --#elif 0 && defined(__C251__) -+#elif defined(__KEIL__) && defined(__C166__) - # pragma warning disable = 322 --#endif --#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) --# if (_MSC_VER >= 1300) -+#elif defined(__GNUC__) && defined(__GNUC_MINOR__) && !defined(__PATHSCALE__) -+# if ((__GNUC__-0) >= 5 || ((__GNUC__-0) == 4 && (__GNUC_MINOR__-0) >= 2)) -+# pragma GCC diagnostic ignored "-Wundef" -+# endif -+#elif defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) -+# if ((_MSC_VER-0) >= 1300) - # pragma warning(disable: 4668) - # endif - #endif -+#endif -+#if 0 && defined(__POCC__) && defined(_WIN32) -+# if (__POCC__ >= 400) -+# pragma warn(disable: 2216) -+# endif -+#endif - #if 0 && defined(__WATCOMC__) - # if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060) - # pragma warning 203 9 -@@ -82,13 +72,29 @@ - #if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__) - # pragma option -h - #endif -+#if !(LZO_CFG_NO_DISABLE_WCRTNONSTDC) -+#ifndef _CRT_NONSTDC_NO_DEPRECATE -+#define _CRT_NONSTDC_NO_DEPRECATE 1 -+#endif -+#ifndef _CRT_NONSTDC_NO_WARNINGS -+#define _CRT_NONSTDC_NO_WARNINGS 1 -+#endif -+#ifndef _CRT_SECURE_NO_DEPRECATE -+#define _CRT_SECURE_NO_DEPRECATE 1 -+#endif -+#ifndef _CRT_SECURE_NO_WARNINGS -+#define _CRT_SECURE_NO_WARNINGS 1 -+#endif -+#endif - #if 0 --#define LZO_0xffffL 0xfffful --#define LZO_0xffffffffL 0xfffffffful -+#define LZO_0xffffUL 0xfffful -+#define LZO_0xffffffffUL 0xfffffffful - #else --#define LZO_0xffffL 65535ul --#define LZO_0xffffffffL 4294967295ul -+#define LZO_0xffffUL 65535ul -+#define LZO_0xffffffffUL 4294967295ul - #endif -+#define LZO_0xffffL LZO_0xffffUL -+#define LZO_0xffffffffL LZO_0xffffffffUL - #if (LZO_0xffffL == LZO_0xffffffffL) - # error "your preprocessor is broken 1" - #endif -@@ -103,6 +109,13 @@ - # error "your preprocessor is broken 4" - #endif - #endif -+#if defined(__COUNTER__) -+# ifndef LZO_CFG_USE_COUNTER -+# define LZO_CFG_USE_COUNTER 1 -+# endif -+#else -+# undef LZO_CFG_USE_COUNTER -+#endif - #if (UINT_MAX == LZO_0xffffL) - #if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__) - # if !defined(MSDOS) -@@ -233,14 +246,31 @@ - #endif - #define LZO_PP_STRINGIZE(x) #x - #define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x) -+#define LZO_PP_CONCAT0() /*empty*/ -+#define LZO_PP_CONCAT1(a) a - #define LZO_PP_CONCAT2(a,b) a ## b - #define LZO_PP_CONCAT3(a,b,c) a ## b ## c - #define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d - #define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e -+#define LZO_PP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f -+#define LZO_PP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g -+#define LZO_PP_ECONCAT0() LZO_PP_CONCAT0() -+#define LZO_PP_ECONCAT1(a) LZO_PP_CONCAT1(a) - #define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b) - #define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c) - #define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d) - #define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e) -+#define LZO_PP_ECONCAT6(a,b,c,d,e,f) LZO_PP_CONCAT6(a,b,c,d,e,f) -+#define LZO_PP_ECONCAT7(a,b,c,d,e,f,g) LZO_PP_CONCAT7(a,b,c,d,e,f,g) -+#define LZO_PP_EMPTY /*empty*/ -+#define LZO_PP_EMPTY0() /*empty*/ -+#define LZO_PP_EMPTY1(a) /*empty*/ -+#define LZO_PP_EMPTY2(a,b) /*empty*/ -+#define LZO_PP_EMPTY3(a,b,c) /*empty*/ -+#define LZO_PP_EMPTY4(a,b,c,d) /*empty*/ -+#define LZO_PP_EMPTY5(a,b,c,d,e) /*empty*/ -+#define LZO_PP_EMPTY6(a,b,c,d,e,f) /*empty*/ -+#define LZO_PP_EMPTY7(a,b,c,d,e,f,g) /*empty*/ - #if 1 - #define LZO_CPP_STRINGIZE(x) #x - #define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x) -@@ -248,12 +278,16 @@ - #define LZO_CPP_CONCAT3(a,b,c) a ## b ## c - #define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d - #define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e -+#define LZO_CPP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f -+#define LZO_CPP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g - #define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b) - #define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c) - #define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d) - #define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e) -+#define LZO_CPP_ECONCAT6(a,b,c,d,e,f) LZO_CPP_CONCAT6(a,b,c,d,e,f) -+#define LZO_CPP_ECONCAT7(a,b,c,d,e,f,g) LZO_CPP_CONCAT7(a,b,c,d,e,f,g) - #endif --#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o)) -+#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-!!(b))) - (o)) << 1) + (o)*!!(b)) - #if 1 && defined(__cplusplus) - # if !defined(__STDC_CONSTANT_MACROS) - # define __STDC_CONSTANT_MACROS 1 -@@ -263,9 +297,13 @@ - # endif - #endif - #if defined(__cplusplus) --# define LZO_EXTERN_C extern "C" -+# define LZO_EXTERN_C extern "C" -+# define LZO_EXTERN_C_BEGIN extern "C" { -+# define LZO_EXTERN_C_END } - #else --# define LZO_EXTERN_C extern -+# define LZO_EXTERN_C extern -+# define LZO_EXTERN_C_BEGIN /*empty*/ -+# define LZO_EXTERN_C_END /*empty*/ - #endif - #if !defined(__LZO_OS_OVERRIDE) - #if (LZO_OS_FREESTANDING) -@@ -366,12 +404,12 @@ - #elif defined(__VMS) - # define LZO_OS_VMS 1 - # define LZO_INFO_OS "vms" --#elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) -+#elif (defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__) - # define LZO_OS_CONSOLE 1 - # define LZO_OS_CONSOLE_PS2 1 - # define LZO_INFO_OS "console" - # define LZO_INFO_OS_CONSOLE "ps2" --#elif (defined(__mips__) && defined(__psp__)) -+#elif defined(__mips__) && defined(__psp__) - # define LZO_OS_CONSOLE 1 - # define LZO_OS_CONSOLE_PSP 1 - # define LZO_INFO_OS "console" -@@ -399,9 +437,18 @@ - # elif defined(__linux__) || defined(__linux) || defined(__LINUX__) - # define LZO_OS_POSIX_LINUX 1 - # define LZO_INFO_OS_POSIX "linux" --# elif defined(__APPLE__) || defined(__MACOS__) --# define LZO_OS_POSIX_MACOSX 1 --# define LZO_INFO_OS_POSIX "macosx" -+# elif defined(__APPLE__) && defined(__MACH__) -+# if ((__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__-0) >= 20000) -+# define LZO_OS_POSIX_DARWIN 1040 -+# define LZO_INFO_OS_POSIX "darwin_iphone" -+# elif ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0) >= 1040) -+# define LZO_OS_POSIX_DARWIN __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ -+# define LZO_INFO_OS_POSIX "darwin" -+# else -+# define LZO_OS_POSIX_DARWIN 1 -+# define LZO_INFO_OS_POSIX "darwin" -+# endif -+# define LZO_OS_POSIX_MACOSX LZO_OS_POSIX_DARWIN - # elif defined(__minix__) || defined(__minix) - # define LZO_OS_POSIX_MINIX 1 - # define LZO_INFO_OS_POSIX "minix" -@@ -436,18 +483,18 @@ - #endif - #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) - # if (UINT_MAX != LZO_0xffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - # if (ULONG_MAX != LZO_0xffffffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - #endif - #if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64) - # if (UINT_MAX != LZO_0xffffffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - # if (ULONG_MAX != LZO_0xffffffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - #endif - #if defined(CIL) && defined(_GNUCC) && defined(__GNUC__) -@@ -463,59 +510,65 @@ - # define LZO_INFO_CC "sdcc" - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC) - #elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__) --# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__) -+# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + (__PATHCC_MINOR__-0) * 0x100 + (__PATHCC_PATCHLEVEL__-0)) - # define LZO_INFO_CC "Pathscale C" - # define LZO_INFO_CCVER __PATHSCALE__ --#elif defined(__INTEL_COMPILER) --# define LZO_CC_INTELC 1 -+# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -+# define LZO_CC_PATHSCALE_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) -+# endif -+#elif defined(__INTEL_COMPILER) && ((__INTEL_COMPILER-0) > 0) -+# define LZO_CC_INTELC __INTEL_COMPILER - # define LZO_INFO_CC "Intel C" - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER) --# if defined(_WIN32) || defined(_WIN64) --# define LZO_CC_SYNTAX_MSC 1 --# else --# define LZO_CC_SYNTAX_GNUC 1 -+# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) -+# define LZO_CC_INTELC_MSC _MSC_VER -+# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -+# define LZO_CC_INTELC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) - # endif - #elif defined(__POCC__) && defined(_WIN32) - # define LZO_CC_PELLESC 1 - # define LZO_INFO_CC "Pelles C" - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__) --#elif defined(__clang__) && defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -+#elif defined(__ARMCC_VERSION) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) - # if defined(__GNUC_PATCHLEVEL__) --# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) -+# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) - # else --# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) -+# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) - # endif -+# define LZO_CC_ARMCC __ARMCC_VERSION -+# define LZO_INFO_CC "ARM C Compiler" -+# define LZO_INFO_CCVER __VERSION__ -+#elif defined(__clang__) && defined(__llvm__) && defined(__VERSION__) - # if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) --# define LZO_CC_CLANG_CLANG (__clang_major__ * 0x10000L + __clang_minor__ * 0x100 + __clang_patchlevel__) -+# define LZO_CC_CLANG (__clang_major__ * 0x10000L + (__clang_minor__-0) * 0x100 + (__clang_patchlevel__-0)) - # else --# define LZO_CC_CLANG_CLANG 0x010000L -+# define LZO_CC_CLANG 0x010000L -+# endif -+# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) -+# define LZO_CC_CLANG_MSC _MSC_VER -+# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -+# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) - # endif --# define LZO_CC_CLANG LZO_CC_CLANG_GNUC - # define LZO_INFO_CC "clang" - # define LZO_INFO_CCVER __VERSION__ - #elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) - # if defined(__GNUC_PATCHLEVEL__) --# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) -+# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) - # else --# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) -+# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) - # endif - # define LZO_CC_LLVM LZO_CC_LLVM_GNUC - # define LZO_INFO_CC "llvm-gcc" - # define LZO_INFO_CCVER __VERSION__ --#elif defined(__GNUC__) && defined(__VERSION__) --# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) --# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) --# elif defined(__GNUC_MINOR__) --# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) --# else --# define LZO_CC_GNUC (__GNUC__ * 0x10000L) --# endif --# define LZO_INFO_CC "gcc" --# define LZO_INFO_CCVER __VERSION__ - #elif defined(__ACK__) && defined(_ACK) - # define LZO_CC_ACK 1 - # define LZO_INFO_CC "Amsterdam Compiler Kit C" - # define LZO_INFO_CCVER "unknown" -+#elif defined(__ARMCC_VERSION) && !defined(__GNUC__) -+# define LZO_CC_ARMCC __ARMCC_VERSION -+# define LZO_CC_ARMCC_ARMCC __ARMCC_VERSION -+# define LZO_INFO_CC "ARM C Compiler" -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ARMCC_VERSION) - #elif defined(__AZTEC_C__) - # define LZO_CC_AZTECC 1 - # define LZO_INFO_CC "Aztec C" -@@ -540,10 +593,23 @@ - # define LZO_CC_DECC 1 - # define LZO_INFO_CC "DEC C" - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC) -+#elif (defined(__ghs) || defined(__ghs__)) && defined(__GHS_VERSION_NUMBER) && ((__GHS_VERSION_NUMBER-0) > 0) -+# define LZO_CC_GHS 1 -+# define LZO_INFO_CC "Green Hills C" -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__GHS_VERSION_NUMBER) -+# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) -+# define LZO_CC_GHS_MSC _MSC_VER -+# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -+# define LZO_CC_GHS_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) -+# endif - #elif defined(__HIGHC__) - # define LZO_CC_HIGHC 1 - # define LZO_INFO_CC "MetaWare High C" - # define LZO_INFO_CCVER "unknown" -+#elif defined(__HP_aCC) && ((__HP_aCC-0) > 0) -+# define LZO_CC_HPACC __HP_aCC -+# define LZO_INFO_CC "HP aCC" -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__HP_aCC) - #elif defined(__IAR_SYSTEMS_ICC__) - # define LZO_CC_IARC 1 - # define LZO_INFO_CC "IAR C" -@@ -552,10 +618,14 @@ - # else - # define LZO_INFO_CCVER "unknown" - # endif --#elif defined(__IBMC__) --# define LZO_CC_IBMC 1 -+#elif defined(__IBMC__) && ((__IBMC__-0) > 0) -+# define LZO_CC_IBMC __IBMC__ - # define LZO_INFO_CC "IBM C" - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__) -+#elif defined(__IBMCPP__) && ((__IBMCPP__-0) > 0) -+# define LZO_CC_IBMC __IBMCPP__ -+# define LZO_INFO_CC "IBM C" -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMCPP__) - #elif defined(__KEIL__) && defined(__C166__) - # define LZO_CC_KEILC 1 - # define LZO_INFO_CC "Keil C" -@@ -572,16 +642,8 @@ - # else - # define LZO_INFO_CCVER "unknown" - # endif --#elif defined(_MSC_VER) --# define LZO_CC_MSC 1 --# define LZO_INFO_CC "Microsoft C" --# if defined(_MSC_FULL_VER) --# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) --# else --# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) --# endif --#elif defined(__MWERKS__) --# define LZO_CC_MWERKS 1 -+#elif defined(__MWERKS__) && ((__MWERKS__-0) > 0) -+# define LZO_CC_MWERKS __MWERKS__ - # define LZO_INFO_CC "Metrowerks C" - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__) - #elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386) -@@ -592,6 +654,15 @@ - # define LZO_CC_PACIFICC 1 - # define LZO_INFO_CC "Pacific C" - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__) -+#elif defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) -+# if defined(__PGIC_PATCHLEVEL__) -+# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100 + (__PGIC_PATCHLEVEL__-0)) -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) "." LZO_PP_MACRO_EXPAND(__PGIC_PATCHLEVEL__) -+# else -+# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100) -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) ".0" -+# endif -+# define LZO_INFO_CC "Portland Group PGI C" - #elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__)) - # define LZO_CC_PGI 1 - # define LZO_INFO_CC "Portland Group PGI C" -@@ -606,7 +677,7 @@ - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__) - #elif defined(__SUNPRO_C) - # define LZO_INFO_CC "SunPro C" --# if ((__SUNPRO_C)+0 > 0) -+# if ((__SUNPRO_C-0) > 0) - # define LZO_CC_SUNPROC __SUNPRO_C - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C) - # else -@@ -615,7 +686,7 @@ - # endif - #elif defined(__SUNPRO_CC) - # define LZO_INFO_CC "SunPro C" --# if ((__SUNPRO_CC)+0 > 0) -+# if ((__SUNPRO_CC-0) > 0) - # define LZO_CC_SUNPROC __SUNPRO_CC - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC) - # else -@@ -641,16 +712,46 @@ - #elif defined(__ZTC__) - # define LZO_CC_ZORTECHC 1 - # define LZO_INFO_CC "Zortech C" --# if (__ZTC__ == 0x310) -+# if ((__ZTC__-0) == 0x310) - # define LZO_INFO_CCVER "0x310" - # else - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__) - # endif -+#elif defined(__GNUC__) && defined(__VERSION__) -+# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) -+# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) -+# elif defined(__GNUC_MINOR__) -+# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) -+# else -+# define LZO_CC_GNUC (__GNUC__ * 0x10000L) -+# endif -+# define LZO_INFO_CC "gcc" -+# define LZO_INFO_CCVER __VERSION__ -+#elif defined(_MSC_VER) && ((_MSC_VER-0) > 0) -+# define LZO_CC_MSC _MSC_VER -+# define LZO_INFO_CC "Microsoft C" -+# if defined(_MSC_FULL_VER) -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) -+# else -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) -+# endif - #else - # define LZO_CC_UNKNOWN 1 - # define LZO_INFO_CC "unknown" - # define LZO_INFO_CCVER "unknown" - #endif -+#if (LZO_CC_GNUC) && defined(__OPEN64__) -+# if defined(__OPENCC__) && defined(__OPENCC_MINOR__) && defined(__OPENCC_PATCHLEVEL__) -+# define LZO_CC_OPEN64 (__OPENCC__ * 0x10000L + (__OPENCC_MINOR__-0) * 0x100 + (__OPENCC_PATCHLEVEL__-0)) -+# define LZO_CC_OPEN64_GNUC LZO_CC_GNUC -+# endif -+#endif -+#if (LZO_CC_GNUC) && defined(__PCC__) -+# if defined(__PCC__) && defined(__PCC_MINOR__) && defined(__PCC_MINORMINOR__) -+# define LZO_CC_PCC (__PCC__ * 0x10000L + (__PCC_MINOR__-0) * 0x100 + (__PCC_MINORMINOR__-0)) -+# define LZO_CC_PCC_GNUC LZO_CC_GNUC -+# endif -+#endif - #if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER) - # error "LZO_CC_MSC: _MSC_FULL_VER is not defined" - #endif -@@ -668,8 +769,10 @@ - # define LZO_INFO_ARCH "generic" - #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) - # define LZO_ARCH_I086 1 --# define LZO_ARCH_IA16 1 - # define LZO_INFO_ARCH "i086" -+#elif defined(__aarch64__) -+# define LZO_ARCH_ARM64 1 -+# define LZO_INFO_ARCH "arm64" - #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) - # define LZO_ARCH_ALPHA 1 - # define LZO_INFO_ARCH "alpha" -@@ -685,10 +788,10 @@ - # define LZO_INFO_ARCH "arm_thumb" - #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) - # define LZO_ARCH_ARM 1 --# if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1) -+# if defined(__CPU_MODE__) && ((__CPU_MODE__-0) == 1) - # define LZO_ARCH_ARM_THUMB 1 - # define LZO_INFO_ARCH "arm_thumb" --# elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2) -+# elif defined(__CPU_MODE__) && ((__CPU_MODE__-0) == 2) - # define LZO_INFO_ARCH "arm" - # else - # define LZO_INFO_ARCH "arm" -@@ -806,53 +909,147 @@ - # error "FIXME - missing define for CPU architecture" - #endif - #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32) --# error "FIXME - missing WIN32 define for CPU architecture" -+# error "FIXME - missing LZO_OS_WIN32 define for CPU architecture" - #endif - #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64) --# error "FIXME - missing WIN64 define for CPU architecture" -+# error "FIXME - missing LZO_OS_WIN64 define for CPU architecture" - #endif - #if (LZO_OS_OS216 || LZO_OS_WIN16) - # define LZO_ARCH_I086PM 1 --# define LZO_ARCH_IA16PM 1 - #elif 1 && (LZO_OS_DOS16 && defined(BLX286)) - # define LZO_ARCH_I086PM 1 --# define LZO_ARCH_IA16PM 1 - #elif 1 && (LZO_OS_DOS16 && defined(DOSX286)) - # define LZO_ARCH_I086PM 1 --# define LZO_ARCH_IA16PM 1 - #elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__)) - # define LZO_ARCH_I086PM 1 --# define LZO_ARCH_IA16PM 1 - #endif --#if (LZO_ARCH_ARM_THUMB) && !(LZO_ARCH_ARM) --# error "this should not happen" -+#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) -+# define LZO_ARCH_X64 1 -+#elif (!LZO_ARCH_AMD64 && LZO_ARCH_X64) && defined(__LZO_ARCH_OVERRIDE) -+# define LZO_ARCH_AMD64 1 -+#endif -+#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) -+# define LZO_ARCH_AARCH64 1 -+#elif (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) && defined(__LZO_ARCH_OVERRIDE) -+# define LZO_ARCH_ARM64 1 -+#endif -+#if (LZO_ARCH_I386 && !LZO_ARCH_X86) -+# define LZO_ARCH_X86 1 -+#elif (!LZO_ARCH_I386 && LZO_ARCH_X86) && defined(__LZO_ARCH_OVERRIDE) -+# define LZO_ARCH_I386 1 -+#endif -+#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) || (!LZO_ARCH_AMD64 && LZO_ARCH_X64) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) || (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ARCH_I386 && !LZO_ARCH_X86) || (!LZO_ARCH_I386 && LZO_ARCH_X86) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ARCH_ARM_THUMB && !LZO_ARCH_ARM) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ARCH_ARM_THUMB1 && !LZO_ARCH_ARM_THUMB) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ARCH_ARM_THUMB2 && !LZO_ARCH_ARM_THUMB) -+# error "unexpected configuration - check your compiler defines" - #endif --#if (LZO_ARCH_I086PM) && !(LZO_ARCH_I086) --# error "this should not happen" -+#if (LZO_ARCH_ARM_THUMB1 && LZO_ARCH_ARM_THUMB2) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ARCH_I086PM && !LZO_ARCH_I086) -+# error "unexpected configuration - check your compiler defines" - #endif - #if (LZO_ARCH_I086) - # if (UINT_MAX != LZO_0xffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - # if (ULONG_MAX != LZO_0xffffffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - #endif - #if (LZO_ARCH_I386) - # if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - # if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - # if (ULONG_MAX != LZO_0xffffffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" -+# endif -+#endif -+#if (LZO_ARCH_AMD64 || LZO_ARCH_I386) -+# if !defined(LZO_TARGET_FEATURE_SSE2) -+# if defined(__SSE2__) -+# define LZO_TARGET_FEATURE_SSE2 1 -+# elif defined(_MSC_VER) && ((defined(_M_IX86_FP) && ((_M_IX86_FP)+0 >= 2)) || defined(_M_AMD64)) -+# define LZO_TARGET_FEATURE_SSE2 1 -+# endif -+# endif -+# if !defined(LZO_TARGET_FEATURE_SSSE3) -+# if (LZO_TARGET_FEATURE_SSE2) -+# if defined(__SSSE3__) -+# define LZO_TARGET_FEATURE_SSSE3 1 -+# elif defined(_MSC_VER) && defined(__AVX__) -+# define LZO_TARGET_FEATURE_SSSE3 1 -+# endif -+# endif -+# endif -+# if !defined(LZO_TARGET_FEATURE_SSE4_2) -+# if (LZO_TARGET_FEATURE_SSSE3) -+# if defined(__SSE4_2__) -+# define LZO_TARGET_FEATURE_SSE4_2 1 -+# endif -+# endif -+# endif -+# if !defined(LZO_TARGET_FEATURE_AVX) -+# if (LZO_TARGET_FEATURE_SSSE3) -+# if defined(__AVX__) -+# define LZO_TARGET_FEATURE_AVX 1 -+# endif -+# endif -+# endif -+# if !defined(LZO_TARGET_FEATURE_AVX2) -+# if (LZO_TARGET_FEATURE_AVX) -+# if defined(__AVX2__) -+# define LZO_TARGET_FEATURE_AVX2 1 -+# endif -+# endif -+# endif -+#endif -+#if (LZO_TARGET_FEATURE_SSSE3 && !(LZO_TARGET_FEATURE_SSE2)) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_TARGET_FEATURE_SSE4_2 && !(LZO_TARGET_FEATURE_SSSE3)) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_TARGET_FEATURE_AVX && !(LZO_TARGET_FEATURE_SSSE3)) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_TARGET_FEATURE_AVX2 && !(LZO_TARGET_FEATURE_AVX)) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ARCH_ARM) -+# if !defined(LZO_TARGET_FEATURE_NEON) -+# if defined(__ARM_NEON__) -+# define LZO_TARGET_FEATURE_NEON 1 -+# endif -+# endif -+#elif (LZO_ARCH_ARM64) -+# if !defined(LZO_TARGET_FEATURE_NEON) -+# if 1 -+# define LZO_TARGET_FEATURE_NEON 1 -+# endif - # endif - #endif --#if !defined(__LZO_MM_OVERRIDE) -+#if 0 -+#elif !defined(__LZO_MM_OVERRIDE) - #if (LZO_ARCH_I086) - #if (UINT_MAX != LZO_0xffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - #endif - #if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) - # define LZO_MM_TINY 1 -@@ -879,7 +1076,7 @@ - #elif (LZO_CC_ZORTECHC && defined(__VCM__)) - # define LZO_MM_LARGE 1 - #else --# error "unknown memory model" -+# error "unknown LZO_ARCH_I086 memory model" - #endif - #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) - #define LZO_HAVE_MM_HUGE_PTR 1 -@@ -902,10 +1099,10 @@ - #endif - #if (LZO_ARCH_I086PM) && !(LZO_HAVE_MM_HUGE_PTR) - # if (LZO_OS_DOS16) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # elif (LZO_CC_ZORTECHC) - # else --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - #endif - #ifdef __cplusplus -@@ -937,7 +1134,7 @@ extern "C" { - #endif - #elif (LZO_ARCH_C166) - #if !defined(__MODEL__) --# error "FIXME - C166 __MODEL__" -+# error "FIXME - LZO_ARCH_C166 __MODEL__" - #elif ((__MODEL__) == 0) - # define LZO_MM_SMALL 1 - #elif ((__MODEL__) == 1) -@@ -951,11 +1148,11 @@ extern "C" { - #elif ((__MODEL__) == 5) - # define LZO_MM_XSMALL 1 - #else --# error "FIXME - C166 __MODEL__" -+# error "FIXME - LZO_ARCH_C166 __MODEL__" - #endif - #elif (LZO_ARCH_MCS251) - #if !defined(__MODEL__) --# error "FIXME - MCS251 __MODEL__" -+# error "FIXME - LZO_ARCH_MCS251 __MODEL__" - #elif ((__MODEL__) == 0) - # define LZO_MM_SMALL 1 - #elif ((__MODEL__) == 2) -@@ -967,11 +1164,11 @@ extern "C" { - #elif ((__MODEL__) == 5) - # define LZO_MM_XSMALL 1 - #else --# error "FIXME - MCS251 __MODEL__" -+# error "FIXME - LZO_ARCH_MCS251 __MODEL__" - #endif - #elif (LZO_ARCH_MCS51) - #if !defined(__MODEL__) --# error "FIXME - MCS51 __MODEL__" -+# error "FIXME - LZO_ARCH_MCS51 __MODEL__" - #elif ((__MODEL__) == 1) - # define LZO_MM_SMALL 1 - #elif ((__MODEL__) == 2) -@@ -983,7 +1180,7 @@ extern "C" { - #elif ((__MODEL__) == 5) - # define LZO_MM_XSMALL 1 - #else --# error "FIXME - MCS51 __MODEL__" -+# error "FIXME - LZO_ARCH_MCS51 __MODEL__" - #endif - #elif (LZO_ARCH_CRAY_PVP) - # define LZO_MM_PVP 1 -@@ -1010,462 +1207,270 @@ extern "C" { - # error "unknown memory model" - #endif - #endif --#if defined(SIZEOF_SHORT) --# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) -+#if !defined(__lzo_gnuc_extension__) -+#if (LZO_CC_GNUC >= 0x020800ul) -+# define __lzo_gnuc_extension__ __extension__ -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define __lzo_gnuc_extension__ __extension__ -+#elif (LZO_CC_IBMC >= 600) -+# define __lzo_gnuc_extension__ __extension__ -+#else - #endif --#if defined(SIZEOF_INT) --# define LZO_SIZEOF_INT (SIZEOF_INT) - #endif --#if defined(SIZEOF_LONG) --# define LZO_SIZEOF_LONG (SIZEOF_LONG) -+#if !defined(__lzo_gnuc_extension__) -+# define __lzo_gnuc_extension__ /*empty*/ - #endif --#if defined(SIZEOF_LONG_LONG) --# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) -+#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) && defined(__cplusplus) && 0 -+# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) -+# define LZO_CFG_USE_NEW_STYLE_CASTS 0 -+# elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1200)) -+# define LZO_CFG_USE_NEW_STYLE_CASTS 0 -+# else -+# define LZO_CFG_USE_NEW_STYLE_CASTS 1 -+# endif - #endif --#if defined(SIZEOF___INT16) --# define LZO_SIZEOF___INT16 (SIZEOF___INT16) -+#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) -+# define LZO_CFG_USE_NEW_STYLE_CASTS 0 - #endif --#if defined(SIZEOF___INT32) --# define LZO_SIZEOF___INT32 (SIZEOF___INT32) -+#if !defined(__cplusplus) -+# if defined(LZO_CFG_USE_NEW_STYLE_CASTS) -+# undef LZO_CFG_USE_NEW_STYLE_CASTS -+# endif -+# define LZO_CFG_USE_NEW_STYLE_CASTS 0 - #endif --#if defined(SIZEOF___INT64) --# define LZO_SIZEOF___INT64 (SIZEOF___INT64) -+#if !defined(LZO_REINTERPRET_CAST) -+# if (LZO_CFG_USE_NEW_STYLE_CASTS) -+# define LZO_REINTERPRET_CAST(t,e) (reinterpret_cast (e)) -+# endif - #endif --#if defined(SIZEOF_VOID_P) --# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) -+#if !defined(LZO_REINTERPRET_CAST) -+# define LZO_REINTERPRET_CAST(t,e) ((t) (e)) - #endif --#if defined(SIZEOF_SIZE_T) --# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) -+#if !defined(LZO_STATIC_CAST) -+# if (LZO_CFG_USE_NEW_STYLE_CASTS) -+# define LZO_STATIC_CAST(t,e) (static_cast (e)) -+# endif - #endif --#if defined(SIZEOF_PTRDIFF_T) --# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) -+#if !defined(LZO_STATIC_CAST) -+# define LZO_STATIC_CAST(t,e) ((t) (e)) - #endif --#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) --#if !defined(LZO_SIZEOF_SHORT) --# if (LZO_ARCH_CRAY_PVP) --# define LZO_SIZEOF_SHORT 8 --# elif (USHRT_MAX == LZO_0xffffL) --# define LZO_SIZEOF_SHORT 2 --# elif (__LZO_LSR(USHRT_MAX,7) == 1) --# define LZO_SIZEOF_SHORT 1 --# elif (__LZO_LSR(USHRT_MAX,15) == 1) --# define LZO_SIZEOF_SHORT 2 --# elif (__LZO_LSR(USHRT_MAX,31) == 1) --# define LZO_SIZEOF_SHORT 4 --# elif (__LZO_LSR(USHRT_MAX,63) == 1) --# define LZO_SIZEOF_SHORT 8 --# elif (__LZO_LSR(USHRT_MAX,127) == 1) --# define LZO_SIZEOF_SHORT 16 --# else --# error "LZO_SIZEOF_SHORT" --# endif -+#if !defined(LZO_STATIC_CAST2) -+# define LZO_STATIC_CAST2(t1,t2,e) LZO_STATIC_CAST(t1, LZO_STATIC_CAST(t2, e)) - #endif --#if !defined(LZO_SIZEOF_INT) --# if (LZO_ARCH_CRAY_PVP) --# define LZO_SIZEOF_INT 8 --# elif (UINT_MAX == LZO_0xffffL) --# define LZO_SIZEOF_INT 2 --# elif (UINT_MAX == LZO_0xffffffffL) --# define LZO_SIZEOF_INT 4 --# elif (__LZO_LSR(UINT_MAX,7) == 1) --# define LZO_SIZEOF_INT 1 --# elif (__LZO_LSR(UINT_MAX,15) == 1) --# define LZO_SIZEOF_INT 2 --# elif (__LZO_LSR(UINT_MAX,31) == 1) --# define LZO_SIZEOF_INT 4 --# elif (__LZO_LSR(UINT_MAX,63) == 1) --# define LZO_SIZEOF_INT 8 --# elif (__LZO_LSR(UINT_MAX,127) == 1) --# define LZO_SIZEOF_INT 16 --# else --# error "LZO_SIZEOF_INT" -+#if !defined(LZO_UNCONST_CAST) -+# if (LZO_CFG_USE_NEW_STYLE_CASTS) -+# define LZO_UNCONST_CAST(t,e) (const_cast (e)) -+# elif (LZO_HAVE_MM_HUGE_PTR) -+# define LZO_UNCONST_CAST(t,e) ((t) (e)) -+# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((const void *) (e))))) - # endif - #endif --#if !defined(LZO_SIZEOF_LONG) --# if (ULONG_MAX == LZO_0xffffffffL) --# define LZO_SIZEOF_LONG 4 --# elif (__LZO_LSR(ULONG_MAX,7) == 1) --# define LZO_SIZEOF_LONG 1 --# elif (__LZO_LSR(ULONG_MAX,15) == 1) --# define LZO_SIZEOF_LONG 2 --# elif (__LZO_LSR(ULONG_MAX,31) == 1) --# define LZO_SIZEOF_LONG 4 --# elif (__LZO_LSR(ULONG_MAX,63) == 1) --# define LZO_SIZEOF_LONG 8 --# elif (__LZO_LSR(ULONG_MAX,127) == 1) --# define LZO_SIZEOF_LONG 16 --# else --# error "LZO_SIZEOF_LONG" -+#if !defined(LZO_UNCONST_CAST) -+# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((const void *) (e)))) -+#endif -+#if !defined(LZO_UNCONST_VOLATILE_CAST) -+# if (LZO_CFG_USE_NEW_STYLE_CASTS) -+# define LZO_UNCONST_VOLATILE_CAST(t,e) (const_cast (e)) -+# elif (LZO_HAVE_MM_HUGE_PTR) -+# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) (e)) -+# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) - # endif - #endif --#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) --#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) --# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) --# if (LZO_CC_GNUC >= 0x030300ul) --# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) --# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG --# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) --# define LZO_SIZEOF_LONG_LONG 4 --# endif --# endif -+#if !defined(LZO_UNCONST_VOLATILE_CAST) -+# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((volatile const void *) (e)))) -+#endif -+#if !defined(LZO_UNVOLATILE_CAST) -+# if (LZO_CFG_USE_NEW_STYLE_CASTS) -+# define LZO_UNVOLATILE_CAST(t,e) (const_cast (e)) -+# elif (LZO_HAVE_MM_HUGE_PTR) -+# define LZO_UNVOLATILE_CAST(t,e) ((t) (e)) -+# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((volatile void *) (e))))) - # endif - #endif -+#if !defined(LZO_UNVOLATILE_CAST) -+# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((volatile void *) (e)))) - #endif --#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) --#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) --#if (LZO_ARCH_I086 && LZO_CC_DMC) --#elif (LZO_CC_CILLY) && defined(__GNUC__) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define LZO_SIZEOF_LONG_LONG 8 --#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (LZO_OS_WIN64 || defined(_WIN64)) --# define LZO_SIZEOF___INT64 8 --#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) --# define LZO_SIZEOF___INT64 8 --#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) --# define LZO_SIZEOF___INT64 8 --#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) --# define LZO_SIZEOF___INT64 8 --#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) --# define LZO_SIZEOF___INT64 8 --#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64)) --# define LZO_SIZEOF___INT64 8 --#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) --#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) --# define LZO_SIZEOF_LONG_LONG 8 -+#if !defined(LZO_UNVOLATILE_CONST_CAST) -+# if (LZO_CFG_USE_NEW_STYLE_CASTS) -+# define LZO_UNVOLATILE_CONST_CAST(t,e) (const_cast (e)) -+# elif (LZO_HAVE_MM_HUGE_PTR) -+# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) (e)) -+# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) -+# endif - #endif -+#if !defined(LZO_UNVOLATILE_CONST_CAST) -+# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((volatile const void *) (e)))) - #endif -+#if !defined(LZO_PCAST) -+# if (LZO_HAVE_MM_HUGE_PTR) -+# define LZO_PCAST(t,e) ((t) (e)) -+# endif - #endif --#if defined(__cplusplus) && (LZO_CC_GNUC) --# if (LZO_CC_GNUC < 0x020800ul) --# undef LZO_SIZEOF_LONG_LONG -+#if !defined(LZO_PCAST) -+# define LZO_PCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(void *, e)) -+#endif -+#if !defined(LZO_CCAST) -+# if (LZO_HAVE_MM_HUGE_PTR) -+# define LZO_CCAST(t,e) ((t) (e)) - # endif - #endif --#if (LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG) --# undef LZO_SIZEOF_LONG_LONG -+#if !defined(LZO_CCAST) -+# define LZO_CCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(const void *, e)) - #endif --#if !defined(LZO_SIZEOF_VOID_P) --#if (LZO_ARCH_I086) --# define __LZO_WORDSIZE 2 --# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) --# define LZO_SIZEOF_VOID_P 2 --# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) --# define LZO_SIZEOF_VOID_P 4 --# else --# error "LZO_MM" -+#if !defined(LZO_ICONV) -+# define LZO_ICONV(t,e) LZO_STATIC_CAST(t, e) -+#endif -+#if !defined(LZO_ICAST) -+# define LZO_ICAST(t,e) LZO_STATIC_CAST(t, e) -+#endif -+#if !defined(LZO_ITRUNC) -+# define LZO_ITRUNC(t,e) LZO_STATIC_CAST(t, e) -+#endif -+#if !defined(__lzo_cte) -+# if (LZO_CC_MSC || LZO_CC_WATCOMC) -+# define __lzo_cte(e) ((void)0,(e)) -+# elif 1 -+# define __lzo_cte(e) ((void)0,(e)) - # endif --#elif (LZO_ARCH_AVR || LZO_ARCH_Z80) --# define __LZO_WORDSIZE 1 --# define LZO_SIZEOF_VOID_P 2 --#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) --# define LZO_SIZEOF_VOID_P 2 --#elif (LZO_ARCH_H8300) --# if defined(__NORMAL_MODE__) --# define __LZO_WORDSIZE 4 --# define LZO_SIZEOF_VOID_P 2 --# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) --# define __LZO_WORDSIZE 4 --# define LZO_SIZEOF_VOID_P 4 --# else --# define __LZO_WORDSIZE 2 --# define LZO_SIZEOF_VOID_P 2 --# endif --# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) --# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT --# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT --# endif --#elif (LZO_ARCH_M16C) --# define __LZO_WORDSIZE 2 --# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) --# define LZO_SIZEOF_VOID_P 4 --# else --# define LZO_SIZEOF_VOID_P 2 --# endif --#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) --# define __LZO_WORDSIZE 8 --# define LZO_SIZEOF_VOID_P 4 --#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) --# define __LZO_WORDSIZE 8 --# define LZO_SIZEOF_VOID_P 8 --#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) --# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG --# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG --# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG --#elif (LZO_OS_OS400 || defined(__OS400__)) --# define __LZO_WORDSIZE LZO_SIZEOF_LONG --# define LZO_SIZEOF_VOID_P 16 --# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG --# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG --#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) --# define LZO_SIZEOF_VOID_P 8 --# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG --# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG --#elif (LZO_ARCH_SPU) --# if 0 --# define __LZO_WORDSIZE 16 --# endif --# define LZO_SIZEOF_VOID_P 4 --#else --# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG - #endif -+#if !defined(__lzo_cte) -+# define __lzo_cte(e) (e) - #endif --#if !defined(LZO_WORDSIZE) --# if defined(__LZO_WORDSIZE) --# define LZO_WORDSIZE __LZO_WORDSIZE -+#if !defined(LZO_BLOCK_BEGIN) -+# define LZO_BLOCK_BEGIN do { -+# define LZO_BLOCK_END } while __lzo_cte(0) -+#endif -+#if !defined(LZO_UNUSED) -+# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) -+# define LZO_UNUSED(var) ((void) &var) -+# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) -+# define LZO_UNUSED(var) if (&var) ; else -+# elif (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x030200ul)) -+# define LZO_UNUSED(var) ((void) &var) -+# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define LZO_UNUSED(var) ((void) var) -+# elif (LZO_CC_MSC && (_MSC_VER < 900)) -+# define LZO_UNUSED(var) if (&var) ; else -+# elif (LZO_CC_KEILC) -+# define LZO_UNUSED(var) {LZO_EXTERN_C int lzo_unused__[1-2*!(sizeof(var)>0)];} -+# elif (LZO_CC_PACIFICC) -+# define LZO_UNUSED(var) ((void) sizeof(var)) -+# elif (LZO_CC_WATCOMC) && defined(__cplusplus) -+# define LZO_UNUSED(var) ((void) var) - # else --# define LZO_WORDSIZE LZO_SIZEOF_VOID_P -+# define LZO_UNUSED(var) ((void) &var) - # endif - #endif --#if !defined(LZO_SIZEOF_SIZE_T) --#if (LZO_ARCH_I086 || LZO_ARCH_M16C) --# define LZO_SIZEOF_SIZE_T 2 --#else --# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P --#endif --#endif --#if !defined(LZO_SIZEOF_PTRDIFF_T) --#if (LZO_ARCH_I086) --# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) --# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P --# elif (LZO_MM_COMPACT || LZO_MM_LARGE) --# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) --# define LZO_SIZEOF_PTRDIFF_T 4 --# else --# define LZO_SIZEOF_PTRDIFF_T 2 --# endif -+#if !defined(LZO_UNUSED_FUNC) -+# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) -+# define LZO_UNUSED_FUNC(func) ((void) func) -+# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) -+# define LZO_UNUSED_FUNC(func) if (func) ; else -+# elif (LZO_CC_CLANG || LZO_CC_LLVM) -+# define LZO_UNUSED_FUNC(func) ((void) &func) -+# elif (LZO_CC_MSC && (_MSC_VER < 900)) -+# define LZO_UNUSED_FUNC(func) if (func) ; else -+# elif (LZO_CC_MSC) -+# define LZO_UNUSED_FUNC(func) ((void) &func) -+# elif (LZO_CC_KEILC || LZO_CC_PELLESC) -+# define LZO_UNUSED_FUNC(func) {LZO_EXTERN_C int lzo_unused_func__[1-2*!(sizeof((int)func)>0)];} - # else --# error "LZO_MM" -+# define LZO_UNUSED_FUNC(func) ((void) func) - # endif --#else --# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T --#endif - #endif --#if (LZO_ABI_NEUTRAL_ENDIAN) --# undef LZO_ABI_BIG_ENDIAN --# undef LZO_ABI_LITTLE_ENDIAN --#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) --#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) --# define LZO_ABI_BIG_ENDIAN 1 --#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) --# define LZO_ABI_LITTLE_ENDIAN 1 --#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) --# define LZO_ABI_LITTLE_ENDIAN 1 --#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390) --# define LZO_ABI_BIG_ENDIAN 1 --#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) --# if (__LITTLE_ENDIAN__ == 1) --# define LZO_ABI_LITTLE_ENDIAN 1 -+#if !defined(LZO_UNUSED_LABEL) -+# if (LZO_CC_CLANG >= 0x020800ul) -+# define LZO_UNUSED_LABEL(l) (__lzo_gnuc_extension__ ((void) ((const void *) &&l))) -+# elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) -+# define LZO_UNUSED_LABEL(l) if __lzo_cte(0) goto l - # else --# define LZO_ABI_BIG_ENDIAN 1 -+# define LZO_UNUSED_LABEL(l) switch (0) case 1:goto l - # endif --#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) --# define LZO_ABI_BIG_ENDIAN 1 --#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) --# define LZO_ABI_LITTLE_ENDIAN 1 --#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) --# define LZO_ABI_BIG_ENDIAN 1 --#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) --# define LZO_ABI_LITTLE_ENDIAN 1 --#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) --# define LZO_ABI_BIG_ENDIAN 1 --#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) --# define LZO_ABI_LITTLE_ENDIAN 1 --#endif --#endif --#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) --# error "this should not happen" --#endif --#if (LZO_ABI_BIG_ENDIAN) --# define LZO_INFO_ABI_ENDIAN "be" --#elif (LZO_ABI_LITTLE_ENDIAN) --# define LZO_INFO_ABI_ENDIAN "le" --#elif (LZO_ABI_NEUTRAL_ENDIAN) --# define LZO_INFO_ABI_ENDIAN "neutral" --#endif --#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) --# define LZO_ABI_I8LP16 1 --# define LZO_INFO_ABI_PM "i8lp16" --#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) --# define LZO_ABI_ILP16 1 --# define LZO_INFO_ABI_PM "ilp16" --#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) --# define LZO_ABI_ILP32 1 --# define LZO_INFO_ABI_PM "ilp32" --#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) --# define LZO_ABI_LLP64 1 --# define LZO_INFO_ABI_PM "llp64" --#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) --# define LZO_ABI_LP64 1 --# define LZO_INFO_ABI_PM "lp64" --#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) --# define LZO_ABI_ILP64 1 --# define LZO_INFO_ABI_PM "ilp64" --#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) --# define LZO_ABI_IP32L64 1 --# define LZO_INFO_ABI_PM "ip32l64" - #endif --#if !defined(__LZO_LIBC_OVERRIDE) --#if (LZO_LIBC_NAKED) --# define LZO_INFO_LIBC "naked" --#elif (LZO_LIBC_FREESTANDING) --# define LZO_INFO_LIBC "freestanding" --#elif (LZO_LIBC_MOSTLY_FREESTANDING) --# define LZO_INFO_LIBC "mfreestanding" --#elif (LZO_LIBC_ISOC90) --# define LZO_INFO_LIBC "isoc90" --#elif (LZO_LIBC_ISOC99) --# define LZO_INFO_LIBC "isoc99" --#elif defined(__dietlibc__) --# define LZO_LIBC_DIETLIBC 1 --# define LZO_INFO_LIBC "dietlibc" --#elif defined(_NEWLIB_VERSION) --# define LZO_LIBC_NEWLIB 1 --# define LZO_INFO_LIBC "newlib" --#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) --# if defined(__UCLIBC_SUBLEVEL__) --# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__) -+#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) -+# if 0 -+# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var -+# elif 0 && (LZO_CC_GNUC) -+# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var - # else --# define LZO_LIBC_UCLIBC 0x00090bL -+# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init - # endif --# define LZO_INFO_LIBC "uclibc" --#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) --# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100) --# define LZO_INFO_LIBC "glibc" --#elif (LZO_CC_MWERKS) && defined(__MSL__) --# define LZO_LIBC_MSL __MSL__ --# define LZO_INFO_LIBC "msl" --#elif 1 && defined(__IAR_SYSTEMS_ICC__) --# define LZO_LIBC_ISOC90 1 --# define LZO_INFO_LIBC "isoc90" --#else --# define LZO_LIBC_DEFAULT 1 --# define LZO_INFO_LIBC "default" --#endif --#endif --#if !defined(__lzo_gnuc_extension__) --#if (LZO_CC_GNUC >= 0x020800ul) --# define __lzo_gnuc_extension__ __extension__ --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define __lzo_gnuc_extension__ __extension__ --#else --# define __lzo_gnuc_extension__ /*empty*/ --#endif --#endif --#if !defined(__lzo_ua_volatile) --# define __lzo_ua_volatile volatile --#endif --#if !defined(__lzo_alignof) --#if (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) --# define __lzo_alignof(e) __alignof__(e) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) --# define __lzo_alignof(e) __alignof__(e) --#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) --# define __lzo_alignof(e) __alignof(e) --#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) --# define __lzo_alignof(e) __alignof__(e) --#endif --#endif --#if defined(__lzo_alignof) --# define __lzo_HAVE_alignof 1 --#endif --#if !defined(__lzo_constructor) --#if (LZO_CC_GNUC >= 0x030400ul) --# define __lzo_constructor __attribute__((__constructor__,__used__)) --#elif (LZO_CC_GNUC >= 0x020700ul) --# define __lzo_constructor __attribute__((__constructor__)) --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define __lzo_constructor __attribute__((__constructor__)) --#endif --#endif --#if defined(__lzo_constructor) --# define __lzo_HAVE_constructor 1 --#endif --#if !defined(__lzo_destructor) --#if (LZO_CC_GNUC >= 0x030400ul) --# define __lzo_destructor __attribute__((__destructor__,__used__)) --#elif (LZO_CC_GNUC >= 0x020700ul) --# define __lzo_destructor __attribute__((__destructor__)) --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define __lzo_destructor __attribute__((__destructor__)) --#endif --#endif --#if defined(__lzo_destructor) --# define __lzo_HAVE_destructor 1 --#endif --#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) --# error "this should not happen" - #endif - #if !defined(__lzo_inline) - #if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) - #elif defined(__cplusplus) - # define __lzo_inline inline -+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) -+# define __lzo_inline inline - #elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) - # define __lzo_inline __inline --#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) - # define __lzo_inline __inline__ - #elif (LZO_CC_DMC) - # define __lzo_inline __inline -+#elif (LZO_CC_GHS) -+# define __lzo_inline __inline__ -+#elif (LZO_CC_IBMC >= 600) -+# define __lzo_inline __inline__ - #elif (LZO_CC_INTELC) - # define __lzo_inline __inline - #elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) - # define __lzo_inline __inline - #elif (LZO_CC_MSC && (_MSC_VER >= 900)) - # define __lzo_inline __inline --#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) -+#elif (LZO_CC_SUNPROC >= 0x5100) - # define __lzo_inline __inline__ --#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) --# define __lzo_inline inline - #endif - #endif - #if defined(__lzo_inline) -+# ifndef __lzo_HAVE_inline - # define __lzo_HAVE_inline 1 -+# endif - #else - # define __lzo_inline /*empty*/ - #endif - #if !defined(__lzo_forceinline) - #if (LZO_CC_GNUC >= 0x030200ul) - # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) -+#elif (LZO_CC_IBMC >= 700) -+# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -+#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) - # define __lzo_forceinline __forceinline --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) - # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) - # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) - #elif (LZO_CC_MSC && (_MSC_VER >= 1200)) - # define __lzo_forceinline __forceinline --#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) -+#elif (LZO_CC_PGI >= 0x0d0a00ul) -+# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -+#elif (LZO_CC_SUNPROC >= 0x5100) - # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) - #endif - #endif - #if defined(__lzo_forceinline) -+# ifndef __lzo_HAVE_forceinline - # define __lzo_HAVE_forceinline 1 -+# endif - #else --# define __lzo_forceinline /*empty*/ -+# define __lzo_forceinline __lzo_inline - #endif - #if !defined(__lzo_noinline) - #if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) - # define __lzo_noinline __attribute__((__noinline__,__used__)) - #elif (LZO_CC_GNUC >= 0x030200ul) - # define __lzo_noinline __attribute__((__noinline__)) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC) -+#elif (LZO_CC_IBMC >= 700) -+# define __lzo_noinline __attribute__((__noinline__)) -+#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) - # define __lzo_noinline __declspec(noinline) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) - # define __lzo_noinline __attribute__((__noinline__)) --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) - # define __lzo_noinline __attribute__((__noinline__)) - #elif (LZO_CC_MSC && (_MSC_VER >= 1300)) - # define __lzo_noinline __declspec(noinline) -@@ -1474,179 +1479,409 @@ extern "C" { - # else - # define __lzo_noinline __declspec(noinline) - # endif --#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) -+#elif (LZO_CC_PGI >= 0x0d0a00ul) -+# define __lzo_noinline __attribute__((__noinline__)) -+#elif (LZO_CC_SUNPROC >= 0x5100) - # define __lzo_noinline __attribute__((__noinline__)) - #endif - #endif - #if defined(__lzo_noinline) -+# ifndef __lzo_HAVE_noinline - # define __lzo_HAVE_noinline 1 -+# endif - #else - # define __lzo_noinline /*empty*/ - #endif - #if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - #endif --#if !defined(__lzo_noreturn) --#if (LZO_CC_GNUC >= 0x020700ul) --# define __lzo_noreturn __attribute__((__noreturn__)) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) --# define __lzo_noreturn __declspec(noreturn) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) --# define __lzo_noreturn __attribute__((__noreturn__)) --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define __lzo_noreturn __attribute__((__noreturn__)) --#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) --# define __lzo_noreturn __declspec(noreturn) -+#if !defined(__lzo_static_inline) -+#if (LZO_CC_IBMC) -+# define __lzo_static_inline __lzo_gnuc_extension__ static __lzo_inline - #endif - #endif --#if defined(__lzo_noreturn) --# define __lzo_HAVE_noreturn 1 --#else --# define __lzo_noreturn /*empty*/ -+#if !defined(__lzo_static_inline) -+# define __lzo_static_inline static __lzo_inline - #endif --#if !defined(__lzo_nothrow) --#if (LZO_CC_GNUC >= 0x030300ul) --# define __lzo_nothrow __attribute__((__nothrow__)) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus) --# define __lzo_nothrow __declspec(nothrow) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 900) && LZO_CC_SYNTAX_GNUC) --# define __lzo_nothrow __attribute__((__nothrow__)) --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define __lzo_nothrow __attribute__((__nothrow__)) --#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) -+#if !defined(__lzo_static_forceinline) -+#if (LZO_CC_IBMC) -+# define __lzo_static_forceinline __lzo_gnuc_extension__ static __lzo_forceinline -+#endif -+#endif -+#if !defined(__lzo_static_forceinline) -+# define __lzo_static_forceinline static __lzo_forceinline -+#endif -+#if !defined(__lzo_static_noinline) -+#if (LZO_CC_IBMC) -+# define __lzo_static_noinline __lzo_gnuc_extension__ static __lzo_noinline -+#endif -+#endif -+#if !defined(__lzo_static_noinline) -+# define __lzo_static_noinline static __lzo_noinline -+#endif -+#if !defined(__lzo_c99_extern_inline) -+#if defined(__GNUC_GNU_INLINE__) -+# define __lzo_c99_extern_inline __lzo_inline -+#elif defined(__GNUC_STDC_INLINE__) -+# define __lzo_c99_extern_inline extern __lzo_inline -+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) -+# define __lzo_c99_extern_inline extern __lzo_inline -+#endif -+#if !defined(__lzo_c99_extern_inline) && (__lzo_HAVE_inline) -+# define __lzo_c99_extern_inline __lzo_inline -+#endif -+#endif -+#if defined(__lzo_c99_extern_inline) -+# ifndef __lzo_HAVE_c99_extern_inline -+# define __lzo_HAVE_c99_extern_inline 1 -+# endif -+#else -+# define __lzo_c99_extern_inline /*empty*/ -+#endif -+#if !defined(__lzo_may_alias) -+#if (LZO_CC_GNUC >= 0x030400ul) -+# define __lzo_may_alias __attribute__((__may_alias__)) -+#elif (LZO_CC_CLANG >= 0x020900ul) -+# define __lzo_may_alias __attribute__((__may_alias__)) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1210)) && 0 -+# define __lzo_may_alias __attribute__((__may_alias__)) -+#elif (LZO_CC_PGI >= 0x0d0a00ul) && 0 -+# define __lzo_may_alias __attribute__((__may_alias__)) -+#endif -+#endif -+#if defined(__lzo_may_alias) -+# ifndef __lzo_HAVE_may_alias -+# define __lzo_HAVE_may_alias 1 -+# endif -+#else -+# define __lzo_may_alias /*empty*/ -+#endif -+#if !defined(__lzo_noreturn) -+#if (LZO_CC_GNUC >= 0x020700ul) -+# define __lzo_noreturn __attribute__((__noreturn__)) -+#elif (LZO_CC_IBMC >= 700) -+# define __lzo_noreturn __attribute__((__noreturn__)) -+#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) -+# define __lzo_noreturn __declspec(noreturn) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) -+# define __lzo_noreturn __attribute__((__noreturn__)) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define __lzo_noreturn __attribute__((__noreturn__)) -+#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) -+# define __lzo_noreturn __declspec(noreturn) -+#elif (LZO_CC_PGI >= 0x0d0a00ul) -+# define __lzo_noreturn __attribute__((__noreturn__)) -+#endif -+#endif -+#if defined(__lzo_noreturn) -+# ifndef __lzo_HAVE_noreturn -+# define __lzo_HAVE_noreturn 1 -+# endif -+#else -+# define __lzo_noreturn /*empty*/ -+#endif -+#if !defined(__lzo_nothrow) -+#if (LZO_CC_GNUC >= 0x030300ul) -+# define __lzo_nothrow __attribute__((__nothrow__)) -+#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) && defined(__cplusplus) -+# define __lzo_nothrow __declspec(nothrow) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 900)) -+# define __lzo_nothrow __attribute__((__nothrow__)) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define __lzo_nothrow __attribute__((__nothrow__)) -+#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) - # define __lzo_nothrow __declspec(nothrow) - #endif - #endif - #if defined(__lzo_nothrow) -+# ifndef __lzo_HAVE_nothrow - # define __lzo_HAVE_nothrow 1 -+# endif - #else - # define __lzo_nothrow /*empty*/ - #endif - #if !defined(__lzo_restrict) - #if (LZO_CC_GNUC >= 0x030400ul) - # define __lzo_restrict __restrict__ --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) -+#elif (LZO_CC_IBMC >= 800) && !defined(__cplusplus) - # define __lzo_restrict __restrict__ --#elif (LZO_CC_CLANG || LZO_CC_LLVM) -+#elif (LZO_CC_IBMC >= 1210) -+# define __lzo_restrict __restrict__ -+#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) -+# define __lzo_restrict __restrict__ -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM) - # define __lzo_restrict __restrict__ - #elif (LZO_CC_MSC && (_MSC_VER >= 1400)) - # define __lzo_restrict __restrict -+#elif (LZO_CC_PGI >= 0x0d0a00ul) -+# define __lzo_restrict __restrict__ - #endif - #endif - #if defined(__lzo_restrict) -+# ifndef __lzo_HAVE_restrict - # define __lzo_HAVE_restrict 1 -+# endif - #else - # define __lzo_restrict /*empty*/ - #endif -+#if !defined(__lzo_alignof) -+#if (LZO_CC_ARMCC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -+# define __lzo_alignof(e) __alignof__(e) -+#elif (LZO_CC_GHS) && !defined(__cplusplus) -+# define __lzo_alignof(e) __alignof__(e) -+#elif (LZO_CC_IBMC >= 600) -+# define __lzo_alignof(e) (__lzo_gnuc_extension__ __alignof__(e)) -+#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) -+# define __lzo_alignof(e) __alignof__(e) -+#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) -+# define __lzo_alignof(e) __alignof(e) -+#elif (LZO_CC_SUNPROC >= 0x5100) -+# define __lzo_alignof(e) __alignof__(e) -+#endif -+#endif -+#if defined(__lzo_alignof) -+# ifndef __lzo_HAVE_alignof -+# define __lzo_HAVE_alignof 1 -+# endif -+#endif -+#if !defined(__lzo_struct_packed) -+#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) -+#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) -+#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) -+#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) -+#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) -+#elif (LZO_CC_GNUC >= 0x030400ul) && !(LZO_CC_PCC_GNUC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) -+# define __lzo_struct_packed(s) struct s { -+# define __lzo_struct_packed_end() } __attribute__((__gcc_struct__,__packed__)); -+# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__gcc_struct__,__packed__)); -+#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) -+# define __lzo_struct_packed(s) struct s { -+# define __lzo_struct_packed_end() } __attribute__((__packed__)); -+# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); -+#elif (LZO_CC_IBMC >= 700) -+# define __lzo_struct_packed(s) __lzo_gnuc_extension__ struct s { -+# define __lzo_struct_packed_end() } __attribute__((__packed__)); -+# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); -+#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) -+# define __lzo_struct_packed(s) __pragma(pack(push,1)) struct s { -+# define __lzo_struct_packed_end() } __pragma(pack(pop)); -+#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) -+# define __lzo_struct_packed(s) _Packed struct s { -+# define __lzo_struct_packed_end() }; -+#endif -+#endif -+#if defined(__lzo_struct_packed) && !defined(__lzo_struct_packed_ma) -+# define __lzo_struct_packed_ma(s) __lzo_struct_packed(s) -+#endif -+#if defined(__lzo_struct_packed_end) && !defined(__lzo_struct_packed_ma_end) -+# define __lzo_struct_packed_ma_end() __lzo_struct_packed_end() -+#endif -+#if !defined(__lzo_byte_struct) -+#if defined(__lzo_struct_packed) -+# define __lzo_byte_struct(s,n) __lzo_struct_packed(s) unsigned char a[n]; __lzo_struct_packed_end() -+# define __lzo_byte_struct_ma(s,n) __lzo_struct_packed_ma(s) unsigned char a[n]; __lzo_struct_packed_ma_end() -+#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_PGI || (LZO_CC_SUNPROC >= 0x5100)) -+# define __lzo_byte_struct(s,n) struct s { unsigned char a[n]; } __attribute__((__packed__)); -+# define __lzo_byte_struct_ma(s,n) struct s { unsigned char a[n]; } __lzo_may_alias __attribute__((__packed__)); -+#endif -+#endif -+#if defined(__lzo_byte_struct) && !defined(__lzo_byte_struct_ma) -+# define __lzo_byte_struct_ma(s,n) __lzo_byte_struct(s,n) -+#endif -+#if !defined(__lzo_struct_align16) && (__lzo_HAVE_alignof) -+#if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x030000ul)) -+#elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) -+#elif (LZO_CC_CILLY || LZO_CC_PCC) -+#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) -+# define __lzo_struct_align16(s) struct __declspec(align(16)) s { -+# define __lzo_struct_align16_end() }; -+# define __lzo_struct_align32(s) struct __declspec(align(32)) s { -+# define __lzo_struct_align32_end() }; -+# define __lzo_struct_align64(s) struct __declspec(align(64)) s { -+# define __lzo_struct_align64_end() }; -+#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || (LZO_CC_IBMC >= 700) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define __lzo_struct_align16(s) struct s { -+# define __lzo_struct_align16_end() } __attribute__((__aligned__(16))); -+# define __lzo_struct_align32(s) struct s { -+# define __lzo_struct_align32_end() } __attribute__((__aligned__(32))); -+# define __lzo_struct_align64(s) struct s { -+# define __lzo_struct_align64_end() } __attribute__((__aligned__(64))); -+#endif -+#endif -+#if !defined(__lzo_union_um) -+#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) -+#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) -+#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER < 810)) -+#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) -+#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) -+#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) -+# define __lzo_union_am(s) union s { -+# define __lzo_union_am_end() } __lzo_may_alias; -+# define __lzo_union_um(s) union s { -+# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); -+#elif (LZO_CC_IBMC >= 700) -+# define __lzo_union_am(s) __lzo_gnuc_extension__ union s { -+# define __lzo_union_am_end() } __lzo_may_alias; -+# define __lzo_union_um(s) __lzo_gnuc_extension__ union s { -+# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); -+#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) -+# define __lzo_union_um(s) __pragma(pack(push,1)) union s { -+# define __lzo_union_um_end() } __pragma(pack(pop)); -+#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) -+# define __lzo_union_um(s) _Packed union s { -+# define __lzo_union_um_end() }; -+#endif -+#endif -+#if !defined(__lzo_union_am) -+# define __lzo_union_am(s) union s { -+# define __lzo_union_am_end() }; -+#endif -+#if !defined(__lzo_constructor) -+#if (LZO_CC_GNUC >= 0x030400ul) -+# define __lzo_constructor __attribute__((__constructor__,__used__)) -+#elif (LZO_CC_GNUC >= 0x020700ul) -+# define __lzo_constructor __attribute__((__constructor__)) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) -+# define __lzo_constructor __attribute__((__constructor__,__used__)) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define __lzo_constructor __attribute__((__constructor__)) -+#endif -+#endif -+#if defined(__lzo_constructor) -+# ifndef __lzo_HAVE_constructor -+# define __lzo_HAVE_constructor 1 -+# endif -+#endif -+#if !defined(__lzo_destructor) -+#if (LZO_CC_GNUC >= 0x030400ul) -+# define __lzo_destructor __attribute__((__destructor__,__used__)) -+#elif (LZO_CC_GNUC >= 0x020700ul) -+# define __lzo_destructor __attribute__((__destructor__)) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) -+# define __lzo_destructor __attribute__((__destructor__,__used__)) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define __lzo_destructor __attribute__((__destructor__)) -+#endif -+#endif -+#if defined(__lzo_destructor) -+# ifndef __lzo_HAVE_destructor -+# define __lzo_HAVE_destructor 1 -+# endif -+#endif -+#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) -+# error "unexpected configuration - check your compiler defines" -+#endif - #if !defined(__lzo_likely) && !defined(__lzo_unlikely) - #if (LZO_CC_GNUC >= 0x030200ul) - # define __lzo_likely(e) (__builtin_expect(!!(e),1)) - # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) -+#elif (LZO_CC_IBMC >= 1010) -+# define __lzo_likely(e) (__builtin_expect(!!(e),1)) -+# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) - #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) - # define __lzo_likely(e) (__builtin_expect(!!(e),1)) - # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) - # define __lzo_likely(e) (__builtin_expect(!!(e),1)) - # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) - #endif - #endif - #if defined(__lzo_likely) -+# ifndef __lzo_HAVE_likely - # define __lzo_HAVE_likely 1 -+# endif - #else - # define __lzo_likely(e) (e) - #endif - #if defined(__lzo_unlikely) -+# ifndef __lzo_HAVE_unlikely - # define __lzo_HAVE_unlikely 1 -+# endif - #else - # define __lzo_unlikely(e) (e) - #endif --#if !defined(LZO_UNUSED) --# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) --# define LZO_UNUSED(var) ((void) &var) --# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) --# define LZO_UNUSED(var) if (&var) ; else --# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define LZO_UNUSED(var) ((void) var) --# elif (LZO_CC_MSC && (_MSC_VER < 900)) --# define LZO_UNUSED(var) if (&var) ; else --# elif (LZO_CC_KEILC) --# define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];} --# elif (LZO_CC_PACIFICC) --# define LZO_UNUSED(var) ((void) sizeof(var)) --# elif (LZO_CC_WATCOMC) && defined(__cplusplus) --# define LZO_UNUSED(var) ((void) var) -+#if !defined(__lzo_static_unused_void_func) -+# if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -+# define __lzo_static_unused_void_func(f) static void __attribute__((__unused__)) f(void) - # else --# define LZO_UNUSED(var) ((void) &var) -+# define __lzo_static_unused_void_func(f) static __lzo_inline void f(void) - # endif - #endif --#if !defined(LZO_UNUSED_FUNC) --# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) --# define LZO_UNUSED_FUNC(func) ((void) func) --# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) --# define LZO_UNUSED_FUNC(func) if (func) ; else --# elif (LZO_CC_CLANG || LZO_CC_LLVM) --# define LZO_UNUSED_FUNC(func) ((void) &func) --# elif (LZO_CC_MSC && (_MSC_VER < 900)) --# define LZO_UNUSED_FUNC(func) if (func) ; else --# elif (LZO_CC_MSC) --# define LZO_UNUSED_FUNC(func) ((void) &func) --# elif (LZO_CC_KEILC || LZO_CC_PELLESC) --# define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];} -+#if !defined(__lzo_loop_forever) -+# if (LZO_CC_IBMC) -+# define __lzo_loop_forever() LZO_BLOCK_BEGIN for (;;) { ; } LZO_BLOCK_END - # else --# define LZO_UNUSED_FUNC(func) ((void) func) -+# define __lzo_loop_forever() do { ; } while __lzo_cte(1) - # endif - #endif --#if !defined(LZO_UNUSED_LABEL) --# if (LZO_CC_WATCOMC) && defined(__cplusplus) --# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l --# elif (LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) --# define LZO_UNUSED_LABEL(l) if (0) goto l --# else --# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l --# endif -+#if !defined(__lzo_unreachable) -+#if (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x020800ul)) -+# define __lzo_unreachable() __builtin_unreachable(); -+#elif (LZO_CC_GNUC >= 0x040500ul) -+# define __lzo_unreachable() __builtin_unreachable(); -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1300)) && 1 -+# define __lzo_unreachable() __builtin_unreachable(); - #endif --#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) -+#endif -+#if defined(__lzo_unreachable) -+# ifndef __lzo_HAVE_unreachable -+# define __lzo_HAVE_unreachable 1 -+# endif -+#else - # if 0 --# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var --# elif 0 && (LZO_CC_GNUC) --# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var -+# define __lzo_unreachable() ((void)0); - # else --# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init -+# define __lzo_unreachable() __lzo_loop_forever(); - # endif - #endif --#if !defined(LZO_UNCONST_CAST) --# if 0 && defined(__cplusplus) --# define LZO_UNCONST_CAST(t,e) (const_cast (e)) --# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((lzo_uintptr_t) ((const void *) (e)))))) --# else --# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e))))) --# endif -+#ifndef __LZO_CTA_NAME -+#if (LZO_CFG_USE_COUNTER) -+# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__COUNTER__) -+#else -+# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__LINE__) -+#endif - #endif - #if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) - # if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) --# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; -+# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END - # elif (LZO_CC_DMC || LZO_CC_SYMANTECC) --# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)]; -+# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1u-2*!(e)]; LZO_EXTERN_C_END - # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) --# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; -+# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END -+# elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020900ul)) && defined(__cplusplus) -+# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN int __LZO_CTA_NAME(lzo_cta_f__)(int [1-2*!(e)]); LZO_EXTERN_C_END -+# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) -+# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__)); LZO_EXTERN_C_END - # else --# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)]; -+# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-2*!(e)]; LZO_EXTERN_C_END - # endif - #endif - #if !defined(LZO_COMPILE_TIME_ASSERT) - # if (LZO_CC_AZTECC) --# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];} -+# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-!(e)];} - # elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) - # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; -+# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) -+# define LZO_COMPILE_TIME_ASSERT(e) {(void) (0/!!(e));} -+# elif (LZO_CC_GNUC >= 0x040700ul) && (LZO_CFG_USE_COUNTER) && defined(__cplusplus) -+# define LZO_COMPILE_TIME_ASSERT(e) {enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__));} -+# elif (LZO_CC_GNUC >= 0x040700ul) -+# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)] __attribute__((__unused__));} - # elif (LZO_CC_MSC && (_MSC_VER < 900)) - # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; - # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) - # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; - # else --# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];} -+# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)];} - # endif - #endif -+LZO_COMPILE_TIME_ASSERT_HEADER(1 == 1) -+#if defined(__cplusplus) -+extern "C" { LZO_COMPILE_TIME_ASSERT_HEADER(2 == 2) } -+#endif -+LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) - #if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) - # if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) - # elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) -@@ -1681,99 +1916,654 @@ extern "C" { - # elif defined(_MT) - # define __lzo_cdecl_sighandler _far _cdecl - # else --# define __lzo_cdecl_sighandler _cdecl -+# define __lzo_cdecl_sighandler _cdecl -+# endif -+# else -+# define __lzo_cdecl_sighandler __cdecl -+# endif -+#elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC) -+# define __lzo_cdecl __cdecl -+#elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC)) -+# define __lzo_cdecl cdecl -+#endif -+#if !defined(__lzo_cdecl) -+# define __lzo_cdecl /*empty*/ -+#endif -+#if !defined(__lzo_cdecl_atexit) -+# define __lzo_cdecl_atexit /*empty*/ -+#endif -+#if !defined(__lzo_cdecl_main) -+# define __lzo_cdecl_main /*empty*/ -+#endif -+#if !defined(__lzo_cdecl_qsort) -+# define __lzo_cdecl_qsort /*empty*/ -+#endif -+#if !defined(__lzo_cdecl_sighandler) -+# define __lzo_cdecl_sighandler /*empty*/ -+#endif -+#if !defined(__lzo_cdecl_va) -+# define __lzo_cdecl_va __lzo_cdecl -+#endif -+#if !(LZO_CFG_NO_WINDOWS_H) -+#if !defined(LZO_HAVE_WINDOWS_H) -+#if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) -+# if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) -+# elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) -+# elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) -+# else -+# define LZO_HAVE_WINDOWS_H 1 -+# endif -+#endif -+#endif -+#endif -+#ifndef LZO_SIZEOF_SHORT -+#if defined(SIZEOF_SHORT) -+# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) -+#elif defined(__SIZEOF_SHORT__) -+# define LZO_SIZEOF_SHORT (__SIZEOF_SHORT__) -+#endif -+#endif -+#ifndef LZO_SIZEOF_INT -+#if defined(SIZEOF_INT) -+# define LZO_SIZEOF_INT (SIZEOF_INT) -+#elif defined(__SIZEOF_INT__) -+# define LZO_SIZEOF_INT (__SIZEOF_INT__) -+#endif -+#endif -+#ifndef LZO_SIZEOF_LONG -+#if defined(SIZEOF_LONG) -+# define LZO_SIZEOF_LONG (SIZEOF_LONG) -+#elif defined(__SIZEOF_LONG__) -+# define LZO_SIZEOF_LONG (__SIZEOF_LONG__) -+#endif -+#endif -+#ifndef LZO_SIZEOF_LONG_LONG -+#if defined(SIZEOF_LONG_LONG) -+# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) -+#elif defined(__SIZEOF_LONG_LONG__) -+# define LZO_SIZEOF_LONG_LONG (__SIZEOF_LONG_LONG__) -+#endif -+#endif -+#ifndef LZO_SIZEOF___INT16 -+#if defined(SIZEOF___INT16) -+# define LZO_SIZEOF___INT16 (SIZEOF___INT16) -+#endif -+#endif -+#ifndef LZO_SIZEOF___INT32 -+#if defined(SIZEOF___INT32) -+# define LZO_SIZEOF___INT32 (SIZEOF___INT32) -+#endif -+#endif -+#ifndef LZO_SIZEOF___INT64 -+#if defined(SIZEOF___INT64) -+# define LZO_SIZEOF___INT64 (SIZEOF___INT64) -+#endif -+#endif -+#ifndef LZO_SIZEOF_VOID_P -+#if defined(SIZEOF_VOID_P) -+# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) -+#elif defined(__SIZEOF_POINTER__) -+# define LZO_SIZEOF_VOID_P (__SIZEOF_POINTER__) -+#endif -+#endif -+#ifndef LZO_SIZEOF_SIZE_T -+#if defined(SIZEOF_SIZE_T) -+# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) -+#elif defined(__SIZEOF_SIZE_T__) -+# define LZO_SIZEOF_SIZE_T (__SIZEOF_SIZE_T__) -+#endif -+#endif -+#ifndef LZO_SIZEOF_PTRDIFF_T -+#if defined(SIZEOF_PTRDIFF_T) -+# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) -+#elif defined(__SIZEOF_PTRDIFF_T__) -+# define LZO_SIZEOF_PTRDIFF_T (__SIZEOF_PTRDIFF_T__) -+#endif -+#endif -+#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) -+#if !defined(LZO_SIZEOF_SHORT) -+# if (LZO_ARCH_CRAY_PVP) -+# define LZO_SIZEOF_SHORT 8 -+# elif (USHRT_MAX == LZO_0xffffL) -+# define LZO_SIZEOF_SHORT 2 -+# elif (__LZO_LSR(USHRT_MAX,7) == 1) -+# define LZO_SIZEOF_SHORT 1 -+# elif (__LZO_LSR(USHRT_MAX,15) == 1) -+# define LZO_SIZEOF_SHORT 2 -+# elif (__LZO_LSR(USHRT_MAX,31) == 1) -+# define LZO_SIZEOF_SHORT 4 -+# elif (__LZO_LSR(USHRT_MAX,63) == 1) -+# define LZO_SIZEOF_SHORT 8 -+# elif (__LZO_LSR(USHRT_MAX,127) == 1) -+# define LZO_SIZEOF_SHORT 16 -+# else -+# error "LZO_SIZEOF_SHORT" -+# endif -+#endif -+LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SHORT == sizeof(short)) -+#if !defined(LZO_SIZEOF_INT) -+# if (LZO_ARCH_CRAY_PVP) -+# define LZO_SIZEOF_INT 8 -+# elif (UINT_MAX == LZO_0xffffL) -+# define LZO_SIZEOF_INT 2 -+# elif (UINT_MAX == LZO_0xffffffffL) -+# define LZO_SIZEOF_INT 4 -+# elif (__LZO_LSR(UINT_MAX,7) == 1) -+# define LZO_SIZEOF_INT 1 -+# elif (__LZO_LSR(UINT_MAX,15) == 1) -+# define LZO_SIZEOF_INT 2 -+# elif (__LZO_LSR(UINT_MAX,31) == 1) -+# define LZO_SIZEOF_INT 4 -+# elif (__LZO_LSR(UINT_MAX,63) == 1) -+# define LZO_SIZEOF_INT 8 -+# elif (__LZO_LSR(UINT_MAX,127) == 1) -+# define LZO_SIZEOF_INT 16 -+# else -+# error "LZO_SIZEOF_INT" -+# endif -+#endif -+LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_INT == sizeof(int)) -+#if !defined(LZO_SIZEOF_LONG) -+# if (ULONG_MAX == LZO_0xffffffffL) -+# define LZO_SIZEOF_LONG 4 -+# elif (__LZO_LSR(ULONG_MAX,7) == 1) -+# define LZO_SIZEOF_LONG 1 -+# elif (__LZO_LSR(ULONG_MAX,15) == 1) -+# define LZO_SIZEOF_LONG 2 -+# elif (__LZO_LSR(ULONG_MAX,31) == 1) -+# define LZO_SIZEOF_LONG 4 -+# elif (__LZO_LSR(ULONG_MAX,39) == 1) -+# define LZO_SIZEOF_LONG 5 -+# elif (__LZO_LSR(ULONG_MAX,63) == 1) -+# define LZO_SIZEOF_LONG 8 -+# elif (__LZO_LSR(ULONG_MAX,127) == 1) -+# define LZO_SIZEOF_LONG 16 -+# else -+# error "LZO_SIZEOF_LONG" -+# endif -+#endif -+LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_LONG == sizeof(long)) -+#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) -+#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) -+# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) -+# if (LZO_CC_GNUC >= 0x030300ul) -+# if ((__LONG_MAX__-0) == (__LONG_LONG_MAX__-0)) -+# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG -+# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) -+# define LZO_SIZEOF_LONG_LONG 4 -+# endif -+# endif -+# endif -+#endif -+#endif -+#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) -+#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) -+#if (LZO_ARCH_I086 && LZO_CC_DMC) -+#elif (LZO_CC_CILLY) && defined(__GNUC__) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_OS_WIN64 || defined(_WIN64)) -+# define LZO_SIZEOF___INT64 8 -+#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) -+# define LZO_SIZEOF___INT64 8 -+#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) -+# define LZO_SIZEOF___INT64 8 -+#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) -+# define LZO_SIZEOF___INT64 8 -+#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) -+# define LZO_SIZEOF___INT64 8 -+#elif (LZO_CC_GHS && defined(__LLONG_BIT) && ((__LLONG_BIT-0) == 64)) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && ((_INTEGRAL_MAX_BITS-0) == 64)) -+# define LZO_SIZEOF___INT64 8 -+#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (defined(__vms) || defined(__VMS)) && ((__INITIAL_POINTER_SIZE-0) == 64) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) -+#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -+# define LZO_SIZEOF_LONG_LONG 8 -+#endif -+#endif -+#endif -+#if defined(__cplusplus) && (LZO_CC_GNUC) -+# if (LZO_CC_GNUC < 0x020800ul) -+# undef LZO_SIZEOF_LONG_LONG -+# endif -+#endif -+#if (LZO_CFG_NO_LONG_LONG) -+# undef LZO_SIZEOF_LONG_LONG -+#elif defined(__NO_LONG_LONG) -+# undef LZO_SIZEOF_LONG_LONG -+#elif defined(_NO_LONGLONG) -+# undef LZO_SIZEOF_LONG_LONG -+#endif -+#if !defined(LZO_WORDSIZE) -+#if (LZO_ARCH_ALPHA) -+# define LZO_WORDSIZE 8 -+#elif (LZO_ARCH_AMD64) -+# define LZO_WORDSIZE 8 -+#elif (LZO_ARCH_AVR) -+# define LZO_WORDSIZE 1 -+#elif (LZO_ARCH_H8300) -+# if defined(__NORMAL_MODE__) -+# define LZO_WORDSIZE 4 -+# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) -+# define LZO_WORDSIZE 4 -+# else -+# define LZO_WORDSIZE 2 -+# endif -+#elif (LZO_ARCH_I086) -+# define LZO_WORDSIZE 2 -+#elif (LZO_ARCH_IA64) -+# define LZO_WORDSIZE 8 -+#elif (LZO_ARCH_M16C) -+# define LZO_WORDSIZE 2 -+#elif (LZO_ARCH_SPU) -+# define LZO_WORDSIZE 4 -+#elif (LZO_ARCH_Z80) -+# define LZO_WORDSIZE 1 -+#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) -+# define LZO_WORDSIZE 8 -+#elif (LZO_OS_OS400 || defined(__OS400__)) -+# define LZO_WORDSIZE 8 -+#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) -+# define LZO_WORDSIZE 8 -+#endif -+#endif -+#if !defined(LZO_SIZEOF_VOID_P) -+#if defined(__ILP32__) || defined(__ILP32) || defined(_ILP32) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 4) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) -+# define LZO_SIZEOF_VOID_P 4 -+#elif defined(__ILP64__) || defined(__ILP64) || defined(_ILP64) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 8) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) -+# define LZO_SIZEOF_VOID_P 8 -+#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) -+# define LZO_SIZEOF_VOID_P 8 -+#elif defined(__LP64__) || defined(__LP64) || defined(_LP64) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) -+# define LZO_SIZEOF_VOID_P 8 -+#elif (LZO_ARCH_AVR) -+# define LZO_SIZEOF_VOID_P 2 -+#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) -+# define LZO_SIZEOF_VOID_P 2 -+#elif (LZO_ARCH_H8300) -+# if defined(__NORMAL_MODE__) -+# define LZO_SIZEOF_VOID_P 2 -+# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) -+# define LZO_SIZEOF_VOID_P 4 -+# else -+# define LZO_SIZEOF_VOID_P 2 -+# endif -+# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) -+# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT -+# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT -+# endif -+#elif (LZO_ARCH_I086) -+# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) -+# define LZO_SIZEOF_VOID_P 2 -+# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) -+# define LZO_SIZEOF_VOID_P 4 -+# else -+# error "invalid LZO_ARCH_I086 memory model" -+# endif -+#elif (LZO_ARCH_M16C) -+# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) -+# define LZO_SIZEOF_VOID_P 4 -+# else -+# define LZO_SIZEOF_VOID_P 2 -+# endif -+#elif (LZO_ARCH_SPU) -+# define LZO_SIZEOF_VOID_P 4 -+#elif (LZO_ARCH_Z80) -+# define LZO_SIZEOF_VOID_P 2 -+#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) -+# define LZO_SIZEOF_VOID_P 4 -+#elif (LZO_OS_OS400 || defined(__OS400__)) -+# if defined(__LLP64_IFC__) -+# define LZO_SIZEOF_VOID_P 8 -+# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -+# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -+# else -+# define LZO_SIZEOF_VOID_P 16 -+# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -+# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -+# endif -+#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) -+# define LZO_SIZEOF_VOID_P 8 -+# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -+# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -+#endif -+#endif -+#if !defined(LZO_SIZEOF_VOID_P) -+# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG -+#endif -+LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_VOID_P == sizeof(void *)) -+#if !defined(LZO_SIZEOF_SIZE_T) -+#if (LZO_ARCH_I086 || LZO_ARCH_M16C) -+# define LZO_SIZEOF_SIZE_T 2 -+#endif -+#endif -+#if !defined(LZO_SIZEOF_SIZE_T) -+# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P -+#endif -+#if defined(offsetof) -+LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SIZE_T == sizeof(size_t)) -+#endif -+#if !defined(LZO_SIZEOF_PTRDIFF_T) -+#if (LZO_ARCH_I086) -+# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) -+# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P -+# elif (LZO_MM_COMPACT || LZO_MM_LARGE) -+# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) -+# define LZO_SIZEOF_PTRDIFF_T 4 -+# else -+# define LZO_SIZEOF_PTRDIFF_T 2 - # endif - # else --# define __lzo_cdecl_sighandler __cdecl -+# error "invalid LZO_ARCH_I086 memory model" - # endif --#elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC) --# define __lzo_cdecl __cdecl --#elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC)) --# define __lzo_cdecl cdecl - #endif --#if !defined(__lzo_cdecl) --# define __lzo_cdecl /*empty*/ - #endif --#if !defined(__lzo_cdecl_atexit) --# define __lzo_cdecl_atexit /*empty*/ -+#if !defined(LZO_SIZEOF_PTRDIFF_T) -+# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T - #endif --#if !defined(__lzo_cdecl_main) --# define __lzo_cdecl_main /*empty*/ -+#if defined(offsetof) -+LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) - #endif --#if !defined(__lzo_cdecl_qsort) --# define __lzo_cdecl_qsort /*empty*/ -+#if !defined(LZO_WORDSIZE) -+# define LZO_WORDSIZE LZO_SIZEOF_VOID_P - #endif --#if !defined(__lzo_cdecl_sighandler) --# define __lzo_cdecl_sighandler /*empty*/ -+#if (LZO_ABI_NEUTRAL_ENDIAN) -+# undef LZO_ABI_BIG_ENDIAN -+# undef LZO_ABI_LITTLE_ENDIAN -+#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) -+#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) -+# define LZO_ABI_BIG_ENDIAN 1 -+#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) -+# define LZO_ABI_LITTLE_ENDIAN 1 -+#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) -+# define LZO_ABI_LITTLE_ENDIAN 1 -+#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390 || LZO_ARCH_SPU) -+# define LZO_ABI_BIG_ENDIAN 1 -+#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) -+# if (__LITTLE_ENDIAN__ == 1) -+# define LZO_ABI_LITTLE_ENDIAN 1 -+# else -+# define LZO_ABI_BIG_ENDIAN 1 -+# endif -+#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) -+# define LZO_ABI_BIG_ENDIAN 1 -+#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) -+# define LZO_ABI_LITTLE_ENDIAN 1 -+#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) -+# define LZO_ABI_BIG_ENDIAN 1 -+#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) -+# define LZO_ABI_LITTLE_ENDIAN 1 -+#elif 1 && (LZO_ARCH_ARM && LZO_CC_ARMCC_ARMCC) -+# if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN) -+# error "unexpected configuration - check your compiler defines" -+# elif defined(__BIG_ENDIAN) -+# define LZO_ABI_BIG_ENDIAN 1 -+# else -+# define LZO_ABI_LITTLE_ENDIAN 1 -+# endif -+# define LZO_ABI_LITTLE_ENDIAN 1 -+#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EB__) && !defined(__AARCH64EL__) -+# define LZO_ABI_BIG_ENDIAN 1 -+#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EL__) && !defined(__AARCH64EB__) -+# define LZO_ABI_LITTLE_ENDIAN 1 -+#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) -+# define LZO_ABI_BIG_ENDIAN 1 -+#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) -+# define LZO_ABI_LITTLE_ENDIAN 1 - #endif --#if !defined(__lzo_cdecl_va) --# define __lzo_cdecl_va __lzo_cdecl - #endif --#if !(LZO_CFG_NO_WINDOWS_H) --#if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) --# if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) --# elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) --# elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) -+#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ABI_BIG_ENDIAN) -+# define LZO_INFO_ABI_ENDIAN "be" -+#elif (LZO_ABI_LITTLE_ENDIAN) -+# define LZO_INFO_ABI_ENDIAN "le" -+#elif (LZO_ABI_NEUTRAL_ENDIAN) -+# define LZO_INFO_ABI_ENDIAN "neutral" -+#endif -+#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) -+# define LZO_ABI_I8LP16 1 -+# define LZO_INFO_ABI_PM "i8lp16" -+#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) -+# define LZO_ABI_ILP16 1 -+# define LZO_INFO_ABI_PM "ilp16" -+#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) -+# define LZO_ABI_LP32 1 -+# define LZO_INFO_ABI_PM "lp32" -+#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) -+# define LZO_ABI_ILP32 1 -+# define LZO_INFO_ABI_PM "ilp32" -+#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) -+# define LZO_ABI_LLP64 1 -+# define LZO_INFO_ABI_PM "llp64" -+#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) -+# define LZO_ABI_LP64 1 -+# define LZO_INFO_ABI_PM "lp64" -+#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) -+# define LZO_ABI_ILP64 1 -+# define LZO_INFO_ABI_PM "ilp64" -+#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) -+# define LZO_ABI_IP32L64 1 -+# define LZO_INFO_ABI_PM "ip32l64" -+#endif -+#if 0 -+#elif !defined(__LZO_LIBC_OVERRIDE) -+#if (LZO_LIBC_NAKED) -+# define LZO_INFO_LIBC "naked" -+#elif (LZO_LIBC_FREESTANDING) -+# define LZO_INFO_LIBC "freestanding" -+#elif (LZO_LIBC_MOSTLY_FREESTANDING) -+# define LZO_INFO_LIBC "mfreestanding" -+#elif (LZO_LIBC_ISOC90) -+# define LZO_INFO_LIBC "isoc90" -+#elif (LZO_LIBC_ISOC99) -+# define LZO_INFO_LIBC "isoc99" -+#elif (LZO_CC_ARMCC_ARMCC) && defined(__ARMCLIB_VERSION) -+# define LZO_LIBC_ISOC90 1 -+# define LZO_INFO_LIBC "isoc90" -+#elif defined(__dietlibc__) -+# define LZO_LIBC_DIETLIBC 1 -+# define LZO_INFO_LIBC "dietlibc" -+#elif defined(_NEWLIB_VERSION) -+# define LZO_LIBC_NEWLIB 1 -+# define LZO_INFO_LIBC "newlib" -+#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) -+# if defined(__UCLIBC_SUBLEVEL__) -+# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + (__UCLIBC_MINOR__-0) * 0x100 + (__UCLIBC_SUBLEVEL__-0)) - # else --# define LZO_HAVE_WINDOWS_H 1 -+# define LZO_LIBC_UCLIBC 0x00090bL - # endif -+# define LZO_INFO_LIBC "uc" "libc" -+#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) -+# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + (__GLIBC_MINOR__-0) * 0x100) -+# define LZO_INFO_LIBC "glibc" -+#elif (LZO_CC_MWERKS) && defined(__MSL__) -+# define LZO_LIBC_MSL __MSL__ -+# define LZO_INFO_LIBC "msl" -+#elif 1 && defined(__IAR_SYSTEMS_ICC__) -+# define LZO_LIBC_ISOC90 1 -+# define LZO_INFO_LIBC "isoc90" -+#else -+# define LZO_LIBC_DEFAULT 1 -+# define LZO_INFO_LIBC "default" -+#endif -+#endif -+#if (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) -+# define LZO_ASM_SYNTAX_MSC 1 -+#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) -+#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) -+#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) -+# define LZO_ASM_SYNTAX_GNUC 1 -+#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) -+# define LZO_ASM_SYNTAX_GNUC 1 -+#elif (LZO_CC_GNUC) -+# define LZO_ASM_SYNTAX_GNUC 1 -+#endif -+#if (LZO_ASM_SYNTAX_GNUC) -+#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) -+# define __LZO_ASM_CLOBBER "ax" -+# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ -+# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY /*empty*/ -+# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ -+#elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1000)) -+# define __LZO_ASM_CLOBBER "memory" -+# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ -+# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "memory" -+# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ -+#else -+# define __LZO_ASM_CLOBBER "cc", "memory" -+# define __LZO_ASM_CLOBBER_LIST_CC : "cc" -+# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "cc", "memory" -+# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ - #endif - #endif - #if (LZO_ARCH_ALPHA) --# define LZO_OPT_AVOID_UINT_INDEX 1 --# define LZO_OPT_AVOID_SHORT 1 --# define LZO_OPT_AVOID_USHORT 1 -+# define LZO_OPT_AVOID_UINT_INDEX 1 - #elif (LZO_ARCH_AMD64) --# define LZO_OPT_AVOID_INT_INDEX 1 --# define LZO_OPT_AVOID_UINT_INDEX 1 --# define LZO_OPT_UNALIGNED16 1 --# define LZO_OPT_UNALIGNED32 1 --# define LZO_OPT_UNALIGNED64 1 --#elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB) -+# define LZO_OPT_AVOID_INT_INDEX 1 -+# define LZO_OPT_AVOID_UINT_INDEX 1 -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED64 -+# define LZO_OPT_UNALIGNED64 1 -+# endif - #elif (LZO_ARCH_ARM) --# define LZO_OPT_AVOID_SHORT 1 --# define LZO_OPT_AVOID_USHORT 1 -+# if defined(__ARM_FEATURE_UNALIGNED) -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif -+# elif defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM+0) >= 7) -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif -+# elif defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM+0) >= 6) && !defined(__TARGET_PROFILE_M) -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif -+# endif -+#elif (LZO_ARCH_ARM64) -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED64 -+# define LZO_OPT_UNALIGNED64 1 -+# endif - #elif (LZO_ARCH_CRIS) --# define LZO_OPT_UNALIGNED16 1 --# define LZO_OPT_UNALIGNED32 1 -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif - #elif (LZO_ARCH_I386) --# define LZO_OPT_UNALIGNED16 1 --# define LZO_OPT_UNALIGNED32 1 -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif - #elif (LZO_ARCH_IA64) --# define LZO_OPT_AVOID_INT_INDEX 1 --# define LZO_OPT_AVOID_UINT_INDEX 1 --# define LZO_OPT_PREFER_POSTINC 1 -+# define LZO_OPT_AVOID_INT_INDEX 1 -+# define LZO_OPT_AVOID_UINT_INDEX 1 -+# define LZO_OPT_PREFER_POSTINC 1 - #elif (LZO_ARCH_M68K) --# define LZO_OPT_PREFER_POSTINC 1 --# define LZO_OPT_PREFER_PREDEC 1 -+# define LZO_OPT_PREFER_POSTINC 1 -+# define LZO_OPT_PREFER_PREDEC 1 - # if defined(__mc68020__) && !defined(__mcoldfire__) --# define LZO_OPT_UNALIGNED16 1 --# define LZO_OPT_UNALIGNED32 1 -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif - # endif - #elif (LZO_ARCH_MIPS) --# define LZO_OPT_AVOID_UINT_INDEX 1 -+# define LZO_OPT_AVOID_UINT_INDEX 1 - #elif (LZO_ARCH_POWERPC) --# define LZO_OPT_PREFER_PREINC 1 --# define LZO_OPT_PREFER_PREDEC 1 -+# define LZO_OPT_PREFER_PREINC 1 -+# define LZO_OPT_PREFER_PREDEC 1 - # if (LZO_ABI_BIG_ENDIAN) --# define LZO_OPT_UNALIGNED16 1 --# define LZO_OPT_UNALIGNED32 1 -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif -+# if (LZO_WORDSIZE == 8) -+# ifndef LZO_OPT_UNALIGNED64 -+# define LZO_OPT_UNALIGNED64 1 -+# endif -+# endif - # endif - #elif (LZO_ARCH_S390) --# define LZO_OPT_UNALIGNED16 1 --# define LZO_OPT_UNALIGNED32 1 --# if (LZO_SIZEOF_SIZE_T == 8) --# define LZO_OPT_UNALIGNED64 1 -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif -+# if (LZO_WORDSIZE == 8) -+# ifndef LZO_OPT_UNALIGNED64 -+# define LZO_OPT_UNALIGNED64 1 -+# endif - # endif - #elif (LZO_ARCH_SH) --# define LZO_OPT_PREFER_POSTINC 1 --# define LZO_OPT_PREFER_PREDEC 1 -+# define LZO_OPT_PREFER_POSTINC 1 -+# define LZO_OPT_PREFER_PREDEC 1 - #endif - #ifndef LZO_CFG_NO_INLINE_ASM --#if (LZO_CC_LLVM) -+#if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) -+# define LZO_CFG_NO_INLINE_ASM 1 -+#elif (LZO_CC_LLVM) - # define LZO_CFG_NO_INLINE_ASM 1 - #endif - #endif -+#if (LZO_CFG_NO_INLINE_ASM) -+# undef LZO_ASM_SYNTAX_MSC -+# undef LZO_ASM_SYNTAX_GNUC -+# undef __LZO_ASM_CLOBBER -+# undef __LZO_ASM_CLOBBER_LIST_CC -+# undef __LZO_ASM_CLOBBER_LIST_CC_MEMORY -+# undef __LZO_ASM_CLOBBER_LIST_EMPTY -+#endif - #ifndef LZO_CFG_NO_UNALIGNED - #if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) - # define LZO_CFG_NO_UNALIGNED 1 -@@ -1784,25 +2574,6 @@ extern "C" { - # undef LZO_OPT_UNALIGNED32 - # undef LZO_OPT_UNALIGNED64 - #endif --#if (LZO_CFG_NO_INLINE_ASM) --#elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) --# define LZO_ASM_SYNTAX_MSC 1 --#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) --#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) --#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) --# define LZO_ASM_SYNTAX_GNUC 1 --#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) --# define LZO_ASM_SYNTAX_GNUC 1 --#endif --#if (LZO_ASM_SYNTAX_GNUC) --#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) --# define __LZO_ASM_CLOBBER "ax" --#elif (LZO_CC_INTELC) --# define __LZO_ASM_CLOBBER "memory" --#else --# define __LZO_ASM_CLOBBER "cc", "memory" --#endif --#endif - #if defined(__LZO_INFOSTR_MM) - #elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM)) - # define __LZO_INFOSTR_MM "" -@@ -1846,7 +2617,382 @@ extern "C" { - #define LZO_INFO_STRING \ - LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \ - " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER -+#if !(LZO_CFG_SKIP_LZO_TYPES) -+#if (!(LZO_SIZEOF_SHORT+0 > 0 && LZO_SIZEOF_INT+0 > 0 && LZO_SIZEOF_LONG+0 > 0)) -+# error "missing defines for sizes" -+#endif -+#if (!(LZO_SIZEOF_PTRDIFF_T+0 > 0 && LZO_SIZEOF_SIZE_T+0 > 0 && LZO_SIZEOF_VOID_P+0 > 0)) -+# error "missing defines for sizes" -+#endif -+#if !defined(lzo_llong_t) -+#if (LZO_SIZEOF_LONG_LONG+0 > 0) -+__lzo_gnuc_extension__ typedef long long lzo_llong_t__; -+__lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; -+# define lzo_llong_t lzo_llong_t__ -+# define lzo_ullong_t lzo_ullong_t__ -+#endif -+#endif -+#if !defined(lzo_int16e_t) -+#if (LZO_SIZEOF_LONG == 2) -+# define lzo_int16e_t long -+# define lzo_uint16e_t unsigned long -+#elif (LZO_SIZEOF_INT == 2) -+# define lzo_int16e_t int -+# define lzo_uint16e_t unsigned int -+#elif (LZO_SIZEOF_SHORT == 2) -+# define lzo_int16e_t short int -+# define lzo_uint16e_t unsigned short int -+#elif 1 && !(LZO_CFG_TYPE_NO_MODE_HI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) -+ typedef int lzo_int16e_hi_t__ __attribute__((__mode__(__HI__))); -+ typedef unsigned int lzo_uint16e_hi_t__ __attribute__((__mode__(__HI__))); -+# define lzo_int16e_t lzo_int16e_hi_t__ -+# define lzo_uint16e_t lzo_uint16e_hi_t__ -+#elif (LZO_SIZEOF___INT16 == 2) -+# define lzo_int16e_t __int16 -+# define lzo_uint16e_t unsigned __int16 -+#else -+#endif -+#endif -+#if defined(lzo_int16e_t) -+# define LZO_SIZEOF_LZO_INT16E_T 2 -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == 2) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == LZO_SIZEOF_LZO_INT16E_T) -+#endif -+#if !defined(lzo_int32e_t) -+#if (LZO_SIZEOF_LONG == 4) -+# define lzo_int32e_t long int -+# define lzo_uint32e_t unsigned long int -+#elif (LZO_SIZEOF_INT == 4) -+# define lzo_int32e_t int -+# define lzo_uint32e_t unsigned int -+#elif (LZO_SIZEOF_SHORT == 4) -+# define lzo_int32e_t short int -+# define lzo_uint32e_t unsigned short int -+#elif (LZO_SIZEOF_LONG_LONG == 4) -+# define lzo_int32e_t lzo_llong_t -+# define lzo_uint32e_t lzo_ullong_t -+#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) && (__INT_MAX__+0 > 2147483647L) -+ typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); -+ typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); -+# define lzo_int32e_t lzo_int32e_si_t__ -+# define lzo_uint32e_t lzo_uint32e_si_t__ -+#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_GNUC >= 0x025f00ul) && defined(__AVR__) && (__LONG_MAX__+0 == 32767L) -+ typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); -+ typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); -+# define lzo_int32e_t lzo_int32e_si_t__ -+# define lzo_uint32e_t lzo_uint32e_si_t__ -+# define LZO_INT32_C(c) (c##LL) -+# define LZO_UINT32_C(c) (c##ULL) -+#elif (LZO_SIZEOF___INT32 == 4) -+# define lzo_int32e_t __int32 -+# define lzo_uint32e_t unsigned __int32 -+#else -+#endif -+#endif -+#if defined(lzo_int32e_t) -+# define LZO_SIZEOF_LZO_INT32E_T 4 -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == 4) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == LZO_SIZEOF_LZO_INT32E_T) -+#endif -+#if !defined(lzo_int64e_t) -+#if (LZO_SIZEOF___INT64 == 8) -+# if (LZO_CC_BORLANDC) && !(LZO_CFG_TYPE_PREFER___INT64) -+# define LZO_CFG_TYPE_PREFER___INT64 1 -+# endif -+#endif -+#if (LZO_SIZEOF_INT == 8) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) -+# define lzo_int64e_t int -+# define lzo_uint64e_t unsigned int -+# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_INT -+#elif (LZO_SIZEOF_LONG == 8) -+# define lzo_int64e_t long int -+# define lzo_uint64e_t unsigned long int -+# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_LONG -+#elif (LZO_SIZEOF_LONG_LONG == 8) && !(LZO_CFG_TYPE_PREFER___INT64) -+# define lzo_int64e_t lzo_llong_t -+# define lzo_uint64e_t lzo_ullong_t -+# if (LZO_CC_BORLANDC) -+# define LZO_INT64_C(c) ((c) + 0ll) -+# define LZO_UINT64_C(c) ((c) + 0ull) -+# elif 0 -+# define LZO_INT64_C(c) (__lzo_gnuc_extension__ (c##LL)) -+# define LZO_UINT64_C(c) (__lzo_gnuc_extension__ (c##ULL)) -+# else -+# define LZO_INT64_C(c) (c##LL) -+# define LZO_UINT64_C(c) (c##ULL) -+# endif -+# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_LONG_LONG -+#elif (LZO_SIZEOF___INT64 == 8) -+# define lzo_int64e_t __int64 -+# define lzo_uint64e_t unsigned __int64 -+# if (LZO_CC_BORLANDC) -+# define LZO_INT64_C(c) ((c) + 0i64) -+# define LZO_UINT64_C(c) ((c) + 0ui64) -+# else -+# define LZO_INT64_C(c) (c##i64) -+# define LZO_UINT64_C(c) (c##ui64) -+# endif -+# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF___INT64 -+#else -+#endif -+#endif -+#if defined(lzo_int64e_t) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == 8) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == LZO_SIZEOF_LZO_INT64E_T) -+#endif -+#if !defined(lzo_int32l_t) -+#if defined(lzo_int32e_t) -+# define lzo_int32l_t lzo_int32e_t -+# define lzo_uint32l_t lzo_uint32e_t -+# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LZO_INT32E_T -+#elif (LZO_SIZEOF_INT >= 4) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) -+# define lzo_int32l_t int -+# define lzo_uint32l_t unsigned int -+# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_INT -+#elif (LZO_SIZEOF_LONG >= 4) -+# define lzo_int32l_t long int -+# define lzo_uint32l_t unsigned long int -+# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LONG -+#else -+# error "lzo_int32l_t" -+#endif -+#endif -+#if 1 -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) >= 4) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) == LZO_SIZEOF_LZO_INT32L_T) -+#endif -+#if !defined(lzo_int64l_t) -+#if defined(lzo_int64e_t) -+# define lzo_int64l_t lzo_int64e_t -+# define lzo_uint64l_t lzo_uint64e_t -+# define LZO_SIZEOF_LZO_INT64L_T LZO_SIZEOF_LZO_INT64E_T -+#else -+#endif -+#endif -+#if defined(lzo_int64l_t) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) >= 8) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) == LZO_SIZEOF_LZO_INT64L_T) -+#endif -+#if !defined(lzo_int32f_t) -+#if (LZO_SIZEOF_SIZE_T >= 8) -+# define lzo_int32f_t lzo_int64l_t -+# define lzo_uint32f_t lzo_uint64l_t -+# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT64L_T -+#else -+# define lzo_int32f_t lzo_int32l_t -+# define lzo_uint32f_t lzo_uint32l_t -+# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT32L_T -+#endif -+#endif -+#if 1 -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) >= 4) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) == LZO_SIZEOF_LZO_INT32F_T) -+#endif -+#if !defined(lzo_int64f_t) -+#if defined(lzo_int64l_t) -+# define lzo_int64f_t lzo_int64l_t -+# define lzo_uint64f_t lzo_uint64l_t -+# define LZO_SIZEOF_LZO_INT64F_T LZO_SIZEOF_LZO_INT64L_T -+#else -+#endif -+#endif -+#if defined(lzo_int64f_t) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) >= 8) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) == LZO_SIZEOF_LZO_INT64F_T) -+#endif -+#if !defined(lzo_intptr_t) -+#if 1 && (LZO_OS_OS400 && (LZO_SIZEOF_VOID_P == 16)) -+# define __LZO_INTPTR_T_IS_POINTER 1 -+ typedef char* lzo_intptr_t; -+ typedef char* lzo_uintptr_t; -+# define lzo_intptr_t lzo_intptr_t -+# define lzo_uintptr_t lzo_uintptr_t -+# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_VOID_P -+#elif (LZO_CC_MSC && (_MSC_VER >= 1300) && (LZO_SIZEOF_VOID_P == 4) && (LZO_SIZEOF_INT == 4)) -+ typedef __w64 int lzo_intptr_t; -+ typedef __w64 unsigned int lzo_uintptr_t; -+# define lzo_intptr_t lzo_intptr_t -+# define lzo_uintptr_t lzo_uintptr_t -+# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT -+#elif (LZO_SIZEOF_SHORT == LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT > LZO_SIZEOF_VOID_P) -+# define lzo_intptr_t short -+# define lzo_uintptr_t unsigned short -+# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_SHORT -+#elif (LZO_SIZEOF_INT >= LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) -+# define lzo_intptr_t int -+# define lzo_uintptr_t unsigned int -+# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT -+#elif (LZO_SIZEOF_LONG >= LZO_SIZEOF_VOID_P) -+# define lzo_intptr_t long -+# define lzo_uintptr_t unsigned long -+# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LONG -+#elif (LZO_SIZEOF_LZO_INT64L_T >= LZO_SIZEOF_VOID_P) -+# define lzo_intptr_t lzo_int64l_t -+# define lzo_uintptr_t lzo_uint64l_t -+# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LZO_INT64L_T -+#else -+# error "lzo_intptr_t" -+#endif -+#endif -+#if 1 -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) >= sizeof(void *)) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) == sizeof(lzo_uintptr_t)) -+#endif -+#if !defined(lzo_word_t) -+#if defined(LZO_WORDSIZE) && (LZO_WORDSIZE+0 > 0) -+#if (LZO_WORDSIZE == LZO_SIZEOF_LZO_INTPTR_T) && !(__LZO_INTPTR_T_IS_POINTER) -+# define lzo_word_t lzo_uintptr_t -+# define lzo_sword_t lzo_intptr_t -+# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INTPTR_T -+#elif (LZO_WORDSIZE == LZO_SIZEOF_LONG) -+# define lzo_word_t unsigned long -+# define lzo_sword_t long -+# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LONG -+#elif (LZO_WORDSIZE == LZO_SIZEOF_INT) -+# define lzo_word_t unsigned int -+# define lzo_sword_t int -+# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_INT -+#elif (LZO_WORDSIZE == LZO_SIZEOF_SHORT) -+# define lzo_word_t unsigned short -+# define lzo_sword_t short -+# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_SHORT -+#elif (LZO_WORDSIZE == 1) -+# define lzo_word_t unsigned char -+# define lzo_sword_t signed char -+# define LZO_SIZEOF_LZO_WORD_T 1 -+#elif (LZO_WORDSIZE == LZO_SIZEOF_LZO_INT64L_T) -+# define lzo_word_t lzo_uint64l_t -+# define lzo_sword_t lzo_int64l_t -+# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INT64L_T -+#elif (LZO_ARCH_SPU) && (LZO_CC_GNUC) -+#if 0 -+ typedef unsigned lzo_word_t __attribute__((__mode__(__V16QI__))); -+ typedef int lzo_sword_t __attribute__((__mode__(__V16QI__))); -+# define lzo_word_t lzo_word_t -+# define lzo_sword_t lzo_sword_t -+# define LZO_SIZEOF_LZO_WORD_T 16 -+#endif -+#else -+# error "lzo_word_t" -+#endif -+#endif -+#endif -+#if 1 && defined(lzo_word_t) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_word_t) == LZO_WORDSIZE) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_sword_t) == LZO_WORDSIZE) -+#endif -+#if 1 -+#define lzo_int8_t signed char -+#define lzo_uint8_t unsigned char -+#define LZO_SIZEOF_LZO_INT8_T 1 -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == 1) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == sizeof(lzo_uint8_t)) -+#endif -+#if defined(lzo_int16e_t) -+#define lzo_int16_t lzo_int16e_t -+#define lzo_uint16_t lzo_uint16e_t -+#define LZO_SIZEOF_LZO_INT16_T LZO_SIZEOF_LZO_INT16E_T -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == 2) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == sizeof(lzo_uint16_t)) -+#endif -+#if defined(lzo_int32e_t) -+#define lzo_int32_t lzo_int32e_t -+#define lzo_uint32_t lzo_uint32e_t -+#define LZO_SIZEOF_LZO_INT32_T LZO_SIZEOF_LZO_INT32E_T -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == 4) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == sizeof(lzo_uint32_t)) -+#endif -+#if defined(lzo_int64e_t) -+#define lzo_int64_t lzo_int64e_t -+#define lzo_uint64_t lzo_uint64e_t -+#define LZO_SIZEOF_LZO_INT64_T LZO_SIZEOF_LZO_INT64E_T -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == 8) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == sizeof(lzo_uint64_t)) -+#endif -+#if 1 -+#define lzo_int_least32_t lzo_int32l_t -+#define lzo_uint_least32_t lzo_uint32l_t -+#define LZO_SIZEOF_LZO_INT_LEAST32_T LZO_SIZEOF_LZO_INT32L_T -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) >= 4) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) == sizeof(lzo_uint_least32_t)) -+#endif -+#if defined(lzo_int64l_t) -+#define lzo_int_least64_t lzo_int64l_t -+#define lzo_uint_least64_t lzo_uint64l_t -+#define LZO_SIZEOF_LZO_INT_LEAST64_T LZO_SIZEOF_LZO_INT64L_T -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) >= 8) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) == sizeof(lzo_uint_least64_t)) -+#endif -+#if 1 -+#define lzo_int_fast32_t lzo_int32f_t -+#define lzo_uint_fast32_t lzo_uint32f_t -+#define LZO_SIZEOF_LZO_INT_FAST32_T LZO_SIZEOF_LZO_INT32F_T -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) >= 4) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) == sizeof(lzo_uint_fast32_t)) -+#endif -+#if defined(lzo_int64f_t) -+#define lzo_int_fast64_t lzo_int64f_t -+#define lzo_uint_fast64_t lzo_uint64f_t -+#define LZO_SIZEOF_LZO_INT_FAST64_T LZO_SIZEOF_LZO_INT64F_T -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) >= 8) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast64_t)) -+#endif -+#if !defined(LZO_INT16_C) -+# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 2) -+# define LZO_INT16_C(c) ((c) + 0) -+# define LZO_UINT16_C(c) ((c) + 0U) -+# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 2) -+# define LZO_INT16_C(c) ((c) + 0L) -+# define LZO_UINT16_C(c) ((c) + 0UL) -+# elif (LZO_SIZEOF_INT >= 2) -+# define LZO_INT16_C(c) (c) -+# define LZO_UINT16_C(c) (c##U) -+# elif (LZO_SIZEOF_LONG >= 2) -+# define LZO_INT16_C(c) (c##L) -+# define LZO_UINT16_C(c) (c##UL) -+# else -+# error "LZO_INT16_C" -+# endif -+#endif -+#if !defined(LZO_INT32_C) -+# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 4) -+# define LZO_INT32_C(c) ((c) + 0) -+# define LZO_UINT32_C(c) ((c) + 0U) -+# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 4) -+# define LZO_INT32_C(c) ((c) + 0L) -+# define LZO_UINT32_C(c) ((c) + 0UL) -+# elif (LZO_SIZEOF_INT >= 4) -+# define LZO_INT32_C(c) (c) -+# define LZO_UINT32_C(c) (c##U) -+# elif (LZO_SIZEOF_LONG >= 4) -+# define LZO_INT32_C(c) (c##L) -+# define LZO_UINT32_C(c) (c##UL) -+# elif (LZO_SIZEOF_LONG_LONG >= 4) -+# define LZO_INT32_C(c) (c##LL) -+# define LZO_UINT32_C(c) (c##ULL) -+# else -+# error "LZO_INT32_C" -+# endif -+#endif -+#if !defined(LZO_INT64_C) && defined(lzo_int64l_t) -+# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 8) -+# define LZO_INT64_C(c) ((c) + 0) -+# define LZO_UINT64_C(c) ((c) + 0U) -+# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 8) -+# define LZO_INT64_C(c) ((c) + 0L) -+# define LZO_UINT64_C(c) ((c) + 0UL) -+# elif (LZO_SIZEOF_INT >= 8) -+# define LZO_INT64_C(c) (c) -+# define LZO_UINT64_C(c) (c##U) -+# elif (LZO_SIZEOF_LONG >= 8) -+# define LZO_INT64_C(c) (c##L) -+# define LZO_UINT64_C(c) (c##UL) -+# else -+# error "LZO_INT64_C" -+# endif -+#endif -+#endif - - #endif /* already included */ - --/* vim:set ts=4 et: */ -+/* vim:set ts=4 sw=4 et: */ -diff --git a/grub-core/lib/minilzo/minilzo.c b/grub-core/lib/minilzo/minilzo.c -index 25a1f68..ab2be5f 100644 ---- a/grub-core/lib/minilzo/minilzo.c -+++ b/grub-core/lib/minilzo/minilzo.c -@@ -2,22 +2,7 @@ - - This file is part of the LZO real-time data compression library. - -- Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer -+ Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer - All Rights Reserved. - - The LZO library is free software; you can redistribute it and/or -@@ -67,12 +52,6 @@ - #if defined(__CYGWIN32__) && !defined(__CYGWIN__) - # define __CYGWIN__ __CYGWIN32__ - #endif --#if defined(__IBMCPP__) && !defined(__IBMC__) --# define __IBMC__ __IBMCPP__ --#endif --#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER) --# define __INTEL_COMPILER __ICL --#endif - #if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE) - # define _ALL_SOURCE 1 - #endif -@@ -81,19 +60,30 @@ - # define __LONG_MAX__ 9223372036854775807L - # endif - #endif --#if defined(__INTEL_COMPILER) && defined(__linux__) -+#if !defined(LZO_CFG_NO_DISABLE_WUNDEF) -+#if defined(__ARMCC_VERSION) -+# pragma diag_suppress 193 -+#elif defined(__clang__) && defined(__clang_minor__) -+# pragma clang diagnostic ignored "-Wundef" -+#elif defined(__INTEL_COMPILER) - # pragma warning(disable: 193) --#endif --#if defined(__KEIL__) && defined(__C166__) --# pragma warning disable = 322 --#elif 0 && defined(__C251__) -+#elif defined(__KEIL__) && defined(__C166__) - # pragma warning disable = 322 --#endif --#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) --# if (_MSC_VER >= 1300) -+#elif defined(__GNUC__) && defined(__GNUC_MINOR__) && !defined(__PATHSCALE__) -+# if ((__GNUC__-0) >= 5 || ((__GNUC__-0) == 4 && (__GNUC_MINOR__-0) >= 2)) -+# pragma GCC diagnostic ignored "-Wundef" -+# endif -+#elif defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) -+# if ((_MSC_VER-0) >= 1300) - # pragma warning(disable: 4668) - # endif - #endif -+#endif -+#if 0 && defined(__POCC__) && defined(_WIN32) -+# if (__POCC__ >= 400) -+# pragma warn(disable: 2216) -+# endif -+#endif - #if 0 && defined(__WATCOMC__) - # if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060) - # pragma warning 203 9 -@@ -102,13 +92,29 @@ - #if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__) - # pragma option -h - #endif -+#if !(LZO_CFG_NO_DISABLE_WCRTNONSTDC) -+#ifndef _CRT_NONSTDC_NO_DEPRECATE -+#define _CRT_NONSTDC_NO_DEPRECATE 1 -+#endif -+#ifndef _CRT_NONSTDC_NO_WARNINGS -+#define _CRT_NONSTDC_NO_WARNINGS 1 -+#endif -+#ifndef _CRT_SECURE_NO_DEPRECATE -+#define _CRT_SECURE_NO_DEPRECATE 1 -+#endif -+#ifndef _CRT_SECURE_NO_WARNINGS -+#define _CRT_SECURE_NO_WARNINGS 1 -+#endif -+#endif - #if 0 --#define LZO_0xffffL 0xfffful --#define LZO_0xffffffffL 0xfffffffful -+#define LZO_0xffffUL 0xfffful -+#define LZO_0xffffffffUL 0xfffffffful - #else --#define LZO_0xffffL 65535ul --#define LZO_0xffffffffL 4294967295ul -+#define LZO_0xffffUL 65535ul -+#define LZO_0xffffffffUL 4294967295ul - #endif -+#define LZO_0xffffL LZO_0xffffUL -+#define LZO_0xffffffffL LZO_0xffffffffUL - #if (LZO_0xffffL == LZO_0xffffffffL) - # error "your preprocessor is broken 1" - #endif -@@ -123,6 +129,13 @@ - # error "your preprocessor is broken 4" - #endif - #endif -+#if defined(__COUNTER__) -+# ifndef LZO_CFG_USE_COUNTER -+# define LZO_CFG_USE_COUNTER 1 -+# endif -+#else -+# undef LZO_CFG_USE_COUNTER -+#endif - #if (UINT_MAX == LZO_0xffffL) - #if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__) - # if !defined(MSDOS) -@@ -253,14 +266,31 @@ - #endif - #define LZO_PP_STRINGIZE(x) #x - #define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x) -+#define LZO_PP_CONCAT0() /*empty*/ -+#define LZO_PP_CONCAT1(a) a - #define LZO_PP_CONCAT2(a,b) a ## b - #define LZO_PP_CONCAT3(a,b,c) a ## b ## c - #define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d - #define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e -+#define LZO_PP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f -+#define LZO_PP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g -+#define LZO_PP_ECONCAT0() LZO_PP_CONCAT0() -+#define LZO_PP_ECONCAT1(a) LZO_PP_CONCAT1(a) - #define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b) - #define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c) - #define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d) - #define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e) -+#define LZO_PP_ECONCAT6(a,b,c,d,e,f) LZO_PP_CONCAT6(a,b,c,d,e,f) -+#define LZO_PP_ECONCAT7(a,b,c,d,e,f,g) LZO_PP_CONCAT7(a,b,c,d,e,f,g) -+#define LZO_PP_EMPTY /*empty*/ -+#define LZO_PP_EMPTY0() /*empty*/ -+#define LZO_PP_EMPTY1(a) /*empty*/ -+#define LZO_PP_EMPTY2(a,b) /*empty*/ -+#define LZO_PP_EMPTY3(a,b,c) /*empty*/ -+#define LZO_PP_EMPTY4(a,b,c,d) /*empty*/ -+#define LZO_PP_EMPTY5(a,b,c,d,e) /*empty*/ -+#define LZO_PP_EMPTY6(a,b,c,d,e,f) /*empty*/ -+#define LZO_PP_EMPTY7(a,b,c,d,e,f,g) /*empty*/ - #if 1 - #define LZO_CPP_STRINGIZE(x) #x - #define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x) -@@ -268,12 +298,16 @@ - #define LZO_CPP_CONCAT3(a,b,c) a ## b ## c - #define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d - #define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e -+#define LZO_CPP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f -+#define LZO_CPP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g - #define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b) - #define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c) - #define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d) - #define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e) -+#define LZO_CPP_ECONCAT6(a,b,c,d,e,f) LZO_CPP_CONCAT6(a,b,c,d,e,f) -+#define LZO_CPP_ECONCAT7(a,b,c,d,e,f,g) LZO_CPP_CONCAT7(a,b,c,d,e,f,g) - #endif --#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o)) -+#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-!!(b))) - (o)) << 1) + (o)*!!(b)) - #if 1 && defined(__cplusplus) - # if !defined(__STDC_CONSTANT_MACROS) - # define __STDC_CONSTANT_MACROS 1 -@@ -283,9 +317,13 @@ - # endif - #endif - #if defined(__cplusplus) --# define LZO_EXTERN_C extern "C" -+# define LZO_EXTERN_C extern "C" -+# define LZO_EXTERN_C_BEGIN extern "C" { -+# define LZO_EXTERN_C_END } - #else --# define LZO_EXTERN_C extern -+# define LZO_EXTERN_C extern -+# define LZO_EXTERN_C_BEGIN /*empty*/ -+# define LZO_EXTERN_C_END /*empty*/ - #endif - #if !defined(__LZO_OS_OVERRIDE) - #if (LZO_OS_FREESTANDING) -@@ -386,12 +424,12 @@ - #elif defined(__VMS) - # define LZO_OS_VMS 1 - # define LZO_INFO_OS "vms" --#elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) -+#elif (defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__) - # define LZO_OS_CONSOLE 1 - # define LZO_OS_CONSOLE_PS2 1 - # define LZO_INFO_OS "console" - # define LZO_INFO_OS_CONSOLE "ps2" --#elif (defined(__mips__) && defined(__psp__)) -+#elif defined(__mips__) && defined(__psp__) - # define LZO_OS_CONSOLE 1 - # define LZO_OS_CONSOLE_PSP 1 - # define LZO_INFO_OS "console" -@@ -419,9 +457,18 @@ - # elif defined(__linux__) || defined(__linux) || defined(__LINUX__) - # define LZO_OS_POSIX_LINUX 1 - # define LZO_INFO_OS_POSIX "linux" --# elif defined(__APPLE__) || defined(__MACOS__) --# define LZO_OS_POSIX_MACOSX 1 --# define LZO_INFO_OS_POSIX "macosx" -+# elif defined(__APPLE__) && defined(__MACH__) -+# if ((__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__-0) >= 20000) -+# define LZO_OS_POSIX_DARWIN 1040 -+# define LZO_INFO_OS_POSIX "darwin_iphone" -+# elif ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0) >= 1040) -+# define LZO_OS_POSIX_DARWIN __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ -+# define LZO_INFO_OS_POSIX "darwin" -+# else -+# define LZO_OS_POSIX_DARWIN 1 -+# define LZO_INFO_OS_POSIX "darwin" -+# endif -+# define LZO_OS_POSIX_MACOSX LZO_OS_POSIX_DARWIN - # elif defined(__minix__) || defined(__minix) - # define LZO_OS_POSIX_MINIX 1 - # define LZO_INFO_OS_POSIX "minix" -@@ -456,18 +503,18 @@ - #endif - #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) - # if (UINT_MAX != LZO_0xffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - # if (ULONG_MAX != LZO_0xffffffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - #endif - #if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64) - # if (UINT_MAX != LZO_0xffffffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - # if (ULONG_MAX != LZO_0xffffffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - #endif - #if defined(CIL) && defined(_GNUCC) && defined(__GNUC__) -@@ -483,59 +530,65 @@ - # define LZO_INFO_CC "sdcc" - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC) - #elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__) --# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__) -+# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + (__PATHCC_MINOR__-0) * 0x100 + (__PATHCC_PATCHLEVEL__-0)) - # define LZO_INFO_CC "Pathscale C" - # define LZO_INFO_CCVER __PATHSCALE__ --#elif defined(__INTEL_COMPILER) --# define LZO_CC_INTELC 1 -+# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -+# define LZO_CC_PATHSCALE_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) -+# endif -+#elif defined(__INTEL_COMPILER) && ((__INTEL_COMPILER-0) > 0) -+# define LZO_CC_INTELC __INTEL_COMPILER - # define LZO_INFO_CC "Intel C" - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER) --# if defined(_WIN32) || defined(_WIN64) --# define LZO_CC_SYNTAX_MSC 1 --# else --# define LZO_CC_SYNTAX_GNUC 1 -+# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) -+# define LZO_CC_INTELC_MSC _MSC_VER -+# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -+# define LZO_CC_INTELC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) - # endif - #elif defined(__POCC__) && defined(_WIN32) - # define LZO_CC_PELLESC 1 - # define LZO_INFO_CC "Pelles C" - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__) --#elif defined(__clang__) && defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -+#elif defined(__ARMCC_VERSION) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) - # if defined(__GNUC_PATCHLEVEL__) --# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) -+# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) - # else --# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) -+# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) - # endif -+# define LZO_CC_ARMCC __ARMCC_VERSION -+# define LZO_INFO_CC "ARM C Compiler" -+# define LZO_INFO_CCVER __VERSION__ -+#elif defined(__clang__) && defined(__llvm__) && defined(__VERSION__) - # if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) --# define LZO_CC_CLANG_CLANG (__clang_major__ * 0x10000L + __clang_minor__ * 0x100 + __clang_patchlevel__) -+# define LZO_CC_CLANG (__clang_major__ * 0x10000L + (__clang_minor__-0) * 0x100 + (__clang_patchlevel__-0)) - # else --# define LZO_CC_CLANG_CLANG 0x010000L -+# define LZO_CC_CLANG 0x010000L -+# endif -+# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) -+# define LZO_CC_CLANG_MSC _MSC_VER -+# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -+# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) - # endif --# define LZO_CC_CLANG LZO_CC_CLANG_GNUC - # define LZO_INFO_CC "clang" - # define LZO_INFO_CCVER __VERSION__ - #elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) - # if defined(__GNUC_PATCHLEVEL__) --# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) -+# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) - # else --# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) -+# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) - # endif - # define LZO_CC_LLVM LZO_CC_LLVM_GNUC - # define LZO_INFO_CC "llvm-gcc" - # define LZO_INFO_CCVER __VERSION__ --#elif defined(__GNUC__) && defined(__VERSION__) --# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) --# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) --# elif defined(__GNUC_MINOR__) --# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) --# else --# define LZO_CC_GNUC (__GNUC__ * 0x10000L) --# endif --# define LZO_INFO_CC "gcc" --# define LZO_INFO_CCVER __VERSION__ - #elif defined(__ACK__) && defined(_ACK) - # define LZO_CC_ACK 1 - # define LZO_INFO_CC "Amsterdam Compiler Kit C" - # define LZO_INFO_CCVER "unknown" -+#elif defined(__ARMCC_VERSION) && !defined(__GNUC__) -+# define LZO_CC_ARMCC __ARMCC_VERSION -+# define LZO_CC_ARMCC_ARMCC __ARMCC_VERSION -+# define LZO_INFO_CC "ARM C Compiler" -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ARMCC_VERSION) - #elif defined(__AZTEC_C__) - # define LZO_CC_AZTECC 1 - # define LZO_INFO_CC "Aztec C" -@@ -560,10 +613,23 @@ - # define LZO_CC_DECC 1 - # define LZO_INFO_CC "DEC C" - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC) -+#elif (defined(__ghs) || defined(__ghs__)) && defined(__GHS_VERSION_NUMBER) && ((__GHS_VERSION_NUMBER-0) > 0) -+# define LZO_CC_GHS 1 -+# define LZO_INFO_CC "Green Hills C" -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__GHS_VERSION_NUMBER) -+# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) -+# define LZO_CC_GHS_MSC _MSC_VER -+# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -+# define LZO_CC_GHS_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) -+# endif - #elif defined(__HIGHC__) - # define LZO_CC_HIGHC 1 - # define LZO_INFO_CC "MetaWare High C" - # define LZO_INFO_CCVER "unknown" -+#elif defined(__HP_aCC) && ((__HP_aCC-0) > 0) -+# define LZO_CC_HPACC __HP_aCC -+# define LZO_INFO_CC "HP aCC" -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__HP_aCC) - #elif defined(__IAR_SYSTEMS_ICC__) - # define LZO_CC_IARC 1 - # define LZO_INFO_CC "IAR C" -@@ -572,10 +638,14 @@ - # else - # define LZO_INFO_CCVER "unknown" - # endif --#elif defined(__IBMC__) --# define LZO_CC_IBMC 1 -+#elif defined(__IBMC__) && ((__IBMC__-0) > 0) -+# define LZO_CC_IBMC __IBMC__ - # define LZO_INFO_CC "IBM C" - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__) -+#elif defined(__IBMCPP__) && ((__IBMCPP__-0) > 0) -+# define LZO_CC_IBMC __IBMCPP__ -+# define LZO_INFO_CC "IBM C" -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMCPP__) - #elif defined(__KEIL__) && defined(__C166__) - # define LZO_CC_KEILC 1 - # define LZO_INFO_CC "Keil C" -@@ -592,16 +662,8 @@ - # else - # define LZO_INFO_CCVER "unknown" - # endif --#elif defined(_MSC_VER) --# define LZO_CC_MSC 1 --# define LZO_INFO_CC "Microsoft C" --# if defined(_MSC_FULL_VER) --# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) --# else --# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) --# endif --#elif defined(__MWERKS__) --# define LZO_CC_MWERKS 1 -+#elif defined(__MWERKS__) && ((__MWERKS__-0) > 0) -+# define LZO_CC_MWERKS __MWERKS__ - # define LZO_INFO_CC "Metrowerks C" - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__) - #elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386) -@@ -612,6 +674,15 @@ - # define LZO_CC_PACIFICC 1 - # define LZO_INFO_CC "Pacific C" - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__) -+#elif defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) -+# if defined(__PGIC_PATCHLEVEL__) -+# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100 + (__PGIC_PATCHLEVEL__-0)) -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) "." LZO_PP_MACRO_EXPAND(__PGIC_PATCHLEVEL__) -+# else -+# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100) -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) ".0" -+# endif -+# define LZO_INFO_CC "Portland Group PGI C" - #elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__)) - # define LZO_CC_PGI 1 - # define LZO_INFO_CC "Portland Group PGI C" -@@ -626,7 +697,7 @@ - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__) - #elif defined(__SUNPRO_C) - # define LZO_INFO_CC "SunPro C" --# if ((__SUNPRO_C)+0 > 0) -+# if ((__SUNPRO_C-0) > 0) - # define LZO_CC_SUNPROC __SUNPRO_C - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C) - # else -@@ -635,7 +706,7 @@ - # endif - #elif defined(__SUNPRO_CC) - # define LZO_INFO_CC "SunPro C" --# if ((__SUNPRO_CC)+0 > 0) -+# if ((__SUNPRO_CC-0) > 0) - # define LZO_CC_SUNPROC __SUNPRO_CC - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC) - # else -@@ -661,16 +732,46 @@ - #elif defined(__ZTC__) - # define LZO_CC_ZORTECHC 1 - # define LZO_INFO_CC "Zortech C" --# if (__ZTC__ == 0x310) -+# if ((__ZTC__-0) == 0x310) - # define LZO_INFO_CCVER "0x310" - # else - # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__) - # endif -+#elif defined(__GNUC__) && defined(__VERSION__) -+# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) -+# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) -+# elif defined(__GNUC_MINOR__) -+# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) -+# else -+# define LZO_CC_GNUC (__GNUC__ * 0x10000L) -+# endif -+# define LZO_INFO_CC "gcc" -+# define LZO_INFO_CCVER __VERSION__ -+#elif defined(_MSC_VER) && ((_MSC_VER-0) > 0) -+# define LZO_CC_MSC _MSC_VER -+# define LZO_INFO_CC "Microsoft C" -+# if defined(_MSC_FULL_VER) -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) -+# else -+# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) -+# endif - #else - # define LZO_CC_UNKNOWN 1 - # define LZO_INFO_CC "unknown" - # define LZO_INFO_CCVER "unknown" - #endif -+#if (LZO_CC_GNUC) && defined(__OPEN64__) -+# if defined(__OPENCC__) && defined(__OPENCC_MINOR__) && defined(__OPENCC_PATCHLEVEL__) -+# define LZO_CC_OPEN64 (__OPENCC__ * 0x10000L + (__OPENCC_MINOR__-0) * 0x100 + (__OPENCC_PATCHLEVEL__-0)) -+# define LZO_CC_OPEN64_GNUC LZO_CC_GNUC -+# endif -+#endif -+#if (LZO_CC_GNUC) && defined(__PCC__) -+# if defined(__PCC__) && defined(__PCC_MINOR__) && defined(__PCC_MINORMINOR__) -+# define LZO_CC_PCC (__PCC__ * 0x10000L + (__PCC_MINOR__-0) * 0x100 + (__PCC_MINORMINOR__-0)) -+# define LZO_CC_PCC_GNUC LZO_CC_GNUC -+# endif -+#endif - #if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER) - # error "LZO_CC_MSC: _MSC_FULL_VER is not defined" - #endif -@@ -688,8 +789,10 @@ - # define LZO_INFO_ARCH "generic" - #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) - # define LZO_ARCH_I086 1 --# define LZO_ARCH_IA16 1 - # define LZO_INFO_ARCH "i086" -+#elif defined(__aarch64__) -+# define LZO_ARCH_ARM64 1 -+# define LZO_INFO_ARCH "arm64" - #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) - # define LZO_ARCH_ALPHA 1 - # define LZO_INFO_ARCH "alpha" -@@ -705,10 +808,10 @@ - # define LZO_INFO_ARCH "arm_thumb" - #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) - # define LZO_ARCH_ARM 1 --# if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1) -+# if defined(__CPU_MODE__) && ((__CPU_MODE__-0) == 1) - # define LZO_ARCH_ARM_THUMB 1 - # define LZO_INFO_ARCH "arm_thumb" --# elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2) -+# elif defined(__CPU_MODE__) && ((__CPU_MODE__-0) == 2) - # define LZO_INFO_ARCH "arm" - # else - # define LZO_INFO_ARCH "arm" -@@ -826,53 +929,147 @@ - # error "FIXME - missing define for CPU architecture" - #endif - #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32) --# error "FIXME - missing WIN32 define for CPU architecture" -+# error "FIXME - missing LZO_OS_WIN32 define for CPU architecture" - #endif - #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64) --# error "FIXME - missing WIN64 define for CPU architecture" -+# error "FIXME - missing LZO_OS_WIN64 define for CPU architecture" - #endif - #if (LZO_OS_OS216 || LZO_OS_WIN16) - # define LZO_ARCH_I086PM 1 --# define LZO_ARCH_IA16PM 1 - #elif 1 && (LZO_OS_DOS16 && defined(BLX286)) - # define LZO_ARCH_I086PM 1 --# define LZO_ARCH_IA16PM 1 - #elif 1 && (LZO_OS_DOS16 && defined(DOSX286)) - # define LZO_ARCH_I086PM 1 --# define LZO_ARCH_IA16PM 1 - #elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__)) - # define LZO_ARCH_I086PM 1 --# define LZO_ARCH_IA16PM 1 - #endif --#if (LZO_ARCH_ARM_THUMB) && !(LZO_ARCH_ARM) --# error "this should not happen" -+#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) -+# define LZO_ARCH_X64 1 -+#elif (!LZO_ARCH_AMD64 && LZO_ARCH_X64) && defined(__LZO_ARCH_OVERRIDE) -+# define LZO_ARCH_AMD64 1 -+#endif -+#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) -+# define LZO_ARCH_AARCH64 1 -+#elif (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) && defined(__LZO_ARCH_OVERRIDE) -+# define LZO_ARCH_ARM64 1 -+#endif -+#if (LZO_ARCH_I386 && !LZO_ARCH_X86) -+# define LZO_ARCH_X86 1 -+#elif (!LZO_ARCH_I386 && LZO_ARCH_X86) && defined(__LZO_ARCH_OVERRIDE) -+# define LZO_ARCH_I386 1 -+#endif -+#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) || (!LZO_ARCH_AMD64 && LZO_ARCH_X64) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) || (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ARCH_I386 && !LZO_ARCH_X86) || (!LZO_ARCH_I386 && LZO_ARCH_X86) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ARCH_ARM_THUMB && !LZO_ARCH_ARM) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ARCH_ARM_THUMB1 && !LZO_ARCH_ARM_THUMB) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ARCH_ARM_THUMB2 && !LZO_ARCH_ARM_THUMB) -+# error "unexpected configuration - check your compiler defines" - #endif --#if (LZO_ARCH_I086PM) && !(LZO_ARCH_I086) --# error "this should not happen" -+#if (LZO_ARCH_ARM_THUMB1 && LZO_ARCH_ARM_THUMB2) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ARCH_I086PM && !LZO_ARCH_I086) -+# error "unexpected configuration - check your compiler defines" - #endif - #if (LZO_ARCH_I086) - # if (UINT_MAX != LZO_0xffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - # if (ULONG_MAX != LZO_0xffffffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - #endif - #if (LZO_ARCH_I386) - # if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - # if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - # if (ULONG_MAX != LZO_0xffffffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" -+# endif -+#endif -+#if (LZO_ARCH_AMD64 || LZO_ARCH_I386) -+# if !defined(LZO_TARGET_FEATURE_SSE2) -+# if defined(__SSE2__) -+# define LZO_TARGET_FEATURE_SSE2 1 -+# elif defined(_MSC_VER) && ((defined(_M_IX86_FP) && ((_M_IX86_FP)+0 >= 2)) || defined(_M_AMD64)) -+# define LZO_TARGET_FEATURE_SSE2 1 -+# endif -+# endif -+# if !defined(LZO_TARGET_FEATURE_SSSE3) -+# if (LZO_TARGET_FEATURE_SSE2) -+# if defined(__SSSE3__) -+# define LZO_TARGET_FEATURE_SSSE3 1 -+# elif defined(_MSC_VER) && defined(__AVX__) -+# define LZO_TARGET_FEATURE_SSSE3 1 -+# endif -+# endif -+# endif -+# if !defined(LZO_TARGET_FEATURE_SSE4_2) -+# if (LZO_TARGET_FEATURE_SSSE3) -+# if defined(__SSE4_2__) -+# define LZO_TARGET_FEATURE_SSE4_2 1 -+# endif -+# endif -+# endif -+# if !defined(LZO_TARGET_FEATURE_AVX) -+# if (LZO_TARGET_FEATURE_SSSE3) -+# if defined(__AVX__) -+# define LZO_TARGET_FEATURE_AVX 1 -+# endif -+# endif -+# endif -+# if !defined(LZO_TARGET_FEATURE_AVX2) -+# if (LZO_TARGET_FEATURE_AVX) -+# if defined(__AVX2__) -+# define LZO_TARGET_FEATURE_AVX2 1 -+# endif -+# endif -+# endif -+#endif -+#if (LZO_TARGET_FEATURE_SSSE3 && !(LZO_TARGET_FEATURE_SSE2)) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_TARGET_FEATURE_SSE4_2 && !(LZO_TARGET_FEATURE_SSSE3)) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_TARGET_FEATURE_AVX && !(LZO_TARGET_FEATURE_SSSE3)) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_TARGET_FEATURE_AVX2 && !(LZO_TARGET_FEATURE_AVX)) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ARCH_ARM) -+# if !defined(LZO_TARGET_FEATURE_NEON) -+# if defined(__ARM_NEON__) -+# define LZO_TARGET_FEATURE_NEON 1 -+# endif -+# endif -+#elif (LZO_ARCH_ARM64) -+# if !defined(LZO_TARGET_FEATURE_NEON) -+# if 1 -+# define LZO_TARGET_FEATURE_NEON 1 -+# endif - # endif - #endif --#if !defined(__LZO_MM_OVERRIDE) -+#if 0 -+#elif !defined(__LZO_MM_OVERRIDE) - #if (LZO_ARCH_I086) - #if (UINT_MAX != LZO_0xffffL) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - #endif - #if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) - # define LZO_MM_TINY 1 -@@ -899,7 +1096,7 @@ - #elif (LZO_CC_ZORTECHC && defined(__VCM__)) - # define LZO_MM_LARGE 1 - #else --# error "unknown memory model" -+# error "unknown LZO_ARCH_I086 memory model" - #endif - #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) - #define LZO_HAVE_MM_HUGE_PTR 1 -@@ -922,10 +1119,10 @@ - #endif - #if (LZO_ARCH_I086PM) && !(LZO_HAVE_MM_HUGE_PTR) - # if (LZO_OS_DOS16) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # elif (LZO_CC_ZORTECHC) - # else --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - # endif - #endif - #ifdef __cplusplus -@@ -957,7 +1154,7 @@ extern "C" { - #endif - #elif (LZO_ARCH_C166) - #if !defined(__MODEL__) --# error "FIXME - C166 __MODEL__" -+# error "FIXME - LZO_ARCH_C166 __MODEL__" - #elif ((__MODEL__) == 0) - # define LZO_MM_SMALL 1 - #elif ((__MODEL__) == 1) -@@ -971,11 +1168,11 @@ extern "C" { - #elif ((__MODEL__) == 5) - # define LZO_MM_XSMALL 1 - #else --# error "FIXME - C166 __MODEL__" -+# error "FIXME - LZO_ARCH_C166 __MODEL__" - #endif - #elif (LZO_ARCH_MCS251) - #if !defined(__MODEL__) --# error "FIXME - MCS251 __MODEL__" -+# error "FIXME - LZO_ARCH_MCS251 __MODEL__" - #elif ((__MODEL__) == 0) - # define LZO_MM_SMALL 1 - #elif ((__MODEL__) == 2) -@@ -987,11 +1184,11 @@ extern "C" { - #elif ((__MODEL__) == 5) - # define LZO_MM_XSMALL 1 - #else --# error "FIXME - MCS251 __MODEL__" -+# error "FIXME - LZO_ARCH_MCS251 __MODEL__" - #endif - #elif (LZO_ARCH_MCS51) - #if !defined(__MODEL__) --# error "FIXME - MCS51 __MODEL__" -+# error "FIXME - LZO_ARCH_MCS51 __MODEL__" - #elif ((__MODEL__) == 1) - # define LZO_MM_SMALL 1 - #elif ((__MODEL__) == 2) -@@ -1003,7 +1200,7 @@ extern "C" { - #elif ((__MODEL__) == 5) - # define LZO_MM_XSMALL 1 - #else --# error "FIXME - MCS51 __MODEL__" -+# error "FIXME - LZO_ARCH_MCS51 __MODEL__" - #endif - #elif (LZO_ARCH_CRAY_PVP) - # define LZO_MM_PVP 1 -@@ -1030,462 +1227,270 @@ extern "C" { - # error "unknown memory model" - #endif - #endif --#if defined(SIZEOF_SHORT) --# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) -+#if !defined(__lzo_gnuc_extension__) -+#if (LZO_CC_GNUC >= 0x020800ul) -+# define __lzo_gnuc_extension__ __extension__ -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define __lzo_gnuc_extension__ __extension__ -+#elif (LZO_CC_IBMC >= 600) -+# define __lzo_gnuc_extension__ __extension__ -+#else - #endif --#if defined(SIZEOF_INT) --# define LZO_SIZEOF_INT (SIZEOF_INT) - #endif --#if defined(SIZEOF_LONG) --# define LZO_SIZEOF_LONG (SIZEOF_LONG) -+#if !defined(__lzo_gnuc_extension__) -+# define __lzo_gnuc_extension__ /*empty*/ - #endif --#if defined(SIZEOF_LONG_LONG) --# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) -+#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) && defined(__cplusplus) && 0 -+# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) -+# define LZO_CFG_USE_NEW_STYLE_CASTS 0 -+# elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1200)) -+# define LZO_CFG_USE_NEW_STYLE_CASTS 0 -+# else -+# define LZO_CFG_USE_NEW_STYLE_CASTS 1 -+# endif - #endif --#if defined(SIZEOF___INT16) --# define LZO_SIZEOF___INT16 (SIZEOF___INT16) -+#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) -+# define LZO_CFG_USE_NEW_STYLE_CASTS 0 - #endif --#if defined(SIZEOF___INT32) --# define LZO_SIZEOF___INT32 (SIZEOF___INT32) -+#if !defined(__cplusplus) -+# if defined(LZO_CFG_USE_NEW_STYLE_CASTS) -+# undef LZO_CFG_USE_NEW_STYLE_CASTS -+# endif -+# define LZO_CFG_USE_NEW_STYLE_CASTS 0 - #endif --#if defined(SIZEOF___INT64) --# define LZO_SIZEOF___INT64 (SIZEOF___INT64) -+#if !defined(LZO_REINTERPRET_CAST) -+# if (LZO_CFG_USE_NEW_STYLE_CASTS) -+# define LZO_REINTERPRET_CAST(t,e) (reinterpret_cast (e)) -+# endif - #endif --#if defined(SIZEOF_VOID_P) --# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) -+#if !defined(LZO_REINTERPRET_CAST) -+# define LZO_REINTERPRET_CAST(t,e) ((t) (e)) - #endif --#if defined(SIZEOF_SIZE_T) --# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) -+#if !defined(LZO_STATIC_CAST) -+# if (LZO_CFG_USE_NEW_STYLE_CASTS) -+# define LZO_STATIC_CAST(t,e) (static_cast (e)) -+# endif - #endif --#if defined(SIZEOF_PTRDIFF_T) --# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) -+#if !defined(LZO_STATIC_CAST) -+# define LZO_STATIC_CAST(t,e) ((t) (e)) - #endif --#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) --#if !defined(LZO_SIZEOF_SHORT) --# if (LZO_ARCH_CRAY_PVP) --# define LZO_SIZEOF_SHORT 8 --# elif (USHRT_MAX == LZO_0xffffL) --# define LZO_SIZEOF_SHORT 2 --# elif (__LZO_LSR(USHRT_MAX,7) == 1) --# define LZO_SIZEOF_SHORT 1 --# elif (__LZO_LSR(USHRT_MAX,15) == 1) --# define LZO_SIZEOF_SHORT 2 --# elif (__LZO_LSR(USHRT_MAX,31) == 1) --# define LZO_SIZEOF_SHORT 4 --# elif (__LZO_LSR(USHRT_MAX,63) == 1) --# define LZO_SIZEOF_SHORT 8 --# elif (__LZO_LSR(USHRT_MAX,127) == 1) --# define LZO_SIZEOF_SHORT 16 --# else --# error "LZO_SIZEOF_SHORT" --# endif -+#if !defined(LZO_STATIC_CAST2) -+# define LZO_STATIC_CAST2(t1,t2,e) LZO_STATIC_CAST(t1, LZO_STATIC_CAST(t2, e)) - #endif --#if !defined(LZO_SIZEOF_INT) --# if (LZO_ARCH_CRAY_PVP) --# define LZO_SIZEOF_INT 8 --# elif (UINT_MAX == LZO_0xffffL) --# define LZO_SIZEOF_INT 2 --# elif (UINT_MAX == LZO_0xffffffffL) --# define LZO_SIZEOF_INT 4 --# elif (__LZO_LSR(UINT_MAX,7) == 1) --# define LZO_SIZEOF_INT 1 --# elif (__LZO_LSR(UINT_MAX,15) == 1) --# define LZO_SIZEOF_INT 2 --# elif (__LZO_LSR(UINT_MAX,31) == 1) --# define LZO_SIZEOF_INT 4 --# elif (__LZO_LSR(UINT_MAX,63) == 1) --# define LZO_SIZEOF_INT 8 --# elif (__LZO_LSR(UINT_MAX,127) == 1) --# define LZO_SIZEOF_INT 16 --# else --# error "LZO_SIZEOF_INT" -+#if !defined(LZO_UNCONST_CAST) -+# if (LZO_CFG_USE_NEW_STYLE_CASTS) -+# define LZO_UNCONST_CAST(t,e) (const_cast (e)) -+# elif (LZO_HAVE_MM_HUGE_PTR) -+# define LZO_UNCONST_CAST(t,e) ((t) (e)) -+# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((const void *) (e))))) - # endif - #endif --#if !defined(LZO_SIZEOF_LONG) --# if (ULONG_MAX == LZO_0xffffffffL) --# define LZO_SIZEOF_LONG 4 --# elif (__LZO_LSR(ULONG_MAX,7) == 1) --# define LZO_SIZEOF_LONG 1 --# elif (__LZO_LSR(ULONG_MAX,15) == 1) --# define LZO_SIZEOF_LONG 2 --# elif (__LZO_LSR(ULONG_MAX,31) == 1) --# define LZO_SIZEOF_LONG 4 --# elif (__LZO_LSR(ULONG_MAX,63) == 1) --# define LZO_SIZEOF_LONG 8 --# elif (__LZO_LSR(ULONG_MAX,127) == 1) --# define LZO_SIZEOF_LONG 16 --# else --# error "LZO_SIZEOF_LONG" -+#if !defined(LZO_UNCONST_CAST) -+# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((const void *) (e)))) -+#endif -+#if !defined(LZO_UNCONST_VOLATILE_CAST) -+# if (LZO_CFG_USE_NEW_STYLE_CASTS) -+# define LZO_UNCONST_VOLATILE_CAST(t,e) (const_cast (e)) -+# elif (LZO_HAVE_MM_HUGE_PTR) -+# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) (e)) -+# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) - # endif - #endif --#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) --#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) --# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) --# if (LZO_CC_GNUC >= 0x030300ul) --# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) --# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG --# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) --# define LZO_SIZEOF_LONG_LONG 4 --# endif --# endif -+#if !defined(LZO_UNCONST_VOLATILE_CAST) -+# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((volatile const void *) (e)))) -+#endif -+#if !defined(LZO_UNVOLATILE_CAST) -+# if (LZO_CFG_USE_NEW_STYLE_CASTS) -+# define LZO_UNVOLATILE_CAST(t,e) (const_cast (e)) -+# elif (LZO_HAVE_MM_HUGE_PTR) -+# define LZO_UNVOLATILE_CAST(t,e) ((t) (e)) -+# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((volatile void *) (e))))) - # endif - #endif -+#if !defined(LZO_UNVOLATILE_CAST) -+# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((volatile void *) (e)))) - #endif --#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) --#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) --#if (LZO_ARCH_I086 && LZO_CC_DMC) --#elif (LZO_CC_CILLY) && defined(__GNUC__) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define LZO_SIZEOF_LONG_LONG 8 --#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (LZO_OS_WIN64 || defined(_WIN64)) --# define LZO_SIZEOF___INT64 8 --#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) --# define LZO_SIZEOF___INT64 8 --#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) --# define LZO_SIZEOF___INT64 8 --#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) --# define LZO_SIZEOF___INT64 8 --#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) --# define LZO_SIZEOF___INT64 8 --#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64)) --# define LZO_SIZEOF___INT64 8 --#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) --# define LZO_SIZEOF_LONG_LONG 8 --#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) --#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) --# define LZO_SIZEOF_LONG_LONG 8 -+#if !defined(LZO_UNVOLATILE_CONST_CAST) -+# if (LZO_CFG_USE_NEW_STYLE_CASTS) -+# define LZO_UNVOLATILE_CONST_CAST(t,e) (const_cast (e)) -+# elif (LZO_HAVE_MM_HUGE_PTR) -+# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) (e)) -+# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) -+# endif - #endif -+#if !defined(LZO_UNVOLATILE_CONST_CAST) -+# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((volatile const void *) (e)))) - #endif -+#if !defined(LZO_PCAST) -+# if (LZO_HAVE_MM_HUGE_PTR) -+# define LZO_PCAST(t,e) ((t) (e)) -+# endif - #endif --#if defined(__cplusplus) && (LZO_CC_GNUC) --# if (LZO_CC_GNUC < 0x020800ul) --# undef LZO_SIZEOF_LONG_LONG -+#if !defined(LZO_PCAST) -+# define LZO_PCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(void *, e)) -+#endif -+#if !defined(LZO_CCAST) -+# if (LZO_HAVE_MM_HUGE_PTR) -+# define LZO_CCAST(t,e) ((t) (e)) - # endif - #endif --#if (LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG) --# undef LZO_SIZEOF_LONG_LONG -+#if !defined(LZO_CCAST) -+# define LZO_CCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(const void *, e)) - #endif --#if !defined(LZO_SIZEOF_VOID_P) --#if (LZO_ARCH_I086) --# define __LZO_WORDSIZE 2 --# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) --# define LZO_SIZEOF_VOID_P 2 --# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) --# define LZO_SIZEOF_VOID_P 4 --# else --# error "LZO_MM" -+#if !defined(LZO_ICONV) -+# define LZO_ICONV(t,e) LZO_STATIC_CAST(t, e) -+#endif -+#if !defined(LZO_ICAST) -+# define LZO_ICAST(t,e) LZO_STATIC_CAST(t, e) -+#endif -+#if !defined(LZO_ITRUNC) -+# define LZO_ITRUNC(t,e) LZO_STATIC_CAST(t, e) -+#endif -+#if !defined(__lzo_cte) -+# if (LZO_CC_MSC || LZO_CC_WATCOMC) -+# define __lzo_cte(e) ((void)0,(e)) -+# elif 1 -+# define __lzo_cte(e) ((void)0,(e)) - # endif --#elif (LZO_ARCH_AVR || LZO_ARCH_Z80) --# define __LZO_WORDSIZE 1 --# define LZO_SIZEOF_VOID_P 2 --#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) --# define LZO_SIZEOF_VOID_P 2 --#elif (LZO_ARCH_H8300) --# if defined(__NORMAL_MODE__) --# define __LZO_WORDSIZE 4 --# define LZO_SIZEOF_VOID_P 2 --# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) --# define __LZO_WORDSIZE 4 --# define LZO_SIZEOF_VOID_P 4 --# else --# define __LZO_WORDSIZE 2 --# define LZO_SIZEOF_VOID_P 2 --# endif --# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) --# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT --# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT --# endif --#elif (LZO_ARCH_M16C) --# define __LZO_WORDSIZE 2 --# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) --# define LZO_SIZEOF_VOID_P 4 --# else --# define LZO_SIZEOF_VOID_P 2 --# endif --#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) --# define __LZO_WORDSIZE 8 --# define LZO_SIZEOF_VOID_P 4 --#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) --# define __LZO_WORDSIZE 8 --# define LZO_SIZEOF_VOID_P 8 --#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) --# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG --# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG --# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG --#elif (LZO_OS_OS400 || defined(__OS400__)) --# define __LZO_WORDSIZE LZO_SIZEOF_LONG --# define LZO_SIZEOF_VOID_P 16 --# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG --# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG --#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) --# define LZO_SIZEOF_VOID_P 8 --# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG --# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG --#elif (LZO_ARCH_SPU) --# if 0 --# define __LZO_WORDSIZE 16 --# endif --# define LZO_SIZEOF_VOID_P 4 --#else --# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG - #endif -+#if !defined(__lzo_cte) -+# define __lzo_cte(e) (e) - #endif --#if !defined(LZO_WORDSIZE) --# if defined(__LZO_WORDSIZE) --# define LZO_WORDSIZE __LZO_WORDSIZE -+#if !defined(LZO_BLOCK_BEGIN) -+# define LZO_BLOCK_BEGIN do { -+# define LZO_BLOCK_END } while __lzo_cte(0) -+#endif -+#if !defined(LZO_UNUSED) -+# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) -+# define LZO_UNUSED(var) ((void) &var) -+# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) -+# define LZO_UNUSED(var) if (&var) ; else -+# elif (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x030200ul)) -+# define LZO_UNUSED(var) ((void) &var) -+# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define LZO_UNUSED(var) ((void) var) -+# elif (LZO_CC_MSC && (_MSC_VER < 900)) -+# define LZO_UNUSED(var) if (&var) ; else -+# elif (LZO_CC_KEILC) -+# define LZO_UNUSED(var) {LZO_EXTERN_C int lzo_unused__[1-2*!(sizeof(var)>0)];} -+# elif (LZO_CC_PACIFICC) -+# define LZO_UNUSED(var) ((void) sizeof(var)) -+# elif (LZO_CC_WATCOMC) && defined(__cplusplus) -+# define LZO_UNUSED(var) ((void) var) - # else --# define LZO_WORDSIZE LZO_SIZEOF_VOID_P -+# define LZO_UNUSED(var) ((void) &var) - # endif - #endif --#if !defined(LZO_SIZEOF_SIZE_T) --#if (LZO_ARCH_I086 || LZO_ARCH_M16C) --# define LZO_SIZEOF_SIZE_T 2 --#else --# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P --#endif --#endif --#if !defined(LZO_SIZEOF_PTRDIFF_T) --#if (LZO_ARCH_I086) --# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) --# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P --# elif (LZO_MM_COMPACT || LZO_MM_LARGE) --# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) --# define LZO_SIZEOF_PTRDIFF_T 4 --# else --# define LZO_SIZEOF_PTRDIFF_T 2 --# endif -+#if !defined(LZO_UNUSED_FUNC) -+# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) -+# define LZO_UNUSED_FUNC(func) ((void) func) -+# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) -+# define LZO_UNUSED_FUNC(func) if (func) ; else -+# elif (LZO_CC_CLANG || LZO_CC_LLVM) -+# define LZO_UNUSED_FUNC(func) ((void) &func) -+# elif (LZO_CC_MSC && (_MSC_VER < 900)) -+# define LZO_UNUSED_FUNC(func) if (func) ; else -+# elif (LZO_CC_MSC) -+# define LZO_UNUSED_FUNC(func) ((void) &func) -+# elif (LZO_CC_KEILC || LZO_CC_PELLESC) -+# define LZO_UNUSED_FUNC(func) {LZO_EXTERN_C int lzo_unused_func__[1-2*!(sizeof((int)func)>0)];} - # else --# error "LZO_MM" -+# define LZO_UNUSED_FUNC(func) ((void) func) - # endif --#else --# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T --#endif - #endif --#if (LZO_ABI_NEUTRAL_ENDIAN) --# undef LZO_ABI_BIG_ENDIAN --# undef LZO_ABI_LITTLE_ENDIAN --#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) --#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) --# define LZO_ABI_BIG_ENDIAN 1 --#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) --# define LZO_ABI_LITTLE_ENDIAN 1 --#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) --# define LZO_ABI_LITTLE_ENDIAN 1 --#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390) --# define LZO_ABI_BIG_ENDIAN 1 --#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) --# if (__LITTLE_ENDIAN__ == 1) --# define LZO_ABI_LITTLE_ENDIAN 1 -+#if !defined(LZO_UNUSED_LABEL) -+# if (LZO_CC_CLANG >= 0x020800ul) -+# define LZO_UNUSED_LABEL(l) (__lzo_gnuc_extension__ ((void) ((const void *) &&l))) -+# elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) -+# define LZO_UNUSED_LABEL(l) if __lzo_cte(0) goto l - # else --# define LZO_ABI_BIG_ENDIAN 1 -+# define LZO_UNUSED_LABEL(l) switch (0) case 1:goto l - # endif --#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) --# define LZO_ABI_BIG_ENDIAN 1 --#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) --# define LZO_ABI_LITTLE_ENDIAN 1 --#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) --# define LZO_ABI_BIG_ENDIAN 1 --#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) --# define LZO_ABI_LITTLE_ENDIAN 1 --#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) --# define LZO_ABI_BIG_ENDIAN 1 --#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) --# define LZO_ABI_LITTLE_ENDIAN 1 --#endif --#endif --#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) --# error "this should not happen" --#endif --#if (LZO_ABI_BIG_ENDIAN) --# define LZO_INFO_ABI_ENDIAN "be" --#elif (LZO_ABI_LITTLE_ENDIAN) --# define LZO_INFO_ABI_ENDIAN "le" --#elif (LZO_ABI_NEUTRAL_ENDIAN) --# define LZO_INFO_ABI_ENDIAN "neutral" --#endif --#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) --# define LZO_ABI_I8LP16 1 --# define LZO_INFO_ABI_PM "i8lp16" --#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) --# define LZO_ABI_ILP16 1 --# define LZO_INFO_ABI_PM "ilp16" --#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) --# define LZO_ABI_ILP32 1 --# define LZO_INFO_ABI_PM "ilp32" --#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) --# define LZO_ABI_LLP64 1 --# define LZO_INFO_ABI_PM "llp64" --#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) --# define LZO_ABI_LP64 1 --# define LZO_INFO_ABI_PM "lp64" --#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) --# define LZO_ABI_ILP64 1 --# define LZO_INFO_ABI_PM "ilp64" --#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) --# define LZO_ABI_IP32L64 1 --# define LZO_INFO_ABI_PM "ip32l64" - #endif --#if !defined(__LZO_LIBC_OVERRIDE) --#if (LZO_LIBC_NAKED) --# define LZO_INFO_LIBC "naked" --#elif (LZO_LIBC_FREESTANDING) --# define LZO_INFO_LIBC "freestanding" --#elif (LZO_LIBC_MOSTLY_FREESTANDING) --# define LZO_INFO_LIBC "mfreestanding" --#elif (LZO_LIBC_ISOC90) --# define LZO_INFO_LIBC "isoc90" --#elif (LZO_LIBC_ISOC99) --# define LZO_INFO_LIBC "isoc99" --#elif defined(__dietlibc__) --# define LZO_LIBC_DIETLIBC 1 --# define LZO_INFO_LIBC "dietlibc" --#elif defined(_NEWLIB_VERSION) --# define LZO_LIBC_NEWLIB 1 --# define LZO_INFO_LIBC "newlib" --#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) --# if defined(__UCLIBC_SUBLEVEL__) --# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__) -+#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) -+# if 0 -+# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var -+# elif 0 && (LZO_CC_GNUC) -+# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var - # else --# define LZO_LIBC_UCLIBC 0x00090bL -+# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init - # endif --# define LZO_INFO_LIBC "uclibc" --#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) --# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100) --# define LZO_INFO_LIBC "glibc" --#elif (LZO_CC_MWERKS) && defined(__MSL__) --# define LZO_LIBC_MSL __MSL__ --# define LZO_INFO_LIBC "msl" --#elif 1 && defined(__IAR_SYSTEMS_ICC__) --# define LZO_LIBC_ISOC90 1 --# define LZO_INFO_LIBC "isoc90" --#else --# define LZO_LIBC_DEFAULT 1 --# define LZO_INFO_LIBC "default" --#endif --#endif --#if !defined(__lzo_gnuc_extension__) --#if (LZO_CC_GNUC >= 0x020800ul) --# define __lzo_gnuc_extension__ __extension__ --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define __lzo_gnuc_extension__ __extension__ --#else --# define __lzo_gnuc_extension__ /*empty*/ --#endif --#endif --#if !defined(__lzo_ua_volatile) --# define __lzo_ua_volatile volatile --#endif --#if !defined(__lzo_alignof) --#if (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) --# define __lzo_alignof(e) __alignof__(e) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) --# define __lzo_alignof(e) __alignof__(e) --#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) --# define __lzo_alignof(e) __alignof(e) --#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) --# define __lzo_alignof(e) __alignof__(e) --#endif --#endif --#if defined(__lzo_alignof) --# define __lzo_HAVE_alignof 1 --#endif --#if !defined(__lzo_constructor) --#if (LZO_CC_GNUC >= 0x030400ul) --# define __lzo_constructor __attribute__((__constructor__,__used__)) --#elif (LZO_CC_GNUC >= 0x020700ul) --# define __lzo_constructor __attribute__((__constructor__)) --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define __lzo_constructor __attribute__((__constructor__)) --#endif --#endif --#if defined(__lzo_constructor) --# define __lzo_HAVE_constructor 1 --#endif --#if !defined(__lzo_destructor) --#if (LZO_CC_GNUC >= 0x030400ul) --# define __lzo_destructor __attribute__((__destructor__,__used__)) --#elif (LZO_CC_GNUC >= 0x020700ul) --# define __lzo_destructor __attribute__((__destructor__)) --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define __lzo_destructor __attribute__((__destructor__)) --#endif --#endif --#if defined(__lzo_destructor) --# define __lzo_HAVE_destructor 1 --#endif --#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) --# error "this should not happen" - #endif - #if !defined(__lzo_inline) - #if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) - #elif defined(__cplusplus) - # define __lzo_inline inline -+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) -+# define __lzo_inline inline - #elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) - # define __lzo_inline __inline --#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) - # define __lzo_inline __inline__ - #elif (LZO_CC_DMC) - # define __lzo_inline __inline -+#elif (LZO_CC_GHS) -+# define __lzo_inline __inline__ -+#elif (LZO_CC_IBMC >= 600) -+# define __lzo_inline __inline__ - #elif (LZO_CC_INTELC) - # define __lzo_inline __inline - #elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) - # define __lzo_inline __inline - #elif (LZO_CC_MSC && (_MSC_VER >= 900)) - # define __lzo_inline __inline --#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) -+#elif (LZO_CC_SUNPROC >= 0x5100) - # define __lzo_inline __inline__ --#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) --# define __lzo_inline inline - #endif - #endif - #if defined(__lzo_inline) -+# ifndef __lzo_HAVE_inline - # define __lzo_HAVE_inline 1 -+# endif - #else - # define __lzo_inline /*empty*/ - #endif - #if !defined(__lzo_forceinline) - #if (LZO_CC_GNUC >= 0x030200ul) - # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) -+#elif (LZO_CC_IBMC >= 700) -+# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -+#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) - # define __lzo_forceinline __forceinline --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) - # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) - # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) - #elif (LZO_CC_MSC && (_MSC_VER >= 1200)) - # define __lzo_forceinline __forceinline --#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) -+#elif (LZO_CC_PGI >= 0x0d0a00ul) -+# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -+#elif (LZO_CC_SUNPROC >= 0x5100) - # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) - #endif - #endif - #if defined(__lzo_forceinline) -+# ifndef __lzo_HAVE_forceinline - # define __lzo_HAVE_forceinline 1 -+# endif - #else --# define __lzo_forceinline /*empty*/ -+# define __lzo_forceinline __lzo_inline - #endif - #if !defined(__lzo_noinline) - #if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) - # define __lzo_noinline __attribute__((__noinline__,__used__)) - #elif (LZO_CC_GNUC >= 0x030200ul) - # define __lzo_noinline __attribute__((__noinline__)) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC) -+#elif (LZO_CC_IBMC >= 700) -+# define __lzo_noinline __attribute__((__noinline__)) -+#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) - # define __lzo_noinline __declspec(noinline) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) - # define __lzo_noinline __attribute__((__noinline__)) --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) - # define __lzo_noinline __attribute__((__noinline__)) - #elif (LZO_CC_MSC && (_MSC_VER >= 1300)) - # define __lzo_noinline __declspec(noinline) -@@ -1494,179 +1499,409 @@ extern "C" { - # else - # define __lzo_noinline __declspec(noinline) - # endif --#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) -+#elif (LZO_CC_PGI >= 0x0d0a00ul) -+# define __lzo_noinline __attribute__((__noinline__)) -+#elif (LZO_CC_SUNPROC >= 0x5100) - # define __lzo_noinline __attribute__((__noinline__)) - #endif - #endif - #if defined(__lzo_noinline) -+# ifndef __lzo_HAVE_noinline - # define __lzo_HAVE_noinline 1 -+# endif - #else - # define __lzo_noinline /*empty*/ - #endif - #if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) --# error "this should not happen" -+# error "unexpected configuration - check your compiler defines" - #endif --#if !defined(__lzo_noreturn) --#if (LZO_CC_GNUC >= 0x020700ul) --# define __lzo_noreturn __attribute__((__noreturn__)) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) --# define __lzo_noreturn __declspec(noreturn) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) --# define __lzo_noreturn __attribute__((__noreturn__)) --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define __lzo_noreturn __attribute__((__noreturn__)) --#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) --# define __lzo_noreturn __declspec(noreturn) -+#if !defined(__lzo_static_inline) -+#if (LZO_CC_IBMC) -+# define __lzo_static_inline __lzo_gnuc_extension__ static __lzo_inline - #endif - #endif --#if defined(__lzo_noreturn) --# define __lzo_HAVE_noreturn 1 --#else --# define __lzo_noreturn /*empty*/ -+#if !defined(__lzo_static_inline) -+# define __lzo_static_inline static __lzo_inline - #endif --#if !defined(__lzo_nothrow) --#if (LZO_CC_GNUC >= 0x030300ul) --# define __lzo_nothrow __attribute__((__nothrow__)) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus) --# define __lzo_nothrow __declspec(nothrow) --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 900) && LZO_CC_SYNTAX_GNUC) --# define __lzo_nothrow __attribute__((__nothrow__)) --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+#if !defined(__lzo_static_forceinline) -+#if (LZO_CC_IBMC) -+# define __lzo_static_forceinline __lzo_gnuc_extension__ static __lzo_forceinline -+#endif -+#endif -+#if !defined(__lzo_static_forceinline) -+# define __lzo_static_forceinline static __lzo_forceinline -+#endif -+#if !defined(__lzo_static_noinline) -+#if (LZO_CC_IBMC) -+# define __lzo_static_noinline __lzo_gnuc_extension__ static __lzo_noinline -+#endif -+#endif -+#if !defined(__lzo_static_noinline) -+# define __lzo_static_noinline static __lzo_noinline -+#endif -+#if !defined(__lzo_c99_extern_inline) -+#if defined(__GNUC_GNU_INLINE__) -+# define __lzo_c99_extern_inline __lzo_inline -+#elif defined(__GNUC_STDC_INLINE__) -+# define __lzo_c99_extern_inline extern __lzo_inline -+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) -+# define __lzo_c99_extern_inline extern __lzo_inline -+#endif -+#if !defined(__lzo_c99_extern_inline) && (__lzo_HAVE_inline) -+# define __lzo_c99_extern_inline __lzo_inline -+#endif -+#endif -+#if defined(__lzo_c99_extern_inline) -+# ifndef __lzo_HAVE_c99_extern_inline -+# define __lzo_HAVE_c99_extern_inline 1 -+# endif -+#else -+# define __lzo_c99_extern_inline /*empty*/ -+#endif -+#if !defined(__lzo_may_alias) -+#if (LZO_CC_GNUC >= 0x030400ul) -+# define __lzo_may_alias __attribute__((__may_alias__)) -+#elif (LZO_CC_CLANG >= 0x020900ul) -+# define __lzo_may_alias __attribute__((__may_alias__)) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1210)) && 0 -+# define __lzo_may_alias __attribute__((__may_alias__)) -+#elif (LZO_CC_PGI >= 0x0d0a00ul) && 0 -+# define __lzo_may_alias __attribute__((__may_alias__)) -+#endif -+#endif -+#if defined(__lzo_may_alias) -+# ifndef __lzo_HAVE_may_alias -+# define __lzo_HAVE_may_alias 1 -+# endif -+#else -+# define __lzo_may_alias /*empty*/ -+#endif -+#if !defined(__lzo_noreturn) -+#if (LZO_CC_GNUC >= 0x020700ul) -+# define __lzo_noreturn __attribute__((__noreturn__)) -+#elif (LZO_CC_IBMC >= 700) -+# define __lzo_noreturn __attribute__((__noreturn__)) -+#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) -+# define __lzo_noreturn __declspec(noreturn) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) -+# define __lzo_noreturn __attribute__((__noreturn__)) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define __lzo_noreturn __attribute__((__noreturn__)) -+#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) -+# define __lzo_noreturn __declspec(noreturn) -+#elif (LZO_CC_PGI >= 0x0d0a00ul) -+# define __lzo_noreturn __attribute__((__noreturn__)) -+#endif -+#endif -+#if defined(__lzo_noreturn) -+# ifndef __lzo_HAVE_noreturn -+# define __lzo_HAVE_noreturn 1 -+# endif -+#else -+# define __lzo_noreturn /*empty*/ -+#endif -+#if !defined(__lzo_nothrow) -+#if (LZO_CC_GNUC >= 0x030300ul) -+# define __lzo_nothrow __attribute__((__nothrow__)) -+#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) && defined(__cplusplus) -+# define __lzo_nothrow __declspec(nothrow) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 900)) -+# define __lzo_nothrow __attribute__((__nothrow__)) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) - # define __lzo_nothrow __attribute__((__nothrow__)) - #elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) - # define __lzo_nothrow __declspec(nothrow) - #endif - #endif - #if defined(__lzo_nothrow) -+# ifndef __lzo_HAVE_nothrow - # define __lzo_HAVE_nothrow 1 -+# endif - #else - # define __lzo_nothrow /*empty*/ - #endif - #if !defined(__lzo_restrict) - #if (LZO_CC_GNUC >= 0x030400ul) - # define __lzo_restrict __restrict__ --#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) -+#elif (LZO_CC_IBMC >= 800) && !defined(__cplusplus) - # define __lzo_restrict __restrict__ --#elif (LZO_CC_CLANG || LZO_CC_LLVM) -+#elif (LZO_CC_IBMC >= 1210) -+# define __lzo_restrict __restrict__ -+#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) -+# define __lzo_restrict __restrict__ -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM) - # define __lzo_restrict __restrict__ - #elif (LZO_CC_MSC && (_MSC_VER >= 1400)) - # define __lzo_restrict __restrict -+#elif (LZO_CC_PGI >= 0x0d0a00ul) -+# define __lzo_restrict __restrict__ - #endif - #endif - #if defined(__lzo_restrict) -+# ifndef __lzo_HAVE_restrict - # define __lzo_HAVE_restrict 1 -+# endif - #else - # define __lzo_restrict /*empty*/ - #endif -+#if !defined(__lzo_alignof) -+#if (LZO_CC_ARMCC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -+# define __lzo_alignof(e) __alignof__(e) -+#elif (LZO_CC_GHS) && !defined(__cplusplus) -+# define __lzo_alignof(e) __alignof__(e) -+#elif (LZO_CC_IBMC >= 600) -+# define __lzo_alignof(e) (__lzo_gnuc_extension__ __alignof__(e)) -+#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) -+# define __lzo_alignof(e) __alignof__(e) -+#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) -+# define __lzo_alignof(e) __alignof(e) -+#elif (LZO_CC_SUNPROC >= 0x5100) -+# define __lzo_alignof(e) __alignof__(e) -+#endif -+#endif -+#if defined(__lzo_alignof) -+# ifndef __lzo_HAVE_alignof -+# define __lzo_HAVE_alignof 1 -+# endif -+#endif -+#if !defined(__lzo_struct_packed) -+#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) -+#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) -+#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) -+#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) -+#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) -+#elif (LZO_CC_GNUC >= 0x030400ul) && !(LZO_CC_PCC_GNUC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) -+# define __lzo_struct_packed(s) struct s { -+# define __lzo_struct_packed_end() } __attribute__((__gcc_struct__,__packed__)); -+# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__gcc_struct__,__packed__)); -+#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) -+# define __lzo_struct_packed(s) struct s { -+# define __lzo_struct_packed_end() } __attribute__((__packed__)); -+# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); -+#elif (LZO_CC_IBMC >= 700) -+# define __lzo_struct_packed(s) __lzo_gnuc_extension__ struct s { -+# define __lzo_struct_packed_end() } __attribute__((__packed__)); -+# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); -+#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) -+# define __lzo_struct_packed(s) __pragma(pack(push,1)) struct s { -+# define __lzo_struct_packed_end() } __pragma(pack(pop)); -+#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) -+# define __lzo_struct_packed(s) _Packed struct s { -+# define __lzo_struct_packed_end() }; -+#endif -+#endif -+#if defined(__lzo_struct_packed) && !defined(__lzo_struct_packed_ma) -+# define __lzo_struct_packed_ma(s) __lzo_struct_packed(s) -+#endif -+#if defined(__lzo_struct_packed_end) && !defined(__lzo_struct_packed_ma_end) -+# define __lzo_struct_packed_ma_end() __lzo_struct_packed_end() -+#endif -+#if !defined(__lzo_byte_struct) -+#if defined(__lzo_struct_packed) -+# define __lzo_byte_struct(s,n) __lzo_struct_packed(s) unsigned char a[n]; __lzo_struct_packed_end() -+# define __lzo_byte_struct_ma(s,n) __lzo_struct_packed_ma(s) unsigned char a[n]; __lzo_struct_packed_ma_end() -+#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_PGI || (LZO_CC_SUNPROC >= 0x5100)) -+# define __lzo_byte_struct(s,n) struct s { unsigned char a[n]; } __attribute__((__packed__)); -+# define __lzo_byte_struct_ma(s,n) struct s { unsigned char a[n]; } __lzo_may_alias __attribute__((__packed__)); -+#endif -+#endif -+#if defined(__lzo_byte_struct) && !defined(__lzo_byte_struct_ma) -+# define __lzo_byte_struct_ma(s,n) __lzo_byte_struct(s,n) -+#endif -+#if !defined(__lzo_struct_align16) && (__lzo_HAVE_alignof) -+#if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x030000ul)) -+#elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) -+#elif (LZO_CC_CILLY || LZO_CC_PCC) -+#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) -+# define __lzo_struct_align16(s) struct __declspec(align(16)) s { -+# define __lzo_struct_align16_end() }; -+# define __lzo_struct_align32(s) struct __declspec(align(32)) s { -+# define __lzo_struct_align32_end() }; -+# define __lzo_struct_align64(s) struct __declspec(align(64)) s { -+# define __lzo_struct_align64_end() }; -+#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || (LZO_CC_IBMC >= 700) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define __lzo_struct_align16(s) struct s { -+# define __lzo_struct_align16_end() } __attribute__((__aligned__(16))); -+# define __lzo_struct_align32(s) struct s { -+# define __lzo_struct_align32_end() } __attribute__((__aligned__(32))); -+# define __lzo_struct_align64(s) struct s { -+# define __lzo_struct_align64_end() } __attribute__((__aligned__(64))); -+#endif -+#endif -+#if !defined(__lzo_union_um) -+#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) -+#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) -+#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER < 810)) -+#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) -+#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) -+#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) -+# define __lzo_union_am(s) union s { -+# define __lzo_union_am_end() } __lzo_may_alias; -+# define __lzo_union_um(s) union s { -+# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); -+#elif (LZO_CC_IBMC >= 700) -+# define __lzo_union_am(s) __lzo_gnuc_extension__ union s { -+# define __lzo_union_am_end() } __lzo_may_alias; -+# define __lzo_union_um(s) __lzo_gnuc_extension__ union s { -+# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); -+#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) -+# define __lzo_union_um(s) __pragma(pack(push,1)) union s { -+# define __lzo_union_um_end() } __pragma(pack(pop)); -+#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) -+# define __lzo_union_um(s) _Packed union s { -+# define __lzo_union_um_end() }; -+#endif -+#endif -+#if !defined(__lzo_union_am) -+# define __lzo_union_am(s) union s { -+# define __lzo_union_am_end() }; -+#endif -+#if !defined(__lzo_constructor) -+#if (LZO_CC_GNUC >= 0x030400ul) -+# define __lzo_constructor __attribute__((__constructor__,__used__)) -+#elif (LZO_CC_GNUC >= 0x020700ul) -+# define __lzo_constructor __attribute__((__constructor__)) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) -+# define __lzo_constructor __attribute__((__constructor__,__used__)) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define __lzo_constructor __attribute__((__constructor__)) -+#endif -+#endif -+#if defined(__lzo_constructor) -+# ifndef __lzo_HAVE_constructor -+# define __lzo_HAVE_constructor 1 -+# endif -+#endif -+#if !defined(__lzo_destructor) -+#if (LZO_CC_GNUC >= 0x030400ul) -+# define __lzo_destructor __attribute__((__destructor__,__used__)) -+#elif (LZO_CC_GNUC >= 0x020700ul) -+# define __lzo_destructor __attribute__((__destructor__)) -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) -+# define __lzo_destructor __attribute__((__destructor__,__used__)) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define __lzo_destructor __attribute__((__destructor__)) -+#endif -+#endif -+#if defined(__lzo_destructor) -+# ifndef __lzo_HAVE_destructor -+# define __lzo_HAVE_destructor 1 -+# endif -+#endif -+#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) -+# error "unexpected configuration - check your compiler defines" -+#endif - #if !defined(__lzo_likely) && !defined(__lzo_unlikely) - #if (LZO_CC_GNUC >= 0x030200ul) - # define __lzo_likely(e) (__builtin_expect(!!(e),1)) - # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) -+#elif (LZO_CC_IBMC >= 1010) -+# define __lzo_likely(e) (__builtin_expect(!!(e),1)) -+# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) - #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) - # define __lzo_likely(e) (__builtin_expect(!!(e),1)) - # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) --#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) - # define __lzo_likely(e) (__builtin_expect(!!(e),1)) - # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) - #endif - #endif - #if defined(__lzo_likely) -+# ifndef __lzo_HAVE_likely - # define __lzo_HAVE_likely 1 -+# endif - #else - # define __lzo_likely(e) (e) - #endif - #if defined(__lzo_unlikely) -+# ifndef __lzo_HAVE_unlikely - # define __lzo_HAVE_unlikely 1 -+# endif - #else - # define __lzo_unlikely(e) (e) - #endif --#if !defined(LZO_UNUSED) --# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) --# define LZO_UNUSED(var) ((void) &var) --# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) --# define LZO_UNUSED(var) if (&var) ; else --# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define LZO_UNUSED(var) ((void) var) --# elif (LZO_CC_MSC && (_MSC_VER < 900)) --# define LZO_UNUSED(var) if (&var) ; else --# elif (LZO_CC_KEILC) --# define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];} --# elif (LZO_CC_PACIFICC) --# define LZO_UNUSED(var) ((void) sizeof(var)) --# elif (LZO_CC_WATCOMC) && defined(__cplusplus) --# define LZO_UNUSED(var) ((void) var) -+#if !defined(__lzo_static_unused_void_func) -+# if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -+# define __lzo_static_unused_void_func(f) static void __attribute__((__unused__)) f(void) - # else --# define LZO_UNUSED(var) ((void) &var) -+# define __lzo_static_unused_void_func(f) static __lzo_inline void f(void) - # endif - #endif --#if !defined(LZO_UNUSED_FUNC) --# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) --# define LZO_UNUSED_FUNC(func) ((void) func) --# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) --# define LZO_UNUSED_FUNC(func) if (func) ; else --# elif (LZO_CC_CLANG || LZO_CC_LLVM) --# define LZO_UNUSED_FUNC(func) ((void) &func) --# elif (LZO_CC_MSC && (_MSC_VER < 900)) --# define LZO_UNUSED_FUNC(func) if (func) ; else --# elif (LZO_CC_MSC) --# define LZO_UNUSED_FUNC(func) ((void) &func) --# elif (LZO_CC_KEILC || LZO_CC_PELLESC) --# define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];} -+#if !defined(__lzo_loop_forever) -+# if (LZO_CC_IBMC) -+# define __lzo_loop_forever() LZO_BLOCK_BEGIN for (;;) { ; } LZO_BLOCK_END - # else --# define LZO_UNUSED_FUNC(func) ((void) func) -+# define __lzo_loop_forever() do { ; } while __lzo_cte(1) - # endif - #endif --#if !defined(LZO_UNUSED_LABEL) --# if (LZO_CC_WATCOMC) && defined(__cplusplus) --# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l --# elif (LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) --# define LZO_UNUSED_LABEL(l) if (0) goto l --# else --# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l --# endif -+#if !defined(__lzo_unreachable) -+#if (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x020800ul)) -+# define __lzo_unreachable() __builtin_unreachable(); -+#elif (LZO_CC_GNUC >= 0x040500ul) -+# define __lzo_unreachable() __builtin_unreachable(); -+#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1300)) && 1 -+# define __lzo_unreachable() __builtin_unreachable(); - #endif --#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) -+#endif -+#if defined(__lzo_unreachable) -+# ifndef __lzo_HAVE_unreachable -+# define __lzo_HAVE_unreachable 1 -+# endif -+#else - # if 0 --# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var --# elif 0 && (LZO_CC_GNUC) --# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var -+# define __lzo_unreachable() ((void)0); - # else --# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init -+# define __lzo_unreachable() __lzo_loop_forever(); - # endif - #endif --#if !defined(LZO_UNCONST_CAST) --# if 0 && defined(__cplusplus) --# define LZO_UNCONST_CAST(t,e) (const_cast (e)) --# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) --# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((lzo_uintptr_t) ((const void *) (e)))))) --# else --# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e))))) --# endif -+#ifndef __LZO_CTA_NAME -+#if (LZO_CFG_USE_COUNTER) -+# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__COUNTER__) -+#else -+# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__LINE__) -+#endif - #endif - #if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) - # if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) --# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; -+# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END - # elif (LZO_CC_DMC || LZO_CC_SYMANTECC) --# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)]; -+# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1u-2*!(e)]; LZO_EXTERN_C_END - # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) --# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; -+# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END -+# elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020900ul)) && defined(__cplusplus) -+# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN int __LZO_CTA_NAME(lzo_cta_f__)(int [1-2*!(e)]); LZO_EXTERN_C_END -+# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) -+# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__)); LZO_EXTERN_C_END - # else --# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)]; -+# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-2*!(e)]; LZO_EXTERN_C_END - # endif - #endif - #if !defined(LZO_COMPILE_TIME_ASSERT) - # if (LZO_CC_AZTECC) --# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];} -+# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-!(e)];} - # elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) - # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; -+# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) -+# define LZO_COMPILE_TIME_ASSERT(e) {(void) (0/!!(e));} -+# elif (LZO_CC_GNUC >= 0x040700ul) && (LZO_CFG_USE_COUNTER) && defined(__cplusplus) -+# define LZO_COMPILE_TIME_ASSERT(e) {enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__));} -+# elif (LZO_CC_GNUC >= 0x040700ul) -+# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)] __attribute__((__unused__));} - # elif (LZO_CC_MSC && (_MSC_VER < 900)) - # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; - # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) - # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; - # else --# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];} -+# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)];} - # endif - #endif -+LZO_COMPILE_TIME_ASSERT_HEADER(1 == 1) -+#if defined(__cplusplus) -+extern "C" { LZO_COMPILE_TIME_ASSERT_HEADER(2 == 2) } -+#endif -+LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) - #if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) - # if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) - # elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) -@@ -1730,6 +1965,7 @@ extern "C" { - # define __lzo_cdecl_va __lzo_cdecl - #endif - #if !(LZO_CFG_NO_WINDOWS_H) -+#if !defined(LZO_HAVE_WINDOWS_H) - #if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) - # if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) - # elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) -@@ -1739,60 +1975,614 @@ extern "C" { - # endif - #endif - #endif -+#endif -+#ifndef LZO_SIZEOF_SHORT -+#if defined(SIZEOF_SHORT) -+# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) -+#elif defined(__SIZEOF_SHORT__) -+# define LZO_SIZEOF_SHORT (__SIZEOF_SHORT__) -+#endif -+#endif -+#ifndef LZO_SIZEOF_INT -+#if defined(SIZEOF_INT) -+# define LZO_SIZEOF_INT (SIZEOF_INT) -+#elif defined(__SIZEOF_INT__) -+# define LZO_SIZEOF_INT (__SIZEOF_INT__) -+#endif -+#endif -+#ifndef LZO_SIZEOF_LONG -+#if defined(SIZEOF_LONG) -+# define LZO_SIZEOF_LONG (SIZEOF_LONG) -+#elif defined(__SIZEOF_LONG__) -+# define LZO_SIZEOF_LONG (__SIZEOF_LONG__) -+#endif -+#endif -+#ifndef LZO_SIZEOF_LONG_LONG -+#if defined(SIZEOF_LONG_LONG) -+# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) -+#elif defined(__SIZEOF_LONG_LONG__) -+# define LZO_SIZEOF_LONG_LONG (__SIZEOF_LONG_LONG__) -+#endif -+#endif -+#ifndef LZO_SIZEOF___INT16 -+#if defined(SIZEOF___INT16) -+# define LZO_SIZEOF___INT16 (SIZEOF___INT16) -+#endif -+#endif -+#ifndef LZO_SIZEOF___INT32 -+#if defined(SIZEOF___INT32) -+# define LZO_SIZEOF___INT32 (SIZEOF___INT32) -+#endif -+#endif -+#ifndef LZO_SIZEOF___INT64 -+#if defined(SIZEOF___INT64) -+# define LZO_SIZEOF___INT64 (SIZEOF___INT64) -+#endif -+#endif -+#ifndef LZO_SIZEOF_VOID_P -+#if defined(SIZEOF_VOID_P) -+# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) -+#elif defined(__SIZEOF_POINTER__) -+# define LZO_SIZEOF_VOID_P (__SIZEOF_POINTER__) -+#endif -+#endif -+#ifndef LZO_SIZEOF_SIZE_T -+#if defined(SIZEOF_SIZE_T) -+# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) -+#elif defined(__SIZEOF_SIZE_T__) -+# define LZO_SIZEOF_SIZE_T (__SIZEOF_SIZE_T__) -+#endif -+#endif -+#ifndef LZO_SIZEOF_PTRDIFF_T -+#if defined(SIZEOF_PTRDIFF_T) -+# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) -+#elif defined(__SIZEOF_PTRDIFF_T__) -+# define LZO_SIZEOF_PTRDIFF_T (__SIZEOF_PTRDIFF_T__) -+#endif -+#endif -+#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) -+#if !defined(LZO_SIZEOF_SHORT) -+# if (LZO_ARCH_CRAY_PVP) -+# define LZO_SIZEOF_SHORT 8 -+# elif (USHRT_MAX == LZO_0xffffL) -+# define LZO_SIZEOF_SHORT 2 -+# elif (__LZO_LSR(USHRT_MAX,7) == 1) -+# define LZO_SIZEOF_SHORT 1 -+# elif (__LZO_LSR(USHRT_MAX,15) == 1) -+# define LZO_SIZEOF_SHORT 2 -+# elif (__LZO_LSR(USHRT_MAX,31) == 1) -+# define LZO_SIZEOF_SHORT 4 -+# elif (__LZO_LSR(USHRT_MAX,63) == 1) -+# define LZO_SIZEOF_SHORT 8 -+# elif (__LZO_LSR(USHRT_MAX,127) == 1) -+# define LZO_SIZEOF_SHORT 16 -+# else -+# error "LZO_SIZEOF_SHORT" -+# endif -+#endif -+LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SHORT == sizeof(short)) -+#if !defined(LZO_SIZEOF_INT) -+# if (LZO_ARCH_CRAY_PVP) -+# define LZO_SIZEOF_INT 8 -+# elif (UINT_MAX == LZO_0xffffL) -+# define LZO_SIZEOF_INT 2 -+# elif (UINT_MAX == LZO_0xffffffffL) -+# define LZO_SIZEOF_INT 4 -+# elif (__LZO_LSR(UINT_MAX,7) == 1) -+# define LZO_SIZEOF_INT 1 -+# elif (__LZO_LSR(UINT_MAX,15) == 1) -+# define LZO_SIZEOF_INT 2 -+# elif (__LZO_LSR(UINT_MAX,31) == 1) -+# define LZO_SIZEOF_INT 4 -+# elif (__LZO_LSR(UINT_MAX,63) == 1) -+# define LZO_SIZEOF_INT 8 -+# elif (__LZO_LSR(UINT_MAX,127) == 1) -+# define LZO_SIZEOF_INT 16 -+# else -+# error "LZO_SIZEOF_INT" -+# endif -+#endif -+LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_INT == sizeof(int)) -+#if !defined(LZO_SIZEOF_LONG) -+# if (ULONG_MAX == LZO_0xffffffffL) -+# define LZO_SIZEOF_LONG 4 -+# elif (__LZO_LSR(ULONG_MAX,7) == 1) -+# define LZO_SIZEOF_LONG 1 -+# elif (__LZO_LSR(ULONG_MAX,15) == 1) -+# define LZO_SIZEOF_LONG 2 -+# elif (__LZO_LSR(ULONG_MAX,31) == 1) -+# define LZO_SIZEOF_LONG 4 -+# elif (__LZO_LSR(ULONG_MAX,39) == 1) -+# define LZO_SIZEOF_LONG 5 -+# elif (__LZO_LSR(ULONG_MAX,63) == 1) -+# define LZO_SIZEOF_LONG 8 -+# elif (__LZO_LSR(ULONG_MAX,127) == 1) -+# define LZO_SIZEOF_LONG 16 -+# else -+# error "LZO_SIZEOF_LONG" -+# endif -+#endif -+LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_LONG == sizeof(long)) -+#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) -+#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) -+# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) -+# if (LZO_CC_GNUC >= 0x030300ul) -+# if ((__LONG_MAX__-0) == (__LONG_LONG_MAX__-0)) -+# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG -+# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) -+# define LZO_SIZEOF_LONG_LONG 4 -+# endif -+# endif -+# endif -+#endif -+#endif -+#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) -+#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) -+#if (LZO_ARCH_I086 && LZO_CC_DMC) -+#elif (LZO_CC_CILLY) && defined(__GNUC__) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_OS_WIN64 || defined(_WIN64)) -+# define LZO_SIZEOF___INT64 8 -+#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) -+# define LZO_SIZEOF___INT64 8 -+#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) -+# define LZO_SIZEOF___INT64 8 -+#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) -+# define LZO_SIZEOF___INT64 8 -+#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) -+# define LZO_SIZEOF___INT64 8 -+#elif (LZO_CC_GHS && defined(__LLONG_BIT) && ((__LLONG_BIT-0) == 64)) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && ((_INTEGRAL_MAX_BITS-0) == 64)) -+# define LZO_SIZEOF___INT64 8 -+#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (defined(__vms) || defined(__VMS)) && ((__INITIAL_POINTER_SIZE-0) == 64) -+# define LZO_SIZEOF_LONG_LONG 8 -+#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) -+#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -+# define LZO_SIZEOF_LONG_LONG 8 -+#endif -+#endif -+#endif -+#if defined(__cplusplus) && (LZO_CC_GNUC) -+# if (LZO_CC_GNUC < 0x020800ul) -+# undef LZO_SIZEOF_LONG_LONG -+# endif -+#endif -+#if (LZO_CFG_NO_LONG_LONG) -+# undef LZO_SIZEOF_LONG_LONG -+#elif defined(__NO_LONG_LONG) -+# undef LZO_SIZEOF_LONG_LONG -+#elif defined(_NO_LONGLONG) -+# undef LZO_SIZEOF_LONG_LONG -+#endif -+#if !defined(LZO_WORDSIZE) -+#if (LZO_ARCH_ALPHA) -+# define LZO_WORDSIZE 8 -+#elif (LZO_ARCH_AMD64) -+# define LZO_WORDSIZE 8 -+#elif (LZO_ARCH_AVR) -+# define LZO_WORDSIZE 1 -+#elif (LZO_ARCH_H8300) -+# if defined(__NORMAL_MODE__) -+# define LZO_WORDSIZE 4 -+# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) -+# define LZO_WORDSIZE 4 -+# else -+# define LZO_WORDSIZE 2 -+# endif -+#elif (LZO_ARCH_I086) -+# define LZO_WORDSIZE 2 -+#elif (LZO_ARCH_IA64) -+# define LZO_WORDSIZE 8 -+#elif (LZO_ARCH_M16C) -+# define LZO_WORDSIZE 2 -+#elif (LZO_ARCH_SPU) -+# define LZO_WORDSIZE 4 -+#elif (LZO_ARCH_Z80) -+# define LZO_WORDSIZE 1 -+#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) -+# define LZO_WORDSIZE 8 -+#elif (LZO_OS_OS400 || defined(__OS400__)) -+# define LZO_WORDSIZE 8 -+#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) -+# define LZO_WORDSIZE 8 -+#endif -+#endif -+#if !defined(LZO_SIZEOF_VOID_P) -+#if defined(__ILP32__) || defined(__ILP32) || defined(_ILP32) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 4) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) -+# define LZO_SIZEOF_VOID_P 4 -+#elif defined(__ILP64__) || defined(__ILP64) || defined(_ILP64) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 8) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) -+# define LZO_SIZEOF_VOID_P 8 -+#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) -+# define LZO_SIZEOF_VOID_P 8 -+#elif defined(__LP64__) || defined(__LP64) || defined(_LP64) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) -+# define LZO_SIZEOF_VOID_P 8 -+#elif (LZO_ARCH_AVR) -+# define LZO_SIZEOF_VOID_P 2 -+#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) -+# define LZO_SIZEOF_VOID_P 2 -+#elif (LZO_ARCH_H8300) -+# if defined(__NORMAL_MODE__) -+# define LZO_SIZEOF_VOID_P 2 -+# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) -+# define LZO_SIZEOF_VOID_P 4 -+# else -+# define LZO_SIZEOF_VOID_P 2 -+# endif -+# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) -+# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT -+# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT -+# endif -+#elif (LZO_ARCH_I086) -+# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) -+# define LZO_SIZEOF_VOID_P 2 -+# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) -+# define LZO_SIZEOF_VOID_P 4 -+# else -+# error "invalid LZO_ARCH_I086 memory model" -+# endif -+#elif (LZO_ARCH_M16C) -+# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) -+# define LZO_SIZEOF_VOID_P 4 -+# else -+# define LZO_SIZEOF_VOID_P 2 -+# endif -+#elif (LZO_ARCH_SPU) -+# define LZO_SIZEOF_VOID_P 4 -+#elif (LZO_ARCH_Z80) -+# define LZO_SIZEOF_VOID_P 2 -+#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) -+# define LZO_SIZEOF_VOID_P 4 -+#elif (LZO_OS_OS400 || defined(__OS400__)) -+# if defined(__LLP64_IFC__) -+# define LZO_SIZEOF_VOID_P 8 -+# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -+# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -+# else -+# define LZO_SIZEOF_VOID_P 16 -+# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -+# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -+# endif -+#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) -+# define LZO_SIZEOF_VOID_P 8 -+# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -+# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -+#endif -+#endif -+#if !defined(LZO_SIZEOF_VOID_P) -+# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG -+#endif -+LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_VOID_P == sizeof(void *)) -+#if !defined(LZO_SIZEOF_SIZE_T) -+#if (LZO_ARCH_I086 || LZO_ARCH_M16C) -+# define LZO_SIZEOF_SIZE_T 2 -+#endif -+#endif -+#if !defined(LZO_SIZEOF_SIZE_T) -+# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P -+#endif -+#if defined(offsetof) -+LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SIZE_T == sizeof(size_t)) -+#endif -+#if !defined(LZO_SIZEOF_PTRDIFF_T) -+#if (LZO_ARCH_I086) -+# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) -+# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P -+# elif (LZO_MM_COMPACT || LZO_MM_LARGE) -+# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) -+# define LZO_SIZEOF_PTRDIFF_T 4 -+# else -+# define LZO_SIZEOF_PTRDIFF_T 2 -+# endif -+# else -+# error "invalid LZO_ARCH_I086 memory model" -+# endif -+#endif -+#endif -+#if !defined(LZO_SIZEOF_PTRDIFF_T) -+# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T -+#endif -+#if defined(offsetof) -+LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) -+#endif -+#if !defined(LZO_WORDSIZE) -+# define LZO_WORDSIZE LZO_SIZEOF_VOID_P -+#endif -+#if (LZO_ABI_NEUTRAL_ENDIAN) -+# undef LZO_ABI_BIG_ENDIAN -+# undef LZO_ABI_LITTLE_ENDIAN -+#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) -+#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) -+# define LZO_ABI_BIG_ENDIAN 1 -+#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) -+# define LZO_ABI_LITTLE_ENDIAN 1 -+#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) -+# define LZO_ABI_LITTLE_ENDIAN 1 -+#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390 || LZO_ARCH_SPU) -+# define LZO_ABI_BIG_ENDIAN 1 -+#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) -+# if (__LITTLE_ENDIAN__ == 1) -+# define LZO_ABI_LITTLE_ENDIAN 1 -+# else -+# define LZO_ABI_BIG_ENDIAN 1 -+# endif -+#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) -+# define LZO_ABI_BIG_ENDIAN 1 -+#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) -+# define LZO_ABI_LITTLE_ENDIAN 1 -+#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) -+# define LZO_ABI_BIG_ENDIAN 1 -+#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) -+# define LZO_ABI_LITTLE_ENDIAN 1 -+#elif 1 && (LZO_ARCH_ARM && LZO_CC_ARMCC_ARMCC) -+# if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN) -+# error "unexpected configuration - check your compiler defines" -+# elif defined(__BIG_ENDIAN) -+# define LZO_ABI_BIG_ENDIAN 1 -+# else -+# define LZO_ABI_LITTLE_ENDIAN 1 -+# endif -+# define LZO_ABI_LITTLE_ENDIAN 1 -+#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EB__) && !defined(__AARCH64EL__) -+# define LZO_ABI_BIG_ENDIAN 1 -+#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EL__) && !defined(__AARCH64EB__) -+# define LZO_ABI_LITTLE_ENDIAN 1 -+#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) -+# define LZO_ABI_BIG_ENDIAN 1 -+#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) -+# define LZO_ABI_LITTLE_ENDIAN 1 -+#endif -+#endif -+#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) -+# error "unexpected configuration - check your compiler defines" -+#endif -+#if (LZO_ABI_BIG_ENDIAN) -+# define LZO_INFO_ABI_ENDIAN "be" -+#elif (LZO_ABI_LITTLE_ENDIAN) -+# define LZO_INFO_ABI_ENDIAN "le" -+#elif (LZO_ABI_NEUTRAL_ENDIAN) -+# define LZO_INFO_ABI_ENDIAN "neutral" -+#endif -+#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) -+# define LZO_ABI_I8LP16 1 -+# define LZO_INFO_ABI_PM "i8lp16" -+#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) -+# define LZO_ABI_ILP16 1 -+# define LZO_INFO_ABI_PM "ilp16" -+#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) -+# define LZO_ABI_LP32 1 -+# define LZO_INFO_ABI_PM "lp32" -+#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) -+# define LZO_ABI_ILP32 1 -+# define LZO_INFO_ABI_PM "ilp32" -+#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) -+# define LZO_ABI_LLP64 1 -+# define LZO_INFO_ABI_PM "llp64" -+#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) -+# define LZO_ABI_LP64 1 -+# define LZO_INFO_ABI_PM "lp64" -+#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) -+# define LZO_ABI_ILP64 1 -+# define LZO_INFO_ABI_PM "ilp64" -+#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) -+# define LZO_ABI_IP32L64 1 -+# define LZO_INFO_ABI_PM "ip32l64" -+#endif -+#if 0 -+#elif !defined(__LZO_LIBC_OVERRIDE) -+#if (LZO_LIBC_NAKED) -+# define LZO_INFO_LIBC "naked" -+#elif (LZO_LIBC_FREESTANDING) -+# define LZO_INFO_LIBC "freestanding" -+#elif (LZO_LIBC_MOSTLY_FREESTANDING) -+# define LZO_INFO_LIBC "mfreestanding" -+#elif (LZO_LIBC_ISOC90) -+# define LZO_INFO_LIBC "isoc90" -+#elif (LZO_LIBC_ISOC99) -+# define LZO_INFO_LIBC "isoc99" -+#elif (LZO_CC_ARMCC_ARMCC) && defined(__ARMCLIB_VERSION) -+# define LZO_LIBC_ISOC90 1 -+# define LZO_INFO_LIBC "isoc90" -+#elif defined(__dietlibc__) -+# define LZO_LIBC_DIETLIBC 1 -+# define LZO_INFO_LIBC "dietlibc" -+#elif defined(_NEWLIB_VERSION) -+# define LZO_LIBC_NEWLIB 1 -+# define LZO_INFO_LIBC "newlib" -+#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) -+# if defined(__UCLIBC_SUBLEVEL__) -+# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + (__UCLIBC_MINOR__-0) * 0x100 + (__UCLIBC_SUBLEVEL__-0)) -+# else -+# define LZO_LIBC_UCLIBC 0x00090bL -+# endif -+# define LZO_INFO_LIBC "uc" "libc" -+#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) -+# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + (__GLIBC_MINOR__-0) * 0x100) -+# define LZO_INFO_LIBC "glibc" -+#elif (LZO_CC_MWERKS) && defined(__MSL__) -+# define LZO_LIBC_MSL __MSL__ -+# define LZO_INFO_LIBC "msl" -+#elif 1 && defined(__IAR_SYSTEMS_ICC__) -+# define LZO_LIBC_ISOC90 1 -+# define LZO_INFO_LIBC "isoc90" -+#else -+# define LZO_LIBC_DEFAULT 1 -+# define LZO_INFO_LIBC "default" -+#endif -+#endif -+#if (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) -+# define LZO_ASM_SYNTAX_MSC 1 -+#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) -+#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) -+#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) -+# define LZO_ASM_SYNTAX_GNUC 1 -+#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) -+# define LZO_ASM_SYNTAX_GNUC 1 -+#elif (LZO_CC_GNUC) -+# define LZO_ASM_SYNTAX_GNUC 1 -+#endif -+#if (LZO_ASM_SYNTAX_GNUC) -+#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) -+# define __LZO_ASM_CLOBBER "ax" -+# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ -+# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY /*empty*/ -+# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ -+#elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1000)) -+# define __LZO_ASM_CLOBBER "memory" -+# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ -+# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "memory" -+# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ -+#else -+# define __LZO_ASM_CLOBBER "cc", "memory" -+# define __LZO_ASM_CLOBBER_LIST_CC : "cc" -+# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "cc", "memory" -+# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ -+#endif -+#endif - #if (LZO_ARCH_ALPHA) --# define LZO_OPT_AVOID_UINT_INDEX 1 --# define LZO_OPT_AVOID_SHORT 1 --# define LZO_OPT_AVOID_USHORT 1 -+# define LZO_OPT_AVOID_UINT_INDEX 1 - #elif (LZO_ARCH_AMD64) --# define LZO_OPT_AVOID_INT_INDEX 1 --# define LZO_OPT_AVOID_UINT_INDEX 1 --# define LZO_OPT_UNALIGNED16 1 --# define LZO_OPT_UNALIGNED32 1 --# define LZO_OPT_UNALIGNED64 1 --#elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB) -+# define LZO_OPT_AVOID_INT_INDEX 1 -+# define LZO_OPT_AVOID_UINT_INDEX 1 -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED64 -+# define LZO_OPT_UNALIGNED64 1 -+# endif - #elif (LZO_ARCH_ARM) --# define LZO_OPT_AVOID_SHORT 1 --# define LZO_OPT_AVOID_USHORT 1 -+# if defined(__ARM_FEATURE_UNALIGNED) -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif -+# elif defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM+0) >= 7) -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif -+# elif defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM+0) >= 6) && !defined(__TARGET_PROFILE_M) -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif -+# endif -+#elif (LZO_ARCH_ARM64) -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED64 -+# define LZO_OPT_UNALIGNED64 1 -+# endif - #elif (LZO_ARCH_CRIS) --# define LZO_OPT_UNALIGNED16 1 --# define LZO_OPT_UNALIGNED32 1 -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif - #elif (LZO_ARCH_I386) --# define LZO_OPT_UNALIGNED16 1 --# define LZO_OPT_UNALIGNED32 1 -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif - #elif (LZO_ARCH_IA64) --# define LZO_OPT_AVOID_INT_INDEX 1 --# define LZO_OPT_AVOID_UINT_INDEX 1 --# define LZO_OPT_PREFER_POSTINC 1 -+# define LZO_OPT_AVOID_INT_INDEX 1 -+# define LZO_OPT_AVOID_UINT_INDEX 1 -+# define LZO_OPT_PREFER_POSTINC 1 - #elif (LZO_ARCH_M68K) --# define LZO_OPT_PREFER_POSTINC 1 --# define LZO_OPT_PREFER_PREDEC 1 -+# define LZO_OPT_PREFER_POSTINC 1 -+# define LZO_OPT_PREFER_PREDEC 1 - # if defined(__mc68020__) && !defined(__mcoldfire__) --# define LZO_OPT_UNALIGNED16 1 --# define LZO_OPT_UNALIGNED32 1 -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif - # endif - #elif (LZO_ARCH_MIPS) --# define LZO_OPT_AVOID_UINT_INDEX 1 -+# define LZO_OPT_AVOID_UINT_INDEX 1 - #elif (LZO_ARCH_POWERPC) --# define LZO_OPT_PREFER_PREINC 1 --# define LZO_OPT_PREFER_PREDEC 1 -+# define LZO_OPT_PREFER_PREINC 1 -+# define LZO_OPT_PREFER_PREDEC 1 - # if (LZO_ABI_BIG_ENDIAN) --# define LZO_OPT_UNALIGNED16 1 --# define LZO_OPT_UNALIGNED32 1 -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif -+# if (LZO_WORDSIZE == 8) -+# ifndef LZO_OPT_UNALIGNED64 -+# define LZO_OPT_UNALIGNED64 1 -+# endif -+# endif - # endif - #elif (LZO_ARCH_S390) --# define LZO_OPT_UNALIGNED16 1 --# define LZO_OPT_UNALIGNED32 1 --# if (LZO_SIZEOF_SIZE_T == 8) --# define LZO_OPT_UNALIGNED64 1 -+# ifndef LZO_OPT_UNALIGNED16 -+# define LZO_OPT_UNALIGNED16 1 -+# endif -+# ifndef LZO_OPT_UNALIGNED32 -+# define LZO_OPT_UNALIGNED32 1 -+# endif -+# if (LZO_WORDSIZE == 8) -+# ifndef LZO_OPT_UNALIGNED64 -+# define LZO_OPT_UNALIGNED64 1 -+# endif - # endif - #elif (LZO_ARCH_SH) --# define LZO_OPT_PREFER_POSTINC 1 --# define LZO_OPT_PREFER_PREDEC 1 -+# define LZO_OPT_PREFER_POSTINC 1 -+# define LZO_OPT_PREFER_PREDEC 1 - #endif - #ifndef LZO_CFG_NO_INLINE_ASM --#if (LZO_CC_LLVM) -+#if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) - # define LZO_CFG_NO_INLINE_ASM 1 -+#elif (LZO_CC_LLVM) -+# define LZO_CFG_NO_INLINE_ASM 1 -+#endif - #endif -+#if (LZO_CFG_NO_INLINE_ASM) -+# undef LZO_ASM_SYNTAX_MSC -+# undef LZO_ASM_SYNTAX_GNUC -+# undef __LZO_ASM_CLOBBER -+# undef __LZO_ASM_CLOBBER_LIST_CC -+# undef __LZO_ASM_CLOBBER_LIST_CC_MEMORY -+# undef __LZO_ASM_CLOBBER_LIST_EMPTY - #endif - #ifndef LZO_CFG_NO_UNALIGNED - #if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) -@@ -1804,25 +2594,6 @@ extern "C" { - # undef LZO_OPT_UNALIGNED32 - # undef LZO_OPT_UNALIGNED64 - #endif --#if (LZO_CFG_NO_INLINE_ASM) --#elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) --# define LZO_ASM_SYNTAX_MSC 1 --#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) --#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) --#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) --# define LZO_ASM_SYNTAX_GNUC 1 --#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) --# define LZO_ASM_SYNTAX_GNUC 1 --#endif --#if (LZO_ASM_SYNTAX_GNUC) --#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) --# define __LZO_ASM_CLOBBER "ax" --#elif (LZO_CC_INTELC) --# define __LZO_ASM_CLOBBER "memory" --#else --# define __LZO_ASM_CLOBBER "cc", "memory" --#endif --#endif - #if defined(__LZO_INFOSTR_MM) - #elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM)) - # define __LZO_INFOSTR_MM "" -@@ -1866,6 +2637,381 @@ extern "C" { - #define LZO_INFO_STRING \ - LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \ - " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER -+#if !(LZO_CFG_SKIP_LZO_TYPES) -+#if (!(LZO_SIZEOF_SHORT+0 > 0 && LZO_SIZEOF_INT+0 > 0 && LZO_SIZEOF_LONG+0 > 0)) -+# error "missing defines for sizes" -+#endif -+#if (!(LZO_SIZEOF_PTRDIFF_T+0 > 0 && LZO_SIZEOF_SIZE_T+0 > 0 && LZO_SIZEOF_VOID_P+0 > 0)) -+# error "missing defines for sizes" -+#endif -+#if !defined(lzo_llong_t) -+#if (LZO_SIZEOF_LONG_LONG+0 > 0) -+__lzo_gnuc_extension__ typedef long long lzo_llong_t__; -+__lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; -+# define lzo_llong_t lzo_llong_t__ -+# define lzo_ullong_t lzo_ullong_t__ -+#endif -+#endif -+#if !defined(lzo_int16e_t) -+#if (LZO_SIZEOF_LONG == 2) -+# define lzo_int16e_t long -+# define lzo_uint16e_t unsigned long -+#elif (LZO_SIZEOF_INT == 2) -+# define lzo_int16e_t int -+# define lzo_uint16e_t unsigned int -+#elif (LZO_SIZEOF_SHORT == 2) -+# define lzo_int16e_t short int -+# define lzo_uint16e_t unsigned short int -+#elif 1 && !(LZO_CFG_TYPE_NO_MODE_HI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) -+ typedef int lzo_int16e_hi_t__ __attribute__((__mode__(__HI__))); -+ typedef unsigned int lzo_uint16e_hi_t__ __attribute__((__mode__(__HI__))); -+# define lzo_int16e_t lzo_int16e_hi_t__ -+# define lzo_uint16e_t lzo_uint16e_hi_t__ -+#elif (LZO_SIZEOF___INT16 == 2) -+# define lzo_int16e_t __int16 -+# define lzo_uint16e_t unsigned __int16 -+#else -+#endif -+#endif -+#if defined(lzo_int16e_t) -+# define LZO_SIZEOF_LZO_INT16E_T 2 -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == 2) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == LZO_SIZEOF_LZO_INT16E_T) -+#endif -+#if !defined(lzo_int32e_t) -+#if (LZO_SIZEOF_LONG == 4) -+# define lzo_int32e_t long int -+# define lzo_uint32e_t unsigned long int -+#elif (LZO_SIZEOF_INT == 4) -+# define lzo_int32e_t int -+# define lzo_uint32e_t unsigned int -+#elif (LZO_SIZEOF_SHORT == 4) -+# define lzo_int32e_t short int -+# define lzo_uint32e_t unsigned short int -+#elif (LZO_SIZEOF_LONG_LONG == 4) -+# define lzo_int32e_t lzo_llong_t -+# define lzo_uint32e_t lzo_ullong_t -+#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) && (__INT_MAX__+0 > 2147483647L) -+ typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); -+ typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); -+# define lzo_int32e_t lzo_int32e_si_t__ -+# define lzo_uint32e_t lzo_uint32e_si_t__ -+#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_GNUC >= 0x025f00ul) && defined(__AVR__) && (__LONG_MAX__+0 == 32767L) -+ typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); -+ typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); -+# define lzo_int32e_t lzo_int32e_si_t__ -+# define lzo_uint32e_t lzo_uint32e_si_t__ -+# define LZO_INT32_C(c) (c##LL) -+# define LZO_UINT32_C(c) (c##ULL) -+#elif (LZO_SIZEOF___INT32 == 4) -+# define lzo_int32e_t __int32 -+# define lzo_uint32e_t unsigned __int32 -+#else -+#endif -+#endif -+#if defined(lzo_int32e_t) -+# define LZO_SIZEOF_LZO_INT32E_T 4 -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == 4) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == LZO_SIZEOF_LZO_INT32E_T) -+#endif -+#if !defined(lzo_int64e_t) -+#if (LZO_SIZEOF___INT64 == 8) -+# if (LZO_CC_BORLANDC) && !(LZO_CFG_TYPE_PREFER___INT64) -+# define LZO_CFG_TYPE_PREFER___INT64 1 -+# endif -+#endif -+#if (LZO_SIZEOF_INT == 8) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) -+# define lzo_int64e_t int -+# define lzo_uint64e_t unsigned int -+# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_INT -+#elif (LZO_SIZEOF_LONG == 8) -+# define lzo_int64e_t long int -+# define lzo_uint64e_t unsigned long int -+# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_LONG -+#elif (LZO_SIZEOF_LONG_LONG == 8) && !(LZO_CFG_TYPE_PREFER___INT64) -+# define lzo_int64e_t lzo_llong_t -+# define lzo_uint64e_t lzo_ullong_t -+# if (LZO_CC_BORLANDC) -+# define LZO_INT64_C(c) ((c) + 0ll) -+# define LZO_UINT64_C(c) ((c) + 0ull) -+# elif 0 -+# define LZO_INT64_C(c) (__lzo_gnuc_extension__ (c##LL)) -+# define LZO_UINT64_C(c) (__lzo_gnuc_extension__ (c##ULL)) -+# else -+# define LZO_INT64_C(c) (c##LL) -+# define LZO_UINT64_C(c) (c##ULL) -+# endif -+# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_LONG_LONG -+#elif (LZO_SIZEOF___INT64 == 8) -+# define lzo_int64e_t __int64 -+# define lzo_uint64e_t unsigned __int64 -+# if (LZO_CC_BORLANDC) -+# define LZO_INT64_C(c) ((c) + 0i64) -+# define LZO_UINT64_C(c) ((c) + 0ui64) -+# else -+# define LZO_INT64_C(c) (c##i64) -+# define LZO_UINT64_C(c) (c##ui64) -+# endif -+# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF___INT64 -+#else -+#endif -+#endif -+#if defined(lzo_int64e_t) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == 8) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == LZO_SIZEOF_LZO_INT64E_T) -+#endif -+#if !defined(lzo_int32l_t) -+#if defined(lzo_int32e_t) -+# define lzo_int32l_t lzo_int32e_t -+# define lzo_uint32l_t lzo_uint32e_t -+# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LZO_INT32E_T -+#elif (LZO_SIZEOF_INT >= 4) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) -+# define lzo_int32l_t int -+# define lzo_uint32l_t unsigned int -+# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_INT -+#elif (LZO_SIZEOF_LONG >= 4) -+# define lzo_int32l_t long int -+# define lzo_uint32l_t unsigned long int -+# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LONG -+#else -+# error "lzo_int32l_t" -+#endif -+#endif -+#if 1 -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) >= 4) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) == LZO_SIZEOF_LZO_INT32L_T) -+#endif -+#if !defined(lzo_int64l_t) -+#if defined(lzo_int64e_t) -+# define lzo_int64l_t lzo_int64e_t -+# define lzo_uint64l_t lzo_uint64e_t -+# define LZO_SIZEOF_LZO_INT64L_T LZO_SIZEOF_LZO_INT64E_T -+#else -+#endif -+#endif -+#if defined(lzo_int64l_t) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) >= 8) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) == LZO_SIZEOF_LZO_INT64L_T) -+#endif -+#if !defined(lzo_int32f_t) -+#if (LZO_SIZEOF_SIZE_T >= 8) -+# define lzo_int32f_t lzo_int64l_t -+# define lzo_uint32f_t lzo_uint64l_t -+# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT64L_T -+#else -+# define lzo_int32f_t lzo_int32l_t -+# define lzo_uint32f_t lzo_uint32l_t -+# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT32L_T -+#endif -+#endif -+#if 1 -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) >= 4) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) == LZO_SIZEOF_LZO_INT32F_T) -+#endif -+#if !defined(lzo_int64f_t) -+#if defined(lzo_int64l_t) -+# define lzo_int64f_t lzo_int64l_t -+# define lzo_uint64f_t lzo_uint64l_t -+# define LZO_SIZEOF_LZO_INT64F_T LZO_SIZEOF_LZO_INT64L_T -+#else -+#endif -+#endif -+#if defined(lzo_int64f_t) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) >= 8) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) == LZO_SIZEOF_LZO_INT64F_T) -+#endif -+#if !defined(lzo_intptr_t) -+#if 1 && (LZO_OS_OS400 && (LZO_SIZEOF_VOID_P == 16)) -+# define __LZO_INTPTR_T_IS_POINTER 1 -+ typedef char* lzo_intptr_t; -+ typedef char* lzo_uintptr_t; -+# define lzo_intptr_t lzo_intptr_t -+# define lzo_uintptr_t lzo_uintptr_t -+# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_VOID_P -+#elif (LZO_CC_MSC && (_MSC_VER >= 1300) && (LZO_SIZEOF_VOID_P == 4) && (LZO_SIZEOF_INT == 4)) -+ typedef __w64 int lzo_intptr_t; -+ typedef __w64 unsigned int lzo_uintptr_t; -+# define lzo_intptr_t lzo_intptr_t -+# define lzo_uintptr_t lzo_uintptr_t -+# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT -+#elif (LZO_SIZEOF_SHORT == LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT > LZO_SIZEOF_VOID_P) -+# define lzo_intptr_t short -+# define lzo_uintptr_t unsigned short -+# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_SHORT -+#elif (LZO_SIZEOF_INT >= LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) -+# define lzo_intptr_t int -+# define lzo_uintptr_t unsigned int -+# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT -+#elif (LZO_SIZEOF_LONG >= LZO_SIZEOF_VOID_P) -+# define lzo_intptr_t long -+# define lzo_uintptr_t unsigned long -+# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LONG -+#elif (LZO_SIZEOF_LZO_INT64L_T >= LZO_SIZEOF_VOID_P) -+# define lzo_intptr_t lzo_int64l_t -+# define lzo_uintptr_t lzo_uint64l_t -+# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LZO_INT64L_T -+#else -+# error "lzo_intptr_t" -+#endif -+#endif -+#if 1 -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) >= sizeof(void *)) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) == sizeof(lzo_uintptr_t)) -+#endif -+#if !defined(lzo_word_t) -+#if defined(LZO_WORDSIZE) && (LZO_WORDSIZE+0 > 0) -+#if (LZO_WORDSIZE == LZO_SIZEOF_LZO_INTPTR_T) && !(__LZO_INTPTR_T_IS_POINTER) -+# define lzo_word_t lzo_uintptr_t -+# define lzo_sword_t lzo_intptr_t -+# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INTPTR_T -+#elif (LZO_WORDSIZE == LZO_SIZEOF_LONG) -+# define lzo_word_t unsigned long -+# define lzo_sword_t long -+# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LONG -+#elif (LZO_WORDSIZE == LZO_SIZEOF_INT) -+# define lzo_word_t unsigned int -+# define lzo_sword_t int -+# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_INT -+#elif (LZO_WORDSIZE == LZO_SIZEOF_SHORT) -+# define lzo_word_t unsigned short -+# define lzo_sword_t short -+# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_SHORT -+#elif (LZO_WORDSIZE == 1) -+# define lzo_word_t unsigned char -+# define lzo_sword_t signed char -+# define LZO_SIZEOF_LZO_WORD_T 1 -+#elif (LZO_WORDSIZE == LZO_SIZEOF_LZO_INT64L_T) -+# define lzo_word_t lzo_uint64l_t -+# define lzo_sword_t lzo_int64l_t -+# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INT64L_T -+#elif (LZO_ARCH_SPU) && (LZO_CC_GNUC) -+#if 0 -+ typedef unsigned lzo_word_t __attribute__((__mode__(__V16QI__))); -+ typedef int lzo_sword_t __attribute__((__mode__(__V16QI__))); -+# define lzo_word_t lzo_word_t -+# define lzo_sword_t lzo_sword_t -+# define LZO_SIZEOF_LZO_WORD_T 16 -+#endif -+#else -+# error "lzo_word_t" -+#endif -+#endif -+#endif -+#if 1 && defined(lzo_word_t) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_word_t) == LZO_WORDSIZE) -+ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_sword_t) == LZO_WORDSIZE) -+#endif -+#if 1 -+#define lzo_int8_t signed char -+#define lzo_uint8_t unsigned char -+#define LZO_SIZEOF_LZO_INT8_T 1 -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == 1) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == sizeof(lzo_uint8_t)) -+#endif -+#if defined(lzo_int16e_t) -+#define lzo_int16_t lzo_int16e_t -+#define lzo_uint16_t lzo_uint16e_t -+#define LZO_SIZEOF_LZO_INT16_T LZO_SIZEOF_LZO_INT16E_T -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == 2) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == sizeof(lzo_uint16_t)) -+#endif -+#if defined(lzo_int32e_t) -+#define lzo_int32_t lzo_int32e_t -+#define lzo_uint32_t lzo_uint32e_t -+#define LZO_SIZEOF_LZO_INT32_T LZO_SIZEOF_LZO_INT32E_T -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == 4) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == sizeof(lzo_uint32_t)) -+#endif -+#if defined(lzo_int64e_t) -+#define lzo_int64_t lzo_int64e_t -+#define lzo_uint64_t lzo_uint64e_t -+#define LZO_SIZEOF_LZO_INT64_T LZO_SIZEOF_LZO_INT64E_T -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == 8) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == sizeof(lzo_uint64_t)) -+#endif -+#if 1 -+#define lzo_int_least32_t lzo_int32l_t -+#define lzo_uint_least32_t lzo_uint32l_t -+#define LZO_SIZEOF_LZO_INT_LEAST32_T LZO_SIZEOF_LZO_INT32L_T -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) >= 4) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) == sizeof(lzo_uint_least32_t)) -+#endif -+#if defined(lzo_int64l_t) -+#define lzo_int_least64_t lzo_int64l_t -+#define lzo_uint_least64_t lzo_uint64l_t -+#define LZO_SIZEOF_LZO_INT_LEAST64_T LZO_SIZEOF_LZO_INT64L_T -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) >= 8) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) == sizeof(lzo_uint_least64_t)) -+#endif -+#if 1 -+#define lzo_int_fast32_t lzo_int32f_t -+#define lzo_uint_fast32_t lzo_uint32f_t -+#define LZO_SIZEOF_LZO_INT_FAST32_T LZO_SIZEOF_LZO_INT32F_T -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) >= 4) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) == sizeof(lzo_uint_fast32_t)) -+#endif -+#if defined(lzo_int64f_t) -+#define lzo_int_fast64_t lzo_int64f_t -+#define lzo_uint_fast64_t lzo_uint64f_t -+#define LZO_SIZEOF_LZO_INT_FAST64_T LZO_SIZEOF_LZO_INT64F_T -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) >= 8) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast64_t)) -+#endif -+#if !defined(LZO_INT16_C) -+# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 2) -+# define LZO_INT16_C(c) ((c) + 0) -+# define LZO_UINT16_C(c) ((c) + 0U) -+# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 2) -+# define LZO_INT16_C(c) ((c) + 0L) -+# define LZO_UINT16_C(c) ((c) + 0UL) -+# elif (LZO_SIZEOF_INT >= 2) -+# define LZO_INT16_C(c) (c) -+# define LZO_UINT16_C(c) (c##U) -+# elif (LZO_SIZEOF_LONG >= 2) -+# define LZO_INT16_C(c) (c##L) -+# define LZO_UINT16_C(c) (c##UL) -+# else -+# error "LZO_INT16_C" -+# endif -+#endif -+#if !defined(LZO_INT32_C) -+# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 4) -+# define LZO_INT32_C(c) ((c) + 0) -+# define LZO_UINT32_C(c) ((c) + 0U) -+# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 4) -+# define LZO_INT32_C(c) ((c) + 0L) -+# define LZO_UINT32_C(c) ((c) + 0UL) -+# elif (LZO_SIZEOF_INT >= 4) -+# define LZO_INT32_C(c) (c) -+# define LZO_UINT32_C(c) (c##U) -+# elif (LZO_SIZEOF_LONG >= 4) -+# define LZO_INT32_C(c) (c##L) -+# define LZO_UINT32_C(c) (c##UL) -+# elif (LZO_SIZEOF_LONG_LONG >= 4) -+# define LZO_INT32_C(c) (c##LL) -+# define LZO_UINT32_C(c) (c##ULL) -+# else -+# error "LZO_INT32_C" -+# endif -+#endif -+#if !defined(LZO_INT64_C) && defined(lzo_int64l_t) -+# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 8) -+# define LZO_INT64_C(c) ((c) + 0) -+# define LZO_UINT64_C(c) ((c) + 0U) -+# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 8) -+# define LZO_INT64_C(c) ((c) + 0L) -+# define LZO_UINT64_C(c) ((c) + 0UL) -+# elif (LZO_SIZEOF_INT >= 8) -+# define LZO_INT64_C(c) (c) -+# define LZO_UINT64_C(c) (c##U) -+# elif (LZO_SIZEOF_LONG >= 8) -+# define LZO_INT64_C(c) (c##L) -+# define LZO_UINT64_C(c) (c##UL) -+# else -+# error "LZO_INT64_C" -+# endif -+#endif -+#endif - - #endif - -@@ -1874,7 +3020,7 @@ extern "C" { - #undef LZO_HAVE_CONFIG_H - #include "minilzo.h" - --#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2050) -+#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2080) - # error "version mismatch in miniLZO source files" - #endif - -@@ -1886,23 +3032,9 @@ extern "C" { - #define __LZO_CONF_H 1 - - #if !defined(__LZO_IN_MINILZO) --#if (LZO_CFG_FREESTANDING) -+#if defined(LZO_CFG_FREESTANDING) && (LZO_CFG_FREESTANDING) - # define LZO_LIBC_FREESTANDING 1 - # define LZO_OS_FREESTANDING 1 --# define ACC_LIBC_FREESTANDING 1 --# define ACC_OS_FREESTANDING 1 --#endif --#if (LZO_CFG_NO_UNALIGNED) --# define ACC_CFG_NO_UNALIGNED 1 --#endif --#if (LZO_ARCH_GENERIC) --# define ACC_ARCH_GENERIC 1 --#endif --#if (LZO_ABI_NEUTRAL_ENDIAN) --# define ACC_ABI_NEUTRAL_ENDIAN 1 --#endif --#if (LZO_HAVE_CONFIG_H) --# define ACC_CONFIG_NO_HEADER 1 - #endif - #if defined(LZO_CFG_EXTRA_CONFIG_HEADER) - # include LZO_CFG_EXTRA_CONFIG_HEADER -@@ -1911,22 +3043,27 @@ extern "C" { - # error "include this file first" - #endif - #include "lzo/lzoconf.h" -+#if defined(LZO_CFG_EXTRA_CONFIG_HEADER2) -+# include LZO_CFG_EXTRA_CONFIG_HEADER2 -+#endif - #endif - --#if (LZO_VERSION < 0x02000) || !defined(__LZOCONF_H_INCLUDED) -+#if (LZO_VERSION < 0x2080) || !defined(__LZOCONF_H_INCLUDED) - # error "version mismatch" - #endif - --#if (LZO_CC_BORLANDC && LZO_ARCH_I086) --# pragma option -h -+#if (LZO_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1100)) -+# pragma warning(disable: 4702) - #endif -- - #if (LZO_CC_MSC && (_MSC_VER >= 1000)) - # pragma warning(disable: 4127 4701) -+# pragma warning(disable: 4514 4710 4711) - #endif - #if (LZO_CC_MSC && (_MSC_VER >= 1300)) - # pragma warning(disable: 4820) --# pragma warning(disable: 4514 4710 4711) -+#endif -+#if (LZO_CC_MSC && (_MSC_VER >= 1800)) -+# pragma warning(disable: 4746) - #endif - - #if (LZO_CC_SUNPROC) -@@ -1937,48 +3074,15 @@ extern "C" { - #endif - #endif - --#if (__LZO_MMODEL_HUGE) && !(LZO_HAVE_MM_HUGE_PTR) --# error "this should not happen - check defines for __huge" --#endif -- --#if defined(__LZO_IN_MINILZO) || defined(LZO_CFG_FREESTANDING) --#elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) --# define ACC_WANT_ACC_INCD_H 1 --# define ACC_WANT_ACC_INCE_H 1 --# define ACC_WANT_ACC_INCI_H 1 -+#if defined(__LZO_IN_MINILZO) || (LZO_CFG_FREESTANDING) - #elif 1 - # include - #else --# define ACC_WANT_ACC_INCD_H 1 -+# define LZO_WANT_ACC_INCD_H 1 - #endif -- --#if (LZO_ARCH_I086) --# define ACC_MM_AHSHIFT LZO_MM_AHSHIFT --# define ACC_PTR_FP_OFF(x) (((const unsigned __far*)&(x))[0]) --# define ACC_PTR_FP_SEG(x) (((const unsigned __far*)&(x))[1]) --# define ACC_PTR_MK_FP(s,o) ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o))) --#endif -- --#if !defined(lzo_uintptr_t) --# if defined(__LZO_MMODEL_HUGE) --# define lzo_uintptr_t unsigned long --# elif 1 && defined(LZO_OS_OS400) && (LZO_SIZEOF_VOID_P == 16) --# define __LZO_UINTPTR_T_IS_POINTER 1 -- typedef char* lzo_uintptr_t; --# define lzo_uintptr_t lzo_uintptr_t --# elif (LZO_SIZEOF_SIZE_T == LZO_SIZEOF_VOID_P) --# define lzo_uintptr_t size_t --# elif (LZO_SIZEOF_LONG == LZO_SIZEOF_VOID_P) --# define lzo_uintptr_t unsigned long --# elif (LZO_SIZEOF_INT == LZO_SIZEOF_VOID_P) --# define lzo_uintptr_t unsigned int --# elif (LZO_SIZEOF_LONG_LONG == LZO_SIZEOF_VOID_P) --# define lzo_uintptr_t unsigned long long --# else --# define lzo_uintptr_t size_t --# endif -+#if defined(LZO_HAVE_CONFIG_H) -+# define LZO_CFG_NO_CONFIG_HEADER 1 - #endif --LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) - - #if 1 && !defined(LZO_CFG_FREESTANDING) - #if 1 && !defined(HAVE_STRING_H) -@@ -2002,6 +3106,23 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) - #include - #endif - -+#if 1 || defined(lzo_int8_t) || defined(lzo_uint8_t) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == 1) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint8_t) == 1) -+#endif -+#if 1 || defined(lzo_int16_t) || defined(lzo_uint16_t) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == 2) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint16_t) == 2) -+#endif -+#if 1 || defined(lzo_int32_t) || defined(lzo_uint32_t) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == 4) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32_t) == 4) -+#endif -+#if defined(lzo_int64_t) || defined(lzo_uint64_t) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == 8) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint64_t) == 8) -+#endif -+ - #if (LZO_CFG_FREESTANDING) - # undef HAVE_MEMCMP - # undef HAVE_MEMCPY -@@ -2012,169 +3133,635 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) - #if !(HAVE_MEMCMP) - # undef memcmp - # define memcmp(a,b,c) lzo_memcmp(a,b,c) --#elif !(__LZO_MMODEL_HUGE) -+#else - # undef lzo_memcmp - # define lzo_memcmp(a,b,c) memcmp(a,b,c) - #endif - #if !(HAVE_MEMCPY) - # undef memcpy - # define memcpy(a,b,c) lzo_memcpy(a,b,c) --#elif !(__LZO_MMODEL_HUGE) -+#else - # undef lzo_memcpy - # define lzo_memcpy(a,b,c) memcpy(a,b,c) - #endif - #if !(HAVE_MEMMOVE) - # undef memmove - # define memmove(a,b,c) lzo_memmove(a,b,c) --#elif !(__LZO_MMODEL_HUGE) -+#else - # undef lzo_memmove - # define lzo_memmove(a,b,c) memmove(a,b,c) - #endif - #if !(HAVE_MEMSET) - # undef memset - # define memset(a,b,c) lzo_memset(a,b,c) --#elif !(__LZO_MMODEL_HUGE) -+#else - # undef lzo_memset - # define lzo_memset(a,b,c) memset(a,b,c) - #endif - --#undef NDEBUG --#if (LZO_CFG_FREESTANDING) --# undef LZO_DEBUG --# define NDEBUG 1 --# undef assert --# define assert(e) ((void)0) -+#undef NDEBUG -+#if (LZO_CFG_FREESTANDING) -+# undef LZO_DEBUG -+# define NDEBUG 1 -+# undef assert -+# define assert(e) ((void)0) -+#else -+# if !defined(LZO_DEBUG) -+# define NDEBUG 1 -+# endif -+# include -+#endif -+ -+#if 0 && defined(__BOUNDS_CHECKING_ON) -+# include -+#else -+# define BOUNDS_CHECKING_OFF_DURING(stmt) stmt -+# define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr) -+#endif -+ -+#if (LZO_CFG_PGO) -+# undef __lzo_likely -+# undef __lzo_unlikely -+# define __lzo_likely(e) (e) -+# define __lzo_unlikely(e) (e) -+#endif -+ -+#undef _ -+#undef __ -+#undef ___ -+#undef ____ -+#undef _p0 -+#undef _p1 -+#undef _p2 -+#undef _p3 -+#undef _p4 -+#undef _s0 -+#undef _s1 -+#undef _s2 -+#undef _s3 -+#undef _s4 -+#undef _ww -+ -+#if 1 -+# define LZO_BYTE(x) ((unsigned char) (x)) -+#else -+# define LZO_BYTE(x) ((unsigned char) ((x) & 0xff)) -+#endif -+ -+#define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b)) -+#define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b)) -+#define LZO_MAX3(a,b,c) ((a) >= (b) ? LZO_MAX(a,c) : LZO_MAX(b,c)) -+#define LZO_MIN3(a,b,c) ((a) <= (b) ? LZO_MIN(a,c) : LZO_MIN(b,c)) -+ -+#define lzo_sizeof(type) ((lzo_uint) (sizeof(type))) -+ -+#define LZO_HIGH(array) ((lzo_uint) (sizeof(array)/sizeof(*(array)))) -+ -+#define LZO_SIZE(bits) (1u << (bits)) -+#define LZO_MASK(bits) (LZO_SIZE(bits) - 1) -+ -+#define LZO_USIZE(bits) ((lzo_uint) 1 << (bits)) -+#define LZO_UMASK(bits) (LZO_USIZE(bits) - 1) -+ -+#if !defined(DMUL) -+#if 0 -+ -+# define DMUL(a,b) ((lzo_xint) ((lzo_uint32_t)(a) * (lzo_uint32_t)(b))) -+#else -+# define DMUL(a,b) ((lzo_xint) ((a) * (b))) -+#endif -+#endif -+ -+#ifndef __LZO_FUNC_H -+#define __LZO_FUNC_H 1 -+ -+#if !defined(LZO_BITOPS_USE_ASM_BITSCAN) && !defined(LZO_BITOPS_USE_GNUC_BITSCAN) && !defined(LZO_BITOPS_USE_MSC_BITSCAN) -+#if 1 && (LZO_ARCH_AMD64) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_ASM_SYNTAX_GNUC) -+#define LZO_BITOPS_USE_ASM_BITSCAN 1 -+#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_LLVM && (!defined(__llvm_tools_version__) || (__llvm_tools_version__+0 >= 0x010500ul)))) -+#define LZO_BITOPS_USE_GNUC_BITSCAN 1 -+#elif (LZO_OS_WIN32 || LZO_OS_WIN64) && ((LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 1010)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) -+#define LZO_BITOPS_USE_MSC_BITSCAN 1 -+#if (LZO_CC_MSC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) -+#include -+#endif -+#if (LZO_CC_MSC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) -+#pragma intrinsic(_BitScanReverse) -+#pragma intrinsic(_BitScanForward) -+#endif -+#if (LZO_CC_MSC) && (LZO_ARCH_AMD64) -+#pragma intrinsic(_BitScanReverse64) -+#pragma intrinsic(_BitScanForward64) -+#endif -+#endif -+#endif -+ -+__lzo_static_forceinline unsigned lzo_bitops_ctlz32_func(lzo_uint32_t v) -+{ -+#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) -+ unsigned long r; (void) _BitScanReverse(&r, v); return (unsigned) r ^ 31; -+#define lzo_bitops_ctlz32(v) lzo_bitops_ctlz32_func(v) -+#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) && (LZO_ASM_SYNTAX_GNUC) -+ lzo_uint32_t r; -+ __asm__("bsr %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); -+ return (unsigned) r ^ 31; -+#define lzo_bitops_ctlz32(v) lzo_bitops_ctlz32_func(v) -+#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_INT == 4) -+ unsigned r; r = (unsigned) __builtin_clz(v); return r; -+#define lzo_bitops_ctlz32(v) ((unsigned) __builtin_clz(v)) -+#else -+ LZO_UNUSED(v); return 0; -+#endif -+} -+ -+#if defined(lzo_uint64_t) -+__lzo_static_forceinline unsigned lzo_bitops_ctlz64_func(lzo_uint64_t v) -+{ -+#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64) -+ unsigned long r; (void) _BitScanReverse64(&r, v); return (unsigned) r ^ 63; -+#define lzo_bitops_ctlz64(v) lzo_bitops_ctlz64_func(v) -+#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64) && (LZO_ASM_SYNTAX_GNUC) -+ lzo_uint64_t r; -+ __asm__("bsr %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); -+ return (unsigned) r ^ 63; -+#define lzo_bitops_ctlz64(v) lzo_bitops_ctlz64_func(v) -+#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG == 8) && (LZO_WORDSIZE >= 8) -+ unsigned r; r = (unsigned) __builtin_clzl(v); return r; -+#define lzo_bitops_ctlz64(v) ((unsigned) __builtin_clzl(v)) -+#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG_LONG == 8) && (LZO_WORDSIZE >= 8) -+ unsigned r; r = (unsigned) __builtin_clzll(v); return r; -+#define lzo_bitops_ctlz64(v) ((unsigned) __builtin_clzll(v)) -+#else -+ LZO_UNUSED(v); return 0; -+#endif -+} -+#endif -+ -+__lzo_static_forceinline unsigned lzo_bitops_cttz32_func(lzo_uint32_t v) -+{ -+#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) -+ unsigned long r; (void) _BitScanForward(&r, v); return (unsigned) r; -+#define lzo_bitops_cttz32(v) lzo_bitops_cttz32_func(v) -+#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) && (LZO_ASM_SYNTAX_GNUC) -+ lzo_uint32_t r; -+ __asm__("bsf %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); -+ return (unsigned) r; -+#define lzo_bitops_cttz32(v) lzo_bitops_cttz32_func(v) -+#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_INT >= 4) -+ unsigned r; r = (unsigned) __builtin_ctz(v); return r; -+#define lzo_bitops_cttz32(v) ((unsigned) __builtin_ctz(v)) -+#else -+ LZO_UNUSED(v); return 0; -+#endif -+} -+ -+#if defined(lzo_uint64_t) -+__lzo_static_forceinline unsigned lzo_bitops_cttz64_func(lzo_uint64_t v) -+{ -+#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64) -+ unsigned long r; (void) _BitScanForward64(&r, v); return (unsigned) r; -+#define lzo_bitops_cttz64(v) lzo_bitops_cttz64_func(v) -+#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64) && (LZO_ASM_SYNTAX_GNUC) -+ lzo_uint64_t r; -+ __asm__("bsf %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); -+ return (unsigned) r; -+#define lzo_bitops_cttz64(v) lzo_bitops_cttz64_func(v) -+#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG >= 8) && (LZO_WORDSIZE >= 8) -+ unsigned r; r = (unsigned) __builtin_ctzl(v); return r; -+#define lzo_bitops_cttz64(v) ((unsigned) __builtin_ctzl(v)) -+#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG_LONG >= 8) && (LZO_WORDSIZE >= 8) -+ unsigned r; r = (unsigned) __builtin_ctzll(v); return r; -+#define lzo_bitops_cttz64(v) ((unsigned) __builtin_ctzll(v)) -+#else -+ LZO_UNUSED(v); return 0; -+#endif -+} -+#endif -+ -+#if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -+static void __attribute__((__unused__)) -+#else -+__lzo_static_forceinline void -+#endif -+lzo_bitops_unused_funcs(void) -+{ -+ LZO_UNUSED_FUNC(lzo_bitops_ctlz32_func); -+ LZO_UNUSED_FUNC(lzo_bitops_cttz32_func); -+#if defined(lzo_uint64_t) -+ LZO_UNUSED_FUNC(lzo_bitops_ctlz64_func); -+ LZO_UNUSED_FUNC(lzo_bitops_cttz64_func); -+#endif -+ LZO_UNUSED_FUNC(lzo_bitops_unused_funcs); -+} -+ -+#if defined(__lzo_alignof) && !(LZO_CFG_NO_UNALIGNED) -+#ifndef __lzo_memops_tcheck -+#define __lzo_memops_tcheck(t,a,b) ((void)0, sizeof(t) == (a) && __lzo_alignof(t) == (b)) -+#endif -+#endif -+#ifndef lzo_memops_TU0p -+#define lzo_memops_TU0p void __LZO_MMODEL * -+#endif -+#ifndef lzo_memops_TU1p -+#define lzo_memops_TU1p unsigned char __LZO_MMODEL * -+#endif -+#ifndef lzo_memops_TU2p -+#if (LZO_OPT_UNALIGNED16) -+typedef lzo_uint16_t __lzo_may_alias lzo_memops_TU2; -+#define lzo_memops_TU2p volatile lzo_memops_TU2 * -+#elif defined(__lzo_byte_struct) -+__lzo_byte_struct(lzo_memops_TU2_struct,2) -+typedef struct lzo_memops_TU2_struct lzo_memops_TU2; -+#else -+struct lzo_memops_TU2_struct { unsigned char a[2]; } __lzo_may_alias; -+typedef struct lzo_memops_TU2_struct lzo_memops_TU2; -+#endif -+#ifndef lzo_memops_TU2p -+#define lzo_memops_TU2p lzo_memops_TU2 * -+#endif -+#endif -+#ifndef lzo_memops_TU4p -+#if (LZO_OPT_UNALIGNED32) -+typedef lzo_uint32_t __lzo_may_alias lzo_memops_TU4; -+#define lzo_memops_TU4p volatile lzo_memops_TU4 __LZO_MMODEL * -+#elif defined(__lzo_byte_struct) -+__lzo_byte_struct(lzo_memops_TU4_struct,4) -+typedef struct lzo_memops_TU4_struct lzo_memops_TU4; -+#else -+struct lzo_memops_TU4_struct { unsigned char a[4]; } __lzo_may_alias; -+typedef struct lzo_memops_TU4_struct lzo_memops_TU4; -+#endif -+#ifndef lzo_memops_TU4p -+#define lzo_memops_TU4p lzo_memops_TU4 __LZO_MMODEL * -+#endif -+#endif -+#ifndef lzo_memops_TU8p -+#if (LZO_OPT_UNALIGNED64) -+typedef lzo_uint64_t __lzo_may_alias lzo_memops_TU8; -+#define lzo_memops_TU8p volatile lzo_memops_TU8 __LZO_MMODEL * -+#elif defined(__lzo_byte_struct) -+__lzo_byte_struct(lzo_memops_TU8_struct,8) -+typedef struct lzo_memops_TU8_struct lzo_memops_TU8; -+#else -+struct lzo_memops_TU8_struct { unsigned char a[8]; } __lzo_may_alias; -+typedef struct lzo_memops_TU8_struct lzo_memops_TU8; -+#endif -+#ifndef lzo_memops_TU8p -+#define lzo_memops_TU8p lzo_memops_TU8 __LZO_MMODEL * -+#endif -+#endif -+#ifndef lzo_memops_set_TU1p -+#define lzo_memops_set_TU1p volatile lzo_memops_TU1p -+#endif -+#ifndef lzo_memops_move_TU1p -+#define lzo_memops_move_TU1p lzo_memops_TU1p -+#endif -+#define LZO_MEMOPS_SET1(dd,cc) \ -+ LZO_BLOCK_BEGIN \ -+ lzo_memops_set_TU1p d__1 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ -+ d__1[0] = LZO_BYTE(cc); \ -+ LZO_BLOCK_END -+#define LZO_MEMOPS_SET2(dd,cc) \ -+ LZO_BLOCK_BEGIN \ -+ lzo_memops_set_TU1p d__2 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ -+ d__2[0] = LZO_BYTE(cc); d__2[1] = LZO_BYTE(cc); \ -+ LZO_BLOCK_END -+#define LZO_MEMOPS_SET3(dd,cc) \ -+ LZO_BLOCK_BEGIN \ -+ lzo_memops_set_TU1p d__3 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ -+ d__3[0] = LZO_BYTE(cc); d__3[1] = LZO_BYTE(cc); d__3[2] = LZO_BYTE(cc); \ -+ LZO_BLOCK_END -+#define LZO_MEMOPS_SET4(dd,cc) \ -+ LZO_BLOCK_BEGIN \ -+ lzo_memops_set_TU1p d__4 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ -+ d__4[0] = LZO_BYTE(cc); d__4[1] = LZO_BYTE(cc); d__4[2] = LZO_BYTE(cc); d__4[3] = LZO_BYTE(cc); \ -+ LZO_BLOCK_END -+#define LZO_MEMOPS_MOVE1(dd,ss) \ -+ LZO_BLOCK_BEGIN \ -+ lzo_memops_move_TU1p d__1 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ -+ const lzo_memops_move_TU1p s__1 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ -+ d__1[0] = s__1[0]; \ -+ LZO_BLOCK_END -+#define LZO_MEMOPS_MOVE2(dd,ss) \ -+ LZO_BLOCK_BEGIN \ -+ lzo_memops_move_TU1p d__2 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ -+ const lzo_memops_move_TU1p s__2 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ -+ d__2[0] = s__2[0]; d__2[1] = s__2[1]; \ -+ LZO_BLOCK_END -+#define LZO_MEMOPS_MOVE3(dd,ss) \ -+ LZO_BLOCK_BEGIN \ -+ lzo_memops_move_TU1p d__3 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ -+ const lzo_memops_move_TU1p s__3 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ -+ d__3[0] = s__3[0]; d__3[1] = s__3[1]; d__3[2] = s__3[2]; \ -+ LZO_BLOCK_END -+#define LZO_MEMOPS_MOVE4(dd,ss) \ -+ LZO_BLOCK_BEGIN \ -+ lzo_memops_move_TU1p d__4 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ -+ const lzo_memops_move_TU1p s__4 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ -+ d__4[0] = s__4[0]; d__4[1] = s__4[1]; d__4[2] = s__4[2]; d__4[3] = s__4[3]; \ -+ LZO_BLOCK_END -+#define LZO_MEMOPS_MOVE8(dd,ss) \ -+ LZO_BLOCK_BEGIN \ -+ lzo_memops_move_TU1p d__8 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ -+ const lzo_memops_move_TU1p s__8 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ -+ d__8[0] = s__8[0]; d__8[1] = s__8[1]; d__8[2] = s__8[2]; d__8[3] = s__8[3]; \ -+ d__8[4] = s__8[4]; d__8[5] = s__8[5]; d__8[6] = s__8[6]; d__8[7] = s__8[7]; \ -+ LZO_BLOCK_END -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU1p)0)==1) -+#define LZO_MEMOPS_COPY1(dd,ss) LZO_MEMOPS_MOVE1(dd,ss) -+#if (LZO_OPT_UNALIGNED16) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU2p)0)==2) -+#define LZO_MEMOPS_COPY2(dd,ss) \ -+ * (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss) -+#elif defined(__lzo_memops_tcheck) -+#define LZO_MEMOPS_COPY2(dd,ss) \ -+ LZO_BLOCK_BEGIN if (__lzo_memops_tcheck(lzo_memops_TU2,2,1)) { \ -+ * (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss); \ -+ } else { LZO_MEMOPS_MOVE2(dd,ss); } LZO_BLOCK_END -+#else -+#define LZO_MEMOPS_COPY2(dd,ss) LZO_MEMOPS_MOVE2(dd,ss) -+#endif -+#if (LZO_OPT_UNALIGNED32) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU4p)0)==4) -+#define LZO_MEMOPS_COPY4(dd,ss) \ -+ * (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss) -+#elif defined(__lzo_memops_tcheck) -+#define LZO_MEMOPS_COPY4(dd,ss) \ -+ LZO_BLOCK_BEGIN if (__lzo_memops_tcheck(lzo_memops_TU4,4,1)) { \ -+ * (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss); \ -+ } else { LZO_MEMOPS_MOVE4(dd,ss); } LZO_BLOCK_END -+#else -+#define LZO_MEMOPS_COPY4(dd,ss) LZO_MEMOPS_MOVE4(dd,ss) -+#endif -+#if (LZO_WORDSIZE != 8) -+#define LZO_MEMOPS_COPY8(dd,ss) \ -+ LZO_BLOCK_BEGIN LZO_MEMOPS_COPY4(dd,ss); LZO_MEMOPS_COPY4((lzo_memops_TU1p)(lzo_memops_TU0p)(dd)+4,(const lzo_memops_TU1p)(const lzo_memops_TU0p)(ss)+4); LZO_BLOCK_END -+#else -+#if (LZO_OPT_UNALIGNED64) -+LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU8p)0)==8) -+#define LZO_MEMOPS_COPY8(dd,ss) \ -+ * (lzo_memops_TU8p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss) -+#elif (LZO_OPT_UNALIGNED32) -+#define LZO_MEMOPS_COPY8(dd,ss) \ -+ LZO_BLOCK_BEGIN LZO_MEMOPS_COPY4(dd,ss); LZO_MEMOPS_COPY4((lzo_memops_TU1p)(lzo_memops_TU0p)(dd)+4,(const lzo_memops_TU1p)(const lzo_memops_TU0p)(ss)+4); LZO_BLOCK_END -+#elif defined(__lzo_memops_tcheck) -+#define LZO_MEMOPS_COPY8(dd,ss) \ -+ LZO_BLOCK_BEGIN if (__lzo_memops_tcheck(lzo_memops_TU8,8,1)) { \ -+ * (lzo_memops_TU8p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss); \ -+ } else { LZO_MEMOPS_MOVE8(dd,ss); } LZO_BLOCK_END -+#else -+#define LZO_MEMOPS_COPY8(dd,ss) LZO_MEMOPS_MOVE8(dd,ss) -+#endif -+#endif -+#define LZO_MEMOPS_COPYN(dd,ss,nn) \ -+ LZO_BLOCK_BEGIN \ -+ lzo_memops_TU1p d__n = (lzo_memops_TU1p) (lzo_memops_TU0p) (dd); \ -+ const lzo_memops_TU1p s__n = (const lzo_memops_TU1p) (const lzo_memops_TU0p) (ss); \ -+ lzo_uint n__n = (nn); \ -+ while ((void)0, n__n >= 8) { LZO_MEMOPS_COPY8(d__n, s__n); d__n += 8; s__n += 8; n__n -= 8; } \ -+ if ((void)0, n__n >= 4) { LZO_MEMOPS_COPY4(d__n, s__n); d__n += 4; s__n += 4; n__n -= 4; } \ -+ if ((void)0, n__n > 0) do { *d__n++ = *s__n++; } while (--n__n > 0); \ -+ LZO_BLOCK_END -+ -+__lzo_static_forceinline lzo_uint16_t lzo_memops_get_le16(const lzo_voidp ss) -+{ -+ lzo_uint16_t v; -+#if (LZO_ABI_LITTLE_ENDIAN) -+ LZO_MEMOPS_COPY2(&v, ss); -+#elif (LZO_OPT_UNALIGNED16 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) -+ const lzo_memops_TU2p s = (const lzo_memops_TU2p) ss; -+ unsigned long vv; -+ __asm__("lhbrx %0,0,%1" : "=r" (vv) : "r" (s), "m" (*s)); -+ v = (lzo_uint16_t) vv; - #else --# if !defined(LZO_DEBUG) --# define NDEBUG 1 --# endif --# include -+ const lzo_memops_TU1p s = (const lzo_memops_TU1p) ss; -+ v = (lzo_uint16_t) (((lzo_uint16_t)s[0]) | ((lzo_uint16_t)s[1] << 8)); - #endif -- --#if 0 && defined(__BOUNDS_CHECKING_ON) --# include -+ return v; -+} -+#if (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) -+#define LZO_MEMOPS_GET_LE16(ss) * (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss) - #else --# define BOUNDS_CHECKING_OFF_DURING(stmt) stmt --# define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr) -+#define LZO_MEMOPS_GET_LE16(ss) lzo_memops_get_le16(ss) - #endif - --#if !defined(__lzo_inline) --# define __lzo_inline /*empty*/ --#endif --#if !defined(__lzo_forceinline) --# define __lzo_forceinline /*empty*/ -+__lzo_static_forceinline lzo_uint32_t lzo_memops_get_le32(const lzo_voidp ss) -+{ -+ lzo_uint32_t v; -+#if (LZO_ABI_LITTLE_ENDIAN) -+ LZO_MEMOPS_COPY4(&v, ss); -+#elif (LZO_OPT_UNALIGNED32 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) -+ const lzo_memops_TU4p s = (const lzo_memops_TU4p) ss; -+ unsigned long vv; -+ __asm__("lwbrx %0,0,%1" : "=r" (vv) : "r" (s), "m" (*s)); -+ v = (lzo_uint32_t) vv; -+#else -+ const lzo_memops_TU1p s = (const lzo_memops_TU1p) ss; -+ v = (lzo_uint32_t) (((lzo_uint32_t)s[0]) | ((lzo_uint32_t)s[1] << 8) | ((lzo_uint32_t)s[2] << 16) | ((lzo_uint32_t)s[3] << 24)); - #endif --#if !defined(__lzo_noinline) --# define __lzo_noinline /*empty*/ -+ return v; -+} -+#if (LZO_OPT_UNALIGNED32) && (LZO_ABI_LITTLE_ENDIAN) -+#define LZO_MEMOPS_GET_LE32(ss) * (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss) -+#else -+#define LZO_MEMOPS_GET_LE32(ss) lzo_memops_get_le32(ss) - #endif - --#if (LZO_CFG_PGO) --# undef __acc_likely --# undef __acc_unlikely --# undef __lzo_likely --# undef __lzo_unlikely --# define __acc_likely(e) (e) --# define __acc_unlikely(e) (e) --# define __lzo_likely(e) (e) --# define __lzo_unlikely(e) (e) -+#if (LZO_OPT_UNALIGNED64) && (LZO_ABI_LITTLE_ENDIAN) -+#define LZO_MEMOPS_GET_LE64(ss) * (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss) - #endif - --#if 1 --# define LZO_BYTE(x) ((unsigned char) (x)) -+__lzo_static_forceinline lzo_uint16_t lzo_memops_get_ne16(const lzo_voidp ss) -+{ -+ lzo_uint16_t v; -+ LZO_MEMOPS_COPY2(&v, ss); -+ return v; -+} -+#if (LZO_OPT_UNALIGNED16) -+#define LZO_MEMOPS_GET_NE16(ss) * (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss) - #else --# define LZO_BYTE(x) ((unsigned char) ((x) & 0xff)) -+#define LZO_MEMOPS_GET_NE16(ss) lzo_memops_get_ne16(ss) - #endif - --#define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b)) --#define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b)) --#define LZO_MAX3(a,b,c) ((a) >= (b) ? LZO_MAX(a,c) : LZO_MAX(b,c)) --#define LZO_MIN3(a,b,c) ((a) <= (b) ? LZO_MIN(a,c) : LZO_MIN(b,c)) -- --#define lzo_sizeof(type) ((lzo_uint) (sizeof(type))) -+__lzo_static_forceinline lzo_uint32_t lzo_memops_get_ne32(const lzo_voidp ss) -+{ -+ lzo_uint32_t v; -+ LZO_MEMOPS_COPY4(&v, ss); -+ return v; -+} -+#if (LZO_OPT_UNALIGNED32) -+#define LZO_MEMOPS_GET_NE32(ss) * (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss) -+#else -+#define LZO_MEMOPS_GET_NE32(ss) lzo_memops_get_ne32(ss) -+#endif - --#define LZO_HIGH(array) ((lzo_uint) (sizeof(array)/sizeof(*(array)))) -+#if (LZO_OPT_UNALIGNED64) -+#define LZO_MEMOPS_GET_NE64(ss) * (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss) -+#endif - --#define LZO_SIZE(bits) (1u << (bits)) --#define LZO_MASK(bits) (LZO_SIZE(bits) - 1) -+__lzo_static_forceinline void lzo_memops_put_le16(lzo_voidp dd, lzo_uint16_t vv) -+{ -+#if (LZO_ABI_LITTLE_ENDIAN) -+ LZO_MEMOPS_COPY2(dd, &vv); -+#elif (LZO_OPT_UNALIGNED16 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) -+ lzo_memops_TU2p d = (lzo_memops_TU2p) dd; -+ unsigned long v = vv; -+ __asm__("sthbrx %2,0,%1" : "=m" (*d) : "r" (d), "r" (v)); -+#else -+ lzo_memops_TU1p d = (lzo_memops_TU1p) dd; -+ d[0] = LZO_BYTE((vv ) & 0xff); -+ d[1] = LZO_BYTE((vv >> 8) & 0xff); -+#endif -+} -+#if (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) -+#define LZO_MEMOPS_PUT_LE16(dd,vv) (* (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = (vv)) -+#else -+#define LZO_MEMOPS_PUT_LE16(dd,vv) lzo_memops_put_le16(dd,vv) -+#endif - --#define LZO_LSIZE(bits) (1ul << (bits)) --#define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1) -+__lzo_static_forceinline void lzo_memops_put_le32(lzo_voidp dd, lzo_uint32_t vv) -+{ -+#if (LZO_ABI_LITTLE_ENDIAN) -+ LZO_MEMOPS_COPY4(dd, &vv); -+#elif (LZO_OPT_UNALIGNED32 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) -+ lzo_memops_TU4p d = (lzo_memops_TU4p) dd; -+ unsigned long v = vv; -+ __asm__("stwbrx %2,0,%1" : "=m" (*d) : "r" (d), "r" (v)); -+#else -+ lzo_memops_TU1p d = (lzo_memops_TU1p) dd; -+ d[0] = LZO_BYTE((vv ) & 0xff); -+ d[1] = LZO_BYTE((vv >> 8) & 0xff); -+ d[2] = LZO_BYTE((vv >> 16) & 0xff); -+ d[3] = LZO_BYTE((vv >> 24) & 0xff); -+#endif -+} -+#if (LZO_OPT_UNALIGNED32) && (LZO_ABI_LITTLE_ENDIAN) -+#define LZO_MEMOPS_PUT_LE32(dd,vv) (* (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = (vv)) -+#else -+#define LZO_MEMOPS_PUT_LE32(dd,vv) lzo_memops_put_le32(dd,vv) -+#endif - --#define LZO_USIZE(bits) ((lzo_uint) 1 << (bits)) --#define LZO_UMASK(bits) (LZO_USIZE(bits) - 1) -+__lzo_static_forceinline void lzo_memops_put_ne16(lzo_voidp dd, lzo_uint16_t vv) -+{ -+ LZO_MEMOPS_COPY2(dd, &vv); -+} -+#if (LZO_OPT_UNALIGNED16) -+#define LZO_MEMOPS_PUT_NE16(dd,vv) (* (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = (vv)) -+#else -+#define LZO_MEMOPS_PUT_NE16(dd,vv) lzo_memops_put_ne16(dd,vv) -+#endif - --#if !defined(DMUL) --#if 0 -+__lzo_static_forceinline void lzo_memops_put_ne32(lzo_voidp dd, lzo_uint32_t vv) -+{ -+ LZO_MEMOPS_COPY4(dd, &vv); -+} -+#if (LZO_OPT_UNALIGNED32) -+#define LZO_MEMOPS_PUT_NE32(dd,vv) (* (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = (vv)) -+#else -+#define LZO_MEMOPS_PUT_NE32(dd,vv) lzo_memops_put_ne32(dd,vv) -+#endif - --# define DMUL(a,b) ((lzo_xint) ((lzo_uint32)(a) * (lzo_uint32)(b))) -+#if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -+static void __attribute__((__unused__)) - #else --# define DMUL(a,b) ((lzo_xint) ((a) * (b))) -+__lzo_static_forceinline void - #endif -+lzo_memops_unused_funcs(void) -+{ -+ LZO_UNUSED_FUNC(lzo_memops_get_le16); -+ LZO_UNUSED_FUNC(lzo_memops_get_le32); -+ LZO_UNUSED_FUNC(lzo_memops_get_ne16); -+ LZO_UNUSED_FUNC(lzo_memops_get_ne32); -+ LZO_UNUSED_FUNC(lzo_memops_put_le16); -+ LZO_UNUSED_FUNC(lzo_memops_put_le32); -+ LZO_UNUSED_FUNC(lzo_memops_put_ne16); -+ LZO_UNUSED_FUNC(lzo_memops_put_ne32); -+ LZO_UNUSED_FUNC(lzo_memops_unused_funcs); -+} -+ - #endif - --#if 1 && (LZO_ARCH_AMD64 || LZO_ARCH_I386 || LZO_ARCH_POWERPC) --# if (LZO_SIZEOF_SHORT == 2) --# define LZO_UNALIGNED_OK_2 1 --# endif --# if (LZO_SIZEOF_INT == 4) --# define LZO_UNALIGNED_OK_4 1 --# endif -+#ifndef UA_SET1 -+#define UA_SET1 LZO_MEMOPS_SET1 - #endif --#if 1 && (LZO_ARCH_AMD64) --# if defined(LZO_UINT64_MAX) --# define LZO_UNALIGNED_OK_8 1 --# endif -+#ifndef UA_SET2 -+#define UA_SET2 LZO_MEMOPS_SET2 - #endif --#if (LZO_CFG_NO_UNALIGNED) --# undef LZO_UNALIGNED_OK_2 --# undef LZO_UNALIGNED_OK_4 --# undef LZO_UNALIGNED_OK_8 --#endif -- --#undef UA_GET16 --#undef UA_SET16 --#undef UA_COPY16 --#undef UA_GET32 --#undef UA_SET32 --#undef UA_COPY32 --#undef UA_GET64 --#undef UA_SET64 --#undef UA_COPY64 --#if defined(LZO_UNALIGNED_OK_2) -- LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(unsigned short) == 2) --# if 1 && defined(ACC_UA_COPY16) --# define UA_GET16 ACC_UA_GET16 --# define UA_SET16 ACC_UA_SET16 --# define UA_COPY16 ACC_UA_COPY16 --# else --# define UA_GET16(p) (* (__lzo_ua_volatile const lzo_ushortp) (__lzo_ua_volatile const lzo_voidp) (p)) --# define UA_SET16(p,v) ((* (__lzo_ua_volatile lzo_ushortp) (__lzo_ua_volatile lzo_voidp) (p)) = (unsigned short) (v)) --# define UA_COPY16(d,s) UA_SET16(d, UA_GET16(s)) --# endif -+#ifndef UA_SET3 -+#define UA_SET3 LZO_MEMOPS_SET3 - #endif --#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) -- LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32) == 4) --# if 1 && defined(ACC_UA_COPY32) --# define UA_GET32 ACC_UA_GET32 --# define UA_SET32 ACC_UA_SET32 --# define UA_COPY32 ACC_UA_COPY32 --# else --# define UA_GET32(p) (* (__lzo_ua_volatile const lzo_uint32p) (__lzo_ua_volatile const lzo_voidp) (p)) --# define UA_SET32(p,v) ((* (__lzo_ua_volatile lzo_uint32p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint32) (v)) --# define UA_COPY32(d,s) UA_SET32(d, UA_GET32(s)) --# endif -+#ifndef UA_SET4 -+#define UA_SET4 LZO_MEMOPS_SET4 - #endif --#if defined(LZO_UNALIGNED_OK_8) -- LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint64) == 8) --# if 1 && defined(ACC_UA_COPY64) --# define UA_GET64 ACC_UA_GET64 --# define UA_SET64 ACC_UA_SET64 --# define UA_COPY64 ACC_UA_COPY64 --# else --# define UA_GET64(p) (* (__lzo_ua_volatile const lzo_uint64p) (__lzo_ua_volatile const lzo_voidp) (p)) --# define UA_SET64(p,v) ((* (__lzo_ua_volatile lzo_uint64p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint64) (v)) --# define UA_COPY64(d,s) UA_SET64(d, UA_GET64(s)) --# endif -+#ifndef UA_MOVE1 -+#define UA_MOVE1 LZO_MEMOPS_MOVE1 -+#endif -+#ifndef UA_MOVE2 -+#define UA_MOVE2 LZO_MEMOPS_MOVE2 -+#endif -+#ifndef UA_MOVE3 -+#define UA_MOVE3 LZO_MEMOPS_MOVE3 -+#endif -+#ifndef UA_MOVE4 -+#define UA_MOVE4 LZO_MEMOPS_MOVE4 -+#endif -+#ifndef UA_MOVE8 -+#define UA_MOVE8 LZO_MEMOPS_MOVE8 -+#endif -+#ifndef UA_COPY1 -+#define UA_COPY1 LZO_MEMOPS_COPY1 -+#endif -+#ifndef UA_COPY2 -+#define UA_COPY2 LZO_MEMOPS_COPY2 -+#endif -+#ifndef UA_COPY3 -+#define UA_COPY3 LZO_MEMOPS_COPY3 -+#endif -+#ifndef UA_COPY4 -+#define UA_COPY4 LZO_MEMOPS_COPY4 -+#endif -+#ifndef UA_COPY8 -+#define UA_COPY8 LZO_MEMOPS_COPY8 -+#endif -+#ifndef UA_COPYN -+#define UA_COPYN LZO_MEMOPS_COPYN -+#endif -+#ifndef UA_COPYN_X -+#define UA_COPYN_X LZO_MEMOPS_COPYN -+#endif -+#ifndef UA_GET_LE16 -+#define UA_GET_LE16 LZO_MEMOPS_GET_LE16 -+#endif -+#ifndef UA_GET_LE32 -+#define UA_GET_LE32 LZO_MEMOPS_GET_LE32 -+#endif -+#ifdef LZO_MEMOPS_GET_LE64 -+#ifndef UA_GET_LE64 -+#define UA_GET_LE64 LZO_MEMOPS_GET_LE64 -+#endif -+#endif -+#ifndef UA_GET_NE16 -+#define UA_GET_NE16 LZO_MEMOPS_GET_NE16 -+#endif -+#ifndef UA_GET_NE32 -+#define UA_GET_NE32 LZO_MEMOPS_GET_NE32 -+#endif -+#ifdef LZO_MEMOPS_GET_NE64 -+#ifndef UA_GET_NE64 -+#define UA_GET_NE64 LZO_MEMOPS_GET_NE64 -+#endif -+#endif -+#ifndef UA_PUT_LE16 -+#define UA_PUT_LE16 LZO_MEMOPS_PUT_LE16 -+#endif -+#ifndef UA_PUT_LE32 -+#define UA_PUT_LE32 LZO_MEMOPS_PUT_LE32 -+#endif -+#ifndef UA_PUT_NE16 -+#define UA_PUT_NE16 LZO_MEMOPS_PUT_NE16 -+#endif -+#ifndef UA_PUT_NE32 -+#define UA_PUT_NE32 LZO_MEMOPS_PUT_NE32 - #endif - - #define MEMCPY8_DS(dest,src,len) \ -@@ -2195,25 +3782,10 @@ LZO_EXTERN(const lzo_bytep) lzo_copyright(void); - extern "C" { - #endif - --#if !defined(lzo_uintptr_t) --# if (__LZO_MMODEL_HUGE) --# define lzo_uintptr_t unsigned long --# else --# define lzo_uintptr_t acc_uintptr_t --# ifdef __ACC_INTPTR_T_IS_POINTER --# define __LZO_UINTPTR_T_IS_POINTER 1 --# endif --# endif --#endif -- - #if (LZO_ARCH_I086) --#define PTR(a) ((lzo_bytep) (a)) --#define PTR_ALIGNED_4(a) ((ACC_PTR_FP_OFF(a) & 3) == 0) --#define PTR_ALIGNED2_4(a,b) (((ACC_PTR_FP_OFF(a) | ACC_PTR_FP_OFF(b)) & 3) == 0) -+#error "LZO_ARCH_I086 is unsupported" - #elif (LZO_MM_PVP) --#define PTR(a) ((lzo_bytep) (a)) --#define PTR_ALIGNED_8(a) ((((lzo_uintptr_t)(a)) >> 61) == 0) --#define PTR_ALIGNED2_8(a,b) ((((lzo_uintptr_t)(a)|(lzo_uintptr_t)(b)) >> 61) == 0) -+#error "LZO_MM_PVP is unsupported" - #else - #define PTR(a) ((lzo_uintptr_t) (a)) - #define PTR_LINEAR(a) PTR(a) -@@ -2243,24 +3815,28 @@ typedef union - unsigned long a_ulong; - lzo_int a_lzo_int; - lzo_uint a_lzo_uint; -- lzo_int32 a_lzo_int32; -- lzo_uint32 a_lzo_uint32; --#if defined(LZO_UINT64_MAX) -- lzo_int64 a_lzo_int64; -- lzo_uint64 a_lzo_uint64; --#endif -+ lzo_xint a_lzo_xint; -+ lzo_int16_t a_lzo_int16_t; -+ lzo_uint16_t a_lzo_uint16_t; -+ lzo_int32_t a_lzo_int32_t; -+ lzo_uint32_t a_lzo_uint32_t; -+#if defined(lzo_uint64_t) -+ lzo_int64_t a_lzo_int64_t; -+ lzo_uint64_t a_lzo_uint64_t; -+#endif -+ size_t a_size_t; - ptrdiff_t a_ptrdiff_t; - lzo_uintptr_t a_lzo_uintptr_t; -- lzo_voidp a_lzo_voidp; - void * a_void_p; -- lzo_bytep a_lzo_bytep; -- lzo_bytepp a_lzo_bytepp; -- lzo_uintp a_lzo_uintp; -- lzo_uint * a_lzo_uint_p; -- lzo_uint32p a_lzo_uint32p; -- lzo_uint32 * a_lzo_uint32_p; -- unsigned char * a_uchar_p; - char * a_char_p; -+ unsigned char * a_uchar_p; -+ const void * a_c_void_p; -+ const char * a_c_char_p; -+ const unsigned char * a_c_uchar_p; -+ lzo_voidp a_lzo_voidp; -+ lzo_bytep a_lzo_bytep; -+ const lzo_voidp a_c_lzo_voidp; -+ const lzo_bytep a_c_lzo_bytep; - } - lzo_full_align_t; - -@@ -2276,18 +3852,14 @@ lzo_full_align_t; - - #ifndef LZO_DICT_USE_PTR - #define LZO_DICT_USE_PTR 1 --#if 0 && (LZO_ARCH_I086) --# undef LZO_DICT_USE_PTR --# define LZO_DICT_USE_PTR 0 --#endif - #endif - - #if (LZO_DICT_USE_PTR) - # define lzo_dict_t const lzo_bytep --# define lzo_dict_p lzo_dict_t __LZO_MMODEL * -+# define lzo_dict_p lzo_dict_t * - #else - # define lzo_dict_t lzo_uint --# define lzo_dict_p lzo_dict_t __LZO_MMODEL * -+# define lzo_dict_p lzo_dict_t * - #endif - - #endif -@@ -2300,10 +3872,9 @@ __lzo_ptr_linear(const lzo_voidp ptr) - lzo_uintptr_t p; - - #if (LZO_ARCH_I086) -- p = (((lzo_uintptr_t)(ACC_PTR_FP_SEG(ptr))) << (16 - ACC_MM_AHSHIFT)) + (ACC_PTR_FP_OFF(ptr)); -+#error "LZO_ARCH_I086 is unsupported" - #elif (LZO_MM_PVP) -- p = (lzo_uintptr_t) (ptr); -- p = (p << 3) | (p >> 61); -+#error "LZO_MM_PVP is unsupported" - #else - p = (lzo_uintptr_t) PTR_LINEAR(ptr); - #endif -@@ -2314,9 +3885,8 @@ __lzo_ptr_linear(const lzo_voidp ptr) - LZO_PUBLIC(unsigned) - __lzo_align_gap(const lzo_voidp ptr, lzo_uint size) - { --#if defined(__LZO_UINTPTR_T_IS_POINTER) -- size_t n = (size_t) ptr; -- n = (((n + size - 1) / size) * size) - n; -+#if (__LZO_UINTPTR_T_IS_POINTER) -+#error "__LZO_UINTPTR_T_IS_POINTER is unsupported" - #else - lzo_uintptr_t p, n; - p = __lzo_ptr_linear(ptr); -@@ -2342,7 +3912,7 @@ static const char __lzo_copyright[] = - #else - "\r\n\n" - "LZO data compression library.\n" -- "$Copyright: LZO Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\n" -+ "$Copyright: LZO Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer\n" - "\n" - "http://www.oberhumer.com $\n\n" - "$Id: LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE " $\n" -@@ -2352,11 +3922,7 @@ static const char __lzo_copyright[] = - LZO_PUBLIC(const lzo_bytep) - lzo_copyright(void) - { --#if (LZO_OS_DOS16 && LZO_CC_TURBOC) -- return (lzo_voidp) __lzo_copyright; --#else - return (const lzo_bytep) __lzo_copyright; --#endif - } - - LZO_PUBLIC(unsigned) -@@ -2393,16 +3959,16 @@ _lzo_version_date(void) - #define LZO_NMAX 5552 - - #define LZO_DO1(buf,i) s1 += buf[i]; s2 += s1 --#define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1); --#define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2); --#define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4); --#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8); -+#define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1) -+#define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2) -+#define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4) -+#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8) - --LZO_PUBLIC(lzo_uint32) --lzo_adler32(lzo_uint32 adler, const lzo_bytep buf, lzo_uint len) -+LZO_PUBLIC(lzo_uint32_t) -+lzo_adler32(lzo_uint32_t adler, const lzo_bytep buf, lzo_uint len) - { -- lzo_uint32 s1 = adler & 0xffff; -- lzo_uint32 s2 = (adler >> 16) & 0xffff; -+ lzo_uint32_t s1 = adler & 0xffff; -+ lzo_uint32_t s2 = (adler >> 16) & 0xffff; - unsigned k; - - if (buf == NULL) -@@ -2459,8 +4025,8 @@ lzo_adler32(lzo_uint32 adler, const lzo_bytep buf, lzo_uint len) - LZOLIB_PUBLIC(int, lzo_hmemcmp) (const lzo_hvoid_p s1, const lzo_hvoid_p s2, lzo_hsize_t len) - { - #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCMP) -- const lzo_hbyte_p p1 = (const lzo_hbyte_p) s1; -- const lzo_hbyte_p p2 = (const lzo_hbyte_p) s2; -+ const lzo_hbyte_p p1 = LZO_STATIC_CAST(const lzo_hbyte_p, s1); -+ const lzo_hbyte_p p2 = LZO_STATIC_CAST(const lzo_hbyte_p, s2); - if __lzo_likely(len > 0) do - { - int d = *p1 - *p2; -@@ -2476,8 +4042,8 @@ LZOLIB_PUBLIC(int, lzo_hmemcmp) (const lzo_hvoid_p s1, const lzo_hvoid_p s2, lzo - LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemcpy) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len) - { - #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCPY) -- lzo_hbyte_p p1 = (lzo_hbyte_p) dest; -- const lzo_hbyte_p p2 = (const lzo_hbyte_p) src; -+ lzo_hbyte_p p1 = LZO_STATIC_CAST(lzo_hbyte_p, dest); -+ const lzo_hbyte_p p2 = LZO_STATIC_CAST(const lzo_hbyte_p, src); - if (!(len > 0) || p1 == p2) - return dest; - do -@@ -2491,8 +4057,8 @@ LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemcpy) (lzo_hvoid_p dest, const lzo_hvoid_p src - LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemmove) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len) - { - #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMMOVE) -- lzo_hbyte_p p1 = (lzo_hbyte_p) dest; -- const lzo_hbyte_p p2 = (const lzo_hbyte_p) src; -+ lzo_hbyte_p p1 = LZO_STATIC_CAST(lzo_hbyte_p, dest); -+ const lzo_hbyte_p p2 = LZO_STATIC_CAST(const lzo_hbyte_p, src); - if (!(len > 0) || p1 == p2) - return dest; - if (p1 < p2) -@@ -2514,16 +4080,17 @@ LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemmove) (lzo_hvoid_p dest, const lzo_hvoid_p sr - return memmove(dest, src, len); - #endif - } --LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int c, lzo_hsize_t len) -+LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int cc, lzo_hsize_t len) - { - #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMSET) -- lzo_hbyte_p p = (lzo_hbyte_p) s; -+ lzo_hbyte_p p = LZO_STATIC_CAST(lzo_hbyte_p, s); -+ unsigned char c = LZO_ITRUNC(unsigned char, cc); - if __lzo_likely(len > 0) do -- *p++ = (unsigned char) c; -+ *p++ = c; - while __lzo_likely(--len > 0); - return s; - #else -- return memset(s, c, len); -+ return memset(s, cc, len); - #endif - } - #undef LZOLIB_PUBLIC -@@ -2532,105 +4099,28 @@ LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int c, lzo_hsize_t len) - - #if !defined(__LZO_IN_MINILZO) - --#define ACC_WANT_ACC_CHK_CH 1 --#undef ACCCHK_ASSERT -- -- ACCCHK_ASSERT_IS_SIGNED_T(lzo_int) -- ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint) -- -- ACCCHK_ASSERT_IS_SIGNED_T(lzo_int32) -- ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint32) -- ACCCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0) -- ACCCHK_ASSERT(sizeof(lzo_uint32) >= 4) --#if defined(LZO_UINT64_MAX) -- ACCCHK_ASSERT(sizeof(lzo_uint64) == 8) -- ACCCHK_ASSERT_IS_SIGNED_T(lzo_int64) -- ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint64) --#endif -- --#if !defined(__LZO_UINTPTR_T_IS_POINTER) -- ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t) --#endif -- ACCCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) -- -- ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_xint) -- ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint32)) -- ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint)) -- ACCCHK_ASSERT(sizeof(lzo_xint) == sizeof(lzo_uint32) || sizeof(lzo_xint) == sizeof(lzo_uint)) -+#define LZO_WANT_ACC_CHK_CH 1 -+#undef LZOCHK_ASSERT - -+ LZOCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0) -+ LZOCHK_ASSERT_IS_SIGNED_T(lzo_int) -+ LZOCHK_ASSERT_IS_UNSIGNED_T(lzo_uint) -+#if !(__LZO_UINTPTR_T_IS_POINTER) -+ LZOCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t) - #endif --#undef ACCCHK_ASSERT -+ LZOCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) -+ LZOCHK_ASSERT_IS_UNSIGNED_T(lzo_xint) - --#if 0 --#define WANT_lzo_bitops_clz32 1 --#define WANT_lzo_bitops_clz64 1 --#endif --#define WANT_lzo_bitops_ctz32 1 --#define WANT_lzo_bitops_ctz64 1 -- --#if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) --#include --#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0 --#pragma intrinsic(_BitScanReverse) --static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v) --{ -- unsigned long r; -- (void) _BitScanReverse(&r, v); -- return (unsigned) r; --} --#define lzo_bitops_clz32 lzo_bitops_clz32 --#endif --#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0 --#pragma intrinsic(_BitScanReverse64) --static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v) --{ -- unsigned long r; -- (void) _BitScanReverse64(&r, v); -- return (unsigned) r; --} --#define lzo_bitops_clz64 lzo_bitops_clz64 --#endif --#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) --#pragma intrinsic(_BitScanForward) --static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v) --{ -- unsigned long r; -- (void) _BitScanForward(&r, v); -- return (unsigned) r; --} --#define lzo_bitops_ctz32 lzo_bitops_ctz32 --#endif --#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) --#pragma intrinsic(_BitScanForward64) --static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v) --{ -- unsigned long r; -- (void) _BitScanForward64(&r, v); -- return (unsigned) r; --} --#define lzo_bitops_ctz64 lzo_bitops_ctz64 - #endif -+#undef LZOCHK_ASSERT - --#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || LZO_CC_LLVM) --#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) --#define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v)) --#endif --#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) --#define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v)) --#endif --#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) --#define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v)) --#endif --#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) --#define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v)) --#endif --#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32) --#define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v)) --#endif --#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX) --#define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v)) --#endif -+union lzo_config_check_union { -+ lzo_uint a[2]; -+ unsigned char b[2*LZO_MAX(8,sizeof(lzo_uint))]; -+#if defined(lzo_uint64_t) -+ lzo_uint64_t c[2]; - #endif -+}; - - #if 0 - #define u2p(ptr,off) ((lzo_voidp) (((lzo_bytep)(lzo_voidp)(ptr)) + (off))) -@@ -2644,73 +4134,101 @@ static __lzo_noinline lzo_voidp u2p(lzo_voidp ptr, lzo_uint off) - LZO_PUBLIC(int) - _lzo_config_check(void) - { -- lzo_bool r = 1; -- union { -- lzo_xint a[2]; unsigned char b[2*LZO_MAX(8,sizeof(lzo_xint))]; --#if defined(LZO_UNALIGNED_OK_8) -- lzo_uint64 c[2]; --#endif -- unsigned short x[2]; lzo_uint32 y[2]; lzo_uint z[2]; -- } u; -+#if (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x030100ul && LZO_CC_CLANG < 0x030300ul)) -+# if 0 -+ volatile -+# endif -+#endif -+ union lzo_config_check_union u; - lzo_voidp p; -+ unsigned r = 1; - - u.a[0] = u.a[1] = 0; - p = u2p(&u, 0); - r &= ((* (lzo_bytep) p) == 0); --#if !defined(LZO_CFG_NO_CONFIG_CHECK) --#if defined(LZO_ABI_BIG_ENDIAN) -+#if !(LZO_CFG_NO_CONFIG_CHECK) -+#if (LZO_ABI_BIG_ENDIAN) - u.a[0] = u.a[1] = 0; u.b[sizeof(lzo_uint) - 1] = 128; - p = u2p(&u, 0); - r &= ((* (lzo_uintp) p) == 128); - #endif --#if defined(LZO_ABI_LITTLE_ENDIAN) -+#if (LZO_ABI_LITTLE_ENDIAN) - u.a[0] = u.a[1] = 0; u.b[0] = 128; - p = u2p(&u, 0); - r &= ((* (lzo_uintp) p) == 128); - #endif --#if defined(LZO_UNALIGNED_OK_2) - u.a[0] = u.a[1] = 0; -- u.b[0] = 1; u.b[sizeof(unsigned short) + 1] = 2; -+ u.b[0] = 1; u.b[3] = 2; - p = u2p(&u, 1); -- r &= ((* (lzo_ushortp) p) == 0); -+ r &= UA_GET_NE16(p) == 0; -+ r &= UA_GET_LE16(p) == 0; -+ u.b[1] = 128; -+ r &= UA_GET_LE16(p) == 128; -+ u.b[2] = 129; -+ r &= UA_GET_LE16(p) == LZO_UINT16_C(0x8180); -+#if (LZO_ABI_BIG_ENDIAN) -+ r &= UA_GET_NE16(p) == LZO_UINT16_C(0x8081); -+#endif -+#if (LZO_ABI_LITTLE_ENDIAN) -+ r &= UA_GET_NE16(p) == LZO_UINT16_C(0x8180); - #endif --#if defined(LZO_UNALIGNED_OK_4) - u.a[0] = u.a[1] = 0; -- u.b[0] = 3; u.b[sizeof(lzo_uint32) + 1] = 4; -+ u.b[0] = 3; u.b[5] = 4; - p = u2p(&u, 1); -- r &= ((* (lzo_uint32p) p) == 0); -+ r &= UA_GET_NE32(p) == 0; -+ r &= UA_GET_LE32(p) == 0; -+ u.b[1] = 128; -+ r &= UA_GET_LE32(p) == 128; -+ u.b[2] = 129; u.b[3] = 130; u.b[4] = 131; -+ r &= UA_GET_LE32(p) == LZO_UINT32_C(0x83828180); -+#if (LZO_ABI_BIG_ENDIAN) -+ r &= UA_GET_NE32(p) == LZO_UINT32_C(0x80818283); - #endif --#if defined(LZO_UNALIGNED_OK_8) -+#if (LZO_ABI_LITTLE_ENDIAN) -+ r &= UA_GET_NE32(p) == LZO_UINT32_C(0x83828180); -+#endif -+#if defined(UA_GET_NE64) - u.c[0] = u.c[1] = 0; -- u.b[0] = 5; u.b[sizeof(lzo_uint64) + 1] = 6; -+ u.b[0] = 5; u.b[9] = 6; - p = u2p(&u, 1); -- r &= ((* (lzo_uint64p) p) == 0); --#endif --#if defined(lzo_bitops_clz32) -- { unsigned i; lzo_uint32 v = 1; -- for (i = 0; i < 31; i++, v <<= 1) -- r &= lzo_bitops_clz32(v) == 31 - i; -- } --#endif --#if defined(lzo_bitops_clz64) -- { unsigned i; lzo_uint64 v = 1; -- for (i = 0; i < 63; i++, v <<= 1) -- r &= lzo_bitops_clz64(v) == 63 - i; -- } --#endif --#if defined(lzo_bitops_ctz32) -- { unsigned i; lzo_uint32 v = 1; -- for (i = 0; i < 31; i++, v <<= 1) -- r &= lzo_bitops_ctz32(v) == i; -- } --#endif --#if defined(lzo_bitops_ctz64) -- { unsigned i; lzo_uint64 v = 1; -- for (i = 0; i < 63; i++, v <<= 1) -- r &= lzo_bitops_ctz64(v) == i; -- } --#endif --#endif -+ u.c[0] = u.c[1] = 0; -+ r &= UA_GET_NE64(p) == 0; -+#if defined(UA_GET_LE64) -+ r &= UA_GET_LE64(p) == 0; -+ u.b[1] = 128; -+ r &= UA_GET_LE64(p) == 128; -+#endif -+#endif -+#if defined(lzo_bitops_ctlz32) -+ { unsigned i = 0; lzo_uint32_t v; -+ for (v = 1; v != 0 && r == 1; v <<= 1, i++) { -+ r &= lzo_bitops_ctlz32(v) == 31 - i; -+ r &= lzo_bitops_ctlz32_func(v) == 31 - i; -+ }} -+#endif -+#if defined(lzo_bitops_ctlz64) -+ { unsigned i = 0; lzo_uint64_t v; -+ for (v = 1; v != 0 && r == 1; v <<= 1, i++) { -+ r &= lzo_bitops_ctlz64(v) == 63 - i; -+ r &= lzo_bitops_ctlz64_func(v) == 63 - i; -+ }} -+#endif -+#if defined(lzo_bitops_cttz32) -+ { unsigned i = 0; lzo_uint32_t v; -+ for (v = 1; v != 0 && r == 1; v <<= 1, i++) { -+ r &= lzo_bitops_cttz32(v) == i; -+ r &= lzo_bitops_cttz32_func(v) == i; -+ }} -+#endif -+#if defined(lzo_bitops_cttz64) -+ { unsigned i = 0; lzo_uint64_t v; -+ for (v = 1; v != 0 && r == 1; v <<= 1, i++) { -+ r &= lzo_bitops_cttz64(v) == i; -+ r &= lzo_bitops_cttz64_func(v) == i; -+ }} -+#endif -+#endif -+ LZO_UNUSED_FUNC(lzo_bitops_unused_funcs); - - return r == 1 ? LZO_E_OK : LZO_E_ERROR; - } -@@ -2724,11 +4242,11 @@ __lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5, - #if defined(__LZO_IN_MINILZO) - #elif (LZO_CC_MSC && ((_MSC_VER) < 700)) - #else --#define ACC_WANT_ACC_CHK_CH 1 --#undef ACCCHK_ASSERT --#define ACCCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr) -+#define LZO_WANT_ACC_CHK_CH 1 -+#undef LZOCHK_ASSERT -+#define LZOCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr) - #endif --#undef ACCCHK_ASSERT -+#undef LZOCHK_ASSERT - - if (v == 0) - return LZO_E_ERROR; -@@ -2736,7 +4254,7 @@ __lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5, - r = (s1 == -1 || s1 == (int) sizeof(short)) && - (s2 == -1 || s2 == (int) sizeof(int)) && - (s3 == -1 || s3 == (int) sizeof(long)) && -- (s4 == -1 || s4 == (int) sizeof(lzo_uint32)) && -+ (s4 == -1 || s4 == (int) sizeof(lzo_uint32_t)) && - (s5 == -1 || s5 == (int) sizeof(lzo_uint)) && - (s6 == -1 || s6 == (int) lzo_sizeof_dict_t) && - (s7 == -1 || s7 == (int) sizeof(char *)) && -@@ -2779,11 +4297,11 @@ int __far __pascal LibMain ( int a, short b, short c, long d ) - - #if !defined(MINILZO_CFG_SKIP_LZO1X_1_COMPRESS) - --#if 1 && defined(UA_GET32) -+#if 1 && defined(UA_GET_LE32) - #undef LZO_DICT_USE_PTR - #define LZO_DICT_USE_PTR 0 - #undef lzo_dict_t --#define lzo_dict_t unsigned short -+#define lzo_dict_t lzo_uint16_t - #endif - - #define LZO_NEED_DICT_H 1 -@@ -3088,77 +4606,7 @@ DVAL_ASSERT(lzo_xint dv, const lzo_bytep p) - #endif - - #if 1 && defined(DO_COMPRESS) && !defined(do_compress) --# define do_compress LZO_CPP_ECONCAT2(DO_COMPRESS,_core) --#endif -- --#if defined(UA_GET64) --# define WANT_lzo_bitops_ctz64 1 --#elif defined(UA_GET32) --# define WANT_lzo_bitops_ctz32 1 --#endif -- --#if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) --#include --#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0 --#pragma intrinsic(_BitScanReverse) --static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v) --{ -- unsigned long r; -- (void) _BitScanReverse(&r, v); -- return (unsigned) r; --} --#define lzo_bitops_clz32 lzo_bitops_clz32 --#endif --#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0 --#pragma intrinsic(_BitScanReverse64) --static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v) --{ -- unsigned long r; -- (void) _BitScanReverse64(&r, v); -- return (unsigned) r; --} --#define lzo_bitops_clz64 lzo_bitops_clz64 --#endif --#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) --#pragma intrinsic(_BitScanForward) --static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v) --{ -- unsigned long r; -- (void) _BitScanForward(&r, v); -- return (unsigned) r; --} --#define lzo_bitops_ctz32 lzo_bitops_ctz32 --#endif --#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) --#pragma intrinsic(_BitScanForward64) --static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v) --{ -- unsigned long r; -- (void) _BitScanForward64(&r, v); -- return (unsigned) r; --} --#define lzo_bitops_ctz64 lzo_bitops_ctz64 --#endif -- --#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || LZO_CC_LLVM) --#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) --#define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v)) --#endif --#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) --#define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v)) --#endif --#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) --#define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v)) --#endif --#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) --#define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v)) --#endif --#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32) --#define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v)) --#endif --#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX) --#define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v)) --#endif -+# define do_compress LZO_PP_ECONCAT2(DO_COMPRESS,_core) - #endif - - static __lzo_noinline lzo_uint -@@ -3166,7 +4614,7 @@ do_compress ( const lzo_bytep in , lzo_uint in_len, - lzo_bytep out, lzo_uintp out_len, - lzo_uint ti, lzo_voidp wrkmem) - { -- register const lzo_bytep ip; -+ const lzo_bytep ip; - lzo_bytep op; - const lzo_bytep const in_end = in + in_len; - const lzo_bytep const ip_end = in + in_len - 20; -@@ -3175,7 +4623,7 @@ do_compress ( const lzo_bytep in , lzo_uint in_len, - - op = out; - ip = in; -- ii = ip - ti; -+ ii = ip; - - ip += ti < 4 ? 4 - ti : 0; - for (;;) -@@ -3205,8 +4653,8 @@ next: - goto literal; - - try_match: --#if defined(UA_GET32) -- if (UA_GET32(m_pos) != UA_GET32(ip)) -+#if (LZO_OPT_UNALIGNED32) -+ if (UA_GET_NE32(m_pos) != UA_GET_NE32(ip)) - #else - if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3]) - #endif -@@ -3221,49 +4669,43 @@ literal: - lzo_uint m_off; - lzo_uint m_len; - { -- lzo_uint32 dv; -+ lzo_uint32_t dv; - lzo_uint dindex; - literal: - ip += 1 + ((ip - ii) >> 5); - next: - if __lzo_unlikely(ip >= ip_end) - break; -- dv = UA_GET32(ip); -+ dv = UA_GET_LE32(ip); - dindex = DINDEX(dv,ip); - GINDEX(m_off,m_pos,in+dict,dindex,in); - UPDATE_I(dict,0,dindex,ip,in); -- if __lzo_unlikely(dv != UA_GET32(m_pos)) -+ if __lzo_unlikely(dv != UA_GET_LE32(m_pos)) - goto literal; - } - #endif - -+ ii -= ti; ti = 0; - { -- register lzo_uint t = pd(ip,ii); -+ lzo_uint t = pd(ip,ii); - if (t != 0) - { - if (t <= 3) - { -- op[-2] |= LZO_BYTE(t); --#if defined(UA_COPY32) -- UA_COPY32(op, ii); -+ op[-2] = LZO_BYTE(op[-2] | t); -+#if (LZO_OPT_UNALIGNED32) -+ UA_COPY4(op, ii); - op += t; - #else - { do *op++ = *ii++; while (--t > 0); } - #endif - } --#if defined(UA_COPY32) || defined(UA_COPY64) -+#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64) - else if (t <= 16) - { - *op++ = LZO_BYTE(t - 3); --#if defined(UA_COPY64) -- UA_COPY64(op, ii); -- UA_COPY64(op+8, ii+8); --#else -- UA_COPY32(op, ii); -- UA_COPY32(op+4, ii+4); -- UA_COPY32(op+8, ii+8); -- UA_COPY32(op+12, ii+12); --#endif -+ UA_COPY8(op, ii); -+ UA_COPY8(op+8, ii+8); - op += t; - } - #endif -@@ -3273,31 +4715,21 @@ next: - *op++ = LZO_BYTE(t - 3); - else - { -- register lzo_uint tt = t - 18; -+ lzo_uint tt = t - 18; - *op++ = 0; - while __lzo_unlikely(tt > 255) - { - tt -= 255; --#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) -- * (volatile unsigned char *) op++ = 0; --#else -- *op++ = 0; --#endif -+ UA_SET1(op, 0); -+ op++; - } - assert(tt > 0); - *op++ = LZO_BYTE(tt); - } --#if defined(UA_COPY32) || defined(UA_COPY64) -+#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64) - do { --#if defined(UA_COPY64) -- UA_COPY64(op, ii); -- UA_COPY64(op+8, ii+8); --#else -- UA_COPY32(op, ii); -- UA_COPY32(op+4, ii+4); -- UA_COPY32(op+8, ii+8); -- UA_COPY32(op+12, ii+12); --#endif -+ UA_COPY8(op, ii); -+ UA_COPY8(op+8, ii+8); - op += 16; ii += 16; t -= 16; - } while (t >= 16); if (t > 0) - #endif -@@ -3307,19 +4739,26 @@ next: - } - m_len = 4; - { --#if defined(UA_GET64) -- lzo_uint64 v; -- v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len); -+#if (LZO_OPT_UNALIGNED64) -+ lzo_uint64_t v; -+ v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len); - if __lzo_unlikely(v == 0) { - do { - m_len += 8; -- v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len); -+ v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len); - if __lzo_unlikely(ip + m_len >= ip_end) - goto m_len_done; - } while (v == 0); - } --#if (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz64) -- m_len += lzo_bitops_ctz64(v) / CHAR_BIT; -+#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64) -+ m_len += lzo_bitops_ctlz64(v) / CHAR_BIT; -+#elif (LZO_ABI_BIG_ENDIAN) -+ if ((v >> (64 - CHAR_BIT)) == 0) do { -+ v <<= CHAR_BIT; -+ m_len += 1; -+ } while ((v >> (64 - CHAR_BIT)) == 0); -+#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64) -+ m_len += lzo_bitops_cttz64(v) / CHAR_BIT; - #elif (LZO_ABI_LITTLE_ENDIAN) - if ((v & UCHAR_MAX) == 0) do { - v >>= CHAR_BIT; -@@ -3330,19 +4769,30 @@ next: - m_len += 1; - } while (ip[m_len] == m_pos[m_len]); - #endif --#elif defined(UA_GET32) -- lzo_uint32 v; -- v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len); -+#elif (LZO_OPT_UNALIGNED32) -+ lzo_uint32_t v; -+ v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); - if __lzo_unlikely(v == 0) { - do { - m_len += 4; -- v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len); -+ v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); -+ if (v != 0) -+ break; -+ m_len += 4; -+ v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); - if __lzo_unlikely(ip + m_len >= ip_end) - goto m_len_done; - } while (v == 0); - } --#if (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz32) -- m_len += lzo_bitops_ctz32(v) / CHAR_BIT; -+#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz32) -+ m_len += lzo_bitops_ctlz32(v) / CHAR_BIT; -+#elif (LZO_ABI_BIG_ENDIAN) -+ if ((v >> (32 - CHAR_BIT)) == 0) do { -+ v <<= CHAR_BIT; -+ m_len += 1; -+ } while ((v >> (32 - CHAR_BIT)) == 0); -+#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz32) -+ m_len += lzo_bitops_cttz32(v) / CHAR_BIT; - #elif (LZO_ABI_LITTLE_ENDIAN) - if ((v & UCHAR_MAX) == 0) do { - v >>= CHAR_BIT; -@@ -3357,6 +4807,27 @@ next: - if __lzo_unlikely(ip[m_len] == m_pos[m_len]) { - do { - m_len += 1; -+ if (ip[m_len] != m_pos[m_len]) -+ break; -+ m_len += 1; -+ if (ip[m_len] != m_pos[m_len]) -+ break; -+ m_len += 1; -+ if (ip[m_len] != m_pos[m_len]) -+ break; -+ m_len += 1; -+ if (ip[m_len] != m_pos[m_len]) -+ break; -+ m_len += 1; -+ if (ip[m_len] != m_pos[m_len]) -+ break; -+ m_len += 1; -+ if (ip[m_len] != m_pos[m_len]) -+ break; -+ m_len += 1; -+ if (ip[m_len] != m_pos[m_len]) -+ break; -+ m_len += 1; - if __lzo_unlikely(ip + m_len >= ip_end) - goto m_len_done; - } while (ip[m_len] == m_pos[m_len]); -@@ -3390,11 +4861,8 @@ m_len_done: - while __lzo_unlikely(m_len > 255) - { - m_len -= 255; --#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) -- * (volatile unsigned char *) op++ = 0; --#else -- *op++ = 0; --#endif -+ UA_SET1(op, 0); -+ op++; - } - *op++ = LZO_BYTE(m_len); - } -@@ -3413,11 +4881,8 @@ m_len_done: - while __lzo_unlikely(m_len > 255) - { - m_len -= 255; --#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) -- * (volatile unsigned char *) op++ = 0; --#else -- *op++ = 0; --#endif -+ UA_SET1(op, 0); -+ op++; - } - *op++ = LZO_BYTE(m_len); - } -@@ -3428,7 +4893,7 @@ m_len_done: - } - - *out_len = pd(op, out); -- return pd(in_end,ii); -+ return pd(in_end,ii-ti); - } - - LZO_PUBLIC(int) -@@ -3468,7 +4933,7 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, - if (op == out && t <= 238) - *op++ = LZO_BYTE(17 + t); - else if (t <= 3) -- op[-2] |= LZO_BYTE(t); -+ op[-2] = LZO_BYTE(op[-2] | t); - else if (t <= 18) - *op++ = LZO_BYTE(t - 3); - else -@@ -3479,17 +4944,14 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, - while (tt > 255) - { - tt -= 255; --#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) -- -- * (volatile unsigned char *) op++ = 0; --#else -- *op++ = 0; --#endif -+ UA_SET1(op, 0); -+ op++; - } - assert(tt > 0); - *op++ = LZO_BYTE(tt); - } -- do *op++ = *ii++; while (--t > 0); -+ UA_COPYN(op, ii, t); -+ op += t; - } - - *op++ = M4_MARKER | 1; -@@ -3526,10 +4988,13 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, - - #undef TEST_IP - #undef TEST_OP -+#undef TEST_IP_AND_TEST_OP - #undef TEST_LB - #undef TEST_LBO - #undef NEED_IP - #undef NEED_OP -+#undef TEST_IV -+#undef TEST_OV - #undef HAVE_TEST_IP - #undef HAVE_TEST_OP - #undef HAVE_NEED_IP -@@ -3544,6 +5009,7 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, - # if (LZO_TEST_OVERRUN_INPUT >= 2) - # define NEED_IP(x) \ - if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun -+# define TEST_IV(x) if ((x) > (lzo_uint)0 - (511)) goto input_overrun - # endif - #endif - -@@ -3555,12 +5021,13 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, - # undef TEST_OP - # define NEED_OP(x) \ - if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun -+# define TEST_OV(x) if ((x) > (lzo_uint)0 - (511)) goto output_overrun - # endif - #endif - - #if defined(LZO_TEST_OVERRUN_LOOKBEHIND) --# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun --# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun -+# define TEST_LB(m_pos) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op)) goto lookbehind_overrun -+# define TEST_LBO(m_pos,o) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op-(o))) goto lookbehind_overrun - #else - # define TEST_LB(m_pos) ((void) 0) - # define TEST_LBO(m_pos,o) ((void) 0) -@@ -3581,15 +5048,27 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, - # define TEST_OP 1 - #endif - -+#if defined(HAVE_TEST_IP) && defined(HAVE_TEST_OP) -+# define TEST_IP_AND_TEST_OP (TEST_IP && TEST_OP) -+#elif defined(HAVE_TEST_IP) -+# define TEST_IP_AND_TEST_OP TEST_IP -+#elif defined(HAVE_TEST_OP) -+# define TEST_IP_AND_TEST_OP TEST_OP -+#else -+# define TEST_IP_AND_TEST_OP 1 -+#endif -+ - #if defined(NEED_IP) - # define HAVE_NEED_IP 1 - #else - # define NEED_IP(x) ((void) 0) -+# define TEST_IV(x) ((void) 0) - #endif - #if defined(NEED_OP) - # define HAVE_NEED_OP 1 - #else - # define NEED_OP(x) ((void) 0) -+# define TEST_OV(x) ((void) 0) - #endif - - #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) -@@ -3606,14 +5085,14 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, - lzo_voidp wrkmem ) - #endif - { -- register lzo_bytep op; -- register const lzo_bytep ip; -- register lzo_uint t; -+ lzo_bytep op; -+ const lzo_bytep ip; -+ lzo_uint t; - #if defined(COPY_DICT) - lzo_uint m_off; - const lzo_bytep dict_end; - #else -- register const lzo_bytep m_pos; -+ const lzo_bytep m_pos; - #endif - - const lzo_bytep const ip_end = in + in_len; -@@ -3648,43 +5127,45 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, - op = out; - ip = in; - -+ NEED_IP(1); - if (*ip > 17) - { - t = *ip++ - 17; - if (t < 4) - goto match_next; -- assert(t > 0); NEED_OP(t); NEED_IP(t+1); -+ assert(t > 0); NEED_OP(t); NEED_IP(t+3); - do *op++ = *ip++; while (--t > 0); - goto first_literal_run; - } - -- while (TEST_IP && TEST_OP) -+ for (;;) - { -+ NEED_IP(3); - t = *ip++; - if (t >= 16) - goto match; - if (t == 0) - { -- NEED_IP(1); - while (*ip == 0) - { - t += 255; - ip++; -+ TEST_IV(t); - NEED_IP(1); - } - t += 15 + *ip++; - } -- assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); --#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) -+ assert(t > 0); NEED_OP(t+3); NEED_IP(t+6); -+#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) - t += 3; - if (t >= 8) do - { -- UA_COPY64(op,ip); -+ UA_COPY8(op,ip); - op += 8; ip += 8; t -= 8; - } while (t >= 8); - if (t >= 4) - { -- UA_COPY32(op,ip); -+ UA_COPY4(op,ip); - op += 4; ip += 4; t -= 4; - } - if (t > 0) -@@ -3692,19 +5173,19 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, - *op++ = *ip++; - if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } - } --#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) --#if !defined(LZO_UNALIGNED_OK_4) -+#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) -+#if !(LZO_OPT_UNALIGNED32) - if (PTR_ALIGNED2_4(op,ip)) - { - #endif -- UA_COPY32(op,ip); -+ UA_COPY4(op,ip); - op += 4; ip += 4; - if (--t > 0) - { - if (t >= 4) - { - do { -- UA_COPY32(op,ip); -+ UA_COPY4(op,ip); - op += 4; ip += 4; t -= 4; - } while (t >= 4); - if (t > 0) do *op++ = *ip++; while (--t > 0); -@@ -3712,12 +5193,12 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, - else - do *op++ = *ip++; while (--t > 0); - } --#if !defined(LZO_UNALIGNED_OK_4) -+#if !(LZO_OPT_UNALIGNED32) - } - else - #endif - #endif --#if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8) -+#if !(LZO_OPT_UNALIGNED32) - { - *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; - do *op++ = *ip++; while (--t > 0); -@@ -3753,7 +5234,7 @@ first_literal_run: - #endif - goto match_done; - -- do { -+ for (;;) { - match: - if (t >= 64) - { -@@ -3813,14 +5294,15 @@ match: - t &= 31; - if (t == 0) - { -- NEED_IP(1); - while (*ip == 0) - { - t += 255; - ip++; -+ TEST_OV(t); - NEED_IP(1); - } - t += 31 + *ip++; -+ NEED_IP(2); - } - #if defined(COPY_DICT) - #if defined(LZO1Z) -@@ -3836,9 +5318,9 @@ match: - m_pos = op - off; - last_m_off = off; - } --#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) -+#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) - m_pos = op - 1; -- m_pos -= UA_GET16(ip) >> 2; -+ m_pos -= UA_GET_LE16(ip) >> 2; - #else - m_pos = op - 1; - m_pos -= (ip[0] >> 2) + (ip[1] << 6); -@@ -3857,14 +5339,15 @@ match: - t &= 7; - if (t == 0) - { -- NEED_IP(1); - while (*ip == 0) - { - t += 255; - ip++; -+ TEST_OV(t); - NEED_IP(1); - } - t += 7 + *ip++; -+ NEED_IP(2); - } - #if defined(COPY_DICT) - #if defined(LZO1Z) -@@ -3882,8 +5365,8 @@ match: - #else - #if defined(LZO1Z) - m_pos -= (ip[0] << 6) + (ip[1] >> 2); --#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) -- m_pos -= UA_GET16(ip) >> 2; -+#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) -+ m_pos -= UA_GET_LE16(ip) >> 2; - #else - m_pos -= (ip[0] >> 2) + (ip[1] << 6); - #endif -@@ -3931,18 +5414,18 @@ match: - #else - - TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); --#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) -+#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) - if (op - m_pos >= 8) - { - t += (3 - 1); - if (t >= 8) do - { -- UA_COPY64(op,m_pos); -+ UA_COPY8(op,m_pos); - op += 8; m_pos += 8; t -= 8; - } while (t >= 8); - if (t >= 4) - { -- UA_COPY32(op,m_pos); -+ UA_COPY4(op,m_pos); - op += 4; m_pos += 4; t -= 4; - } - if (t > 0) -@@ -3952,8 +5435,8 @@ match: - } - } - else --#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) --#if !defined(LZO_UNALIGNED_OK_4) -+#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) -+#if !(LZO_OPT_UNALIGNED32) - if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) - { - assert((op - m_pos) >= 4); -@@ -3961,10 +5444,10 @@ match: - if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) - { - #endif -- UA_COPY32(op,m_pos); -+ UA_COPY4(op,m_pos); - op += 4; m_pos += 4; t -= 4 - (3 - 1); - do { -- UA_COPY32(op,m_pos); -+ UA_COPY4(op,m_pos); - op += 4; m_pos += 4; t -= 4; - } while (t >= 4); - if (t > 0) do *op++ = *m_pos++; while (--t > 0); -@@ -3989,7 +5472,7 @@ match_done: - break; - - match_next: -- assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1); -+ assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+3); - #if 0 - do *op++ = *ip++; while (--t > 0); - #else -@@ -3997,16 +5480,10 @@ match_next: - if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } - #endif - t = *ip++; -- } while (TEST_IP && TEST_OP); -+ } - } - --#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) -- *out_len = pd(op, out); -- return LZO_E_EOF_NOT_FOUND; --#endif -- - eof_found: -- assert(t == 1); - *out_len = pd(op, out); - return (ip == ip_end ? LZO_E_OK : - (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); -@@ -4052,10 +5529,13 @@ lookbehind_overrun: - - #undef TEST_IP - #undef TEST_OP -+#undef TEST_IP_AND_TEST_OP - #undef TEST_LB - #undef TEST_LBO - #undef NEED_IP - #undef NEED_OP -+#undef TEST_IV -+#undef TEST_OV - #undef HAVE_TEST_IP - #undef HAVE_TEST_OP - #undef HAVE_NEED_IP -@@ -4070,6 +5550,7 @@ lookbehind_overrun: - # if (LZO_TEST_OVERRUN_INPUT >= 2) - # define NEED_IP(x) \ - if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun -+# define TEST_IV(x) if ((x) > (lzo_uint)0 - (511)) goto input_overrun - # endif - #endif - -@@ -4081,12 +5562,13 @@ lookbehind_overrun: - # undef TEST_OP - # define NEED_OP(x) \ - if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun -+# define TEST_OV(x) if ((x) > (lzo_uint)0 - (511)) goto output_overrun - # endif - #endif - - #if defined(LZO_TEST_OVERRUN_LOOKBEHIND) --# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun --# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun -+# define TEST_LB(m_pos) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op)) goto lookbehind_overrun -+# define TEST_LBO(m_pos,o) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op-(o))) goto lookbehind_overrun - #else - # define TEST_LB(m_pos) ((void) 0) - # define TEST_LBO(m_pos,o) ((void) 0) -@@ -4107,15 +5589,27 @@ lookbehind_overrun: - # define TEST_OP 1 - #endif - -+#if defined(HAVE_TEST_IP) && defined(HAVE_TEST_OP) -+# define TEST_IP_AND_TEST_OP (TEST_IP && TEST_OP) -+#elif defined(HAVE_TEST_IP) -+# define TEST_IP_AND_TEST_OP TEST_IP -+#elif defined(HAVE_TEST_OP) -+# define TEST_IP_AND_TEST_OP TEST_OP -+#else -+# define TEST_IP_AND_TEST_OP 1 -+#endif -+ - #if defined(NEED_IP) - # define HAVE_NEED_IP 1 - #else - # define NEED_IP(x) ((void) 0) -+# define TEST_IV(x) ((void) 0) - #endif - #if defined(NEED_OP) - # define HAVE_NEED_OP 1 - #else - # define NEED_OP(x) ((void) 0) -+# define TEST_OV(x) ((void) 0) - #endif - - #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) -@@ -4132,14 +5626,14 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, - lzo_voidp wrkmem ) - #endif - { -- register lzo_bytep op; -- register const lzo_bytep ip; -- register lzo_uint t; -+ lzo_bytep op; -+ const lzo_bytep ip; -+ lzo_uint t; - #if defined(COPY_DICT) - lzo_uint m_off; - const lzo_bytep dict_end; - #else -- register const lzo_bytep m_pos; -+ const lzo_bytep m_pos; - #endif - - const lzo_bytep const ip_end = in + in_len; -@@ -4174,43 +5668,45 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, - op = out; - ip = in; - -+ NEED_IP(1); - if (*ip > 17) - { - t = *ip++ - 17; - if (t < 4) - goto match_next; -- assert(t > 0); NEED_OP(t); NEED_IP(t+1); -+ assert(t > 0); NEED_OP(t); NEED_IP(t+3); - do *op++ = *ip++; while (--t > 0); - goto first_literal_run; - } - -- while (TEST_IP && TEST_OP) -+ for (;;) - { -+ NEED_IP(3); - t = *ip++; - if (t >= 16) - goto match; - if (t == 0) - { -- NEED_IP(1); - while (*ip == 0) - { - t += 255; - ip++; -+ TEST_IV(t); - NEED_IP(1); - } - t += 15 + *ip++; - } -- assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); --#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) -+ assert(t > 0); NEED_OP(t+3); NEED_IP(t+6); -+#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) - t += 3; - if (t >= 8) do - { -- UA_COPY64(op,ip); -+ UA_COPY8(op,ip); - op += 8; ip += 8; t -= 8; - } while (t >= 8); - if (t >= 4) - { -- UA_COPY32(op,ip); -+ UA_COPY4(op,ip); - op += 4; ip += 4; t -= 4; - } - if (t > 0) -@@ -4218,19 +5714,19 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, - *op++ = *ip++; - if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } - } --#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) --#if !defined(LZO_UNALIGNED_OK_4) -+#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) -+#if !(LZO_OPT_UNALIGNED32) - if (PTR_ALIGNED2_4(op,ip)) - { - #endif -- UA_COPY32(op,ip); -+ UA_COPY4(op,ip); - op += 4; ip += 4; - if (--t > 0) - { - if (t >= 4) - { - do { -- UA_COPY32(op,ip); -+ UA_COPY4(op,ip); - op += 4; ip += 4; t -= 4; - } while (t >= 4); - if (t > 0) do *op++ = *ip++; while (--t > 0); -@@ -4238,12 +5734,12 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, - else - do *op++ = *ip++; while (--t > 0); - } --#if !defined(LZO_UNALIGNED_OK_4) -+#if !(LZO_OPT_UNALIGNED32) - } - else - #endif - #endif --#if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8) -+#if !(LZO_OPT_UNALIGNED32) - { - *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; - do *op++ = *ip++; while (--t > 0); -@@ -4279,7 +5775,7 @@ first_literal_run: - #endif - goto match_done; - -- do { -+ for (;;) { - match: - if (t >= 64) - { -@@ -4339,14 +5835,15 @@ match: - t &= 31; - if (t == 0) - { -- NEED_IP(1); - while (*ip == 0) - { - t += 255; - ip++; -+ TEST_OV(t); - NEED_IP(1); - } - t += 31 + *ip++; -+ NEED_IP(2); - } - #if defined(COPY_DICT) - #if defined(LZO1Z) -@@ -4362,9 +5859,9 @@ match: - m_pos = op - off; - last_m_off = off; - } --#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) -+#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) - m_pos = op - 1; -- m_pos -= UA_GET16(ip) >> 2; -+ m_pos -= UA_GET_LE16(ip) >> 2; - #else - m_pos = op - 1; - m_pos -= (ip[0] >> 2) + (ip[1] << 6); -@@ -4383,14 +5880,15 @@ match: - t &= 7; - if (t == 0) - { -- NEED_IP(1); - while (*ip == 0) - { - t += 255; - ip++; -+ TEST_OV(t); - NEED_IP(1); - } - t += 7 + *ip++; -+ NEED_IP(2); - } - #if defined(COPY_DICT) - #if defined(LZO1Z) -@@ -4408,8 +5906,8 @@ match: - #else - #if defined(LZO1Z) - m_pos -= (ip[0] << 6) + (ip[1] >> 2); --#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) -- m_pos -= UA_GET16(ip) >> 2; -+#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) -+ m_pos -= UA_GET_LE16(ip) >> 2; - #else - m_pos -= (ip[0] >> 2) + (ip[1] << 6); - #endif -@@ -4457,18 +5955,18 @@ match: - #else - - TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); --#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) -+#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) - if (op - m_pos >= 8) - { - t += (3 - 1); - if (t >= 8) do - { -- UA_COPY64(op,m_pos); -+ UA_COPY8(op,m_pos); - op += 8; m_pos += 8; t -= 8; - } while (t >= 8); - if (t >= 4) - { -- UA_COPY32(op,m_pos); -+ UA_COPY4(op,m_pos); - op += 4; m_pos += 4; t -= 4; - } - if (t > 0) -@@ -4478,8 +5976,8 @@ match: - } - } - else --#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) --#if !defined(LZO_UNALIGNED_OK_4) -+#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) -+#if !(LZO_OPT_UNALIGNED32) - if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) - { - assert((op - m_pos) >= 4); -@@ -4487,10 +5985,10 @@ match: - if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) - { - #endif -- UA_COPY32(op,m_pos); -+ UA_COPY4(op,m_pos); - op += 4; m_pos += 4; t -= 4 - (3 - 1); - do { -- UA_COPY32(op,m_pos); -+ UA_COPY4(op,m_pos); - op += 4; m_pos += 4; t -= 4; - } while (t >= 4); - if (t > 0) do *op++ = *m_pos++; while (--t > 0); -@@ -4515,7 +6013,7 @@ match_done: - break; - - match_next: -- assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1); -+ assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+3); - #if 0 - do *op++ = *ip++; while (--t > 0); - #else -@@ -4523,16 +6021,10 @@ match_next: - if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } - #endif - t = *ip++; -- } while (TEST_IP && TEST_OP); -+ } - } - --#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) -- *out_len = pd(op, out); -- return LZO_E_EOF_NOT_FOUND; --#endif -- - eof_found: -- assert(t == 1); - *out_len = pd(op, out); - return (ip == ip_end ? LZO_E_OK : - (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); -@@ -4559,4 +6051,3 @@ lookbehind_overrun: - #endif - - /***** End of minilzo.c *****/ -- -diff --git a/grub-core/lib/minilzo/minilzo.h b/grub-core/lib/minilzo/minilzo.h -index 74fefa9..7937454 100644 ---- a/grub-core/lib/minilzo/minilzo.h -+++ b/grub-core/lib/minilzo/minilzo.h -@@ -2,22 +2,7 @@ - - This file is part of the LZO real-time data compression library. - -- Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer -- Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer -+ Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer - All Rights Reserved. - - The LZO library is free software; you can redistribute it and/or -@@ -50,7 +35,7 @@ - #ifndef __MINILZO_H - #define __MINILZO_H 1 - --#define MINILZO_VERSION 0x2050 -+#define MINILZO_VERSION 0x2080 - - #ifdef __LZOCONF_H - # error "you cannot use both LZO and miniLZO" -@@ -78,7 +63,7 @@ extern "C" { - */ - - #define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS --#define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t)) -+#define LZO1X_1_MEM_COMPRESS ((lzo_uint32_t) (16384L * lzo_sizeof_dict_t)) - #define LZO1X_MEM_DECOMPRESS (0) - - --- -1.8.3.1 - diff --git a/0012-Move-bash-completion-script-922997.patch b/0014-Move-bash-completion-script-922997.patch similarity index 83% rename from 0012-Move-bash-completion-script-922997.patch rename to 0014-Move-bash-completion-script-922997.patch index 6e46b61249d89d65b6577b67eda19fd0d3e651e1..6bf0b4b9aeb1f09b932ea55125144c05274cb3d0 100644 --- a/0012-Move-bash-completion-script-922997.patch +++ b/0014-Move-bash-completion-script-922997.patch @@ -1,7 +1,7 @@ -From 11d400b4b4f1475cf1a75e7f216524a903e7df7c Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 3 Apr 2013 14:35:34 -0400 -Subject: [PATCH 012/220] Move bash completion script (#922997) +Subject: [PATCH] Move bash completion script (#922997) Apparently these go in a new place now. --- @@ -10,10 +10,10 @@ Apparently these go in a new place now. 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac -index 7656f24..d283af6 100644 +index 7517fc49d98..8331f95b645 100644 --- a/configure.ac +++ b/configure.ac -@@ -305,6 +305,14 @@ AC_SUBST(grubdirname) +@@ -314,6 +314,14 @@ AC_SUBST(grubdirname) AC_DEFINE_UNQUOTED(GRUB_DIR_NAME, "$grubdirname", [Default grub directory name]) @@ -28,7 +28,7 @@ index 7656f24..d283af6 100644 # # Checks for build programs. # -@@ -516,6 +524,9 @@ HOST_CFLAGS="$HOST_CFLAGS $grub_cv_cc_w_extra_flags" +@@ -525,6 +533,9 @@ HOST_CFLAGS="$HOST_CFLAGS $grub_cv_cc_w_extra_flags" # Check for target programs. # @@ -39,7 +39,7 @@ index 7656f24..d283af6 100644 if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then tmp_ac_tool_prefix="$ac_tool_prefix" diff --git a/util/bash-completion.d/Makefile.am b/util/bash-completion.d/Makefile.am -index 136287c..61108f0 100644 +index 136287cf1bf..61108f05429 100644 --- a/util/bash-completion.d/Makefile.am +++ b/util/bash-completion.d/Makefile.am @@ -6,7 +6,6 @@ EXTRA_DIST = $(bash_completion_source) @@ -50,6 +50,3 @@ index 136287c..61108f0 100644 bashcompletion_DATA = $(bash_completion_script) $(bash_completion_script): $(bash_completion_source) $(top_builddir)/config.status --- -1.8.3.1 - diff --git a/0015-Add-GRUB_DISABLE_UUID.patch b/0015-Add-GRUB_DISABLE_UUID.patch deleted file mode 100644 index fe853dc28baf49988a8d36a93592cfae55fb5662..0000000000000000000000000000000000000000 --- a/0015-Add-GRUB_DISABLE_UUID.patch +++ /dev/null @@ -1,109 +0,0 @@ -From be1ed0f8e7ddf8747049c6e132c25032d2fef9ca Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 4 Sep 2014 16:49:25 -0400 -Subject: [PATCH 015/220] Add GRUB_DISABLE_UUID. - -This will cause "search --fs-uuid --set=root ..." not to be generated by -grub2-mkconfig, and instead simply attempt to use the grub device name -as it understands it. - -Signed-off-by: Peter Jones ---- - docs/grub.texi | 7 +++++++ - util/grub-mkconfig.in | 22 +++++++++++++++++++--- - util/grub-mkconfig_lib.in | 4 ++-- - 3 files changed, 28 insertions(+), 5 deletions(-) - -diff --git a/docs/grub.texi b/docs/grub.texi -index 8779507..6f52430 100644 ---- a/docs/grub.texi -+++ b/docs/grub.texi -@@ -1441,6 +1441,13 @@ enable the use of partition UUIDs, set this option to @samp{false}. - If this option is set to @samp{true}, disable the generation of recovery - mode menu entries. - -+@item GRUB_DISABLE_UUID -+Normally, @command{grub-mkconfig} will generate menu entries that use -+universally-unique identifiers (UUIDs) to identify various filesystems to -+search for files. This is usually more reliable, but in some cases it may -+not be appropriate. To disable this use of UUIDs, set this option to -+@samp{true}. -+ - @item GRUB_VIDEO_BACKEND - If graphical video support is required, either because the @samp{gfxterm} - graphical terminal is in use or because @samp{GRUB_GFXPAYLOAD_LINUX} is set, -diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index 523d4e0..9ecbcfb 100644 ---- a/util/grub-mkconfig.in -+++ b/util/grub-mkconfig.in -@@ -133,12 +133,12 @@ fi - - # Device containing our userland. Typically used for root= parameter. - GRUB_DEVICE="`${grub_probe} --target=device /`" --GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true --GRUB_DEVICE_PARTUUID="`${grub_probe} --device ${GRUB_DEVICE} --target=partuuid 2> /dev/null`" || true -+GRUB_DEVICE_UUID_GENERATED="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true -+GRUB_DEVICE_PARTUUID_GENERATED="`${grub_probe} --device ${GRUB_DEVICE} --target=partuuid 2> /dev/null`" || true - - # Device containing our /boot partition. Usually the same as GRUB_DEVICE. - GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`" --GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true -+GRUB_DEVICE_BOOT_UUID_GENERATED="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true - - # Filesystem for the device containing our userland. Used for stuff like - # choosing Hurd filesystem module. -@@ -158,6 +158,21 @@ if test -f ${sysconfdir}/default/grub ; then - . ${sysconfdir}/default/grub - fi - -+if [ "x$GRUB_DISABLE_UUID" != "xtrue" ]; then -+ if [ -z "$GRUB_DEVICE_UUID" ]; then -+ GRUB_DEVICE_UUID="$GRUB_DEVICE_UUID_GENERATED" -+ fi -+ if [ -z "$GRUB_DEVICE_BOOT_UUID" ]; then -+ GRUB_DEVICE_BOOT_UUID="$GRUB_DEVICE_BOOT_UUID_GENERATED" -+ fi -+ if [ -z "$GRUB_DEVICE_UUID" ]; then -+ GRUB_DEVICE_UUID="$GRUB_DEVICE_UUID_GENERATED" -+ fi -+ if [ -z "$GRUB_DEVICE_PART_UUID" ]; then -+ GRUB_DEVICE_PART_UUID="$GRUB_DEVICE_PART_UUID_GENERATED" -+ fi -+fi -+ - # XXX: should this be deprecated at some point? - if [ "x${GRUB_TERMINAL}" != "x" ] ; then - GRUB_TERMINAL_INPUT="${GRUB_TERMINAL}" -@@ -227,6 +242,7 @@ export GRUB_DEFAULT \ - GRUB_DISABLE_LINUX_UUID \ - GRUB_DISABLE_LINUX_PARTUUID \ - GRUB_DISABLE_RECOVERY \ -+ GRUB_DISABLE_UUID \ - GRUB_VIDEO_BACKEND \ - GRUB_GFXMODE \ - GRUB_BACKGROUND \ -diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in -index 0f801ca..1001a12 100644 ---- a/util/grub-mkconfig_lib.in -+++ b/util/grub-mkconfig_lib.in -@@ -156,7 +156,7 @@ prepare_grub_to_access_device () - if [ "x$fs_hint" != x ]; then - echo "set root='$fs_hint'" - fi -- if fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then -+ if [ "x$GRUB_DISABLE_UUID" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then - hints="`"${grub_probe}" --device $@ --target=hints_string 2> /dev/null`" || hints= - echo "if [ x\$feature_platform_search_hint = xy ]; then" - echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}" -@@ -173,7 +173,7 @@ grub_get_device_id () - IFS=' - ' - device="$1" -- if fs_uuid="`"${grub_probe}" --device ${device} --target=fs_uuid 2> /dev/null`" ; then -+ if [ "x$GRUB_DISABLE_UUID" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device ${device} --target=fs_uuid 2> /dev/null`" ; then - echo "$fs_uuid"; - else - echo $device |sed 's, ,_,g' --- -1.8.3.1 - diff --git a/0014-Allow-fallback-to-include-entries-by-title-not-just-.patch b/0015-Allow-fallback-to-include-entries-by-title-not-just-.patch similarity index 86% rename from 0014-Allow-fallback-to-include-entries-by-title-not-just-.patch rename to 0015-Allow-fallback-to-include-entries-by-title-not-just-.patch index 9a4eac86656771177cf00b173e6dedeba839b846..f2a4a82c1199a076368b6dbac4c7d6be4ad442c5 100644 --- a/0014-Allow-fallback-to-include-entries-by-title-not-just-.patch +++ b/0015-Allow-fallback-to-include-entries-by-title-not-just-.patch @@ -1,8 +1,8 @@ -From f12a6d6082e3d532b676e3835e833df2d818416b Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Fri, 5 Sep 2014 10:07:04 -0400 -Subject: [PATCH 014/220] Allow "fallback" to include entries by title, not - just number. +Subject: [PATCH] Allow "fallback" to include entries by title, not just + number. Resolves: rhbz#1026084 @@ -12,10 +12,10 @@ Signed-off-by: Peter Jones 1 file changed, 58 insertions(+), 27 deletions(-) diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c -index d5e0c79..9175ad2 100644 +index 8397886fa05..d7a222e681b 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c -@@ -163,16 +163,41 @@ grub_menu_set_timeout (int timeout) +@@ -163,15 +163,40 @@ grub_menu_set_timeout (int timeout) } } @@ -51,14 +51,13 @@ index d5e0c79..9175ad2 100644 -get_and_remove_first_entry_number (const char *name) +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; val = grub_env_get (name); if (! val) -@@ -182,9 +207,39 @@ get_and_remove_first_entry_number (const char *name) +@@ -181,9 +206,39 @@ get_and_remove_first_entry_number (const char *name) entry = (int) grub_strtoul (val, &tail, 0); @@ -99,7 +98,7 @@ index d5e0c79..9175ad2 100644 while (*tail && grub_isspace (*tail)) tail++; grub_env_set (name, tail); -@@ -347,7 +402,7 @@ grub_menu_execute_with_fallback (grub_menu_t menu, +@@ -346,7 +401,7 @@ grub_menu_execute_with_fallback (grub_menu_t menu, grub_menu_execute_entry (entry, 1); /* Deal with fallback entries. */ @@ -108,7 +107,7 @@ index d5e0c79..9175ad2 100644 >= 0) { grub_print_error (); -@@ -465,30 +520,6 @@ grub_menu_register_viewer (struct grub_menu_viewer *viewer) +@@ -464,30 +519,6 @@ grub_menu_register_viewer (struct grub_menu_viewer *viewer) viewers = viewer; } @@ -139,6 +138,3 @@ index d5e0c79..9175ad2 100644 /* Get the entry number from the variable NAME. */ static int get_entry_number (grub_menu_t menu, const char *name) --- -1.8.3.1 - diff --git a/0016-Make-exit-take-a-return-code.patch b/0016-Make-exit-take-a-return-code.patch index 4f409bd8fca304677cc82c03ad0ac2e773477a9c..39d70573676e088028c053f8e5bdca2f6f2cb422 100644 --- a/0016-Make-exit-take-a-return-code.patch +++ b/0016-Make-exit-take-a-return-code.patch @@ -1,7 +1,7 @@ -From 479a8c2d36a28aaac12bf349ea09999655b90353 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 26 Feb 2014 21:49:12 -0500 -Subject: [PATCH 016/220] Make "exit" take a return code. +Subject: [PATCH] Make "exit" take a return code. This adds "exit" with a return code. With this patch, any "exit" command /may/ include a return code, and on platforms that support @@ -27,10 +27,10 @@ Signed-off-by: Peter Jones 14 files changed, 48 insertions(+), 21 deletions(-) diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c -index 6bbce31..6d66b7c 100644 +index fa498931ed2..2bd3ac76f2d 100644 --- a/grub-core/commands/minicmd.c +++ b/grub-core/commands/minicmd.c -@@ -179,12 +179,24 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)), +@@ -182,12 +182,24 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)), } /* exit */ @@ -60,10 +60,10 @@ index 6bbce31..6d66b7c 100644 } diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index 6e1ceb9..370ce03 100644 +index 8cff7be0289..05d8237a9b2 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c -@@ -164,11 +164,16 @@ grub_reboot (void) +@@ -165,11 +165,16 @@ grub_reboot (void) } void @@ -83,7 +83,7 @@ index 6e1ceb9..370ce03 100644 } diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c -index 425bb96..55ea5a1 100644 +index 425bb960347..55ea5a11ccd 100644 --- a/grub-core/kern/emu/main.c +++ b/grub-core/kern/emu/main.c @@ -67,7 +67,7 @@ grub_reboot (void) @@ -96,10 +96,10 @@ index 425bb96..55ea5a1 100644 grub_reboot (); } diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c -index 65db79b..19cd007 100644 +index dfd8a8ec488..0ff13bcaf8c 100644 --- a/grub-core/kern/emu/misc.c +++ b/grub-core/kern/emu/misc.c -@@ -139,9 +139,10 @@ xasprintf (const char *fmt, ...) +@@ -151,9 +151,10 @@ xasprintf (const char *fmt, ...) #if !defined (GRUB_MACHINE_EMU) || defined (GRUB_UTIL) void @@ -113,7 +113,7 @@ index 65db79b..19cd007 100644 #endif diff --git a/grub-core/kern/i386/coreboot/init.c b/grub-core/kern/i386/coreboot/init.c -index 3314f02..36f9134 100644 +index 3314f027fec..36f9134b7b7 100644 --- a/grub-core/kern/i386/coreboot/init.c +++ b/grub-core/kern/i386/coreboot/init.c @@ -41,7 +41,7 @@ extern grub_uint8_t _end[]; @@ -126,7 +126,7 @@ index 3314f02..36f9134 100644 /* We can't use grub_fatal() in this function. This would create an infinite loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */ diff --git a/grub-core/kern/i386/qemu/init.c b/grub-core/kern/i386/qemu/init.c -index 271b6fb..9fafe98 100644 +index 271b6fbfabd..9fafe98f015 100644 --- a/grub-core/kern/i386/qemu/init.c +++ b/grub-core/kern/i386/qemu/init.c @@ -42,7 +42,7 @@ extern grub_uint8_t _end[]; @@ -139,7 +139,7 @@ index 271b6fb..9fafe98 100644 /* We can't use grub_fatal() in this function. This would create an infinite loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */ diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c -index d483e35..e71d158 100644 +index d483e35eed2..e71d1584164 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c @@ -71,7 +71,7 @@ grub_addr_t grub_ieee1275_original_stack; @@ -152,7 +152,7 @@ index d483e35..e71d158 100644 grub_ieee1275_exit (); } diff --git a/grub-core/kern/mips/arc/init.c b/grub-core/kern/mips/arc/init.c -index 3834a14..86b3a25 100644 +index 2ed3ff3191e..5c40c34078d 100644 --- a/grub-core/kern/mips/arc/init.c +++ b/grub-core/kern/mips/arc/init.c @@ -276,7 +276,7 @@ grub_halt (void) @@ -165,7 +165,7 @@ index 3834a14..86b3a25 100644 GRUB_ARC_FIRMWARE_VECTOR->exit (); diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c -index 7b96531..dff598c 100644 +index 7b96531b983..dff598ca7b0 100644 --- a/grub-core/kern/mips/loongson/init.c +++ b/grub-core/kern/mips/loongson/init.c @@ -304,7 +304,7 @@ grub_halt (void) @@ -178,7 +178,7 @@ index 7b96531..dff598c 100644 grub_halt (); } diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c -index be88b77..8b6c55f 100644 +index be88b77d22d..8b6c55ffc01 100644 --- a/grub-core/kern/mips/qemu_mips/init.c +++ b/grub-core/kern/mips/qemu_mips/init.c @@ -75,7 +75,7 @@ grub_machine_fini (int flags __attribute__ ((unused))) @@ -191,10 +191,10 @@ index be88b77..8b6c55f 100644 grub_halt (); } diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 3b633d5..cd63a8c 100644 +index 3af336ee227..63b586d09cb 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c -@@ -1095,9 +1095,18 @@ grub_abort (void) +@@ -1209,9 +1209,18 @@ grub_abort (void) grub_getkey (); } @@ -215,7 +215,7 @@ index 3b633d5..cd63a8c 100644 grub_fatal (const char *fmt, ...) { diff --git a/grub-core/kern/uboot/init.c b/grub-core/kern/uboot/init.c -index 3e33864..be2a5be 100644 +index 3e338645c57..be2a5be1d07 100644 --- a/grub-core/kern/uboot/init.c +++ b/grub-core/kern/uboot/init.c @@ -39,9 +39,9 @@ extern grub_size_t grub_total_module_size; @@ -240,7 +240,7 @@ index 3e33864..be2a5be 100644 else if (ver > API_SIG_VERSION) { diff --git a/grub-core/kern/xen/init.c b/grub-core/kern/xen/init.c -index 782ca72..708b060 100644 +index 782ca72952a..708b060f324 100644 --- a/grub-core/kern/xen/init.c +++ b/grub-core/kern/xen/init.c @@ -584,7 +584,7 @@ grub_machine_init (void) @@ -253,10 +253,10 @@ index 782ca72..708b060 100644 struct sched_shutdown arg; diff --git a/include/grub/misc.h b/include/grub/misc.h -index ee48eb7..f9135b6 100644 +index 7d2b5519690..fd18e6320b8 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h -@@ -334,7 +334,7 @@ int EXPORT_FUNC(grub_vsnprintf) (char *str, grub_size_t n, const char *fmt, +@@ -353,7 +353,7 @@ int EXPORT_FUNC(grub_vsnprintf) (char *str, grub_size_t n, const char *fmt, char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT; char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) WARN_UNUSED_RESULT; @@ -265,6 +265,3 @@ index ee48eb7..f9135b6 100644 grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r); --- -1.8.3.1 - diff --git a/0018-Make-efi-machines-load-an-env-block-from-a-variable.patch b/0017-Make-efi-machines-load-an-env-block-from-a-variable.patch similarity index 68% rename from 0018-Make-efi-machines-load-an-env-block-from-a-variable.patch rename to 0017-Make-efi-machines-load-an-env-block-from-a-variable.patch index b99effdb8fd8e08a62e276dad2734d95db7e23d6..d0614611df668de8ada17698ea556fe8cbac5a14 100644 --- a/0018-Make-efi-machines-load-an-env-block-from-a-variable.patch +++ b/0017-Make-efi-machines-load-an-env-block-from-a-variable.patch @@ -1,35 +1,43 @@ -From 2c806ded764dd0e69dbc4e1b95a390bb65bbd019 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 7 Dec 2015 14:20:49 -0500 -Subject: [PATCH 018/220] Make efi machines load an env block from a variable +Subject: [PATCH] Make efi machines load an env block from a variable Signed-off-by: Peter Jones --- grub-core/Makefile.core.def | 1 + - grub-core/kern/efi/init.c | 34 +++++++++++++++++++++++++++++++++- - 2 files changed, 34 insertions(+), 1 deletion(-) + grub-core/kern/efi/init.c | 36 +++++++++++++++++++++++++++++++++++- + 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index eb1088f..41b5e16 100644 +index 45d3edaa4dc..c865a08b027 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -203,6 +203,7 @@ kernel = { - efi = term/efi/console.c; - efi = kern/acpi.c; +@@ -207,6 +207,7 @@ kernel = { efi = kern/efi/acpi.c; + efi = kern/efi/sb.c; + efi = kern/lockdown.c; + efi = lib/envblk.c; i386_coreboot = kern/i386/pc/acpi.c; i386_multiboot = kern/i386/pc/acpi.c; i386_coreboot = kern/acpi.c; diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c -index 3dfdf2d..71d2279 100644 +index 7facacf09c7..6d39bd3ad29 100644 --- a/grub-core/kern/efi/init.c +++ b/grub-core/kern/efi/init.c -@@ -25,9 +25,40 @@ +@@ -27,8 +27,11 @@ #include #include #include ++ + #include + +#include ++ + #ifdef GRUB_STACK_PROTECTOR + + static grub_efi_guid_t rng_protocol_guid = GRUB_EFI_RNG_PROTOCOL_GUID; +@@ -82,6 +85,36 @@ stack_protector_init (void) grub_addr_t grub_modbase; @@ -54,8 +62,8 @@ index 3dfdf2d..71d2279 100644 + struct grub_envblk envblk_s = { NULL, 0 }; + grub_envblk_t envblk = &envblk_s; + -+ envblk_s.buf = grub_efi_get_variable ("GRUB_ENV", &efi_grub_guid, -+ &envblk_s.size); ++ grub_efi_get_variable ("GRUB_ENV", &efi_grub_guid, &envblk_s.size, ++ (void **) &envblk_s.buf); + if (!envblk_s.buf || envblk_s.size < 1) + return; + @@ -66,7 +74,7 @@ index 3dfdf2d..71d2279 100644 void grub_efi_init (void) { -@@ -42,10 +73,11 @@ grub_efi_init (void) +@@ -108,10 +141,11 @@ grub_efi_init (void) efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer, 0, 0, 0, NULL); @@ -79,6 +87,3 @@ index 3dfdf2d..71d2279 100644 char **device, char **path); --- -1.8.3.1 - diff --git a/0017-Mark-po-exclude.pot-as-binary-so-git-won-t-try-to-di.patch b/0017-Mark-po-exclude.pot-as-binary-so-git-won-t-try-to-di.patch deleted file mode 100644 index e67aa4b7414957650484bce8fd4ec4cb4b6c4266..0000000000000000000000000000000000000000 --- a/0017-Mark-po-exclude.pot-as-binary-so-git-won-t-try-to-di.patch +++ /dev/null @@ -1,22 +0,0 @@ -From 9851c77af2f615927719300b632f38d51d8f1d27 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 22 Jul 2015 11:21:01 -0400 -Subject: [PATCH 017/220] Mark po/exclude.pot as binary so git won't try to - diff nonprintables. - -Signed-off-by: Peter Jones ---- - .gitattributes | 1 + - 1 file changed, 1 insertion(+) - create mode 100644 .gitattributes - -diff --git a/.gitattributes b/.gitattributes -new file mode 100644 -index 0000000..33ffaa4 ---- /dev/null -+++ b/.gitattributes -@@ -0,0 +1 @@ -+po/exclude.pot binary --- -1.8.3.1 - diff --git a/0022-Migrate-PPC-from-Yaboot-to-Grub2.patch b/0018-Migrate-PPC-from-Yaboot-to-Grub2.patch similarity index 89% rename from 0022-Migrate-PPC-from-Yaboot-to-Grub2.patch rename to 0018-Migrate-PPC-from-Yaboot-to-Grub2.patch index 5465fb7ab50ffa860f6708d036653e5ce388dee9..5cbe731bc19d9ab85e9b79613dcc82761cb14765 100644 --- a/0022-Migrate-PPC-from-Yaboot-to-Grub2.patch +++ b/0018-Migrate-PPC-from-Yaboot-to-Grub2.patch @@ -1,10 +1,13 @@ -From b29012d97aac59ab69aff7806cb012d6270706e2 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Mark Hamzy Date: Wed, 28 Mar 2012 14:46:41 -0500 -Subject: [PATCH 022/220] Migrate PPC from Yaboot to Grub2 +Subject: [PATCH] Migrate PPC from Yaboot to Grub2 -Add configuration support for serial terminal consoles. This will set the -maximum screen size so that text is not overwritten. +Add configuration support for serial terminal consoles. This will set +the maximum screen size so that text is not overwritten. + +Signed-off-by: Mark Hamzy +Signed-off-by: Robbie Harwood --- Makefile.util.def | 7 +++ util/grub.d/20_ppc_terminfo.in | 114 +++++++++++++++++++++++++++++++++++++++++ @@ -12,26 +15,26 @@ maximum screen size so that text is not overwritten. create mode 100644 util/grub.d/20_ppc_terminfo.in diff --git a/Makefile.util.def b/Makefile.util.def -index 969d32f..8717774 100644 +index f8b356cc1fa..2c9b283a230 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -497,6 +497,13 @@ script = { +@@ -508,6 +508,13 @@ script = { + condition = COND_HOST_LINUX; }; - script = { ++script = { + name = '20_ppc_terminfo'; + common = util/grub.d/20_ppc_terminfo.in; + installdir = grubconf; + condition = COND_HOST_LINUX; +}; + -+script = { + script = { name = '30_os-prober'; common = util/grub.d/30_os-prober.in; - installdir = grubconf; diff --git a/util/grub.d/20_ppc_terminfo.in b/util/grub.d/20_ppc_terminfo.in new file mode 100644 -index 0000000..10d6658 +index 00000000000..10d66586820 --- /dev/null +++ b/util/grub.d/20_ppc_terminfo.in @@ -0,0 +1,114 @@ @@ -149,6 +152,3 @@ index 0000000..10d6658 +cat << EOF + terminfo -g ${X}x${Y} ${TERMINAL} +EOF --- -1.8.3.1 - diff --git a/0023-Add-fw_path-variable-revised.patch b/0019-Add-fw_path-variable-revised.patch similarity index 83% rename from 0023-Add-fw_path-variable-revised.patch rename to 0019-Add-fw_path-variable-revised.patch index 2f1bb696a29f7f0b954780e54c59d8f2a62d169e..a8491e8c083d23bd27540ff1e5e16db2509a2579 100644 --- a/0023-Add-fw_path-variable-revised.patch +++ b/0019-Add-fw_path-variable-revised.patch @@ -1,23 +1,26 @@ -From 0a416bfa1cb5647bcba96513edf4f6c8b68c79ba Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Paulo Flabiano Smorigo Date: Wed, 19 Sep 2012 21:22:55 -0300 -Subject: [PATCH 023/220] Add fw_path variable (revised) +Subject: [PATCH] Add fw_path variable (revised) This patch makes grub look for its config file on efi where the app was found. It was originally written by Matthew Garrett, and adapted to fix the "No modules are loaded on grub2 network boot" issue: https://bugzilla.redhat.com/show_bug.cgi?id=857936 + +Signed-off-by: Paulo Flabiano Smorigo +Signed-off-by: Robbie Harwood --- grub-core/kern/main.c | 13 ++++++------- grub-core/normal/main.c | 25 ++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c -index 9cad0c4..8ab7794 100644 +index 73967e2f5b0..d1de9fa6873 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c -@@ -127,16 +127,15 @@ grub_set_prefix_and_root (void) +@@ -128,16 +128,15 @@ grub_set_prefix_and_root (void) grub_machine_get_bootlocation (&fwdevice, &fwpath); @@ -41,10 +44,10 @@ index 9cad0c4..8ab7794 100644 } diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index 222e239..394bfbe 100644 +index 70614de1565..62571e6dfcc 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c -@@ -338,7 +338,30 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), +@@ -339,7 +339,30 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), /* Guess the config filename. It is necessary to make CONFIG static, so that it won't get broken by longjmp. */ char *config; @@ -76,6 +79,3 @@ index 222e239..394bfbe 100644 prefix = grub_env_get ("prefix"); if (prefix) --- -1.8.3.1 - diff --git a/0019-DHCP-client-ID-and-UUID-options-added.patch b/0019-DHCP-client-ID-and-UUID-options-added.patch deleted file mode 100644 index 2d07496c723d286b477b675cb06d351ff758b7f0..0000000000000000000000000000000000000000 --- a/0019-DHCP-client-ID-and-UUID-options-added.patch +++ /dev/null @@ -1,143 +0,0 @@ -From 93dd0d49c319a8611cfe346c21706d2390cbf854 Mon Sep 17 00:00:00 2001 -From: Paulo Flabiano Smorigo -Date: Mon, 8 Jul 2019 14:10:58 +0200 -Subject: [PATCH 019/220] DHCP client ID and UUID options added. - ---- - grub-core/net/bootp.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++----- - include/grub/net.h | 2 ++ - 2 files changed, 79 insertions(+), 8 deletions(-) - -diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index 04cfbb0..0e6e41a 100644 ---- a/grub-core/net/bootp.c -+++ b/grub-core/net/bootp.c -@@ -95,6 +95,49 @@ enum - /* Max timeout when waiting for BOOTP/DHCP reply */ - #define GRUB_DHCP_MAX_PACKET_TIMEOUT 32 - -+static char * -+grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)), -+ const char *val __attribute__ ((unused))) -+{ -+ return NULL; -+} -+ -+static void -+set_env_limn_ro (const char *intername, const char *suffix, -+ const char *value, grub_size_t len) -+{ -+ char *varname, *varvalue; -+ char *ptr; -+ varname = grub_xasprintf ("net_%s_%s", intername, suffix); -+ if (!varname) -+ return; -+ for (ptr = varname; *ptr; ptr++) -+ if (*ptr == ':') -+ *ptr = '_'; -+ varvalue = grub_malloc (len + 1); -+ if (!varvalue) -+ { -+ grub_free (varname); -+ return; -+ } -+ -+ grub_memcpy (varvalue, value, len); -+ varvalue[len] = 0; -+ grub_env_set (varname, varvalue); -+ grub_register_variable_hook (varname, 0, grub_env_write_readonly); -+ grub_env_export (varname); -+ grub_free (varname); -+ grub_free (varvalue); -+} -+ -+static char -+hexdigit (grub_uint8_t val) -+{ -+ if (val < 10) -+ return val + '0'; -+ return val + 'a' - 10; -+} -+ - static const void * - find_dhcp_option (const struct grub_net_bootp_packet *bp, grub_size_t size, - grub_uint8_t opt_code, grub_uint8_t *opt_len) -@@ -152,6 +195,9 @@ again: - if (i + taglength >= size) - return NULL; - -+ grub_dprintf("net", "DHCP option %u (0x%02x) found with length %u.\n", -+ tagtype, tagtype, taglength); -+ - /* FIXME RFC 3396 options concatentation */ - if (tagtype == opt_code) - { -@@ -354,6 +400,37 @@ grub_net_configure_by_dhcp_ack (const char *name, - } - grub_net_add_ipv4_local (inter, mask); - -+ opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_CLIENT_ID, &opt_len); -+ if (opt) -+ { -+ set_env_limn_ro (name, "clientid", (char *) opt, opt_len); -+ } -+ -+ opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_CLIENT_UUID, &opt_len); -+ if (opt && opt_len == 17) -+ { -+ /* The format is 9cfe245e-d0c8-bd45-a79f-54ea5fbd3d97 */ -+ -+ opt += 1; -+ opt_len -= 1; -+ -+ char *val = grub_malloc (2 * opt_len + 4 + 1); -+ int i = 0; -+ int j = 0; -+ for (i = 0; i < opt_len; i++) -+ { -+ val[2 * i + j] = hexdigit (opt[i] >> 4); -+ val[2 * i + 1 + j] = hexdigit (opt[i] & 0xf); -+ -+ if ((i == 3) || (i == 5) || (i == 7) || (i == 9)) -+ { -+ j++; -+ val[2 * i + 1+ j] = '-'; -+ } -+ } -+ set_env_limn_ro (name, "clientuuid", (char *) val, 2 * opt_len + 4); -+ } -+ - /* We do not implement dead gateway detection and the first entry SHOULD - be preferred one */ - opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_ROUTER, &opt_len); -@@ -631,14 +708,6 @@ grub_net_process_dhcp (struct grub_net_buff *nb, - } - } - --static char --hexdigit (grub_uint8_t val) --{ -- if (val < 10) -- return val + '0'; -- return val + 'a' - 10; --} -- - static grub_err_t - grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), - int argc, char **args) -diff --git a/include/grub/net.h b/include/grub/net.h -index 4a9069a..556c54e 100644 ---- a/include/grub/net.h -+++ b/include/grub/net.h -@@ -462,6 +462,8 @@ enum - GRUB_NET_BOOTP_DOMAIN = 0x0f, - GRUB_NET_BOOTP_ROOT_PATH = 0x11, - GRUB_NET_BOOTP_EXTENSIONS_PATH = 0x12, -+ GRUB_NET_BOOTP_CLIENT_ID = 0x3d, -+ GRUB_NET_BOOTP_CLIENT_UUID = 0x61, - GRUB_NET_DHCP_REQUESTED_IP_ADDRESS = 50, - GRUB_NET_DHCP_OVERLOAD = 52, - GRUB_NET_DHCP_MESSAGE_TYPE = 53, --- -1.8.3.1 - diff --git a/0020-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch b/0020-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch deleted file mode 100644 index 4e436b956d1ccfab4f36cd2b65fd8cebf40fa7cd..0000000000000000000000000000000000000000 --- a/0020-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 07241ef86e2d39264a89c5a3d789cb0cc9f41c81 Mon Sep 17 00:00:00 2001 -From: Prarit Bhargava -Date: Wed, 12 Mar 2014 10:58:16 -0400 -Subject: [PATCH 020/220] Fix bad test on GRUB_DISABLE_SUBMENU. - -The file /etc/grub.d/10_linux does - -if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then - -when it should do - -if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then - -which results in submenus in /boot/grub2/grub.cfg when -GRUB_DISABLE_SUBMENU="yes". - -Resolves: rhbz#1063414 ---- - util/grub.d/10_linux.in | 6 +++++- - 1 file changed, 5 insertions(+), 1 deletion(-) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 4532266..58defdb 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -261,7 +261,11 @@ while [ "x$list" != "x" ] ; do - fi - fi - -- if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then -+ if [ "x${GRUB_DISABLE_SUBMENU}" = "xyes" ] || [ "x${GRUB_DISABLE_SUBMENU}" = "xy" ]; then -+ GRUB_DISABLE_SUBMENU="true" -+ fi -+ -+ if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then - linux_entry "${OS}" "${version}" simple \ - "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" - --- -1.8.3.1 - diff --git a/0024-Pass-x-hex-hex-straight-through-unmolested.patch b/0020-Pass-x-hex-hex-straight-through-unmolested.patch similarity index 83% rename from 0024-Pass-x-hex-hex-straight-through-unmolested.patch rename to 0020-Pass-x-hex-hex-straight-through-unmolested.patch index d080ca755670dc7f07c407fd7e203f51f54b7f57..b81abb54583a157bcffbd037a88f4282f550001b 100644 --- a/0024-Pass-x-hex-hex-straight-through-unmolested.patch +++ b/0020-Pass-x-hex-hex-straight-through-unmolested.patch @@ -1,20 +1,22 @@ -From 98acf7f62203f6dda6e735743ce4e4f410d451e1 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 1 Oct 2012 13:24:37 -0400 -Subject: [PATCH 024/220] Pass "\x[[:hex:]][[:hex:]]" straight through - unmolested. +Subject: [PATCH] Pass "\x[[:hex:]][[:hex:]]" straight through unmolested. +Don't munge raw spaces when we're doing our cmdline escaping (#923374) + +Signed-off-by: Peter Jones --- grub-core/commands/wildcard.c | 16 +++++++++++++++- - grub-core/lib/cmdline.c | 34 ++++++++++++++++++++++++++++++++-- + grub-core/lib/cmdline.c | 25 +++++++++++++++++++++++-- grub-core/script/execute.c | 43 +++++++++++++++++++++++++++++++++++++------ - 3 files changed, 84 insertions(+), 9 deletions(-) + 3 files changed, 75 insertions(+), 9 deletions(-) diff --git a/grub-core/commands/wildcard.c b/grub-core/commands/wildcard.c -index 4a106ca..560d437 100644 +index cc3290311f0..8f67a4be7f0 100644 --- a/grub-core/commands/wildcard.c +++ b/grub-core/commands/wildcard.c -@@ -462,6 +462,12 @@ check_file (const char *dir, const char *basename) +@@ -488,6 +488,12 @@ check_file (const char *dir, const char *basename) return ctx.found; } @@ -27,7 +29,7 @@ index 4a106ca..560d437 100644 static void unescape (char *out, const char *in, const char *end) { -@@ -470,7 +476,15 @@ unescape (char *out, const char *in, const char *end) +@@ -496,7 +502,15 @@ unescape (char *out, const char *in, const char *end) for (optr = out, iptr = in; iptr < end;) { @@ -45,7 +47,7 @@ index 4a106ca..560d437 100644 *optr++ = iptr[1]; iptr += 2; diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c -index ed0b149..e0fb0a9 100644 +index ed0b149dca5..8e2294d8ff6 100644 --- a/grub-core/lib/cmdline.c +++ b/grub-core/lib/cmdline.c @@ -20,6 +20,12 @@ @@ -76,21 +78,12 @@ index ed0b149..e0fb0a9 100644 size++; else if (*c == ' ') space = 1; -@@ -86,7 +98,25 @@ grub_create_loader_cmdline (int argc, char *argv[], char *buf, +@@ -86,7 +98,16 @@ grub_create_loader_cmdline (int argc, char *argv[], char *buf, while (*c) { - if (*c == '\\' || *c == '\'' || *c == '"') -+ if (*c == ' ') -+ { -+ *buf++ = '\\'; -+ *buf++ = 'x'; -+ *buf++ = '2'; -+ *buf++ = '0'; -+ c++; -+ continue; -+ } -+ else if (*c == '\\' && *(c+1) == 'x' && ++ if (*c == '\\' && *(c+1) == 'x' && + is_hex(*(c+2)) && is_hex(*(c+3))) + { + *buf++ = *c++; @@ -104,7 +97,7 @@ index ed0b149..e0fb0a9 100644 *buf++ = *c; diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c -index 0d05d6b..ba38b5e 100644 +index ad80399246a..0c6dd9c5201 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -56,6 +56,12 @@ static struct grub_script_scope *scope = 0; @@ -178,6 +171,3 @@ index 0d05d6b..ba38b5e 100644 break; case '$': if (escaped) --- -1.8.3.1 - diff --git a/0021-Add-support-for-UEFI-operating-systems-returned-by-o.patch b/0021-Add-support-for-UEFI-operating-systems-returned-by-o.patch deleted file mode 100644 index 5bc833aaeb0bfd3f7b150302542f14f7ce113981..0000000000000000000000000000000000000000 --- a/0021-Add-support-for-UEFI-operating-systems-returned-by-o.patch +++ /dev/null @@ -1,50 +0,0 @@ -From bfa8c75e6921c3584538c7ecef354f7136133af3 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Wed, 12 Jun 2013 11:51:49 -0400 -Subject: [PATCH 021/220] Add support for UEFI operating systems returned by - os-prober - -os-prober returns UEFI operating systems in the form: - -path:long-name:name - -where path is the path under the EFI directory on the ESP. This is in -contrast to legacy OSes, where path is the device string. Handle this case. ---- - util/grub.d/30_os-prober.in | 21 ++++++++++++++++++--- - 1 file changed, 18 insertions(+), 3 deletions(-) - -diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in -index 515a68c..9b8f596 100644 ---- a/util/grub.d/30_os-prober.in -+++ b/util/grub.d/30_os-prober.in -@@ -328,8 +328,23 @@ EOF - EOF - ;; - *) -- # TRANSLATORS: %s is replaced by OS name. -- gettext_printf "%s is not yet supported by grub-mkconfig.\n" " ${LONGNAME}" >&2 -- ;; -+ case ${DEVICE} in -+ *.efi) -+ cat << EOF -+menuentry '$(echo "${LONGNAME}" | grub_quote)' { -+EOF -+ save_default_entry | grub_add_tab -+ cat << EOF -+ chainloader /EFI/${DEVICE} -+ boot -+} -+EOF -+ ;; -+ *) -+ echo -n " " -+ # TRANSLATORS: %s is replaced by OS name. -+ gettext_printf "%s is not yet supported by grub-mkconfig.\n" "${LONGNAME}" >&2 -+ ;; -+ esac - esac - done --- -1.8.3.1 - diff --git a/0027-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch b/0021-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch similarity index 90% rename from 0027-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch rename to 0021-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch index 450dab898800164e559765329ea592f062a2de3d..da65e1876863ad1c1066796714836ff9beb630b7 100644 --- a/0027-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch +++ b/0021-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch @@ -1,8 +1,8 @@ -From 6f68e870cac4b87ef7caf2bd305de9ffa1907791 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 22 Jan 2013 06:31:38 +0100 -Subject: [PATCH 027/220] blscfg: add blscfg module to parse Boot Loader - Specification snippets +Subject: [PATCH] blscfg: add blscfg module to parse Boot Loader Specification + snippets The BootLoaderSpec (BLS) defines a scheme where different bootloaders can share a format for boot items and a configuration directory that accepts @@ -14,27 +14,28 @@ Signed-off-by: Javier Martinez Canillas Signed-off-by: Will Thompson --- grub-core/Makefile.core.def | 11 + - grub-core/commands/blscfg.c | 1096 ++++++++++++++++++++++++++++++++++++++++ + grub-core/commands/blscfg.c | 1177 ++++++++++++++++++++++++++++++++++++++++ grub-core/commands/legacycfg.c | 5 +- grub-core/commands/loadenv.c | 77 +-- - grub-core/commands/loadenv.h | 93 ++++ grub-core/commands/menuentry.c | 20 +- grub-core/normal/main.c | 6 + + grub-core/commands/loadenv.h | 93 ++++ include/grub/compiler.h | 2 + include/grub/menu.h | 13 + include/grub/normal.h | 2 +- - 10 files changed, 1243 insertions(+), 82 deletions(-) + 10 files changed, 1324 insertions(+), 82 deletions(-) create mode 100644 grub-core/commands/blscfg.c create mode 100644 grub-core/commands/loadenv.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 41b5e16..57e253a 100644 +index c865a08b027..c15e91943b9 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -812,6 +812,16 @@ module = { +@@ -814,6 +814,16 @@ module = { + common = commands/blocklist.c; }; - module = { ++module = { + name = blscfg; + common = commands/blscfg.c; + common = commands/loadenv.h; @@ -44,11 +45,10 @@ index 41b5e16..57e253a 100644 + enable = emu; +}; + -+module = { + module = { name = boot; common = commands/boot.c; - i386_pc = lib/i386/pc/biosnum.c; -@@ -988,6 +998,7 @@ module = { +@@ -980,6 +990,7 @@ module = { module = { name = loadenv; common = commands/loadenv.c; @@ -58,10 +58,10 @@ index 41b5e16..57e253a 100644 diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c new file mode 100644 -index 0000000..54458b1 +index 00000000000..e907a6a5d28 --- /dev/null +++ b/grub-core/commands/blscfg.c -@@ -0,0 +1,1096 @@ +@@ -0,0 +1,1177 @@ +/*-*- Mode: C; c-basic-offset: 2; indent-tabs-mode: t -*-*/ + +/* bls.c - implementation of the boot loader spec */ @@ -227,8 +227,8 @@ index 0000000..54458b1 + + /* loop through each version segment of str1 and str2 and compare them */ + while (*one || *two) { -+ while (*one && !grub_isalnum(*one) && *one != '~') one++; -+ while (*two && !grub_isalnum(*two) && *two != '~') two++; ++ while (*one && !grub_isalnum(*one) && *one != '~' && *one != '+') one++; ++ while (*two && !grub_isalnum(*two) && *two != '~' && *two != '+') two++; + + /* handle the tilde separator, it sorts before everything else */ + if (*one == '~' || *two == '~') { @@ -239,6 +239,21 @@ index 0000000..54458b1 + continue; + } + ++ /* ++ * Handle plus separator. Concept is the same as tilde, ++ * except that if one of the strings ends (base version), ++ * the other is considered as higher version. ++ */ ++ if (*one == '+' || *two == '+') { ++ if (!*one) return -1; ++ if (!*two) return 1; ++ if (*one != '+') goto_return (1); ++ if (*two != '+') goto_return (-1); ++ one++; ++ two++; ++ continue; ++ } ++ + /* If we ran to the end of either, we are finished with the loop */ + if (!(*one && *two)) break; + @@ -649,43 +664,52 @@ index 0000000..54458b1 + list[nlist] = NULL; + } + ++ if (!nlist) ++ { ++ grub_free (list); ++ return NULL; ++ } ++ + if (num) + *num = nlist; + + return list; +} + -+static char *field_append(bool is_var, char *buffer, char *start, char *end) ++static char *field_append(bool is_var, char *buffer, const char *start, const char *end) +{ -+ char *temp = grub_strndup(start, end - start + 1); -+ const char *field = temp; ++ char *tmp = grub_strndup(start, end - start + 1); ++ const char *field = tmp; ++ int term = is_var ? 2 : 1; + + if (is_var) { -+ field = grub_env_get (temp); ++ field = grub_env_get (tmp); + if (!field) + return buffer; + } + -+ if (!buffer) { -+ buffer = grub_strdup(field); -+ if (!buffer) -+ return NULL; -+ } else { -+ buffer = grub_realloc (buffer, grub_strlen(buffer) + grub_strlen(field)); -+ if (!buffer) -+ return NULL; ++ if (!buffer) ++ buffer = grub_zalloc (grub_strlen(field) + term); ++ else ++ buffer = grub_realloc (buffer, grub_strlen(buffer) + grub_strlen(field) + term); + -+ grub_stpcpy (buffer + grub_strlen(buffer), field); -+ } ++ if (!buffer) ++ return NULL; ++ ++ tmp = buffer + grub_strlen(buffer); ++ tmp = grub_stpcpy (tmp, field); ++ ++ if (is_var) ++ tmp = grub_stpcpy (tmp, " "); + + return buffer; +} + -+static char *expand_val(char *value) ++static char *expand_val(const char *value) +{ + char *buffer = NULL; -+ char *start = value; -+ char *end = value; ++ const char *start = value; ++ const char *end = value; + bool is_var = false; + + if (!value) @@ -706,6 +730,8 @@ index 0000000..54458b1 + buffer = field_append(is_var, buffer, start, end); + is_var = false; + start = value; ++ if (*start == ' ') ++ start++; + } + } + @@ -762,6 +788,8 @@ index 0000000..54458b1 + const char *early_initrd = NULL; + char **early_initrds = NULL; + char *initrd_prefix = NULL; ++ char *devicetree = NULL; ++ char *dt = NULL; + char *id = entry->filename; + char *dotconf = id; + char *hotkey = NULL; @@ -773,6 +801,7 @@ index 0000000..54458b1 + + char *src = NULL; + int i, index; ++ bool add_dt_prefix = false; + + grub_dprintf("blscfg", "%s got here\n", __func__); + clinux = bls_get_val (entry, "linux", NULL); @@ -800,6 +829,14 @@ index 0000000..54458b1 + + initrds = bls_make_list (entry, "initrd", NULL); + ++ devicetree = expand_val (bls_get_val (entry, "devicetree", NULL)); ++ ++ if (!devicetree) ++ { ++ devicetree = expand_val (grub_env_get("devicetree")); ++ add_dt_prefix = true; ++ } ++ + hotkey = bls_get_val (entry, "grub_hotkey", NULL); + users = expand_val (bls_get_val (entry, "grub_users", NULL)); + classes = bls_make_list (entry, "grub_class", NULL); @@ -865,7 +902,6 @@ index 0000000..54458b1 + goto finish; + } + -+ + tmp = grub_stpcpy(initrd, "initrd"); + for (i = 0; early_initrds != NULL && early_initrds[i] != NULL; i++) + { @@ -885,21 +921,68 @@ index 0000000..54458b1 + tmp = grub_stpcpy (tmp, "\n"); + } + -+ src = grub_xasprintf ("load_video\n" ++ if (devicetree) ++ { ++ char *prefix = NULL; ++ int dt_size; ++ ++ if (add_dt_prefix) ++ { ++ prefix = grub_strrchr (clinux, '/'); ++ prefix = grub_strndup(clinux, prefix - clinux + 1); ++ if (!prefix) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); ++ goto finish; ++ } ++ } ++ ++ dt_size = sizeof("devicetree " GRUB_BOOT_DEVICE) + grub_strlen(devicetree) + 1; ++ ++ if (add_dt_prefix) ++ { ++ dt_size += grub_strlen(prefix); ++ } ++ ++ dt = grub_malloc (dt_size); ++ if (!dt) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); ++ goto finish; ++ } ++ char *tmp = dt; ++ tmp = grub_stpcpy (dt, "devicetree"); ++ tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE); ++ if (add_dt_prefix) ++ tmp = grub_stpcpy (tmp, prefix); ++ tmp = grub_stpcpy (tmp, devicetree); ++ tmp = grub_stpcpy (tmp, "\n"); ++ ++ grub_free(prefix); ++ } ++ ++ grub_dprintf ("blscfg2", "devicetree %s for id:\"%s\"\n", dt, id); ++ ++ const char *sdval = grub_env_get("save_default"); ++ bool savedefault = ((NULL != sdval) && (grub_strcmp(sdval, "true") == 0)); ++ src = grub_xasprintf ("%sload_video\n" + "set gfxpayload=keep\n" + "insmod gzio\n" + "linux %s%s%s%s\n" -+ "%s", ++ "%s%s", ++ savedefault ? "savedefault\n" : "", + GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "", -+ initrd ? initrd : ""); ++ initrd ? initrd : "", dt ? dt : ""); + + grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0, &index, entry); + grub_dprintf ("blscfg", "Added entry %d id:\"%s\"\n", index, id); + +finish: ++ grub_free (dt); + grub_free (initrd); + grub_free (initrd_prefix); + grub_free (early_initrds); ++ grub_free (devicetree); + grub_free (initrds); + grub_free (options); + grub_free (classes); @@ -1009,14 +1092,12 @@ index 0000000..54458b1 + if (!devid) { +#ifdef GRUB_MACHINE_EMU + devid = "host"; -+#elif defined(GRUB_MACHINE_EFI) -+ devid = grub_env_get ("root"); +#else -+ devid = grub_env_get ("boot"); ++ devid = grub_env_get ("root"); +#endif + if (!devid) + return grub_error (GRUB_ERR_FILE_NOT_FOUND, -+ N_("variable `%s' isn't set"), "boot"); ++ N_("variable `%s' isn't set"), "root"); + } + + grub_dprintf ("blscfg", "opening %s\n", devid); @@ -1159,10 +1240,10 @@ index 0000000..54458b1 + grub_unregister_extcmd (oldcmd); +} diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c -index db7a8f0..891eac5 100644 +index cc5971f4dbd..782761c31aa 100644 --- a/grub-core/commands/legacycfg.c +++ b/grub-core/commands/legacycfg.c -@@ -133,7 +133,7 @@ legacy_file (const char *filename) +@@ -143,7 +143,7 @@ legacy_file (const char *filename) args[0] = oldname; grub_normal_add_menu_entry (1, args, NULL, NULL, "legacy", NULL, NULL, @@ -1171,7 +1252,7 @@ index db7a8f0..891eac5 100644 grub_free (args); entrysrc[0] = 0; grub_free (oldname); -@@ -186,7 +186,8 @@ legacy_file (const char *filename) +@@ -205,7 +205,8 @@ legacy_file (const char *filename) } args[0] = entryname; grub_normal_add_menu_entry (1, args, NULL, NULL, NULL, @@ -1182,7 +1263,7 @@ index db7a8f0..891eac5 100644 } diff --git a/grub-core/commands/loadenv.c b/grub-core/commands/loadenv.c -index 3fd664a..163b9a0 100644 +index 3fd664aac33..163b9a09042 100644 --- a/grub-core/commands/loadenv.c +++ b/grub-core/commands/loadenv.c @@ -28,6 +28,8 @@ @@ -1276,9 +1357,105 @@ index 3fd664a..163b9a0 100644 static grub_err_t grub_cmd_load_env (grub_extcmd_context_t ctxt, int argc, char **args) { +diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c +index 720e6d8ea3b..b194123eb67 100644 +--- a/grub-core/commands/menuentry.c ++++ b/grub-core/commands/menuentry.c +@@ -78,7 +78,7 @@ grub_normal_add_menu_entry (int argc, const char **args, + char **classes, const char *id, + const char *users, const char *hotkey, + const char *prefix, const char *sourcecode, +- int submenu) ++ int submenu, int *index, struct bls_entry *bls) + { + int menu_hotkey = 0; + char **menu_args = NULL; +@@ -149,9 +149,12 @@ grub_normal_add_menu_entry (int argc, const char **args, + if (! menu_title) + goto fail; + ++ grub_dprintf ("menu", "id:\"%s\"\n", id); ++ grub_dprintf ("menu", "title:\"%s\"\n", menu_title); + menu_id = grub_strdup (id ? : menu_title); + if (! menu_id) + goto fail; ++ grub_dprintf ("menu", "menu_id:\"%s\"\n", menu_id); + + /* Save argc, args to pass as parameters to block arg later. */ + menu_args = grub_calloc (argc + 1, sizeof (char *)); +@@ -170,8 +173,12 @@ grub_normal_add_menu_entry (int argc, const char **args, + } + + /* Add the menu entry at the end of the list. */ ++ int ind=0; + while (*last) +- last = &(*last)->next; ++ { ++ ind++; ++ last = &(*last)->next; ++ } + + *last = grub_zalloc (sizeof (**last)); + if (! *last) +@@ -188,8 +195,11 @@ grub_normal_add_menu_entry (int argc, const char **args, + (*last)->args = menu_args; + (*last)->sourcecode = menu_sourcecode; + (*last)->submenu = submenu; ++ (*last)->bls = bls; + + menu->size++; ++ if (index) ++ *index = ind; + return GRUB_ERR_NONE; + + fail: +@@ -286,7 +296,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args) + users, + ctxt->state[2].arg, 0, + ctxt->state[3].arg, +- ctxt->extcmd->cmd->name[0] == 's'); ++ ctxt->extcmd->cmd->name[0] == 's', ++ NULL, NULL); + + src = args[argc - 1]; + args[argc - 1] = NULL; +@@ -303,7 +314,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args) + ctxt->state[0].args, ctxt->state[4].arg, + users, + ctxt->state[2].arg, prefix, src + 1, +- ctxt->extcmd->cmd->name[0] == 's'); ++ ctxt->extcmd->cmd->name[0] == 's', NULL, ++ NULL); + + src[len - 1] = ch; + args[argc - 1] = src; +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 62571e6dfcc..7ca2e5400b1 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -21,6 +21,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -70,6 +71,11 @@ grub_normal_free_menu (grub_menu_t menu) + grub_free (entry->args); + } + ++ if (entry->bls) ++ { ++ entry->bls->visible = 0; ++ } ++ + grub_free ((void *) entry->id); + grub_free ((void *) entry->users); + grub_free ((void *) entry->title); diff --git a/grub-core/commands/loadenv.h b/grub-core/commands/loadenv.h new file mode 100644 -index 0000000..952f461 +index 00000000000..952f46121bd --- /dev/null +++ b/grub-core/commands/loadenv.h @@ -0,0 +1,93 @@ @@ -1375,115 +1552,19 @@ index 0000000..952f461 + + return 0; +} -diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c -index 2c5363d..9faf2be 100644 ---- a/grub-core/commands/menuentry.c -+++ b/grub-core/commands/menuentry.c -@@ -78,7 +78,7 @@ grub_normal_add_menu_entry (int argc, const char **args, - char **classes, const char *id, - const char *users, const char *hotkey, - const char *prefix, const char *sourcecode, -- int submenu) -+ int submenu, int *index, struct bls_entry *bls) - { - int menu_hotkey = 0; - char **menu_args = NULL; -@@ -149,9 +149,12 @@ grub_normal_add_menu_entry (int argc, const char **args, - if (! menu_title) - goto fail; - -+ grub_dprintf ("menu", "id:\"%s\"\n", id); -+ grub_dprintf ("menu", "title:\"%s\"\n", menu_title); - menu_id = grub_strdup (id ? : menu_title); - if (! menu_id) - goto fail; -+ grub_dprintf ("menu", "menu_id:\"%s\"\n", menu_id); - - /* Save argc, args to pass as parameters to block arg later. */ - menu_args = grub_malloc (sizeof (char*) * (argc + 1)); -@@ -170,8 +173,12 @@ grub_normal_add_menu_entry (int argc, const char **args, - } - - /* Add the menu entry at the end of the list. */ -+ int ind=0; - while (*last) -- last = &(*last)->next; -+ { -+ ind++; -+ last = &(*last)->next; -+ } - - *last = grub_zalloc (sizeof (**last)); - if (! *last) -@@ -188,8 +195,11 @@ grub_normal_add_menu_entry (int argc, const char **args, - (*last)->args = menu_args; - (*last)->sourcecode = menu_sourcecode; - (*last)->submenu = submenu; -+ (*last)->bls = bls; - - menu->size++; -+ if (index) -+ *index = ind; - return GRUB_ERR_NONE; - - fail: -@@ -286,7 +296,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args) - users, - ctxt->state[2].arg, 0, - ctxt->state[3].arg, -- ctxt->extcmd->cmd->name[0] == 's'); -+ ctxt->extcmd->cmd->name[0] == 's', -+ NULL, NULL); - - src = args[argc - 1]; - args[argc - 1] = NULL; -@@ -303,7 +314,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args) - ctxt->state[0].args, ctxt->state[4].arg, - users, - ctxt->state[2].arg, prefix, src + 1, -- ctxt->extcmd->cmd->name[0] == 's'); -+ ctxt->extcmd->cmd->name[0] == 's', NULL, -+ NULL); - - src[len - 1] = ch; - args[argc - 1] = src; -diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index 9ef9848..a326b19 100644 ---- a/grub-core/normal/main.c -+++ b/grub-core/normal/main.c -@@ -20,6 +20,7 @@ - #include - #include - #include -+#include - #include - #include - #include -@@ -70,6 +71,11 @@ grub_normal_free_menu (grub_menu_t menu) - grub_free (entry->args); - } - -+ if (entry->bls) -+ { -+ entry->bls->visible = 0; -+ } -+ - grub_free ((void *) entry->id); - grub_free ((void *) entry->users); - grub_free ((void *) entry->title); diff --git a/include/grub/compiler.h b/include/grub/compiler.h -index c9e1d7a..9859ff4 100644 +index 8f3be3ae706..ebafec68957 100644 --- a/include/grub/compiler.h +++ b/include/grub/compiler.h -@@ -48,4 +48,6 @@ - # define WARN_UNUSED_RESULT +@@ -56,4 +56,6 @@ + # define CLANG_PREREQ(maj,min) 0 #endif +#define UNUSED __attribute__((__unused__)) + #endif /* ! GRUB_COMPILER_HEADER */ diff --git a/include/grub/menu.h b/include/grub/menu.h -index ee2b5e9..0acdc2a 100644 +index ee2b5e91045..0acdc2aa6bf 100644 --- a/include/grub/menu.h +++ b/include/grub/menu.h @@ -20,6 +20,16 @@ @@ -1514,7 +1595,7 @@ index ee2b5e9..0acdc2a 100644 typedef struct grub_menu_entry *grub_menu_entry_t; diff --git a/include/grub/normal.h b/include/grub/normal.h -index 218cbab..8839ad8 100644 +index 218cbabccaf..8839ad85a19 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -145,7 +145,7 @@ grub_normal_add_menu_entry (int argc, const char **args, char **classes, @@ -1526,6 +1607,3 @@ index 218cbab..8839ad8 100644 grub_err_t grub_normal_set_password (const char *user, const char *password); --- -1.8.3.1 - diff --git a/0028-Add-devicetree-loading.patch b/0022-Add-devicetree-loading.patch similarity index 84% rename from 0028-Add-devicetree-loading.patch rename to 0022-Add-devicetree-loading.patch index f60d16eb9b992623cb9e0c7ad62a79c927e51ab9..c0728a9890ea370610275f3d83e61e635c393eab 100644 --- a/0028-Add-devicetree-loading.patch +++ b/0022-Add-devicetree-loading.patch @@ -1,7 +1,7 @@ -From 5c649924a8e4d233f922c21408eeeaac5b30bc73 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 14 Jan 2014 13:12:23 -0500 -Subject: [PATCH 028/220] Add devicetree loading +Subject: [PATCH] Add devicetree loading Signed-off-by: Peter Jones @@ -20,10 +20,10 @@ Signed-off-by: David A. Marlin 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index 9ecbcfb..c645351 100644 +index d3e879b8e5c..8ea2315ebc2 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in -@@ -254,7 +254,8 @@ export GRUB_DEFAULT \ +@@ -248,7 +248,8 @@ export GRUB_DEFAULT \ GRUB_ENABLE_CRYPTODISK \ GRUB_BADRAM \ GRUB_OS_PROBER_SKIP_LIST \ @@ -34,23 +34,23 @@ index 9ecbcfb..c645351 100644 if test "x${grub_cfg}" != "x"; then rm -f "${grub_cfg}.new" diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 58defdb..dd31284 100644 +index e8b01c0d0c7..dc75a1c30bf 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in -@@ -155,6 +155,13 @@ EOF +@@ -153,6 +153,13 @@ EOF + sed "s/^/$submenu_indentation/" << EOF + echo '$(echo "$message" | grub_quote)' initrd $(echo $initrd_path) - EOF - fi ++EOF ++ fi + if test -n "${fdt}" ; then + message="$(gettext_printf "Loading fdt ...")" + sed "s/^/$submenu_indentation/" << EOF + echo '$(echo "$message" | grub_quote)' + devicetree ${rel_dirname}/${fdt} -+EOF -+ fi - sed "s/^/$submenu_indentation/" << EOF - } EOF + fi + sed "s/^/$submenu_indentation/" << EOF @@ -236,6 +243,14 @@ while [ "x$list" != "x" ] ; do gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 fi @@ -66,6 +66,3 @@ index 58defdb..dd31284 100644 config= for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do if test -e "${i}" ; then --- -1.8.3.1 - diff --git a/0038-Enable-pager-by-default.-985860.patch b/0023-Enable-pager-by-default.-985860.patch similarity index 78% rename from 0038-Enable-pager-by-default.-985860.patch rename to 0023-Enable-pager-by-default.-985860.patch index f9031b2c93085b37e0f8b613f6fd12152ed6cc26..d92fbcc79a6b59f5b28483289647757b5e880c5b 100644 --- a/0038-Enable-pager-by-default.-985860.patch +++ b/0023-Enable-pager-by-default.-985860.patch @@ -1,7 +1,7 @@ -From 29aa9344700bc787778391d6176c2b3b220838e6 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 28 Oct 2013 10:09:27 -0400 -Subject: [PATCH 038/220] Enable pager by default. (#985860) +Subject: [PATCH] Enable pager by default. (#985860) Signed-off-by: Peter Jones --- @@ -9,7 +9,7 @@ Signed-off-by: Peter Jones 1 file changed, 2 insertions(+) diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in -index 93a9023..858b526 100644 +index 93a90233ead..858b526c925 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -43,6 +43,8 @@ if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then GRUB_DEFAULT_BUTTON='${saved_ @@ -21,6 +21,3 @@ index 93a9023..858b526 100644 if [ -s \$prefix/grubenv ]; then load_env fi --- -1.8.3.1 - diff --git a/0040-Don-t-say-GNU-Linux-in-generated-menus.patch b/0024-Don-t-say-GNU-Linux-in-generated-menus.patch similarity index 86% rename from 0040-Don-t-say-GNU-Linux-in-generated-menus.patch rename to 0024-Don-t-say-GNU-Linux-in-generated-menus.patch index b8593392462d93cc0a2a1d6df5034cb8dfec5c64..f28809503b8bb177aedd17918869258a62e1dc0e 100644 --- a/0040-Don-t-say-GNU-Linux-in-generated-menus.patch +++ b/0024-Don-t-say-GNU-Linux-in-generated-menus.patch @@ -1,7 +1,7 @@ -From b2d841ee307560bbc0a3c4fe4a5516fb8e00dd65 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 14 Mar 2011 14:27:42 -0400 -Subject: [PATCH 040/220] Don't say "GNU/Linux" in generated menus. +Subject: [PATCH] Don't say "GNU/Linux" in generated menus. --- util/grub.d/10_linux.in | 4 ++-- @@ -9,7 +9,7 @@ Subject: [PATCH 040/220] Don't say "GNU/Linux" in generated menus. 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index ceb413f..2b402d8 100644 +index dc75a1c30bf..4a499c53a61 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -29,9 +29,9 @@ export TEXTDOMAINDIR="@localedir@" @@ -25,7 +25,7 @@ index ceb413f..2b402d8 100644 fi diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in -index 96179ea..47e0d3f 100644 +index 3b1f4704921..ada20775a14 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -29,9 +29,9 @@ export TEXTDOMAINDIR="@localedir@" @@ -40,6 +40,3 @@ index 96179ea..47e0d3f 100644 CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" fi --- -1.8.3.1 - diff --git a/0043-Add-.eh_frame-to-list-of-relocations-stripped.patch b/0025-Add-.eh_frame-to-list-of-relocations-stripped.patch similarity index 84% rename from 0043-Add-.eh_frame-to-list-of-relocations-stripped.patch rename to 0025-Add-.eh_frame-to-list-of-relocations-stripped.patch index 8b83ed5da947d530eee281182b7f0173a77398b9..ed48c5c7fe0b41c4a00c7611109ec8ee91223f41 100644 --- a/0043-Add-.eh_frame-to-list-of-relocations-stripped.patch +++ b/0025-Add-.eh_frame-to-list-of-relocations-stripped.patch @@ -1,14 +1,14 @@ -From dcfc32257387a45d41600d52f2393fee402b7271 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Fedora Ninjas Date: Mon, 13 Jan 2014 21:50:59 -0500 -Subject: [PATCH 043/220] Add .eh_frame to list of relocations stripped +Subject: [PATCH] Add .eh_frame to list of relocations stripped --- conf/Makefile.common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/Makefile.common b/conf/Makefile.common -index 6cd71cb..4ba729e 100644 +index 2a1a886f6d5..191b1a70c6b 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common @@ -38,7 +38,7 @@ CFLAGS_KERNEL = $(CFLAGS_PLATFORM) -ffreestanding @@ -20,6 +20,3 @@ index 6cd71cb..4ba729e 100644 CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d --- -1.8.3.1 - diff --git a/0025-Add-X-option-to-printf-functions.patch b/0025-Add-X-option-to-printf-functions.patch deleted file mode 100644 index 30b51f12fd1366236f243adb0c5d4c2dc31228e5..0000000000000000000000000000000000000000 --- a/0025-Add-X-option-to-printf-functions.patch +++ /dev/null @@ -1,58 +0,0 @@ -From 29e1ec69b76c2e5d95cf339e60461f22cb0aeed6 Mon Sep 17 00:00:00 2001 -From: Paulo Flabiano Smorigo -Date: Tue, 27 Nov 2012 16:58:39 -0200 -Subject: [PATCH 025/220] Add %X option to printf functions. - ---- - grub-core/kern/misc.c | 7 +++++-- - 1 file changed, 5 insertions(+), 2 deletions(-) - -diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index cd63a8c..2656a67 100644 ---- a/grub-core/kern/misc.c -+++ b/grub-core/kern/misc.c -@@ -588,7 +588,7 @@ grub_divmod64 (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r) - static inline char * - grub_lltoa (char *str, int c, unsigned long long n) - { -- unsigned base = (c == 'x') ? 16 : 10; -+ unsigned base = ((c == 'x') || (c == 'X')) ? 16 : 10; - char *p; - - if ((long long) n < 0 && c == 'd') -@@ -603,7 +603,7 @@ grub_lltoa (char *str, int c, unsigned long long n) - do - { - unsigned d = (unsigned) (n & 0xf); -- *p++ = (d > 9) ? d + 'a' - 10 : d + '0'; -+ *p++ = (d > 9) ? d + ((c == 'x') ? 'a' : 'A') - 10 : d + '0'; - } - while (n >>= 4); - else -@@ -676,6 +676,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args, - { - case 'p': - case 'x': -+ case 'X': - case 'u': - case 'd': - case 'c': -@@ -762,6 +763,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args, - switch (c) - { - case 'x': -+ case 'X': - case 'u': - args->ptr[curn].type = UNSIGNED_INT + longfmt; - break; -@@ -900,6 +902,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0, - c = 'x'; - /* Fall through. */ - case 'x': -+ case 'X': - case 'u': - case 'd': - { --- -1.8.3.1 - diff --git a/0045-Don-t-require-a-password-to-boot-entries-generated-b.patch b/0026-Don-t-require-a-password-to-boot-entries-generated-b.patch similarity index 80% rename from 0045-Don-t-require-a-password-to-boot-entries-generated-b.patch rename to 0026-Don-t-require-a-password-to-boot-entries-generated-b.patch index 85e461b9185fb45aec6c851d3294ce5c09eb1927..ac9475e3f469b43cd7826c1f55b19439b87067f2 100644 --- a/0045-Don-t-require-a-password-to-boot-entries-generated-b.patch +++ b/0026-Don-t-require-a-password-to-boot-entries-generated-b.patch @@ -1,7 +1,7 @@ -From 226cdd8a7722f5e1a60f21c5a2aea74f458d612d Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 11 Feb 2014 11:14:50 -0500 -Subject: [PATCH 045/220] Don't require a password to boot entries generated by +Subject: [PATCH] Don't require a password to boot entries generated by grub-mkconfig. When we set a password, we just want that to mean you can't /edit/ an entry. @@ -14,7 +14,7 @@ Signed-off-by: Peter Jones 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 2b402d8..d35b0f4 100644 +index 4a499c53a61..cf8d1186981 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -26,7 +26,7 @@ datarootdir="@datarootdir@" @@ -26,6 +26,3 @@ index 2b402d8..d35b0f4 100644 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then OS="$(sed 's, release .*$,,g' /etc/system-release)" --- -1.8.3.1 - diff --git a/0026-Search-for-specific-config-file-for-netboot.patch b/0026-Search-for-specific-config-file-for-netboot.patch deleted file mode 100644 index 98263fb51655c3d3c124638683052b76e6804949..0000000000000000000000000000000000000000 --- a/0026-Search-for-specific-config-file-for-netboot.patch +++ /dev/null @@ -1,203 +0,0 @@ -From 0b390eb5dbd310c6c1a92e001b35981c90f27565 Mon Sep 17 00:00:00 2001 -From: Paulo Flabiano Smorigo -Date: Tue, 27 Nov 2012 17:22:07 -0200 -Subject: [PATCH 026/220] Search for specific config file for netboot - -This patch implements a search for a specific configuration when the config -file is on a remoteserver. It uses the following order: - 1) DHCP client UUID option. - 2) MAC address (in lower case hexadecimal with dash separators); - 3) IP (in upper case hexadecimal) or IPv6; - 4) The original grub.cfg file. - -This procedure is similar to what is used by pxelinux and yaboot: -http://www.syslinux.org/wiki/index.php/PXELINUX#config - -This should close the bugzilla: -https://bugzilla.redhat.com/show_bug.cgi?id=873406 ---- - grub-core/net/net.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++ - grub-core/normal/main.c | 18 ++++++-- - include/grub/net.h | 3 ++ - 3 files changed, 135 insertions(+), 4 deletions(-) - -diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index d5d726a..0645456 100644 ---- a/grub-core/net/net.c -+++ b/grub-core/net/net.c -@@ -1735,6 +1735,124 @@ grub_net_restore_hw (void) - return GRUB_ERR_NONE; - } - -+grub_err_t -+grub_net_search_configfile (char *config) -+{ -+ grub_size_t config_len; -+ char *suffix; -+ -+ auto int search_through (grub_size_t num_tries, grub_size_t slice_size); -+ int search_through (grub_size_t num_tries, grub_size_t slice_size) -+ { -+ while (num_tries-- > 0) -+ { -+ grub_dprintf ("net", "probe %s\n", config); -+ -+ grub_file_t file; -+ file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); -+ -+ if (file) -+ { -+ grub_file_close (file); -+ grub_dprintf ("net", "found!\n"); -+ return 0; -+ } -+ else -+ { -+ if (grub_errno == GRUB_ERR_IO) -+ grub_errno = GRUB_ERR_NONE; -+ } -+ -+ if (grub_strlen (suffix) < slice_size) -+ break; -+ -+ config[grub_strlen (config) - slice_size] = '\0'; -+ } -+ -+ return 1; -+ } -+ -+ config_len = grub_strlen (config); -+ config[config_len] = '-'; -+ suffix = config + config_len + 1; -+ -+ struct grub_net_network_level_interface *inf; -+ FOR_NET_NETWORK_LEVEL_INTERFACES (inf) -+ { -+ /* By the Client UUID. */ -+ -+ char client_uuid_var[sizeof ("net_") + grub_strlen (inf->name) + -+ sizeof ("_clientuuid") + 1]; -+ grub_snprintf (client_uuid_var, sizeof (client_uuid_var), -+ "net_%s_clientuuid", inf->name); -+ -+ const char *client_uuid; -+ client_uuid = grub_env_get (client_uuid_var); -+ -+ if (client_uuid) -+ { -+ grub_strcpy (suffix, client_uuid); -+ if (search_through (1, 0) == 0) return GRUB_ERR_NONE; -+ } -+ -+ /* By the MAC address. */ -+ -+ /* Add ethernet type */ -+ grub_strcpy (suffix, "01-"); -+ -+ grub_net_hwaddr_to_str (&inf->hwaddress, suffix + 3); -+ -+ char *ptr; -+ for (ptr = suffix; *ptr; ptr++) -+ if (*ptr == ':') -+ *ptr = '-'; -+ -+ if (search_through (1, 0) == 0) return GRUB_ERR_NONE; -+ -+ /* By IP address */ -+ -+ switch ((&inf->address)->type) -+ { -+ case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: -+ { -+ grub_uint32_t n = grub_be_to_cpu32 ((&inf->address)->ipv4); -+ grub_snprintf (suffix, GRUB_NET_MAX_STR_ADDR_LEN, "%02X%02X%02X%02X", \ -+ ((n >> 24) & 0xff), ((n >> 16) & 0xff), \ -+ ((n >> 8) & 0xff), ((n >> 0) & 0xff)); -+ -+ if (search_through (8, 1) == 0) return GRUB_ERR_NONE; -+ break; -+ } -+ case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6: -+ { -+ char buf[GRUB_NET_MAX_STR_ADDR_LEN]; -+ struct grub_net_network_level_address base; -+ base.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; -+ grub_memcpy (&base.ipv6, ((&inf->address)->ipv6), 16); -+ grub_net_addr_to_str (&base, buf); -+ -+ for (ptr = buf; *ptr; ptr++) -+ if (*ptr == ':') -+ *ptr = '-'; -+ -+ grub_snprintf (suffix, GRUB_NET_MAX_STR_ADDR_LEN, "%s", buf); -+ if (search_through (1, 0) == 0) return GRUB_ERR_NONE; -+ break; -+ } -+ case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV: -+ return grub_error (GRUB_ERR_BUG, "shouldn't reach here"); -+ default: -+ return grub_error (GRUB_ERR_BUG, -+ "unsupported address type %d", (&inf->address)->type); -+ } -+ } -+ -+ /* Remove the remaining minus sign at the end. */ -+ config[config_len] = '\0'; -+ -+ return GRUB_ERR_NONE; -+} -+ - static struct grub_preboot *fini_hnd; - - static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; -diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index 394bfbe..9ef9848 100644 ---- a/grub-core/normal/main.c -+++ b/grub-core/normal/main.c -@@ -33,6 +33,7 @@ - #include - #include - #include -+#include - #ifdef GRUB_MACHINE_IEEE1275 - #include - #endif -@@ -365,10 +366,19 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), - - prefix = grub_env_get ("prefix"); - if (prefix) -- { -- config = grub_xasprintf ("%s/grub.cfg", prefix); -- if (! config) -- goto quit; -+ { -+ grub_size_t config_len; -+ config_len = grub_strlen (prefix) + -+ sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); -+ config = grub_malloc (config_len); -+ -+ if (! config) -+ goto quit; -+ -+ grub_snprintf (config, config_len, "%s/grub.cfg", prefix); -+ -+ if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0) -+ grub_net_search_configfile (config); - - grub_enter_normal_mode (config); - grub_free (config); -diff --git a/include/grub/net.h b/include/grub/net.h -index 556c54e..ff6d347 100644 ---- a/include/grub/net.h -+++ b/include/grub/net.h -@@ -578,4 +578,7 @@ extern char *grub_net_default_server; - - #define VLANTAG_IDENTIFIER 0x8100 - -+grub_err_t -+grub_net_search_configfile (char *config); -+ - #endif /* ! GRUB_NET_HEADER */ --- -1.8.3.1 - diff --git a/0047-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch b/0027-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch similarity index 95% rename from 0047-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch rename to 0027-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch index 774428bd1b40ba88f7049c7c2484a3488fef2ba6..daa6fae0742d89d1f4cd3c58f0b9c4a80dad388c 100644 --- a/0047-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch +++ b/0027-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch @@ -1,12 +1,12 @@ -From 4e27eb84b310a600b89481245735a7b053f2250c Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 4 Mar 2014 11:00:23 -0500 -Subject: [PATCH 047/220] Replace a lot of man pages with slightly nicer ones. +Subject: [PATCH] Replace a lot of man pages with slightly nicer ones. Replace a bunch of machine generated ones with ones that look nicer. --- - conf/Makefile.extra-dist | 1 - configure.ac | 23 ++++++ + conf/Makefile.extra-dist | 1 - docs/Makefile.am | 2 - docs/man/grub-bios-setup.h2m | 6 -- docs/man/grub-editenv.h2m | 5 -- @@ -44,7 +44,7 @@ Replace a bunch of machine generated ones with ones that look nicer. util/grub-file.1 | 165 ++++++++++++++++++++++++++++++++++++++ util/grub-fstest.1 | 99 +++++++++++++++++++++++ util/grub-glue-efi.1 | 31 +++++++ - util/grub-install.8 | 129 +++++++++++++++++++++++++++++ + util/grub-install.8 | 128 +++++++++++++++++++++++++++++ util/grub-kbdcomp.1 | 19 +++++ util/grub-macbless.1 | 22 +++++ util/grub-menulst2cfg.1 | 12 +++ @@ -64,7 +64,7 @@ Replace a bunch of machine generated ones with ones that look nicer. util/grub-script-check.1 | 21 +++++ util/grub-set-default.8 | 21 +++++ util/grub-sparc64-setup.8 | 12 +++ - 59 files changed, 1319 insertions(+), 147 deletions(-) + 59 files changed, 1318 insertions(+), 147 deletions(-) delete mode 100644 docs/man/grub-bios-setup.h2m delete mode 100644 docs/man/grub-editenv.h2m delete mode 100644 docs/man/grub-emu.h2m @@ -121,23 +121,11 @@ Replace a bunch of machine generated ones with ones that look nicer. create mode 100644 util/grub-set-default.8 create mode 100644 util/grub-sparc64-setup.8 -diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist -index 46c4e95..58d7d95 100644 ---- a/conf/Makefile.extra-dist -+++ b/conf/Makefile.extra-dist -@@ -11,7 +11,6 @@ EXTRA_DIST += unicode - EXTRA_DIST += util/import_gcry.py - EXTRA_DIST += util/import_unicode.py - --EXTRA_DIST += docs/man - EXTRA_DIST += docs/autoiso.cfg - EXTRA_DIST += docs/grub.cfg - EXTRA_DIST += docs/osdetect.cfg diff --git a/configure.ac b/configure.ac -index d283af6..8df400e 100644 +index 8331f95b645..bec8535af70 100644 --- a/configure.ac +++ b/configure.ac -@@ -74,6 +74,29 @@ grub_TRANSFORM([grub-set-default]) +@@ -77,6 +77,29 @@ grub_TRANSFORM([grub-set-default]) grub_TRANSFORM([grub-sparc64-setup]) grub_TRANSFORM([grub-render-label]) grub_TRANSFORM([grub-file]) @@ -167,8 +155,20 @@ index d283af6..8df400e 100644 # Optimization flag. Allow user to override. if test "x$TARGET_CFLAGS" = x; then +diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist +index 8f1485d52a5..b909f2c073a 100644 +--- a/conf/Makefile.extra-dist ++++ b/conf/Makefile.extra-dist +@@ -11,7 +11,6 @@ EXTRA_DIST += unicode + EXTRA_DIST += util/import_gcry.py + EXTRA_DIST += util/import_unicode.py + +-EXTRA_DIST += docs/man + EXTRA_DIST += docs/autoiso.cfg + EXTRA_DIST += docs/grub.cfg + EXTRA_DIST += docs/osdetect.cfg diff --git a/docs/Makefile.am b/docs/Makefile.am -index 93eb396..ab28f19 100644 +index 93eb3962765..ab28f199694 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -5,5 +5,3 @@ info_TEXINFOS = grub.texi grub-dev.texi @@ -179,7 +179,7 @@ index 93eb396..ab28f19 100644 - diff --git a/docs/man/grub-bios-setup.h2m b/docs/man/grub-bios-setup.h2m deleted file mode 100644 -index ac6ede3..0000000 +index ac6ede36296..00000000000 --- a/docs/man/grub-bios-setup.h2m +++ /dev/null @@ -1,6 +0,0 @@ @@ -191,7 +191,7 @@ index ac6ede3..0000000 -.BR grub-mkrescue (1) diff --git a/docs/man/grub-editenv.h2m b/docs/man/grub-editenv.h2m deleted file mode 100644 -index 3859d3d..0000000 +index 3859d3d4c4f..00000000000 --- a/docs/man/grub-editenv.h2m +++ /dev/null @@ -1,5 +0,0 @@ @@ -202,7 +202,7 @@ index 3859d3d..0000000 -.BR grub-set-default (8) diff --git a/docs/man/grub-emu.h2m b/docs/man/grub-emu.h2m deleted file mode 100644 -index ef1c000..0000000 +index ef1c000656a..00000000000 --- a/docs/man/grub-emu.h2m +++ /dev/null @@ -1,6 +0,0 @@ @@ -214,7 +214,7 @@ index ef1c000..0000000 -rather than this program. diff --git a/docs/man/grub-file.h2m b/docs/man/grub-file.h2m deleted file mode 100644 -index e09bb4d..0000000 +index e09bb4d3101..00000000000 --- a/docs/man/grub-file.h2m +++ /dev/null @@ -1,2 +0,0 @@ @@ -222,7 +222,7 @@ index e09bb4d..0000000 -grub-file \- check file type diff --git a/docs/man/grub-fstest.h2m b/docs/man/grub-fstest.h2m deleted file mode 100644 -index 9676b15..0000000 +index 9676b159afd..00000000000 --- a/docs/man/grub-fstest.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -232,7 +232,7 @@ index 9676b15..0000000 -.BR grub-probe (8) diff --git a/docs/man/grub-glue-efi.h2m b/docs/man/grub-glue-efi.h2m deleted file mode 100644 -index c1c6ded..0000000 +index c1c6ded49ff..00000000000 --- a/docs/man/grub-glue-efi.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -242,7 +242,7 @@ index c1c6ded..0000000 -grub-glue-efi processes ia32 and amd64 EFI images and glues them according to Apple format. diff --git a/docs/man/grub-install.h2m b/docs/man/grub-install.h2m deleted file mode 100644 -index 8cbbc87..0000000 +index 8cbbc87a0f2..00000000000 --- a/docs/man/grub-install.h2m +++ /dev/null @@ -1,6 +0,0 @@ @@ -254,7 +254,7 @@ index 8cbbc87..0000000 -.BR grub-mkrescue (1) diff --git a/docs/man/grub-kbdcomp.h2m b/docs/man/grub-kbdcomp.h2m deleted file mode 100644 -index d81f915..0000000 +index d81f9157e01..00000000000 --- a/docs/man/grub-kbdcomp.h2m +++ /dev/null @@ -1,10 +0,0 @@ @@ -270,7 +270,7 @@ index d81f915..0000000 -.BR grub-mklayout (8) diff --git a/docs/man/grub-macbless.h2m b/docs/man/grub-macbless.h2m deleted file mode 100644 -index 0197c00..0000000 +index 0197c0087d7..00000000000 --- a/docs/man/grub-macbless.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -280,7 +280,7 @@ index 0197c00..0000000 -.BR grub-install (1) diff --git a/docs/man/grub-macho2img.h2m b/docs/man/grub-macho2img.h2m deleted file mode 100644 -index d79aaee..0000000 +index d79aaeed8f9..00000000000 --- a/docs/man/grub-macho2img.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -290,7 +290,7 @@ index d79aaee..0000000 -.BR grub-mkimage (1) diff --git a/docs/man/grub-menulst2cfg.h2m b/docs/man/grub-menulst2cfg.h2m deleted file mode 100644 -index c2e0055..0000000 +index c2e0055ed7e..00000000000 --- a/docs/man/grub-menulst2cfg.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -300,7 +300,7 @@ index c2e0055..0000000 -.BR grub-mkconfig (8) diff --git a/docs/man/grub-mkconfig.h2m b/docs/man/grub-mkconfig.h2m deleted file mode 100644 -index 9b42f81..0000000 +index 9b42f813010..00000000000 --- a/docs/man/grub-mkconfig.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -310,7 +310,7 @@ index 9b42f81..0000000 -.BR grub-install (8) diff --git a/docs/man/grub-mkfont.h2m b/docs/man/grub-mkfont.h2m deleted file mode 100644 -index d46fe60..0000000 +index d46fe600eca..00000000000 --- a/docs/man/grub-mkfont.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -320,7 +320,7 @@ index d46fe60..0000000 -.BR grub-mkconfig (8) diff --git a/docs/man/grub-mkimage.h2m b/docs/man/grub-mkimage.h2m deleted file mode 100644 -index f0fbc2b..0000000 +index f0fbc2bb197..00000000000 --- a/docs/man/grub-mkimage.h2m +++ /dev/null @@ -1,6 +0,0 @@ @@ -332,7 +332,7 @@ index f0fbc2b..0000000 -.BR grub-mknetdir (8) diff --git a/docs/man/grub-mklayout.h2m b/docs/man/grub-mklayout.h2m deleted file mode 100644 -index 1e43409..0000000 +index 1e43409c0ab..00000000000 --- a/docs/man/grub-mklayout.h2m +++ /dev/null @@ -1,10 +0,0 @@ @@ -348,7 +348,7 @@ index 1e43409..0000000 -.BR grub-mkconfig (8) diff --git a/docs/man/grub-mknetdir.h2m b/docs/man/grub-mknetdir.h2m deleted file mode 100644 -index a2ef13e..0000000 +index a2ef13ec111..00000000000 --- a/docs/man/grub-mknetdir.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -358,7 +358,7 @@ index a2ef13e..0000000 -.BR grub-mkimage (1) diff --git a/docs/man/grub-mkpasswd-pbkdf2.h2m b/docs/man/grub-mkpasswd-pbkdf2.h2m deleted file mode 100644 -index 4d202f3..0000000 +index 4d202f3da7e..00000000000 --- a/docs/man/grub-mkpasswd-pbkdf2.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -368,7 +368,7 @@ index 4d202f3..0000000 -.BR grub-mkconfig (8) diff --git a/docs/man/grub-mkrelpath.h2m b/docs/man/grub-mkrelpath.h2m deleted file mode 100644 -index d01f396..0000000 +index d01f3961e3f..00000000000 --- a/docs/man/grub-mkrelpath.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -378,7 +378,7 @@ index d01f396..0000000 -.BR grub-probe (8) diff --git a/docs/man/grub-mkrescue.h2m b/docs/man/grub-mkrescue.h2m deleted file mode 100644 -index a427f02..0000000 +index a427f02e3c6..00000000000 --- a/docs/man/grub-mkrescue.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -388,7 +388,7 @@ index a427f02..0000000 -.BR grub-mkimage (1) diff --git a/docs/man/grub-mkstandalone.h2m b/docs/man/grub-mkstandalone.h2m deleted file mode 100644 -index c773139..0000000 +index c77313978ad..00000000000 --- a/docs/man/grub-mkstandalone.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -398,7 +398,7 @@ index c773139..0000000 -.BR grub-mkimage (1) diff --git a/docs/man/grub-mount.h2m b/docs/man/grub-mount.h2m deleted file mode 100644 -index 8d16898..0000000 +index 8d168982d72..00000000000 --- a/docs/man/grub-mount.h2m +++ /dev/null @@ -1,2 +0,0 @@ @@ -406,7 +406,7 @@ index 8d16898..0000000 -grub-mount \- export GRUB filesystem with FUSE diff --git a/docs/man/grub-ofpathname.h2m b/docs/man/grub-ofpathname.h2m deleted file mode 100644 -index 74b43ee..0000000 +index 74b43eea039..00000000000 --- a/docs/man/grub-ofpathname.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -416,7 +416,7 @@ index 74b43ee..0000000 -.BR grub-probe (8) diff --git a/docs/man/grub-pe2elf.h2m b/docs/man/grub-pe2elf.h2m deleted file mode 100644 -index 7ca29bd..0000000 +index 7ca29bd703c..00000000000 --- a/docs/man/grub-pe2elf.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -426,7 +426,7 @@ index 7ca29bd..0000000 -.BR grub-mkimage (1) diff --git a/docs/man/grub-probe.h2m b/docs/man/grub-probe.h2m deleted file mode 100644 -index 6e1ffdc..0000000 +index 6e1ffdcf937..00000000000 --- a/docs/man/grub-probe.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -436,7 +436,7 @@ index 6e1ffdc..0000000 -.BR grub-fstest (1) diff --git a/docs/man/grub-reboot.h2m b/docs/man/grub-reboot.h2m deleted file mode 100644 -index e4acace..0000000 +index e4acace65ce..00000000000 --- a/docs/man/grub-reboot.h2m +++ /dev/null @@ -1,5 +0,0 @@ @@ -447,7 +447,7 @@ index e4acace..0000000 -.BR grub-editenv (1) diff --git a/docs/man/grub-render-label.h2m b/docs/man/grub-render-label.h2m deleted file mode 100644 -index 50ae524..0000000 +index 50ae5247c05..00000000000 --- a/docs/man/grub-render-label.h2m +++ /dev/null @@ -1,3 +0,0 @@ @@ -456,7 +456,7 @@ index 50ae524..0000000 - diff --git a/docs/man/grub-script-check.h2m b/docs/man/grub-script-check.h2m deleted file mode 100644 -index 3653682..0000000 +index 3653682671a..00000000000 --- a/docs/man/grub-script-check.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -466,7 +466,7 @@ index 3653682..0000000 -.BR grub-mkconfig (8) diff --git a/docs/man/grub-set-default.h2m b/docs/man/grub-set-default.h2m deleted file mode 100644 -index 7945001..0000000 +index 7945001c154..00000000000 --- a/docs/man/grub-set-default.h2m +++ /dev/null @@ -1,5 +0,0 @@ @@ -477,7 +477,7 @@ index 7945001..0000000 -.BR grub-editenv (1) diff --git a/docs/man/grub-sparc64-setup.h2m b/docs/man/grub-sparc64-setup.h2m deleted file mode 100644 -index 18f803a..0000000 +index 18f803a50db..00000000000 --- a/docs/man/grub-sparc64-setup.h2m +++ /dev/null @@ -1,6 +0,0 @@ @@ -489,7 +489,7 @@ index 18f803a..0000000 -.BR grub-mkrescue (1) diff --git a/docs/man/grub-syslinux2cfg.h2m b/docs/man/grub-syslinux2cfg.h2m deleted file mode 100644 -index ad25c8a..0000000 +index ad25c8ab753..00000000000 --- a/docs/man/grub-syslinux2cfg.h2m +++ /dev/null @@ -1,4 +0,0 @@ @@ -498,7 +498,7 @@ index ad25c8a..0000000 -[SEE ALSO] -.BR grub-menulst2cfg (8) diff --git a/gentpl.py b/gentpl.py -index 387588c..f05812e 100644 +index c86550d4f9e..2cba0bbbd6f 100644 --- a/gentpl.py +++ b/gentpl.py @@ -805,10 +805,7 @@ def manpage(defn, adddeps): @@ -515,7 +515,7 @@ index 387588c..f05812e 100644 diff --git a/util/grub-bios-setup.8 b/util/grub-bios-setup.8 new file mode 100644 -index 0000000..56f582b +index 00000000000..56f582b3d75 --- /dev/null +++ b/util/grub-bios-setup.8 @@ -0,0 +1,54 @@ @@ -575,7 +575,7 @@ index 0000000..56f582b +.BR "info grub" diff --git a/util/grub-editenv.1 b/util/grub-editenv.1 new file mode 100644 -index 0000000..d28ba03 +index 00000000000..d28ba03ba42 --- /dev/null +++ b/util/grub-editenv.1 @@ -0,0 +1,46 @@ @@ -627,7 +627,7 @@ index 0000000..d28ba03 +.BR "info grub" diff --git a/util/grub-file.1 b/util/grub-file.1 new file mode 100644 -index 0000000..b29cb32 +index 00000000000..b29cb327889 --- /dev/null +++ b/util/grub-file.1 @@ -0,0 +1,165 @@ @@ -798,7 +798,7 @@ index 0000000..b29cb32 +.BR "info grub" diff --git a/util/grub-fstest.1 b/util/grub-fstest.1 new file mode 100644 -index 0000000..792fa78 +index 00000000000..792fa78634c --- /dev/null +++ b/util/grub-fstest.1 @@ -0,0 +1,99 @@ @@ -903,7 +903,7 @@ index 0000000..792fa78 +.BR "info grub" diff --git a/util/grub-glue-efi.1 b/util/grub-glue-efi.1 new file mode 100644 -index 0000000..72bd555 +index 00000000000..72bd555d577 --- /dev/null +++ b/util/grub-glue-efi.1 @@ -0,0 +1,31 @@ @@ -940,10 +940,10 @@ index 0000000..72bd555 +.BR "info grub" diff --git a/util/grub-install.8 b/util/grub-install.8 new file mode 100644 -index 0000000..76272a3 +index 00000000000..1db89e94b3b --- /dev/null +++ b/util/grub-install.8 -@@ -0,0 +1,129 @@ +@@ -0,0 +1,128 @@ +.TH GRUB-INSTALL 1 "Wed Feb 26 2014" +.SH NAME +\fBgrub-install\fR \(em Install GRUB on a device. @@ -1060,12 +1060,11 @@ index 0000000..76272a3 + +.TP +\fB--bootloader-id\fR=\fIID\fR -+Use \fIID\fR as the bootloader ID. This opption is only available on the EFI target platform. ++Use \fIID\fR as the bootloader ID. This option is only available on the EFI target platform. + +.TP +\fB--efi-directory\fR=\fIDIR\fR -+Use \fIDIR\fR as the EFI System Partition root. This opption is only available on the EFI ta -+rget platform. ++Use \fIDIR\fR as the EFI System Partition root. This option is only available on the EFI target platform. + +.TP +\fIINSTALL_DEVICE\fR @@ -1075,7 +1074,7 @@ index 0000000..76272a3 +.BR "info grub" diff --git a/util/grub-kbdcomp.1 b/util/grub-kbdcomp.1 new file mode 100644 -index 0000000..0bb969a +index 00000000000..0bb969a5b43 --- /dev/null +++ b/util/grub-kbdcomp.1 @@ -0,0 +1,19 @@ @@ -1100,7 +1099,7 @@ index 0000000..0bb969a +.BR "info grub" diff --git a/util/grub-macbless.1 b/util/grub-macbless.1 new file mode 100644 -index 0000000..41a9618 +index 00000000000..41a96186f70 --- /dev/null +++ b/util/grub-macbless.1 @@ -0,0 +1,22 @@ @@ -1128,7 +1127,7 @@ index 0000000..41a9618 +.BR "info grub" diff --git a/util/grub-menulst2cfg.1 b/util/grub-menulst2cfg.1 new file mode 100644 -index 0000000..91e2ef8 +index 00000000000..91e2ef87113 --- /dev/null +++ b/util/grub-menulst2cfg.1 @@ -0,0 +1,12 @@ @@ -1146,7 +1145,7 @@ index 0000000..91e2ef8 +.BR "info grub" diff --git a/util/grub-mkconfig.8 b/util/grub-mkconfig.8 new file mode 100644 -index 0000000..a2d1f57 +index 00000000000..a2d1f577b9b --- /dev/null +++ b/util/grub-mkconfig.8 @@ -0,0 +1,17 @@ @@ -1169,7 +1168,7 @@ index 0000000..a2d1f57 +.BR "info grub" diff --git a/util/grub-mkfont.1 b/util/grub-mkfont.1 new file mode 100644 -index 0000000..3494857 +index 00000000000..3494857987d --- /dev/null +++ b/util/grub-mkfont.1 @@ -0,0 +1,87 @@ @@ -1262,7 +1261,7 @@ index 0000000..3494857 +.BR "info grub" diff --git a/util/grub-mkimage.1 b/util/grub-mkimage.1 new file mode 100644 -index 0000000..4dea4f5 +index 00000000000..4dea4f54597 --- /dev/null +++ b/util/grub-mkimage.1 @@ -0,0 +1,95 @@ @@ -1363,7 +1362,7 @@ index 0000000..4dea4f5 +.BR "info grub" diff --git a/util/grub-mklayout.1 b/util/grub-mklayout.1 new file mode 100644 -index 0000000..d1bbc2e +index 00000000000..d1bbc2ec515 --- /dev/null +++ b/util/grub-mklayout.1 @@ -0,0 +1,27 @@ @@ -1396,7 +1395,7 @@ index 0000000..d1bbc2e +.BR "info grub" diff --git a/util/grub-mknetdir.1 b/util/grub-mknetdir.1 new file mode 100644 -index 0000000..fa7e8d4 +index 00000000000..fa7e8d4ef0d --- /dev/null +++ b/util/grub-mknetdir.1 @@ -0,0 +1,12 @@ @@ -1414,7 +1413,7 @@ index 0000000..fa7e8d4 +.BR "info grub" diff --git a/util/grub-mkpasswd-pbkdf2.1 b/util/grub-mkpasswd-pbkdf2.1 new file mode 100644 -index 0000000..73c437c +index 00000000000..73c437c15d8 --- /dev/null +++ b/util/grub-mkpasswd-pbkdf2.1 @@ -0,0 +1,27 @@ @@ -1447,7 +1446,7 @@ index 0000000..73c437c +.BR "info grub" diff --git a/util/grub-mkrelpath.1 b/util/grub-mkrelpath.1 new file mode 100644 -index 0000000..85f1113 +index 00000000000..85f1113621d --- /dev/null +++ b/util/grub-mkrelpath.1 @@ -0,0 +1,12 @@ @@ -1465,7 +1464,7 @@ index 0000000..85f1113 +.BR "info grub" diff --git a/util/grub-mkrescue.1 b/util/grub-mkrescue.1 new file mode 100644 -index 0000000..4ed9fc7 +index 00000000000..4ed9fc723fd --- /dev/null +++ b/util/grub-mkrescue.1 @@ -0,0 +1,123 @@ @@ -1594,7 +1593,7 @@ index 0000000..4ed9fc7 +.BR "info grub" diff --git a/util/grub-mkstandalone.1 b/util/grub-mkstandalone.1 new file mode 100644 -index 0000000..ba2d2bd +index 00000000000..ba2d2bdf279 --- /dev/null +++ b/util/grub-mkstandalone.1 @@ -0,0 +1,100 @@ @@ -1700,7 +1699,7 @@ index 0000000..ba2d2bd +.BR "info grub" diff --git a/util/grub-ofpathname.8 b/util/grub-ofpathname.8 new file mode 100644 -index 0000000..bf3743a +index 00000000000..bf3743aeba1 --- /dev/null +++ b/util/grub-ofpathname.8 @@ -0,0 +1,12 @@ @@ -1718,7 +1717,7 @@ index 0000000..bf3743a +.BR "info grub" diff --git a/util/grub-probe.8 b/util/grub-probe.8 new file mode 100644 -index 0000000..04e26c8 +index 00000000000..04e26c832bb --- /dev/null +++ b/util/grub-probe.8 @@ -0,0 +1,80 @@ @@ -1804,7 +1803,7 @@ index 0000000..04e26c8 +.BR "info grub" diff --git a/util/grub-reboot.8 b/util/grub-reboot.8 new file mode 100644 -index 0000000..faa5e4e +index 00000000000..faa5e4eece2 --- /dev/null +++ b/util/grub-reboot.8 @@ -0,0 +1,21 @@ @@ -1831,7 +1830,7 @@ index 0000000..faa5e4e +.BR "info grub" diff --git a/util/grub-render-label.1 b/util/grub-render-label.1 new file mode 100644 -index 0000000..4d51c8a +index 00000000000..4d51c8abf01 --- /dev/null +++ b/util/grub-render-label.1 @@ -0,0 +1,51 @@ @@ -1888,7 +1887,7 @@ index 0000000..4d51c8a +.BR "info grub" diff --git a/util/grub-script-check.1 b/util/grub-script-check.1 new file mode 100644 -index 0000000..0f1f625 +index 00000000000..0f1f625b05d --- /dev/null +++ b/util/grub-script-check.1 @@ -0,0 +1,21 @@ @@ -1915,7 +1914,7 @@ index 0000000..0f1f625 +.BR "info grub" diff --git a/util/grub-set-default.8 b/util/grub-set-default.8 new file mode 100644 -index 0000000..a96265a +index 00000000000..a96265a1509 --- /dev/null +++ b/util/grub-set-default.8 @@ -0,0 +1,21 @@ @@ -1942,7 +1941,7 @@ index 0000000..a96265a +.BR "info grub" diff --git a/util/grub-sparc64-setup.8 b/util/grub-sparc64-setup.8 new file mode 100644 -index 0000000..37ea2dd +index 00000000000..37ea2dd5eaa --- /dev/null +++ b/util/grub-sparc64-setup.8 @@ -0,0 +1,12 @@ @@ -1958,6 +1957,3 @@ index 0000000..37ea2dd + +.SH SEE ALSO +.BR "info grub" --- -1.8.3.1 - diff --git a/0048-use-fw_path-prefix-when-fallback-searching-for-grub-.patch b/0028-use-fw_path-prefix-when-fallback-searching-for-grub-.patch similarity index 80% rename from 0048-use-fw_path-prefix-when-fallback-searching-for-grub-.patch rename to 0028-use-fw_path-prefix-when-fallback-searching-for-grub-.patch index 5928cfb9461d9f8f14e6882f5b9a90317574f7dd..6b1580bb49c690b1ffa4aad1f94e3b1bc180bbed 100644 --- a/0048-use-fw_path-prefix-when-fallback-searching-for-grub-.patch +++ b/0028-use-fw_path-prefix-when-fallback-searching-for-grub-.patch @@ -1,8 +1,7 @@ -From 612e9b3820efe48896ba9faf320e4f042d053dc2 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Fedora Ninjas Date: Wed, 19 Feb 2014 15:58:43 -0500 -Subject: [PATCH 048/220] use fw_path prefix when fallback searching for grub - config +Subject: [PATCH] use fw_path prefix when fallback searching for grub config When PXE booting via UEFI firmware, grub was searching for grub.cfg in the fw_path directory where the grub application was found. If @@ -18,10 +17,10 @@ Signed-off-by: Mark Salter 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index 7f61c5b..8add30e 100644 +index 7ca2e5400b1..02577502116 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c -@@ -349,7 +349,7 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), +@@ -347,7 +347,7 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), char *config; const char *prefix, *fw_path; @@ -30,7 +29,7 @@ index 7f61c5b..8add30e 100644 if (fw_path) { config = grub_xasprintf ("%s/grub.cfg", fw_path); -@@ -372,7 +372,8 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), +@@ -370,7 +370,8 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), } } @@ -40,6 +39,3 @@ index 7f61c5b..8add30e 100644 if (prefix) { grub_size_t config_len; --- -1.8.3.1 - diff --git a/0029-Don-t-write-messages-to-the-screen.patch b/0029-Don-t-write-messages-to-the-screen.patch deleted file mode 100644 index 61673d8a5adde6970c48b69682ddf8fe30f63307..0000000000000000000000000000000000000000 --- a/0029-Don-t-write-messages-to-the-screen.patch +++ /dev/null @@ -1,179 +0,0 @@ -From 88cba3a10617ef55989762a4195599a399dca957 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Wed, 15 May 2013 13:30:20 -0400 -Subject: [PATCH 029/220] Don't write messages to the screen - -Writing messages to the screen before the menus or boot splash -happens so quickly it looks like something is wrong and isn't -very appealing. ---- - grub-core/boot/i386/pc/boot.S | 3 --- - grub-core/boot/i386/pc/diskboot.S | 5 ----- - grub-core/gettext/gettext.c | 25 +++++-------------------- - grub-core/kern/main.c | 5 ----- - util/grub.d/10_linux.in | 7 ------- - 5 files changed, 5 insertions(+), 40 deletions(-) - -diff --git a/grub-core/boot/i386/pc/boot.S b/grub-core/boot/i386/pc/boot.S -index 2bd0b2d..ea167fe 100644 ---- a/grub-core/boot/i386/pc/boot.S -+++ b/grub-core/boot/i386/pc/boot.S -@@ -249,9 +249,6 @@ real_start: - /* save drive reference first thing! */ - pushw %dx - -- /* print a notification message on the screen */ -- MSG(notification_string) -- - /* set %si to the disk address packet */ - movw $disk_address_packet, %si - -diff --git a/grub-core/boot/i386/pc/diskboot.S b/grub-core/boot/i386/pc/diskboot.S -index c1addc0..68d31de 100644 ---- a/grub-core/boot/i386/pc/diskboot.S -+++ b/grub-core/boot/i386/pc/diskboot.S -@@ -50,11 +50,6 @@ _start: - /* save drive reference first thing! */ - pushw %dx - -- /* print a notification message on the screen */ -- pushw %si -- MSG(notification_string) -- popw %si -- - /* this sets up for the first run through "bootloop" */ - movw $LOCAL(firstlist), %di - -diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c -index 4d02e62..84d520c 100644 ---- a/grub-core/gettext/gettext.c -+++ b/grub-core/gettext/gettext.c -@@ -434,16 +434,12 @@ static char * - grub_gettext_env_write_lang (struct grub_env_var *var - __attribute__ ((unused)), const char *val) - { -- grub_err_t err; -+ grub_err_t __attribute__((__unused__)) err; - err = grub_gettext_init_ext (&main_context, val, grub_env_get ("locale_dir"), - grub_env_get ("prefix")); -- if (err) -- grub_print_error (); - - err = grub_gettext_init_ext (&secondary_context, val, - grub_env_get ("secondary_locale_dir"), 0); -- if (err) -- grub_print_error (); - - return grub_strdup (val); - } -@@ -451,23 +447,19 @@ grub_gettext_env_write_lang (struct grub_env_var *var - void - grub_gettext_reread_prefix (const char *val) - { -- grub_err_t err; -+ grub_err_t __attribute__((__unused__)) err; - err = grub_gettext_init_ext (&main_context, grub_env_get ("lang"), - grub_env_get ("locale_dir"), - val); -- if (err) -- grub_print_error (); - } - - static char * - read_main (struct grub_env_var *var - __attribute__ ((unused)), const char *val) - { -- grub_err_t err; -+ grub_err_t __attribute__((__unused__)) err; - err = grub_gettext_init_ext (&main_context, grub_env_get ("lang"), val, - grub_env_get ("prefix")); -- if (err) -- grub_print_error (); - return grub_strdup (val); - } - -@@ -475,12 +467,9 @@ static char * - read_secondary (struct grub_env_var *var - __attribute__ ((unused)), const char *val) - { -- grub_err_t err; -+ grub_err_t __attribute__((__unused__)) err; - err = grub_gettext_init_ext (&secondary_context, grub_env_get ("lang"), val, - 0); -- if (err) -- grub_print_error (); -- - return grub_strdup (val); - } - -@@ -500,18 +489,14 @@ grub_cmd_translate (grub_command_t cmd __attribute__ ((unused)), - GRUB_MOD_INIT (gettext) - { - const char *lang; -- grub_err_t err; -+ grub_err_t __attribute__((__unused__)) err; - - lang = grub_env_get ("lang"); - - err = grub_gettext_init_ext (&main_context, lang, grub_env_get ("locale_dir"), - grub_env_get ("prefix")); -- if (err) -- grub_print_error (); - err = grub_gettext_init_ext (&secondary_context, lang, - grub_env_get ("secondary_locale_dir"), 0); -- if (err) -- grub_print_error (); - - grub_register_variable_hook ("locale_dir", NULL, read_main); - grub_register_variable_hook ("secondary_locale_dir", NULL, read_secondary); -diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c -index 8ab7794..da47b18 100644 ---- a/grub-core/kern/main.c -+++ b/grub-core/kern/main.c -@@ -268,11 +268,6 @@ grub_main (void) - - grub_boot_time ("After machine init."); - -- /* Hello. */ -- grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT); -- grub_printf ("Welcome to GRUB!\n\n"); -- grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); -- - grub_load_config (); - - grub_boot_time ("Before loading embedded modules."); -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index dd31284..ceb413f 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -138,27 +138,20 @@ linux_entry () - fi - printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" - fi -- message="$(gettext_printf "Loading Linux %s ..." ${version})" - sed "s/^/$submenu_indentation/" << EOF -- echo '$(echo "$message" | grub_quote)' - linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} - EOF - if test -n "${initrd}" ; then -- # TRANSLATORS: ramdisk isn't identifier. Should be translated. -- message="$(gettext_printf "Loading initial ramdisk ...")" - initrd_path= - for i in ${initrd}; do - initrd_path="${initrd_path} ${rel_dirname}/${i}" - done - sed "s/^/$submenu_indentation/" << EOF -- echo '$(echo "$message" | grub_quote)' - initrd $(echo $initrd_path) - EOF - fi - if test -n "${fdt}" ; then -- message="$(gettext_printf "Loading fdt ...")" - sed "s/^/$submenu_indentation/" << EOF -- echo '$(echo "$message" | grub_quote)' - devicetree ${rel_dirname}/${fdt} - EOF - fi --- -1.8.3.1 - diff --git a/0049-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch b/0029-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch similarity index 72% rename from 0049-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch rename to 0029-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch index 57f8ce248f9e12a918be3a298ee13433a6928696..ab49bb1919860b19c433734557991cf04e6cc75f 100644 --- a/0049-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch +++ b/0029-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch @@ -1,19 +1,18 @@ -From 03c186bcadb3cae7a86d1674de33c6a2b8d81089 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 8 Jul 2019 17:33:22 +0200 -Subject: [PATCH 049/220] Try mac/guid/etc before grub.cfg on tftp config - files. +Subject: [PATCH] Try mac/guid/etc before grub.cfg on tftp config files. Signed-off-by: Peter Jones --- - grub-core/normal/main.c | 80 ++++++++++++++++++++++++++----------------------- - 1 file changed, 43 insertions(+), 37 deletions(-) + grub-core/normal/main.c | 97 ++++++++++++++++++++++++++----------------------- + 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index 8add30e..d93bee6 100644 +index 02577502116..880d0ebd454 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c -@@ -347,53 +347,59 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), +@@ -345,61 +345,66 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), /* Guess the config filename. It is necessary to make CONFIG static, so that it won't get broken by longjmp. */ char *config; @@ -42,39 +41,55 @@ index 8add30e..d93bee6 100644 - } - } + const char *prefix; ++ const char *net_search_cfg; ++ int disable_net_search = 0; + prefix = grub_env_get ("fw_path"); if (! prefix) prefix = grub_env_get ("prefix"); ++ ++ net_search_cfg = grub_env_get ("feature_net_search_cfg"); ++ if (net_search_cfg && net_search_cfg[0] == 'n') ++ disable_net_search = 1; + if (prefix) { - grub_size_t config_len; +- int disable_net_search = 0; +- const char *net_search_cfg; +- - config_len = grub_strlen (prefix) + -- sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); +- sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); - config = grub_malloc (config_len); -+ if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0) +- +- if (!config) +- goto quit; +- +- grub_snprintf (config, config_len, "%s/grub.cfg", prefix); +- +- net_search_cfg = grub_env_get ("feature_net_search_cfg"); +- if (net_search_cfg && net_search_cfg[0] == 'n') +- disable_net_search = 1; +- + if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 && + !disable_net_search) +- grub_net_search_config_file (config); + { + grub_size_t config_len; + config_len = grub_strlen (prefix) + + sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); + config = grub_malloc (config_len); -- if (! config) -- goto quit; +- grub_enter_normal_mode (config); +- grub_free (config); +- } + if (! config) + goto quit; - -- grub_snprintf (config, config_len, "%s/grub.cfg", prefix); ++ + grub_snprintf (config, config_len, "%s/grub.cfg", prefix); - -- if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0) -- grub_net_search_configfile (config); ++ + grub_net_search_configfile (config); - -- grub_enter_normal_mode (config); -- grub_free (config); -- } ++ + grub_enter_normal_mode (config); + grub_free (config); + config = NULL; @@ -110,6 +125,3 @@ index 8add30e..d93bee6 100644 } else grub_enter_normal_mode (argv[0]); --- -1.8.3.1 - diff --git a/0053-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch b/0030-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch similarity index 84% rename from 0053-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch rename to 0030-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch index a234d805e256f381f7e8342b5519942dec4bfcbb..245faf7ef547a9f0be5151acd58ba4bbe9fdd553 100644 --- a/0053-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch +++ b/0030-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch @@ -1,8 +1,7 @@ -From 708e24f2d6ffadfa2d1b6638538ddc03a82dbbd6 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 4 Sep 2014 14:23:23 -0400 -Subject: [PATCH 053/220] Generate OS and CLASS in 10_linux from - /etc/os-release +Subject: [PATCH] Generate OS and CLASS in 10_linux from /etc/os-release This makes us use pretty names in the titles we generate in grub2-mkconfig when GRUB_DISTRIBUTOR isn't set. @@ -15,7 +14,7 @@ Signed-off-by: Peter Jones 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index d35b0f4..d12d2d7 100644 +index cf8d1186981..5f6d3c8d52d 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -29,7 +29,8 @@ export TEXTDOMAINDIR="@localedir@" @@ -28,6 +27,3 @@ index d35b0f4..d12d2d7 100644 else OS="${GRUB_DISTRIBUTOR}" CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" --- -1.8.3.1 - diff --git a/0031-Don-t-add-to-highlighted-row.patch b/0031-Don-t-add-to-highlighted-row.patch deleted file mode 100644 index 1f36a149386a1a93ca349905aed4d48757f3b91f..0000000000000000000000000000000000000000 --- a/0031-Don-t-add-to-highlighted-row.patch +++ /dev/null @@ -1,26 +0,0 @@ -From fc5204f8800ecfa4f00fab8ab8cd2720a6d5b55e Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Wed, 15 May 2013 17:49:45 -0400 -Subject: [PATCH 031/220] Don't add '*' to highlighted row - -It is already highlighted. ---- - grub-core/normal/menu_text.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index e22bb91..a3d1f23 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -242,7 +242,7 @@ print_entry (int y, int highlight, grub_menu_entry_t entry, - unicode_title[i] = ' '; - - if (data->geo.num_entries > 1) -- grub_putcode (highlight ? '*' : ' ', data->term); -+ grub_putcode (' ', data->term); - - grub_print_ucs4_menu (unicode_title, - unicode_title + len, --- -1.8.3.1 - diff --git a/0054-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch b/0031-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch similarity index 80% rename from 0054-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch rename to 0031-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch index b34aed433eb108ce5ae8fd4be9376a34bcfef63b..3e2d3ae5c821679b65918ca5cf2738d9fc0a3a8a 100644 --- a/0054-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch +++ b/0031-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch @@ -1,8 +1,7 @@ -From 0fe1927a2ff37806bcdca1243dd2df9cba116091 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 4 Sep 2014 15:52:08 -0400 -Subject: [PATCH 054/220] Minimize the sort ordering for .debug and -rescue- - kernels. +Subject: [PATCH] Minimize the sort ordering for .debug and -rescue- kernels. Resolves: rhbz#1065360 Signed-off-by: Peter Jones @@ -11,10 +10,10 @@ Signed-off-by: Peter Jones 1 file changed, 8 insertions(+) diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in -index 1001a12..1a4a578 100644 +index 301d1ac229a..0f6505bf3b6 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in -@@ -249,6 +249,14 @@ version_test_gt () +@@ -253,6 +253,14 @@ version_test_gt () *.old:*.old) ;; *.old:*) version_test_gt_a="`echo "$version_test_gt_a" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=gt ;; *:*.old) version_test_gt_b="`echo "$version_test_gt_b" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=ge ;; @@ -29,6 +28,3 @@ index 1001a12..1a4a578 100644 esac version_test_numeric "$version_test_gt_a" "$version_test_gt_cmp" "$version_test_gt_b" return "$?" --- -1.8.3.1 - diff --git a/0032-Message-string-cleanups.patch b/0032-Message-string-cleanups.patch deleted file mode 100644 index c9c0b6f9d6cd07d56b2293325835b7beaab05680..0000000000000000000000000000000000000000 --- a/0032-Message-string-cleanups.patch +++ /dev/null @@ -1,71 +0,0 @@ -From cc62054bce6fc5f00f4e302d8fa7615d263f1f5b Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Fri, 7 Jun 2013 11:09:04 -0400 -Subject: [PATCH 032/220] Message string cleanups - -Make use of terminology consistent. Remove jargon. ---- - grub-core/normal/menu_text.c | 21 +++++++++------------ - 1 file changed, 9 insertions(+), 12 deletions(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index a3d1f23..64a8386 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -157,9 +157,8 @@ print_message (int nested, int edit, struct grub_term_output *term, int dry_run) - - if (edit) - { -- ret += grub_print_message_indented_real (_("Minimum Emacs-like screen editing is \ --supported. TAB lists completions. Press Ctrl-x or F10 to boot, Ctrl-c or F2 for a \ --command-line or ESC to discard edits and return to the GRUB menu."), -+ ret += grub_print_message_indented_real (_("Press Ctrl-x or F10 to start, Ctrl-c or F2 for a \ -+command prompt or Escape to discard edits and return to the menu. Pressing Tab lists possible completions."), - STANDARD_MARGIN, STANDARD_MARGIN, - term, dry_run); - } -@@ -167,8 +166,8 @@ command-line or ESC to discard edits and return to the GRUB menu."), - { - char *msg_translated; - -- msg_translated = grub_xasprintf (_("Use the %C and %C keys to select which " -- "entry is highlighted."), -+ msg_translated = grub_xasprintf (_("Use the %C and %C keys to change the " -+ "selection."), - GRUB_UNICODE_UPARROW, - GRUB_UNICODE_DOWNARROW); - if (!msg_translated) -@@ -181,17 +180,15 @@ command-line or ESC to discard edits and return to the GRUB menu."), - if (nested) - { - ret += grub_print_message_indented_real -- (_("Press enter to boot the selected OS, " -- "`e' to edit the commands before booting " -- "or `c' for a command-line. ESC to return previous menu."), -+ (_("Press 'e' to edit the selected item, " -+ "or 'c' for a command prompt. Press Escape to return to the previous menu."), - STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); - } - else - { - ret += grub_print_message_indented_real -- (_("Press enter to boot the selected OS, " -- "`e' to edit the commands before booting " -- "or `c' for a command-line."), -+ (_("Press 'e' to edit the selected item, " -+ "or 'c' for a command prompt."), - STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); - } - } -@@ -443,7 +440,7 @@ menu_text_print_timeout (int timeout, void *dataptr) - || data->timeout_msg == TIMEOUT_TERSE_NO_MARGIN) - msg_translated = grub_xasprintf (_("%ds"), timeout); - else -- msg_translated = grub_xasprintf (_("The highlighted entry will be executed automatically in %ds."), timeout); -+ msg_translated = grub_xasprintf (_("The selected entry will be started automatically in %ds."), timeout); - if (!msg_translated) - { - grub_print_error (); --- -1.8.3.1 - diff --git a/0055-Try-prefix-if-fw_path-doesn-t-work.patch b/0032-Try-prefix-if-fw_path-doesn-t-work.patch similarity index 81% rename from 0055-Try-prefix-if-fw_path-doesn-t-work.patch rename to 0032-Try-prefix-if-fw_path-doesn-t-work.patch index ff684db40404ab27ffd596aa8c5677fea53e34b6..54a876ba87dec5a80a80d3c5906e17d4e99f585f 100644 --- a/0055-Try-prefix-if-fw_path-doesn-t-work.patch +++ b/0032-Try-prefix-if-fw_path-doesn-t-work.patch @@ -1,19 +1,19 @@ -From 75f23ba5e4f8e84b595b0b13f5f7ed744a866099 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 9 Jul 2019 10:35:16 +0200 -Subject: [PATCH 055/220] Try $prefix if $fw_path doesn't work. +Subject: [PATCH] Try $prefix if $fw_path doesn't work. Related: rhbz#1148652 Signed-off-by: Peter Jones --- - grub-core/kern/ieee1275/init.c | 30 ++++++----- + grub-core/kern/ieee1275/init.c | 28 +++++---- grub-core/net/net.c | 2 +- - grub-core/normal/main.c | 118 ++++++++++++++++++++--------------------- - 3 files changed, 75 insertions(+), 75 deletions(-) + grub-core/normal/main.c | 134 ++++++++++++++++++++--------------------- + 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c -index e71d158..0cd2a62 100644 +index e71d1584164..0cd2a627231 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c @@ -127,23 +127,25 @@ grub_machine_get_bootlocation (char **device, char **path) @@ -35,11 +35,10 @@ index e71d158..0cd2a62 100644 { - *lastslash = '\0'; - grub_translate_ieee1275_path (filename); -- ++ char *lastslash = grub_strrchr (filename, '\\'); + - *path = filename; - } -+ char *lastslash = grub_strrchr (filename, '\\'); -+ + /* Truncate at last directory. */ + if (lastslash) + { @@ -57,10 +56,10 @@ index e71d158..0cd2a62 100644 } diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index 0645456..4b7972b 100644 +index 4d3eb5c1a52..0ef148f4adc 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c -@@ -1850,7 +1850,7 @@ grub_net_search_configfile (char *config) +@@ -1869,7 +1869,7 @@ grub_net_search_config_file (char *config) /* Remove the remaining minus sign at the end. */ config[config_len] = '\0'; @@ -70,10 +69,10 @@ index 0645456..4b7972b 100644 static struct grub_preboot *fini_hnd; diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index d93bee6..2fe6743 100644 +index 880d0ebd454..d5df4f815b0 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c -@@ -337,74 +337,72 @@ grub_enter_normal_mode (const char *config) +@@ -335,81 +335,79 @@ grub_enter_normal_mode (const char *config) grub_boot_time ("Exiting normal mode"); } @@ -83,12 +82,19 @@ index d93bee6..2fe6743 100644 + char *config; + const char *prefix; + grub_err_t err = GRUB_ERR_FILE_NOT_FOUND; ++ const char *net_search_cfg; ++ int disable_net_search = 0; + + prefix = grub_env_get (variable); + if (!prefix) + return GRUB_ERR_FILE_NOT_FOUND; + -+ if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0) ++ net_search_cfg = grub_env_get ("feature_net_search_cfg"); ++ if (net_search_cfg && net_search_cfg[0] == 'n') ++ disable_net_search = 1; ++ ++ if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 && ++ !disable_net_search) + { + grub_size_t config_len; + config_len = grub_strlen (prefix) + @@ -99,7 +105,7 @@ index d93bee6..2fe6743 100644 + return GRUB_ERR_FILE_NOT_FOUND; + + grub_snprintf (config, config_len, "%s/grub.cfg", prefix); -+ err = grub_net_search_configfile (config); ++ err = grub_net_search_config_file (config); + } + + if (err != GRUB_ERR_NONE) @@ -131,22 +137,26 @@ index d93bee6..2fe6743 100644 int argc, char *argv[]) { - if (argc == 0) -+ if (argc) -+ grub_enter_normal_mode (argv[0]); -+ else - { +- { - /* Guess the config filename. It is necessary to make CONFIG static, - so that it won't get broken by longjmp. */ - char *config; - const char *prefix; +- const char *net_search_cfg; +- int disable_net_search = 0; - - prefix = grub_env_get ("fw_path"); - if (! prefix) - prefix = grub_env_get ("prefix"); - +- net_search_cfg = grub_env_get ("feature_net_search_cfg"); +- if (net_search_cfg && net_search_cfg[0] == 'n') +- disable_net_search = 1; +- - if (prefix) - { -- if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0) +- if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 && +- !disable_net_search) - { - grub_size_t config_len; - config_len = grub_strlen (prefix) + @@ -191,6 +201,12 @@ index d93bee6..2fe6743 100644 - { - grub_enter_normal_mode (0); - } +- } +- else ++ if (argc) + grub_enter_normal_mode (argv[0]); ++ else ++ { + /* Guess the config filename. */ + grub_err_t err; + err = grub_try_normal ("fw_path"); @@ -198,14 +214,9 @@ index d93bee6..2fe6743 100644 + err = grub_try_normal ("prefix"); + if (err == GRUB_ERR_FILE_NOT_FOUND) + grub_enter_normal_mode (0); - } -- else -- grub_enter_normal_mode (argv[0]); ++ } -quit: return 0; } --- -1.8.3.1 - diff --git a/0033-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch b/0033-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch deleted file mode 100644 index cb207c7c81811d2043cc3250d4d02e16e5c93bd7..0000000000000000000000000000000000000000 --- a/0033-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch +++ /dev/null @@ -1,32 +0,0 @@ -From 9330deb86a791da573563dc319e1874af72eb97c Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Fri, 7 Jun 2013 14:08:23 -0400 -Subject: [PATCH 033/220] Fix border spacing now that we aren't displaying it - ---- - grub-core/normal/menu_text.c | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index 64a8386..1062d64 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -331,12 +331,12 @@ grub_menu_init_page (int nested, int edit, - int empty_lines = 1; - int version_msg = 1; - -- geo->border = 1; -- geo->first_entry_x = 1 /* margin */ + 1 /* border */; -+ geo->border = 0; -+ geo->first_entry_x = 0 /* margin */ + 0 /* border */; - geo->entry_width = grub_term_width (term) - 5; - - geo->first_entry_y = 2 /* two empty lines*/ -- + 1 /* GNU GRUB version text */ + 1 /* top border */; -+ + 0 /* GNU GRUB version text */ + 1 /* top border */; - - geo->timeout_lines = 2; - --- -1.8.3.1 - diff --git a/0057-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch b/0033-Use-rpm-s-sort-for-grub2-mkconfig.patch similarity index 81% rename from 0057-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch rename to 0033-Use-rpm-s-sort-for-grub2-mkconfig.patch index 579266ac8ccdfc341d5902a714b3c20039e28711..ff1c13ecac512d2deee72476b941561256f6662b 100644 --- a/0057-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch +++ b/0033-Use-rpm-s-sort-for-grub2-mkconfig.patch @@ -1,61 +1,38 @@ -From e8cf594751f7bbce4ff01504197ebc25c71c2dc2 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Robert Marshall Date: Mon, 16 Mar 2015 14:14:19 -0400 -Subject: [PATCH 057/220] Use Distribution Package Sort for grub2-mkconfig - (#1124074) +Subject: [PATCH] Use rpm's sort for grub2-mkconfig -Users reported that newly installed kernels on their systems installed -with grub-mkconfig would not appear on the grub boot list in order -starting with the most recent. Added an option for rpm-based systems to -use the rpm-sort library to sort kernels instead. - -Resolves rhbz#1124074 +Add an option for rpm-based systems to use the rpm-sort library to sort +kernels. This avoids problems due to discrepancies between `sort -V` +and rpm. Signed-off-by: Robert Marshall [pjones: fix --enable-rpm-sort configure option] Signed-off-by: Peter Jones +[thierry.vignaud: fix build with rpm-4.16] +Signed-off-by: Thierry Vignaud +[tim: fix disabling grub-rpm-sort by ./configure] +Signed-off-by: Tim Landscheidt +[javierm: don't check for rpmvercmp in librpm] +Signed-off-by: Javier Martinez Canillas +[rharwood: commit message] +Signed-off-by: Robbie Harwood --- - Makefile.util.def | 16 +++ - configure.ac | 29 +++++ + configure.ac | 37 ++++++ + Makefile.util.def | 17 +++ + util/grub-rpm-sort.c | 281 ++++++++++++++++++++++++++++++++++++++++++++++ util/grub-mkconfig_lib.in | 11 +- util/grub-rpm-sort.8 | 12 ++ - util/grub-rpm-sort.c | 281 ++++++++++++++++++++++++++++++++++++++++++++++ - 5 files changed, 348 insertions(+), 1 deletion(-) - create mode 100644 util/grub-rpm-sort.8 + 5 files changed, 357 insertions(+), 1 deletion(-) create mode 100644 util/grub-rpm-sort.c + create mode 100644 util/grub-rpm-sort.8 -diff --git a/Makefile.util.def b/Makefile.util.def -index 1f298d0..843ce09 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -696,6 +696,22 @@ program = { - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; - }; - -+program = { -+ name = grub-rpm-sort; -+ mansection = 8; -+ installdir = sbin; -+ -+ common = grub-core/kern/emu/misc.c; -+ common = grub-core/kern/emu/argp_common.c; -+ common = grub-core/osdep/init.c; -+ common = util/misc.c; -+ common = util/grub-rpm-sort.c; -+ -+ ldadd = libgrubkern.a; -+ ldadd = grub-core/lib/gnulib/libgnu.a; -+ ldadd = '$(LIBDEVMAPPER) $(LIBRPM)'; -+}; -+ - script = { - name = grub-mkconfig; - common = util/grub-mkconfig.in; diff --git a/configure.ac b/configure.ac -index 8df400e..6927615 100644 +index bec8535af70..643a13f9147 100644 --- a/configure.ac +++ b/configure.ac -@@ -69,6 +69,7 @@ grub_TRANSFORM([grub-mkrelpath]) +@@ -72,6 +72,7 @@ grub_TRANSFORM([grub-mkrelpath]) grub_TRANSFORM([grub-mkrescue]) grub_TRANSFORM([grub-probe]) grub_TRANSFORM([grub-reboot]) @@ -63,7 +40,7 @@ index 8df400e..6927615 100644 grub_TRANSFORM([grub-script-check]) grub_TRANSFORM([grub-set-default]) grub_TRANSFORM([grub-sparc64-setup]) -@@ -92,6 +93,7 @@ grub_TRANSFORM([grub-mkrescue.1]) +@@ -95,6 +96,7 @@ grub_TRANSFORM([grub-mkrescue.1]) grub_TRANSFORM([grub-mkstandalone.3]) grub_TRANSFORM([grub-ofpathname.3]) grub_TRANSFORM([grub-probe.3]) @@ -71,7 +48,7 @@ index 8df400e..6927615 100644 grub_TRANSFORM([grub-reboot.3]) grub_TRANSFORM([grub-render-label.3]) grub_TRANSFORM([grub-script-check.3]) -@@ -1802,6 +1804,33 @@ fi +@@ -1860,6 +1862,35 @@ fi AC_SUBST([LIBDEVMAPPER]) @@ -80,6 +57,8 @@ index 8df400e..6927615 100644 + [enable native rpm sorting of kernels in grub (default=guessed)])]) +if test x"$enable_rpm_sort" = xno ; then + rpm_sort_excuse="explicitly disabled" ++else ++ enable_rpm_sort=yes +fi + +if test x"$rpm_sort_excuse" = x ; then @@ -89,15 +68,15 @@ index 8df400e..6927615 100644 +fi + +if test x"$rpm_sort_excuse" = x ; then -+ # Check for rpm library. -+ AC_CHECK_LIB([rpm], [rpmvercmp], [], -+ [rpm_sort_excuse="rpmlib missing rpmvercmp"]) ++ # Check for rpmio library. ++ AC_CHECK_LIB([rpmio], [rpmvercmp], [], ++ [rpm_sort_excuse="rpmio missing rpmvercmp"]) +fi + +if test x"$rpm_sort_excuse" = x ; then -+ LIBRPM="-lrpm"; -+ AC_DEFINE([HAVE_RPM], [1], -+ [Define to 1 if you have the rpm library.]) ++ LIBRPM="-lrpmio"; ++ AC_DEFINE([HAVE_RPMIO], [1], ++ [Define to 1 if you have the rpmio library.]) +fi + +AC_SUBST([LIBRPM]) @@ -105,63 +84,57 @@ index 8df400e..6927615 100644 LIBGEOM= if test x$host_kernel = xkfreebsd; then AC_CHECK_LIB([geom], [geom_gettree], [], -diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in -index 1a4a578..113a41f 100644 ---- a/util/grub-mkconfig_lib.in -+++ b/util/grub-mkconfig_lib.in -@@ -33,6 +33,9 @@ fi - if test "x$grub_mkrelpath" = x; then - grub_mkrelpath="${bindir}/@grub_mkrelpath@" +@@ -2047,6 +2078,7 @@ AM_CONDITIONAL([COND_GRUB_EMU_SDL], [test x$enable_grub_emu_sdl = xyes]) + AM_CONDITIONAL([COND_GRUB_EMU_PCI], [test x$enable_grub_emu_pci = xyes]) + AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes]) + AM_CONDITIONAL([COND_GRUB_MOUNT], [test x$enable_grub_mount = xyes]) ++AM_CONDITIONAL([COND_GRUB_RPM_SORT], [test x$enable_rpm_sort = xyes]) + AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x]) + if test x$FONT_SOURCE != x ; then + HAVE_FONT_SOURCE=1 +@@ -2168,6 +2200,11 @@ echo grub-mount: Yes + else + echo grub-mount: No "($grub_mount_excuse)" fi -+if test "x$grub_rpm_sort" = x; then -+ grub_rpm_sort="${sbindir}/@grub_rpm_sort@" -+fi - - if which gettext >/dev/null 2>/dev/null; then - : -@@ -214,6 +217,12 @@ version_sort () - esac - } - -+if [ "x$grub_rpm_sort" != x -a -x "$grub_rpm_sort" ]; then -+ kernel_sort="$grub_rpm_sort" ++if [ x"$rpm_sort_excuse" = x ]; then ++echo grub-rpm-sort: Yes +else -+ kernel_sort=version_sort ++echo grub-rpm-sort: No "($rpm_sort_excuse)" +fi + if [ x"$starfield_excuse" = x ]; then + echo starfield theme: Yes + echo With DejaVuSans font from $DJVU_FONT_SOURCE +diff --git a/Makefile.util.def b/Makefile.util.def +index 2c9b283a230..bc10cc79722 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -703,6 +703,23 @@ program = { + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; + }; + ++program = { ++ name = grub-rpm-sort; ++ mansection = 8; ++ installdir = sbin; + - version_test_numeric () - { - version_test_numeric_a="$1" -@@ -230,7 +239,7 @@ version_test_numeric () - version_test_numeric_a="$version_test_numeric_b" - version_test_numeric_b="$version_test_numeric_c" - fi -- if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | version_sort | head -n 1 | grep -qx "$version_test_numeric_b" ; then -+ if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | "$kernel_sort" | head -n 1 | grep -qx "$version_test_numeric_b" ; then - return 0 - else - return 1 -diff --git a/util/grub-rpm-sort.8 b/util/grub-rpm-sort.8 -new file mode 100644 -index 0000000..8ce2148 ---- /dev/null -+++ b/util/grub-rpm-sort.8 -@@ -0,0 +1,12 @@ -+.TH GRUB-RPM-SORT 8 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-rpm-sort\fR \(em Sort input according to RPM version compare. -+ -+.SH SYNOPSIS -+\fBgrub-rpm-sort\fR [OPTIONS]. ++ common = grub-core/kern/emu/misc.c; ++ common = grub-core/kern/emu/argp_common.c; ++ common = grub-core/osdep/init.c; ++ common = util/misc.c; ++ common = util/grub-rpm-sort.c; + -+.SH DESCRIPTION -+You should not normally run this program directly. Use grub-mkconfig instead. ++ ldadd = libgrubkern.a; ++ ldadd = grub-core/lib/gnulib/libgnu.a; ++ ldadd = '$(LIBDEVMAPPER) $(LIBRPM)'; ++ condition = COND_GRUB_RPM_SORT; ++}; + -+.SH SEE ALSO -+.BR "info grub" + script = { + name = grub-mkconfig; + common = util/grub-mkconfig.in; diff --git a/util/grub-rpm-sort.c b/util/grub-rpm-sort.c new file mode 100644 -index 0000000..f33bd1e +index 00000000000..f33bd1ed568 --- /dev/null +++ b/util/grub-rpm-sort.c @@ -0,0 +1,281 @@ @@ -446,6 +419,57 @@ index 0000000..f33bd1e + + return 0; +} --- -1.8.3.1 - +diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in +index 0f6505bf3b6..42c2ea9ba50 100644 +--- a/util/grub-mkconfig_lib.in ++++ b/util/grub-mkconfig_lib.in +@@ -33,6 +33,9 @@ fi + if test "x$grub_mkrelpath" = x; then + grub_mkrelpath="${bindir}/@grub_mkrelpath@" + fi ++if test "x$grub_rpm_sort" = x; then ++ grub_rpm_sort="${sbindir}/@grub_rpm_sort@" ++fi + + if command -v gettext >/dev/null; then + : +@@ -218,6 +221,12 @@ version_sort () + esac + } + ++if [ "x$grub_rpm_sort" != x -a -x "$grub_rpm_sort" ]; then ++ kernel_sort="$grub_rpm_sort" ++else ++ kernel_sort=version_sort ++fi ++ + version_test_numeric () + { + version_test_numeric_a="$1" +@@ -234,7 +243,7 @@ version_test_numeric () + version_test_numeric_a="$version_test_numeric_b" + version_test_numeric_b="$version_test_numeric_c" + fi +- if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | version_sort | head -n 1 | grep -qx "$version_test_numeric_b" ; then ++ if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | "$kernel_sort" | head -n 1 | grep -qx "$version_test_numeric_b" ; then + return 0 + else + return 1 +diff --git a/util/grub-rpm-sort.8 b/util/grub-rpm-sort.8 +new file mode 100644 +index 00000000000..8ce21488448 +--- /dev/null ++++ b/util/grub-rpm-sort.8 +@@ -0,0 +1,12 @@ ++.TH GRUB-RPM-SORT 8 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-rpm-sort\fR \(em Sort input according to RPM version compare. ++ ++.SH SYNOPSIS ++\fBgrub-rpm-sort\fR [OPTIONS]. ++ ++.SH DESCRIPTION ++You should not normally run this program directly. Use grub-mkconfig instead. ++ ++.SH SEE ALSO ++.BR "info grub" diff --git a/0059-Make-grub2-mkconfig-construct-titles-that-look-like-.patch b/0034-Make-grub2-mkconfig-construct-titles-that-look-like-.patch similarity index 91% rename from 0059-Make-grub2-mkconfig-construct-titles-that-look-like-.patch rename to 0034-Make-grub2-mkconfig-construct-titles-that-look-like-.patch index 10f709cb44d1b690abf229c24763e22f33238a07..4eb37e1ed475938f4491959feae6650a5d4ab894 100644 --- a/0059-Make-grub2-mkconfig-construct-titles-that-look-like-.patch +++ b/0034-Make-grub2-mkconfig-construct-titles-that-look-like-.patch @@ -1,8 +1,8 @@ -From 95e793ef45a127c800525d629b2fdec583ae8266 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 28 Apr 2015 11:15:03 -0400 -Subject: [PATCH 059/220] Make grub2-mkconfig construct titles that look like - the ones we want elsewhere. +Subject: [PATCH] Make grub2-mkconfig construct titles that look like the ones + we want elsewhere. Resolves: rhbz#1215839 @@ -12,7 +12,7 @@ Signed-off-by: Peter Jones 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index d12d2d7..12a20c9 100644 +index 5f6d3c8d52d..786dbabb4a8 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -78,6 +78,32 @@ case x"$GRUB_FS" in @@ -67,6 +67,3 @@ index d12d2d7..12a20c9 100644 fi echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/" else --- -1.8.3.1 - diff --git a/0034-Use-the-correct-indentation-for-the-term-help-text.patch b/0034-Use-the-correct-indentation-for-the-term-help-text.patch deleted file mode 100644 index f7fae87f7185b493a5212f4741bbc04da775160c..0000000000000000000000000000000000000000 --- a/0034-Use-the-correct-indentation-for-the-term-help-text.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 5e6cef121ba76d88608e6c124ff60e73cf057fe4 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Fri, 7 Jun 2013 14:08:49 -0400 -Subject: [PATCH 034/220] Use the correct indentation for the term help text - -That is consistent with the menu help text ---- - grub-core/normal/main.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index 09d0dfe..7f61c5b 100644 ---- a/grub-core/normal/main.c -+++ b/grub-core/normal/main.c -@@ -432,8 +432,8 @@ grub_normal_reader_init (int nested) - grub_normal_init_page (term, 1); - grub_term_setcursor (term, 1); - -- if (grub_term_width (term) > 3 + STANDARD_MARGIN + 20) -- grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term); -+ if (grub_term_width (term) > 2 * STANDARD_MARGIN + 20) -+ grub_print_message_indented (msg_formatted, STANDARD_MARGIN, STANDARD_MARGIN, term); - else - grub_print_message_indented (msg_formatted, 0, 0, term); - grub_putcode ('\n', term); --- -1.8.3.1 - diff --git a/0060-Add-friendly-grub2-password-config-tool-985962.patch b/0035-Add-friendly-grub2-password-config-tool-985962.patch similarity index 93% rename from 0060-Add-friendly-grub2-password-config-tool-985962.patch rename to 0035-Add-friendly-grub2-password-config-tool-985962.patch index 8ac50f28d796734c95f3ee57c360605cc08f10a2..2d6f18a62096a733d4f8318e57ec77008fe14f98 100644 --- a/0060-Add-friendly-grub2-password-config-tool-985962.patch +++ b/0035-Add-friendly-grub2-password-config-tool-985962.patch @@ -1,7 +1,7 @@ -From a524d461543f57da4f36a9c9c12b329ea8b6629c Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Robert Marshall Date: Thu, 25 Jun 2015 11:13:11 -0400 -Subject: [PATCH 060/220] Add friendly grub2 password config tool (#985962) +Subject: [PATCH] Add friendly grub2 password config tool (#985962) Provided a tool for users to reset the grub2 root user password without having to alter the grub.cfg. The hashed password now @@ -15,8 +15,8 @@ Signed-off-by: Peter Jones [luto: fix grub-setpassword -o's output path] Andy Lutomirski --- - Makefile.util.def | 13 +++++ configure.ac | 1 + + Makefile.util.def | 13 +++++ util/grub-mkconfig.in | 2 + util/grub-set-password.8 | 28 ++++++++++ util/grub-set-password.in | 128 ++++++++++++++++++++++++++++++++++++++++++++++ @@ -26,54 +26,54 @@ Andy Lutomirski create mode 100644 util/grub-set-password.in create mode 100644 util/grub.d/01_users.in +diff --git a/configure.ac b/configure.ac +index 643a13f9147..25e1abb59b9 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -72,6 +72,7 @@ grub_TRANSFORM([grub-mkrelpath]) + grub_TRANSFORM([grub-mkrescue]) + grub_TRANSFORM([grub-probe]) + grub_TRANSFORM([grub-reboot]) ++grub_TRANSFORM([grub-set-password]) + grub_TRANSFORM([grub-rpm-sort]) + grub_TRANSFORM([grub-script-check]) + grub_TRANSFORM([grub-set-default]) diff --git a/Makefile.util.def b/Makefile.util.def -index 843ce09..e50436a 100644 +index bc10cc79722..8ca4c14f0b9 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -452,6 +452,12 @@ script = { + installdir = grubconf; }; - script = { ++script = { + name = '01_users'; + common = util/grub.d/01_users.in; + installdir = grubconf; +}; + -+script = { + script = { name = '10_windows'; common = util/grub.d/10_windows.in; - installdir = grubconf; -@@ -734,6 +740,13 @@ script = { +@@ -741,6 +747,13 @@ script = { + installdir = sbin; }; - script = { ++script = { + name = grub-set-password; + common = util/grub-set-password.in; + mansection = 8; + installdir = sbin; +}; + -+script = { + script = { name = grub-mkconfig_lib; common = util/grub-mkconfig_lib.in; - installdir = noinst; -diff --git a/configure.ac b/configure.ac -index 6927615..6850166 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -69,6 +69,7 @@ grub_TRANSFORM([grub-mkrelpath]) - grub_TRANSFORM([grub-mkrescue]) - grub_TRANSFORM([grub-probe]) - grub_TRANSFORM([grub-reboot]) -+grub_TRANSFORM([grub-set-password]) - grub_TRANSFORM([grub-rpm-sort]) - grub_TRANSFORM([grub-script-check]) - grub_TRANSFORM([grub-set-default]) diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index c645351..4e7a875 100644 +index 8ea2315ebc2..ba14cf6261c 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in -@@ -282,6 +282,8 @@ for i in "${grub_mkconfig_dir}"/* ; do +@@ -276,6 +276,8 @@ for i in "${grub_mkconfig_dir}"/* ; do *~) ;; # emacsen autosave files. FIXME: support other editors */\#*\#) ;; @@ -84,7 +84,7 @@ index c645351..4e7a875 100644 echo diff --git a/util/grub-set-password.8 b/util/grub-set-password.8 new file mode 100644 -index 0000000..9646546 +index 00000000000..9646546e43d --- /dev/null +++ b/util/grub-set-password.8 @@ -0,0 +1,28 @@ @@ -118,7 +118,7 @@ index 0000000..9646546 +.BR "info grub2-mkpasswd-pbkdf2" diff --git a/util/grub-set-password.in b/util/grub-set-password.in new file mode 100644 -index 0000000..5ebf505 +index 00000000000..5ebf50576d6 --- /dev/null +++ b/util/grub-set-password.in @@ -0,0 +1,128 @@ @@ -252,7 +252,7 @@ index 0000000..5ebf505 +fi diff --git a/util/grub.d/01_users.in b/util/grub.d/01_users.in new file mode 100644 -index 0000000..db2f44b +index 00000000000..db2f44bfb78 --- /dev/null +++ b/util/grub.d/01_users.in @@ -0,0 +1,11 @@ @@ -267,6 +267,3 @@ index 0000000..db2f44b + fi +fi +EOF --- -1.8.3.1 - diff --git a/0035-Indent-menu-entries.patch b/0035-Indent-menu-entries.patch deleted file mode 100644 index fde8f7edf770a53a1dae88c5261dc469c83f998c..0000000000000000000000000000000000000000 --- a/0035-Indent-menu-entries.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 7d70ca36c17e14361284f986e4c62e6523bf6b98 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Fri, 7 Jun 2013 14:30:55 -0400 -Subject: [PATCH 035/220] Indent menu entries - ---- - grub-core/normal/menu_text.c | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index 1062d64..ecc60f9 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -239,7 +239,8 @@ print_entry (int y, int highlight, grub_menu_entry_t entry, - unicode_title[i] = ' '; - - if (data->geo.num_entries > 1) -- grub_putcode (' ', data->term); -+ for (i = 0; i < STANDARD_MARGIN; i++) -+ grub_putcode (' ', data->term); - - grub_print_ucs4_menu (unicode_title, - unicode_title + len, --- -1.8.3.1 - diff --git a/0036-Fix-margins.patch b/0036-Fix-margins.patch deleted file mode 100644 index 6c91ecd4e8b6b292d1843f62dfaab54b5b86e989..0000000000000000000000000000000000000000 --- a/0036-Fix-margins.patch +++ /dev/null @@ -1,37 +0,0 @@ -From 61f83fac37fb9bacac50f75e0aa7d304bfabf410 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Fri, 7 Jun 2013 14:59:36 -0400 -Subject: [PATCH 036/220] Fix margins - ---- - grub-core/normal/menu_text.c | 8 +++----- - 1 file changed, 3 insertions(+), 5 deletions(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index ecc60f9..0e43f2c 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -333,17 +333,15 @@ grub_menu_init_page (int nested, int edit, - int version_msg = 1; - - geo->border = 0; -- geo->first_entry_x = 0 /* margin */ + 0 /* border */; -- geo->entry_width = grub_term_width (term) - 5; -+ geo->first_entry_x = 0; /* no margin */ -+ geo->entry_width = grub_term_width (term) - 1; - -- geo->first_entry_y = 2 /* two empty lines*/ -- + 0 /* GNU GRUB version text */ + 1 /* top border */; -+ geo->first_entry_y = 3; /* three empty lines*/ - - geo->timeout_lines = 2; - - /* 3 lines for timeout message and bottom margin. 2 lines for the border. */ - geo->num_entries = grub_term_height (term) - geo->first_entry_y -- - 1 /* bottom border */ - - 1 /* empty line before info message*/ - - geo->timeout_lines /* timeout */ - - 1 /* empty final line */; --- -1.8.3.1 - diff --git a/0061-tcp-add-window-scaling-support.patch b/0036-tcp-add-window-scaling-support.patch similarity index 94% rename from 0061-tcp-add-window-scaling-support.patch rename to 0036-tcp-add-window-scaling-support.patch index 6cf2d79a8b26fe911e0224a101f3944c9b6ea50c..7d1996c8fc233ece5afa67588ee79e6f95bd45bd 100644 --- a/0061-tcp-add-window-scaling-support.patch +++ b/0036-tcp-add-window-scaling-support.patch @@ -1,7 +1,7 @@ -From 685960c950e661dec0d57a353ca01304b94a7092 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 12 Aug 2015 08:57:55 -0700 -Subject: [PATCH 061/220] tcp: add window scaling support +Subject: [PATCH] tcp: add window scaling support Sometimes we have to provision boxes across regions, such as California to Sweden. The http server has a 10 minute timeout, so if we can't get our 250mb @@ -17,7 +17,7 @@ Signed-off-by: Josef Bacik 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/grub-core/net/tcp.c b/grub-core/net/tcp.c -index e8ad34b..7d4b822 100644 +index e8ad34b84d4..7d4b822626d 100644 --- a/grub-core/net/tcp.c +++ b/grub-core/net/tcp.c @@ -106,6 +106,18 @@ struct tcphdr @@ -85,6 +85,3 @@ index e8ad34b..7d4b822 100644 tcp_socket_register (socket); --- -1.8.3.1 - diff --git a/0037-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch b/0037-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch deleted file mode 100644 index ed79a3ee558dc1ae765ddbfdccd36b89f74a87e7..0000000000000000000000000000000000000000 --- a/0037-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 10fe905b3b3364436fe5328724b21def775aec60 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 21 Jun 2013 14:44:08 -0400 -Subject: [PATCH 037/220] Use -2 instead of -1 for our right-hand margin, so - linewrapping works (#976643). - -Signed-off-by: Peter Jones ---- - grub-core/normal/menu_text.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index 0e43f2c..537d4bf 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -334,7 +334,7 @@ grub_menu_init_page (int nested, int edit, - - geo->border = 0; - geo->first_entry_x = 0; /* no margin */ -- geo->entry_width = grub_term_width (term) - 1; -+ geo->entry_width = grub_term_width (term) - 2; - - geo->first_entry_y = 3; /* three empty lines*/ - --- -1.8.3.1 - diff --git a/0064-efinet-and-bootp-add-support-for-dhcpv6.patch b/0037-efinet-and-bootp-add-support-for-dhcpv6.patch similarity index 92% rename from 0064-efinet-and-bootp-add-support-for-dhcpv6.patch rename to 0037-efinet-and-bootp-add-support-for-dhcpv6.patch index a23b63ebe33939eaeffcaea85004f9ee104da054..a9844b89c0caf2e3f0b25ec377f105ef9704fbed 100644 --- a/0064-efinet-and-bootp-add-support-for-dhcpv6.patch +++ b/0037-efinet-and-bootp-add-support-for-dhcpv6.patch @@ -1,31 +1,23 @@ -From af6fa4f3b319c6d71badfba50fcb16619c38605a Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 9 Jul 2019 11:47:37 +0200 -Subject: [PATCH 064/220] efinet and bootp: add support for dhcpv6 +Subject: [PATCH] efinet and bootp: add support for dhcpv6 Signed-off-by: Peter Jones --- - grub-core/net/bootp.c | 174 +++++++++++++++++++++++++++++++++++++ - grub-core/net/drivers/efi/efinet.c | 54 ++++++++++-- + grub-core/net/bootp.c | 173 +++++++++++++++++++++++++++++++++++++ + grub-core/net/drivers/efi/efinet.c | 53 ++++++++++-- grub-core/net/net.c | 72 +++++++++++++++ grub-core/net/tftp.c | 4 + include/grub/efi/api.h | 129 +++++++++++++++++++++++++-- include/grub/net.h | 60 +++++++++++++ - 6 files changed, 479 insertions(+), 14 deletions(-) + 6 files changed, 477 insertions(+), 14 deletions(-) diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index 0e6e41a..8c96959 100644 +index 6fb5627025d..e28fb6a09f9 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c -@@ -23,6 +23,7 @@ - #include - #include - #include -+#include - #include - - struct grub_dhcp_discover_options -@@ -935,6 +936,179 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), +@@ -902,6 +902,179 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), static grub_command_t cmd_getdhcp, cmd_bootp, cmd_dhcp; @@ -206,16 +198,15 @@ index 0e6e41a..8c96959 100644 grub_bootp_init (void) { diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index 5388f95..a57189e 100644 +index 5388f952ba9..173fb63153c 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c -@@ -18,11 +18,15 @@ +@@ -18,11 +18,14 @@ #include #include +#include #include -+#include #include #include #include @@ -225,7 +216,7 @@ index 5388f95..a57189e 100644 GRUB_MOD_LICENSE ("GPLv3+"); -@@ -329,7 +333,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -329,7 +332,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, char **path) { struct grub_net_card *card; @@ -234,7 +225,7 @@ index 5388f95..a57189e 100644 dp = grub_efi_get_device_path (hnd); if (! dp) -@@ -340,14 +344,19 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -340,14 +343,19 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, grub_efi_device_path_t *cdp; struct grub_efi_pxe *pxe; struct grub_efi_pxe_mode *pxe_mode; @@ -255,7 +246,7 @@ index 5388f95..a57189e 100644 int match; /* EDK2 UEFI PXE driver creates pseudo devices with type IPv4/IPv6 -@@ -356,7 +365,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -356,7 +364,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, devices. We skip them when enumerating cards, so here we need to find matching MAC device. */ @@ -263,7 +254,7 @@ index 5388f95..a57189e 100644 if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE)) -@@ -373,16 +381,46 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -373,16 +380,46 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, if (!match) continue; } @@ -316,10 +307,10 @@ index 5388f95..a57189e 100644 } } diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index 4b7972b..f24f1fd 100644 +index 0ef148f4adc..22f2689aaeb 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c -@@ -955,6 +955,78 @@ grub_net_network_level_interface_register (struct grub_net_network_level_interfa +@@ -960,6 +960,78 @@ grub_net_network_level_interface_register (struct grub_net_network_level_interfa grub_net_network_level_interfaces = inter; } @@ -399,19 +390,18 @@ index 4b7972b..f24f1fd 100644 grub_err_t grub_net_add_ipv4_local (struct grub_net_network_level_interface *inter, diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c -index 7d90bf6..1157524 100644 +index 7f44b30f521..4ab2f5c7357 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c -@@ -379,19 +379,23 @@ tftp_open (struct grub_file *file, const char *filename) - return grub_errno; - } +@@ -358,18 +358,22 @@ tftp_open (struct grub_file *file, const char *filename) + file->not_easily_seekable = 1; + file->data = data; + grub_dprintf("tftp", "resolving address for %s\n", file->device->net->server); err = grub_net_resolve_address (file->device->net->server, &addr); if (err) { + grub_dprintf("tftp", "Address resolution failed: %d\n", err); - destroy_pq (data); grub_free (data); return err; } @@ -423,14 +413,14 @@ index 7d90bf6..1157524 100644 if (!data->sock) { + grub_dprintf("tftp", "connection failed\n"); - destroy_pq (data); grub_free (data); return grub_errno; + } diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index addcbfa..d97cdf9 100644 +index f1a52210c0c..117469450d3 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h -@@ -572,10 +572,16 @@ typedef void *grub_efi_handle_t; +@@ -592,10 +592,16 @@ typedef void *grub_efi_handle_t; typedef void *grub_efi_event_t; typedef grub_efi_uint64_t grub_efi_lba_t; typedef grub_efi_uintn_t grub_efi_tpl_t; @@ -451,7 +441,7 @@ index addcbfa..d97cdf9 100644 typedef grub_efi_uint64_t grub_efi_physical_address_t; typedef grub_efi_uint64_t grub_efi_virtual_address_t; -@@ -1450,16 +1456,127 @@ struct grub_efi_simple_text_output_interface +@@ -1474,16 +1480,127 @@ struct grub_efi_simple_text_output_interface }; typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output_interface_t; @@ -582,7 +572,7 @@ index addcbfa..d97cdf9 100644 typedef struct grub_efi_pxe diff --git a/include/grub/net.h b/include/grub/net.h -index ff6d347..3647012 100644 +index 7ae4b6bd805..8a05ec4fe7a 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -447,6 +447,51 @@ struct grub_net_bootp_packet @@ -659,6 +649,3 @@ index ff6d347..3647012 100644 grub_err_t grub_net_add_ipv4_local (struct grub_net_network_level_interface *inf, int mask); --- -1.8.3.1 - diff --git a/0065-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch b/0038-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch similarity index 91% rename from 0065-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch rename to 0038-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch index 8837b09ec33daee58e404985541b333266968d96..bf78c8131abe6bc38d2f3d5630a1ff0abefcc74d 100644 --- a/0065-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch +++ b/0038-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch @@ -1,7 +1,7 @@ -From 6f9c2df8b9b7905038bab5f3627806c00199ae25 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 23 Jun 2016 11:01:39 -0400 -Subject: [PATCH 065/220] Add grub-get-kernel-settings and use it in 10_linux +Subject: [PATCH] Add grub-get-kernel-settings and use it in 10_linux This patch adds grub-get-kernel-settings, which reads the system kernel installation configuration from /etc/sysconfig/kernel, and outputs @@ -11,8 +11,8 @@ debug stanzas. Resolves: rhbz#1226325 --- - Makefile.util.def | 7 ++ configure.ac | 2 + + Makefile.util.def | 7 ++ util/bash-completion.d/grub-completion.bash.in | 22 +++++++ util/grub-get-kernel-settings.3 | 20 ++++++ util/grub-get-kernel-settings.in | 88 ++++++++++++++++++++++++++ @@ -22,29 +22,11 @@ Resolves: rhbz#1226325 create mode 100644 util/grub-get-kernel-settings.3 create mode 100644 util/grub-get-kernel-settings.in -diff --git a/Makefile.util.def b/Makefile.util.def -index e50436a..2215cc7 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -726,6 +726,13 @@ script = { - }; - - script = { -+ name = grub-get-kernel-settings; -+ common = util/grub-get-kernel-settings.in; -+ mansection = 3; -+ installdir = sbin; -+}; -+ -+script = { - name = grub-set-default; - common = util/grub-set-default.in; - mansection = 8; diff --git a/configure.ac b/configure.ac -index 6850166..fc3c2b4 100644 +index 25e1abb59b9..58e57a745fa 100644 --- a/configure.ac +++ b/configure.ac -@@ -62,6 +62,7 @@ grub_TRANSFORM([grub-install]) +@@ -65,6 +65,7 @@ grub_TRANSFORM([grub-install]) grub_TRANSFORM([grub-mkconfig]) grub_TRANSFORM([grub-mkfont]) grub_TRANSFORM([grub-mkimage]) @@ -52,7 +34,7 @@ index 6850166..fc3c2b4 100644 grub_TRANSFORM([grub-glue-efi]) grub_TRANSFORM([grub-mklayout]) grub_TRANSFORM([grub-mkpasswd-pbkdf2]) -@@ -79,6 +80,7 @@ grub_TRANSFORM([grub-file]) +@@ -82,6 +83,7 @@ grub_TRANSFORM([grub-file]) grub_TRANSFORM([grub-bios-setup.3]) grub_TRANSFORM([grub-editenv.1]) grub_TRANSFORM([grub-fstest.3]) @@ -60,14 +42,33 @@ index 6850166..fc3c2b4 100644 grub_TRANSFORM([grub-glue-efi.3]) grub_TRANSFORM([grub-install.1]) grub_TRANSFORM([grub-kbdcomp.3]) +diff --git a/Makefile.util.def b/Makefile.util.def +index 8ca4c14f0b9..43a1c7453b1 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -733,6 +733,13 @@ script = { + installdir = sbin; + }; + ++script = { ++ name = grub-get-kernel-settings; ++ common = util/grub-get-kernel-settings.in; ++ mansection = 3; ++ installdir = sbin; ++}; ++ + script = { + name = grub-set-default; + common = util/grub-set-default.in; diff --git a/util/bash-completion.d/grub-completion.bash.in b/util/bash-completion.d/grub-completion.bash.in -index 44bf135..5c4acd4 100644 +index 44bf135b9f8..5c4acd496d4 100644 --- a/util/bash-completion.d/grub-completion.bash.in +++ b/util/bash-completion.d/grub-completion.bash.in -@@ -265,6 +265,28 @@ unset __grub_sparc64_setup_program +@@ -264,6 +264,28 @@ have ${__grub_sparc64_setup_program} && \ + unset __grub_sparc64_setup_program - # ++# +# grub-get-kernel-settings +# +_grub_get_kernel_settings () { @@ -89,13 +90,12 @@ index 44bf135..5c4acd4 100644 +unset __grub_get_kernel_settings_program + + -+# + # # grub-install # - _grub_install () { diff --git a/util/grub-get-kernel-settings.3 b/util/grub-get-kernel-settings.3 new file mode 100644 -index 0000000..ba33330 +index 00000000000..ba33330e28d --- /dev/null +++ b/util/grub-get-kernel-settings.3 @@ -0,0 +1,20 @@ @@ -121,7 +121,7 @@ index 0000000..ba33330 +.BR "info grub" diff --git a/util/grub-get-kernel-settings.in b/util/grub-get-kernel-settings.in new file mode 100644 -index 0000000..7e87dfc +index 00000000000..7e87dfccc0e --- /dev/null +++ b/util/grub-get-kernel-settings.in @@ -0,0 +1,88 @@ @@ -214,7 +214,7 @@ index 0000000..7e87dfc + echo export GRUB_UPDATE_DEFAULT_KERNEL +fi diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index 4e7a875..6247a0b 100644 +index ba14cf6261c..005f093809b 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -45,6 +45,7 @@ grub_probe="${sbindir}/@grub_probe@" @@ -231,11 +231,11 @@ index 4e7a875..6247a0b 100644 +eval "$("${grub_get_kernel_settings}")" || true + - if [ "x$GRUB_DISABLE_UUID" != "xtrue" ]; then - if [ -z "$GRUB_DEVICE_UUID" ]; then - GRUB_DEVICE_UUID="$GRUB_DEVICE_UUID_GENERATED" + if [ "x${GRUB_DISABLE_UUID}" = "xtrue" ]; then + if [ -z "${GRUB_DISABLE_LINUX_UUID}" ]; then + GRUB_DISABLE_LINUX_UUID="true" diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 12a20c9..55f4aa7 100644 +index 786dbabb4a8..292e333324b 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -111,7 +111,8 @@ linux_entry () @@ -258,7 +258,7 @@ index 12a20c9..55f4aa7 100644 echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/" else echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/" -@@ -295,11 +299,15 @@ while [ "x$list" != "x" ] ; do +@@ -306,11 +310,15 @@ while [ "x$list" != "x" ] ; do fi if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then @@ -276,7 +276,7 @@ index 12a20c9..55f4aa7 100644 if [ -z "$boot_device_id" ]; then boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" fi -@@ -308,10 +316,15 @@ while [ "x$list" != "x" ] ; do +@@ -319,10 +327,15 @@ while [ "x$list" != "x" ] ; do is_top_level=false fi @@ -294,6 +294,3 @@ index 12a20c9..55f4aa7 100644 "single ${GRUB_CMDLINE_LINUX}" fi --- -1.8.3.1 - diff --git a/0039-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch b/0039-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch deleted file mode 100644 index 6507767840db4c2d89d1a48aa6fdef470d36e5c8..0000000000000000000000000000000000000000 --- a/0039-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 72ffa52429b18c75f461c5dfa339c05b4bed2788 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 28 Oct 2013 10:13:27 -0400 -Subject: [PATCH 039/220] F10 doesn't work on serial, so don't tell the user to - hit it (#987443) - -Signed-off-by: Peter Jones ---- - grub-core/normal/menu_text.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index 537d4bf..452d55b 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -157,7 +157,7 @@ print_message (int nested, int edit, struct grub_term_output *term, int dry_run) - - if (edit) - { -- ret += grub_print_message_indented_real (_("Press Ctrl-x or F10 to start, Ctrl-c or F2 for a \ -+ ret += grub_print_message_indented_real (_("Press Ctrl-x to start, Ctrl-c for a \ - command prompt or Escape to discard edits and return to the menu. Pressing Tab lists possible completions."), - STANDARD_MARGIN, STANDARD_MARGIN, - term, dry_run); --- -1.8.3.1 - diff --git a/0067-bz1374141-fix-incorrect-mask-for-ppc64.patch b/0039-bz1374141-fix-incorrect-mask-for-ppc64.patch similarity index 89% rename from 0067-bz1374141-fix-incorrect-mask-for-ppc64.patch rename to 0039-bz1374141-fix-incorrect-mask-for-ppc64.patch index bf2455abb03d4491e28d1e3f9462e9cf77190ffa..ef992f5dab33505802a3be9d76ef6476b566da70 100644 --- a/0067-bz1374141-fix-incorrect-mask-for-ppc64.patch +++ b/0039-bz1374141-fix-incorrect-mask-for-ppc64.patch @@ -1,7 +1,7 @@ -From 293c75639a43d2ff06fe4824cb306ed81e1aa5af Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Masahiro Matsuya Date: Sat, 29 Oct 2016 08:35:26 +0900 -Subject: [PATCH 067/220] bz1374141 fix incorrect mask for ppc64 +Subject: [PATCH] bz1374141 fix incorrect mask for ppc64 The netmask configured in firmware is not respected on ppc64 (big endian). When 255.255.252.0 is set as netmask in firmware, the following is the value of bootpath string in grub_ieee1275_parse_bootpath(). @@ -25,12 +25,15 @@ This patch changes it as below. 0000 0000 0000 0000 0000 0011 1111 1111 # ~grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4)) The count of zero with __builtin_clz can be 22. (clz counts the number of one bits preceding the most significant zero bit) + +Signed-off-by: Masahiro Matsuya +Signed-off-by: Robbie Harwood --- grub-core/net/drivers/ieee1275/ofnet.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c -index ac4e62a..3860b6f 100644 +index ac4e62a95c9..3860b6f78d8 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -220,8 +220,7 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath, @@ -43,6 +46,3 @@ index ac4e62a..3860b6f 100644 } if (gateway_addr.ipv4 != 0) --- -1.8.3.1 - diff --git a/0068-Make-grub_fatal-also-backtrace.patch b/0040-Make-grub_fatal-also-backtrace.patch similarity index 91% rename from 0068-Make-grub_fatal-also-backtrace.patch rename to 0040-Make-grub_fatal-also-backtrace.patch index 29cac5004d5905c98249f2e09cece3aa11bea565..3534b05a046c0d2225eceaaef773bcfbbfa4f497 100644 --- a/0068-Make-grub_fatal-also-backtrace.patch +++ b/0040-Make-grub_fatal-also-backtrace.patch @@ -1,7 +1,7 @@ -From fc5bc8610eb9e556ced1f1b91f9c4f34a51f3852 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 27 Jan 2016 09:22:42 -0500 -Subject: [PATCH 068/220] Make grub_fatal() also backtrace. +Subject: [PATCH] Make grub_fatal() also backtrace. --- grub-core/Makefile.core.def | 3 ++ @@ -13,10 +13,10 @@ Subject: [PATCH 068/220] Make grub_fatal() also backtrace. create mode 100644 grub-core/lib/arm64/backtrace.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 99466b1..ebc5580 100644 +index c15e91943b9..058c88ac3af 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -186,6 +186,9 @@ kernel = { +@@ -188,6 +188,9 @@ kernel = { softdiv = lib/division.c; @@ -27,7 +27,7 @@ index 99466b1..ebc5580 100644 i386_xen = kern/i386/dl.c; i386_xen_pvh = kern/i386/dl.c; diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 1c560ea..04371ac 100644 +index 63b586d09cb..a3e215155bd 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -24,6 +24,7 @@ @@ -38,7 +38,7 @@ index 1c560ea..04371ac 100644 union printf_arg { -@@ -1101,8 +1102,13 @@ grub_xasprintf (const char *fmt, ...) +@@ -1199,8 +1200,13 @@ grub_printf_fmt_check (const char *fmt, const char *fmt_expected) static void __attribute__ ((noreturn)) grub_abort (void) { @@ -55,7 +55,7 @@ index 1c560ea..04371ac 100644 #endif diff --git a/grub-core/lib/arm64/backtrace.c b/grub-core/lib/arm64/backtrace.c new file mode 100644 -index 0000000..1079b53 +index 00000000000..1079b5380e1 --- /dev/null +++ b/grub-core/lib/arm64/backtrace.c @@ -0,0 +1,62 @@ @@ -122,7 +122,7 @@ index 0000000..1079b53 +} + diff --git a/grub-core/lib/backtrace.c b/grub-core/lib/backtrace.c -index 825a880..c0ad6ab 100644 +index 825a8800e25..c0ad6ab8be1 100644 --- a/grub-core/lib/backtrace.c +++ b/grub-core/lib/backtrace.c @@ -29,6 +29,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); @@ -142,7 +142,7 @@ index 825a880..c0ad6ab 100644 } diff --git a/grub-core/lib/i386/backtrace.c b/grub-core/lib/i386/backtrace.c -index c3e03c7..c67273d 100644 +index c3e03c7275c..c67273db3ae 100644 --- a/grub-core/lib/i386/backtrace.c +++ b/grub-core/lib/i386/backtrace.c @@ -15,11 +15,23 @@ @@ -170,6 +170,3 @@ index c3e03c7..c67273d 100644 #include #include #include --- -1.8.3.1 - diff --git a/0041-Don-t-draw-a-border-around-the-menu.patch b/0041-Don-t-draw-a-border-around-the-menu.patch deleted file mode 100644 index e77973aa8c47adb2a1ccdaedb953fb073e17a999..0000000000000000000000000000000000000000 --- a/0041-Don-t-draw-a-border-around-the-menu.patch +++ /dev/null @@ -1,74 +0,0 @@ -From 6d92979792752de9af962a75f399768c655ce92e Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Wed, 15 May 2013 16:47:33 -0400 -Subject: [PATCH 041/220] Don't draw a border around the menu - -It looks cleaner without it. ---- - grub-core/normal/menu_text.c | 43 ------------------------------------------- - 1 file changed, 43 deletions(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index 452d55b..1ed2bd9 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -108,47 +108,6 @@ grub_print_message_indented (const char *msg, int margin_left, int margin_right, - grub_print_message_indented_real (msg, margin_left, margin_right, term, 0); - } - --static void --draw_border (struct grub_term_output *term, const struct grub_term_screen_geometry *geo) --{ -- int i; -- -- grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); -- -- grub_term_gotoxy (term, (struct grub_term_coordinate) { geo->first_entry_x - 1, -- geo->first_entry_y - 1 }); -- grub_putcode (GRUB_UNICODE_CORNER_UL, term); -- for (i = 0; i < geo->entry_width + 1; i++) -- grub_putcode (GRUB_UNICODE_HLINE, term); -- grub_putcode (GRUB_UNICODE_CORNER_UR, term); -- -- for (i = 0; i < geo->num_entries; i++) -- { -- grub_term_gotoxy (term, (struct grub_term_coordinate) { geo->first_entry_x - 1, -- geo->first_entry_y + i }); -- grub_putcode (GRUB_UNICODE_VLINE, term); -- grub_term_gotoxy (term, -- (struct grub_term_coordinate) { geo->first_entry_x + geo->entry_width + 1, -- geo->first_entry_y + i }); -- grub_putcode (GRUB_UNICODE_VLINE, term); -- } -- -- grub_term_gotoxy (term, -- (struct grub_term_coordinate) { geo->first_entry_x - 1, -- geo->first_entry_y - 1 + geo->num_entries + 1 }); -- grub_putcode (GRUB_UNICODE_CORNER_LL, term); -- for (i = 0; i < geo->entry_width + 1; i++) -- grub_putcode (GRUB_UNICODE_HLINE, term); -- grub_putcode (GRUB_UNICODE_CORNER_LR, term); -- -- grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); -- -- grub_term_gotoxy (term, -- (struct grub_term_coordinate) { geo->first_entry_x - 1, -- (geo->first_entry_y - 1 + geo->num_entries -- + GRUB_TERM_MARGIN + 1) }); --} -- - static int - print_message (int nested, int edit, struct grub_term_output *term, int dry_run) - { -@@ -406,8 +365,6 @@ grub_menu_init_page (int nested, int edit, - - grub_term_normal_color = grub_color_menu_normal; - grub_term_highlight_color = grub_color_menu_highlight; -- if (geo->border) -- draw_border (term, geo); - grub_term_normal_color = old_color_normal; - grub_term_highlight_color = old_color_highlight; - geo->timeout_y = geo->first_entry_y + geo->num_entries --- -1.8.3.1 - diff --git a/0069-Fix-up-some-man-pages-rpmdiff-noticed.patch b/0041-Fix-up-some-man-pages-rpmdiff-noticed.patch similarity index 90% rename from 0069-Fix-up-some-man-pages-rpmdiff-noticed.patch rename to 0041-Fix-up-some-man-pages-rpmdiff-noticed.patch index c079cdc4f0924d828e8ae745142a131857fbc70a..be5841754b5e021bbe42b7740e3b2e55945a5314 100644 --- a/0069-Fix-up-some-man-pages-rpmdiff-noticed.patch +++ b/0041-Fix-up-some-man-pages-rpmdiff-noticed.patch @@ -1,7 +1,7 @@ -From b059bbecd37f4111fa514a6b7bbda9910325a0f5 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 23 Sep 2014 09:58:49 -0400 -Subject: [PATCH 069/220] Fix up some man pages rpmdiff noticed. +Subject: [PATCH] Fix up some man pages rpmdiff noticed. --- configure.ac | 2 ++ @@ -13,10 +13,10 @@ Subject: [PATCH 069/220] Fix up some man pages rpmdiff noticed. create mode 100644 util/grub-syslinux2cfg.1 diff --git a/configure.ac b/configure.ac -index fc3c2b4..eb851b8 100644 +index 58e57a745fa..a0030632220 100644 --- a/configure.ac +++ b/configure.ac -@@ -84,6 +84,7 @@ grub_TRANSFORM([grub-get-kernel-settings.3]) +@@ -87,6 +87,7 @@ grub_TRANSFORM([grub-get-kernel-settings.3]) grub_TRANSFORM([grub-glue-efi.3]) grub_TRANSFORM([grub-install.1]) grub_TRANSFORM([grub-kbdcomp.3]) @@ -24,7 +24,7 @@ index fc3c2b4..eb851b8 100644 grub_TRANSFORM([grub-menulst2cfg.1]) grub_TRANSFORM([grub-mkconfig.1]) grub_TRANSFORM([grub-mkfont.3]) -@@ -102,6 +103,7 @@ grub_TRANSFORM([grub-render-label.3]) +@@ -105,6 +106,7 @@ grub_TRANSFORM([grub-render-label.3]) grub_TRANSFORM([grub-script-check.3]) grub_TRANSFORM([grub-set-default.1]) grub_TRANSFORM([grub-sparc64-setup.3]) @@ -34,7 +34,7 @@ index fc3c2b4..eb851b8 100644 if test "x$TARGET_CFLAGS" = x; then diff --git a/util/grub-macbless.8 b/util/grub-macbless.8 new file mode 100644 -index 0000000..ae842f3 +index 00000000000..ae842f3a606 --- /dev/null +++ b/util/grub-macbless.8 @@ -0,0 +1,26 @@ @@ -65,7 +65,7 @@ index 0000000..ae842f3 +.SH SEE ALSO +.BR "info grub" diff --git a/util/grub-mkimage.1 b/util/grub-mkimage.1 -index 4dea4f5..0eaaafe 100644 +index 4dea4f54597..0eaaafe505b 100644 --- a/util/grub-mkimage.1 +++ b/util/grub-mkimage.1 @@ -17,7 +17,7 @@ @@ -79,7 +79,7 @@ index 4dea4f5..0eaaafe 100644 .TP diff --git a/util/grub-syslinux2cfg.1 b/util/grub-syslinux2cfg.1 new file mode 100644 -index 0000000..8530948 +index 00000000000..85309482718 --- /dev/null +++ b/util/grub-syslinux2cfg.1 @@ -0,0 +1,65 @@ @@ -148,6 +148,3 @@ index 0000000..8530948 + +.SH SEE ALSO +.BR "info grub" --- -1.8.3.1 - diff --git a/0071-Make-our-info-pages-say-grub2-where-appropriate.patch b/0042-Make-our-info-pages-say-grub2-where-appropriate.patch similarity index 89% rename from 0071-Make-our-info-pages-say-grub2-where-appropriate.patch rename to 0042-Make-our-info-pages-say-grub2-where-appropriate.patch index 2c199076749ac96a1ea71945c5f91c5d9a6e401d..be28efd517f3d379a1c3ce9775f917ce83cbfefb 100644 --- a/0071-Make-our-info-pages-say-grub2-where-appropriate.patch +++ b/0042-Make-our-info-pages-say-grub2-where-appropriate.patch @@ -1,7 +1,7 @@ -From 13afb4d63420d8e1578efc8f5a3fe66c9c14e88a Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 9 Jul 2019 12:59:58 +0200 -Subject: [PATCH 071/220] Make our info pages say "grub2" where appropriate. +Subject: [PATCH] Make our info pages say "grub2" where appropriate. This needs to be hooked up to --program-transform=, but I haven't had time. @@ -9,11 +9,11 @@ time. Signed-off-by: Peter Jones --- docs/grub-dev.texi | 4 +- - docs/grub.texi | 318 ++++++++++++++++++++++++++--------------------------- - 2 files changed, 161 insertions(+), 161 deletions(-) + docs/grub.texi | 321 ++++++++++++++++++++++++++++------------------------- + 2 files changed, 171 insertions(+), 154 deletions(-) diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi -index ee389fd..e3fed73 100644 +index 6c629a23e2d..19f708ee662 100644 --- a/docs/grub-dev.texi +++ b/docs/grub-dev.texi @@ -1,7 +1,7 @@ @@ -35,7 +35,7 @@ index ee389fd..e3fed73 100644 @setchapternewpage odd diff --git a/docs/grub.texi b/docs/grub.texi -index 221064b..960e5f3 100644 +index 69f08d289f9..0615d0ed97e 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1,7 +1,7 @@ @@ -212,7 +212,7 @@ index 221064b..960e5f3 100644 # @kbd{umount /mnt} @end group @end example -@@ -689,16 +689,16 @@ floppy instead of exposing the USB drive as a hard disk (they call it +@@ -689,30 +689,37 @@ floppy instead of exposing the USB drive as a hard disk (they call it @example # @kbd{losetup /dev/loop0 /dev/sdb1} # @kbd{mount /dev/loop0 /mnt/usb} @@ -223,17 +223,14 @@ index 221064b..960e5f3 100644 This install doesn't conflict with standard install as long as they are in separate directories. --Note that @command{grub-install} is actually just a shell script and the --real task is done by other tools such as @command{grub-mkimage}. Therefore, +Note that @command{grub2-install} is actually just a shell script and the +real task is done by other tools such as @command{grub2-mkimage}. Therefore, - you may run those commands directly to install GRUB, without using --@command{grub-install}. Don't do that, however, unless you are very familiar ++you may run those commands directly to install GRUB, without using +@command{grub2-install}. Don't do that, however, unless you are very familiar - with the internals of GRUB. Installing a boot loader on a running OS may be - extremely dangerous. - -@@ -706,20 +706,20 @@ On EFI systems for fixed disk install you have to mount EFI System Partition. ++with the internals of GRUB. Installing a boot loader on a running OS may be ++extremely dangerous. ++ + On EFI systems for fixed disk install you have to mount EFI System Partition. If you mount it at @file{/boot/efi} then you don't need any special arguments: @example @@ -257,7 +254,7 @@ index 221064b..960e5f3 100644 @end example @node Making a GRUB bootable CD-ROM -@@ -739,10 +739,10 @@ usually also need to include a configuration file @file{grub.cfg} and some +@@ -732,10 +739,10 @@ usually also need to include a configuration file @file{grub.cfg} and some other GRUB modules. To make a simple generic GRUB rescue CD, you can use the @@ -270,7 +267,7 @@ index 221064b..960e5f3 100644 @end example You will often need to include other files in your image. To do this, first -@@ -765,7 +765,7 @@ directory @file{iso/}. +@@ -758,7 +765,7 @@ directory @file{iso/}. Finally, make the image: @example @@ -279,7 +276,7 @@ index 221064b..960e5f3 100644 @end example This produces a file named @file{grub.iso}, which then can be burned -@@ -781,7 +781,7 @@ storage devices. +@@ -774,7 +781,7 @@ storage devices. @node Device map @section The map between BIOS drives and OS devices @@ -288,7 +285,7 @@ index 221064b..960e5f3 100644 etc.) read it to map BIOS drives to OS devices. This file consists of lines like this: -@@ -1225,23 +1225,23 @@ need to write the whole thing by hand. +@@ -1254,23 +1261,23 @@ need to write the whole thing by hand. @node Simple configuration @section Simple configuration handling @@ -317,7 +314,7 @@ index 221064b..960e5f3 100644 valid POSIX shell input; normally, it will just be a sequence of @samp{KEY=value} lines, but if the value contains spaces or other special characters then it must be quoted. For example: -@@ -1279,7 +1279,7 @@ works it's not recommended since titles often contain unstable device names +@@ -1308,7 +1315,7 @@ works it's not recommended since titles often contain unstable device names and may be translated If you set this to @samp{saved}, then the default menu entry will be that @@ -326,7 +323,7 @@ index 221064b..960e5f3 100644 the environment block, which may not be available in all situations (@pxref{Environment block}). -@@ -1290,7 +1290,7 @@ If this option is set to @samp{true}, then, when an entry is selected, save +@@ -1319,7 +1326,7 @@ If this option is set to @samp{true}, then, when an entry is selected, save it as a new default entry for use by future runs of GRUB. This is only useful if @samp{GRUB_DEFAULT=saved}; it is a separate option because @samp{GRUB_DEFAULT=saved} is useful without this option, in conjunction with @@ -335,7 +332,7 @@ index 221064b..960e5f3 100644 This option relies on the environment block, which may not be available in all situations (@pxref{Environment block}). -@@ -1420,7 +1420,7 @@ intel-uc.img intel-ucode.img amd-uc.img amd-ucode.img early_ucode.cpio microcode +@@ -1449,7 +1456,7 @@ intel-uc.img intel-ucode.img amd-uc.img amd-ucode.img early_ucode.cpio microcode @end example @item GRUB_DISABLE_LINUX_UUID @@ -344,7 +341,7 @@ index 221064b..960e5f3 100644 universally-unique identifiers (UUIDs) to identify the root filesystem to the Linux kernel, using a @samp{root=UUID=...} kernel parameter. This is usually more reliable, but in some cases it may not be appropriate. To -@@ -1442,7 +1442,7 @@ If this option is set to @samp{true}, disable the generation of recovery +@@ -1471,7 +1478,7 @@ If this option is set to @samp{true}, disable the generation of recovery mode menu entries. @item GRUB_DISABLE_UUID @@ -353,7 +350,7 @@ index 221064b..960e5f3 100644 universally-unique identifiers (UUIDs) to identify various filesystems to search for files. This is usually more reliable, but in some cases it may not be appropriate. To disable this use of UUIDs, set this option to -@@ -1451,12 +1451,12 @@ not be appropriate. To disable this use of UUIDs, set this option to +@@ -1482,12 +1489,12 @@ not be appropriate. To disable this use of UUIDs, set this option to @item GRUB_VIDEO_BACKEND If graphical video support is required, either because the @samp{gfxterm} graphical terminal is in use or because @samp{GRUB_GFXPAYLOAD_LINUX} is set, @@ -369,7 +366,7 @@ index 221064b..960e5f3 100644 @item GRUB_GFXMODE Set the resolution used on the @samp{gfxterm} graphical terminal. Note that -@@ -1488,7 +1488,7 @@ boot sequence. If you have problems, set this option to @samp{text} and +@@ -1519,7 +1526,7 @@ boot sequence. If you have problems, set this option to @samp{text} and GRUB will tell Linux to boot in normal text mode. @item GRUB_DISABLE_OS_PROBER @@ -378,7 +375,7 @@ index 221064b..960e5f3 100644 @command{os-prober} program, if installed, to discover other operating systems installed on the same system and generate appropriate menu entries for them. Set this option to @samp{true} to disable this. -@@ -1498,7 +1498,7 @@ List of space-separated FS UUIDs of filesystems to be ignored from os-prober +@@ -1529,7 +1536,7 @@ List of space-separated FS UUIDs of filesystems to be ignored from os-prober output. For efi chainloaders it's @@ @item GRUB_DISABLE_SUBMENU @@ -387,7 +384,7 @@ index 221064b..960e5f3 100644 the kernel with highest version number and put all other found kernels or alternative menu entries for recovery mode in submenu. For entries returned by @command{os-prober} first entry will be put on top level and all others -@@ -1506,11 +1506,11 @@ in submenu. If this option is set to @samp{y}, flat menu with all entries +@@ -1537,11 +1544,11 @@ in submenu. If this option is set to @samp{true}, flat menu with all entries on top level will be generated instead. Changing this option will require changing existing values of @samp{GRUB_DEFAULT}, @samp{fallback} (@pxref{fallback}) and @samp{default} (@pxref{default}) environment variables as well as saved @@ -402,7 +399,7 @@ index 221064b..960e5f3 100644 check for encrypted disks and generate additional commands needed to access them during boot. Note that in this case unattended boot is not possible because GRUB will wait for passphrase to unlock encrypted container. -@@ -1569,7 +1569,7 @@ confusing @samp{GRUB_TIMEOUT_STYLE=countdown} or +@@ -1600,7 +1607,7 @@ confusing @samp{GRUB_TIMEOUT_STYLE=countdown} or @end table @@ -411,7 +408,7 @@ index 221064b..960e5f3 100644 edit the scripts in @file{/etc/grub.d} directly. @file{/etc/grub.d/40_custom} is particularly useful for adding entire custom menu entries; simply type the menu entries you want to add at the end of -@@ -1831,7 +1831,7 @@ images as well. +@@ -1862,7 +1869,7 @@ images as well. Mount this partition on/mnt/boot and disable GRUB in all OSes and manually install self-compiled latest GRUB with: @@ -420,7 +417,7 @@ index 221064b..960e5f3 100644 In all the OSes install GRUB tools but disable installing GRUB in bootsector, so you'll have menu.lst and grub.cfg available for use. Also disable os-prober -@@ -1841,20 +1841,20 @@ use by setting: +@@ -1872,20 +1879,20 @@ use by setting: in /etc/default/grub @@ -444,7 +441,7 @@ index 221064b..960e5f3 100644 @} menuentry "Windows XP" @{ -@@ -1917,15 +1917,15 @@ GRUB supports embedding a configuration file directly into the core image, +@@ -1948,15 +1955,15 @@ GRUB supports embedding a configuration file directly into the core image, so that it is loaded before entering normal mode. This is useful, for example, when it is not straightforward to find the real configuration file, or when you need to debug problems with loading that file. @@ -463,7 +460,7 @@ index 221064b..960e5f3 100644 After the embedded configuration file (if any) is executed, GRUB will load the @samp{normal} module (@pxref{normal}), which will then read the real -@@ -1960,13 +1960,13 @@ included in the core image: +@@ -1991,13 +1998,13 @@ included in the core image: @example @group search.fs_label grub root @@ -481,7 +478,7 @@ index 221064b..960e5f3 100644 else echo "Could not find an example configuration file!" fi -@@ -2490,7 +2490,7 @@ grub-mknetdir --net-directory=/srv/tftp --subdir=/boot/grub -d /usr/lib/grub/i38 +@@ -2521,7 +2528,7 @@ grub-mknetdir --net-directory=/srv/tftp --subdir=/boot/grub -d /usr/lib/grub/i38 @end group @end example @@ -490,7 +487,7 @@ index 221064b..960e5f3 100644 server. The grub.cfg file is placed in the same directory as the path output by -@@ -2675,7 +2675,7 @@ team are: +@@ -2715,7 +2722,7 @@ team are: @end table To take full advantage of this function, install GRUB into the MBR @@ -499,7 +496,7 @@ index 221064b..960e5f3 100644 If you have a laptop which has a similar feature and not in the above list could you figure your address and contribute? -@@ -2736,7 +2736,7 @@ bytes. +@@ -2776,7 +2783,7 @@ bytes. The sole function of @file{boot.img} is to read the first sector of the core image from a local disk and jump to it. Because of the size restriction, @file{boot.img} cannot understand any file system structure, so @@ -508,7 +505,7 @@ index 221064b..960e5f3 100644 core image into @file{boot.img} when installing GRUB. @item diskboot.img -@@ -2766,7 +2766,7 @@ images. +@@ -2806,7 +2813,7 @@ images. @item core.img This is the core image of GRUB. It is built dynamically from the kernel @@ -517,7 +514,7 @@ index 221064b..960e5f3 100644 program. Usually, it contains enough modules to access @file{/boot/grub}, and loads everything else (including menu handling, the ability to load target operating systems, and so on) from the file system at run-time. The -@@ -2818,7 +2818,7 @@ GRUB 2 has no single Stage 2 image. Instead, it loads modules from +@@ -2858,7 +2865,7 @@ GRUB 2 has no single Stage 2 image. Instead, it loads modules from In GRUB 2, images for booting from CD-ROM drives are now constructed using @file{cdboot.img} and @file{core.img}, making sure that the core image contains the @samp{iso9660} module. It is usually best to use the @@ -526,7 +523,7 @@ index 221064b..960e5f3 100644 @item nbgrub There is as yet no equivalent for @file{nbgrub} in GRUB 2; it was used by -@@ -2974,8 +2974,8 @@ There are two ways to specify files, by @dfn{absolute file name} and by +@@ -3014,8 +3021,8 @@ There are two ways to specify files, by @dfn{absolute file name} and by An absolute file name resembles a Unix absolute file name, using @samp{/} for the directory separator (not @samp{\} as in DOS). One @@ -537,7 +534,7 @@ index 221064b..960e5f3 100644 disk. If you omit the device name in an absolute file name, GRUB uses GRUB's @dfn{root device} implicitly. So if you set the root device to, say, @samp{(hd1,1)} by the command @samp{set root=(hd1,1)} (@pxref{set}), -@@ -2983,8 +2983,8 @@ then @code{/boot/kernel} is the same as @code{(hd1,1)/boot/kernel}. +@@ -3023,8 +3030,8 @@ then @code{/boot/kernel} is the same as @code{(hd1,1)/boot/kernel}. On ZFS filesystem the first path component must be @var{volume}@samp{@@}[@var{snapshot}]. @@ -548,7 +545,7 @@ index 221064b..960e5f3 100644 @samp{snap-129}. Trailing @samp{@@} after volume name is mandatory even if snapshot name is omitted. -@@ -3387,7 +3387,7 @@ The more recent release of Minix would then be identified as +@@ -3427,7 +3434,7 @@ The more recent release of Minix would then be identified as @samp{other>minix>minix-3.4.0}. This variable is often set by @samp{GRUB_DEFAULT} (@pxref{Simple @@ -557,7 +554,7 @@ index 221064b..960e5f3 100644 @node fallback -@@ -3477,7 +3477,7 @@ If this variable is set, it names the language code that the +@@ -3517,7 +3524,7 @@ If this variable is set, it names the language code that the example, French would be named as @samp{fr}, and Simplified Chinese as @samp{zh_CN}. @@ -566,7 +563,7 @@ index 221064b..960e5f3 100644 reasonable default for this variable based on the system locale. -@@ -3485,10 +3485,10 @@ reasonable default for this variable based on the system locale. +@@ -3525,10 +3532,10 @@ reasonable default for this variable based on the system locale. @subsection locale_dir If this variable is set, it names the directory where translation files may @@ -579,7 +576,7 @@ index 221064b..960e5f3 100644 default for this variable if internationalization is needed and any translation files are available. -@@ -3606,7 +3606,7 @@ input. The default is not to pause output. +@@ -3646,7 +3653,7 @@ input. The default is not to pause output. The location of the @samp{/boot/grub} directory as an absolute file name (@pxref{File name syntax}). This is normally set by GRUB at startup based @@ -588,7 +585,7 @@ index 221064b..960e5f3 100644 dynamically loaded from this directory, so it must be set correctly in order for many parts of GRUB to work. -@@ -3697,17 +3697,17 @@ GRUB provides an ``environment block'' which can be used to save a small +@@ -3737,17 +3744,17 @@ GRUB provides an ``environment block'' which can be used to save a small amount of state. The environment block is a preallocated 1024-byte file, which normally lives @@ -609,7 +606,7 @@ index 221064b..960e5f3 100644 @samp{GRUB_SAVEDEFAULT} (@pxref{Simple configuration}). -@@ -4398,7 +4398,7 @@ Translate @var{string} into the current language. +@@ -4476,7 +4483,7 @@ Translate @var{string} into the current language. The current language code is stored in the @samp{lang} variable in GRUB's environment (@pxref{lang}). Translation files in MO format are read from @@ -618,7 +615,7 @@ index 221064b..960e5f3 100644 @end deffn -@@ -4793,7 +4793,7 @@ Define a user named @var{user} with password @var{clear-password}. +@@ -4871,7 +4878,7 @@ Define a user named @var{user} with password @var{clear-password}. @deffn Command password_pbkdf2 user hashed-password Define a user named @var{user} with password hash @var{hashed-password}. @@ -627,7 +624,7 @@ index 221064b..960e5f3 100644 to generate password hashes. @xref{Security}. @end deffn -@@ -5651,8 +5651,8 @@ The @samp{password} (@pxref{password}) and @samp{password_pbkdf2} +@@ -5814,8 +5821,8 @@ The @samp{password} (@pxref{password}) and @samp{password_pbkdf2} which has an associated password. @samp{password} sets the password in plain text, requiring @file{grub.cfg} to be secure; @samp{password_pbkdf2} sets the password hashed using the Password-Based Key Derivation Function @@ -638,7 +635,7 @@ index 221064b..960e5f3 100644 In order to enable authentication support, the @samp{superusers} environment variable must be set to a list of usernames, separated by any of spaces, -@@ -5696,7 +5696,7 @@ menuentry "May be run by user1 or a superuser" --users user1 @{ +@@ -5860,7 +5867,7 @@ menuentry "May be run by user1 or a superuser" --users user1 @{ @end group @end example @@ -647,28 +644,26 @@ index 221064b..960e5f3 100644 generating configuration files with authentication. You can use @file{/etc/grub.d/40_custom} to add simple superuser authentication, by adding @kbd{set superusers=} and @kbd{password} or @kbd{password_pbkdf2} -@@ -5721,15 +5721,15 @@ verified with a public key currently trusted by GRUB - validation fails, then file @file{foo} cannot be opened. This failure - may halt or otherwise impact the boot process. +@@ -5887,7 +5894,17 @@ may halt or otherwise impact the boot process. --@comment Unfortunately --pubkey is not yet supported by grub-install, --@comment but we should not bring up internal detail grub-mkimage here + An initial trusted public key can be embedded within the GRUB @file{core.img} + using the @code{--pubkey} option to @command{grub-install} +-(@pxref{Invoking grub-install}). ++(@pxref{Invoking grub2-install}). ++ +@comment Unfortunately --pubkey is not yet supported by grub2-install, +@comment but we should not bring up internal detail grub2-mkimage here - @comment in the user guide (as opposed to developer's manual). - - @comment An initial trusted public key can be embedded within the GRUB - @comment @file{core.img} using the @code{--pubkey} option to --@comment @command{grub-mkimage} (@pxref{Invoking grub-install}). Presently it --@comment is necessary to write a custom wrapper around @command{grub-mkimage} --@comment using the @code{--grub-mkimage} flag to @command{grub-install}. ++@comment in the user guide (as opposed to developer's manual). ++ ++@comment An initial trusted public key can be embedded within the GRUB ++@comment @file{core.img} using the @code{--pubkey} option to +@comment @command{grub2-mkimage} (@pxref{Invoking grub2-install}). Presently it +@comment is necessary to write a custom wrapper around @command{grub2-mkimage} +@comment using the @code{--grub-mkimage} flag to @command{grub2-install}. GRUB uses GPG-style detached signatures (meaning that a file @file{foo.sig} will be produced when file @file{foo} is signed), and -@@ -5749,8 +5749,8 @@ gpg --detach-sign /path/to/file +@@ -5907,8 +5924,8 @@ gpg --detach-sign /path/to/file For successful validation of all of GRUB's subcomponents and the loaded OS kernel, they must all be signed. One way to accomplish this is the following (after having already produced the desired @@ -679,7 +674,7 @@ index 221064b..960e5f3 100644 @example @group -@@ -5772,7 +5772,7 @@ See also: @ref{check_signatures}, @ref{verify_detached}, @ref{trust}, +@@ -5930,7 +5947,7 @@ See also: @ref{check_signatures}, @ref{verify_detached}, @ref{trust}, Note that internally signature enforcement is controlled by setting the environment variable @code{check_signatures} equal to @code{enforce}. Passing one or more @code{--pubkey} options to @@ -688,7 +683,7 @@ index 221064b..960e5f3 100644 equal to @code{enforce} in @file{core.img} prior to processing any configuration files. -@@ -6189,10 +6189,10 @@ Required files are: +@@ -6388,10 +6405,10 @@ Required files are: GRUB's normal start-up procedure involves setting the @samp{prefix} environment variable to a value set in the core image by @@ -701,7 +696,7 @@ index 221064b..960e5f3 100644 things GRUB is supposed to do. If, instead, you only get a rescue shell, this usually means that GRUB -@@ -6218,8 +6218,8 @@ normal +@@ -6417,8 +6434,8 @@ normal However, any problem that leaves you in the rescue shell probably means that GRUB was not correctly installed. It may be more useful to try to reinstall @@ -712,7 +707,7 @@ index 221064b..960e5f3 100644 @itemize @bullet{} @item -@@ -6231,7 +6231,7 @@ is usually better to use UUIDs or file system labels and avoid depending on +@@ -6430,7 +6447,7 @@ is usually better to use UUIDs or file system labels and avoid depending on drive ordering entirely. @item @@ -721,7 +716,7 @@ index 221064b..960e5f3 100644 to a partition but GRUB has already been installed in the master boot record, then the GRUB installation in the partition will be ignored. -@@ -6262,21 +6262,21 @@ entry which claims partition start at block 0. This change will not hamper +@@ -6461,21 +6478,21 @@ entry which claims partition start at block 0. This change will not hamper bootability on other machines. @@ -749,7 +744,7 @@ index 221064b..960e5f3 100644 @table @option @item --help -@@ -6292,13 +6292,13 @@ separate partition or a removable disk. +@@ -6491,13 +6508,13 @@ separate partition or a removable disk. If this option is not specified then it defaults to @file{/boot}, so @example @@ -765,7 +760,7 @@ index 221064b..960e5f3 100644 @end example Here is an example in which you have a separate @dfn{boot} partition which is -@@ -6306,16 +6306,16 @@ mounted on +@@ -6505,16 +6522,16 @@ mounted on @file{/mnt/boot}: @example @@ -785,7 +780,7 @@ index 221064b..960e5f3 100644 extra space in the bootloader embedding area for Reed-Solomon error-correcting codes. This enables GRUB to still boot successfully if some blocks are corrupted. The exact amount of protection offered -@@ -6328,17 +6328,17 @@ installation}) where GRUB does not reside in any unpartitioned space +@@ -6527,17 +6544,17 @@ installation}) where GRUB does not reside in any unpartitioned space outside of the MBR. Disable the Reed-Solomon codes with this option. @end table @@ -808,7 +803,7 @@ index 221064b..960e5f3 100644 @table @option @item --help -@@ -6354,17 +6354,17 @@ it to standard output. +@@ -6553,17 +6570,17 @@ it to standard output. @end table @@ -830,7 +825,7 @@ index 221064b..960e5f3 100644 @table @option @item -c @var{number} -@@ -6382,23 +6382,23 @@ Length of the salt. Defaults to 64. +@@ -6581,23 +6598,23 @@ Length of the salt. Defaults to 64. @end table @@ -860,7 +855,7 @@ index 221064b..960e5f3 100644 @table @option @item --help -@@ -6409,17 +6409,17 @@ Print the version number of GRUB and exit. +@@ -6608,17 +6625,17 @@ Print the version number of GRUB and exit. @end table @@ -882,7 +877,7 @@ index 221064b..960e5f3 100644 passed on directly to @command{xorriso} in @command{mkisofs} emulation mode. Options passed to @command{xorriso} will normally be interpreted as @command{mkisofs} options; if the option @samp{--} is used, then anything -@@ -6434,7 +6434,7 @@ mkdir -p disk/boot/grub +@@ -6633,7 +6650,7 @@ mkdir -p disk/boot/grub grub-mkrescue -o grub.iso disk @end example @@ -891,7 +886,7 @@ index 221064b..960e5f3 100644 @table @option @item --help -@@ -6462,15 +6462,15 @@ Use @var{file} as the @command{xorriso} program, rather than the built-in +@@ -6661,15 +6678,15 @@ Use @var{file} as the @command{xorriso} program, rather than the built-in default. @item --grub-mkimage=@var{file} @@ -911,7 +906,7 @@ index 221064b..960e5f3 100644 system or file system image that GRUB understands, using GRUB's file system drivers via FUSE. (It is only available if FUSE development files were present when GRUB was built.) This has a number of uses: -@@ -6502,13 +6502,13 @@ even if nobody has yet written a FUSE module specifically for that file +@@ -6701,13 +6718,13 @@ even if nobody has yet written a FUSE module specifically for that file system type. @end itemize @@ -927,7 +922,7 @@ index 221064b..960e5f3 100644 non-option arguments (if it is given more than one image, it will treat them as a RAID set), and also accepts the following options: -@@ -6530,13 +6530,13 @@ Show debugging output for conditions matching @var{string}. +@@ -6729,13 +6746,13 @@ Show debugging output for conditions matching @var{string}. @item -K prompt|@var{file} @itemx --zfs-key=prompt|@var{file} Load a ZFS encryption key. If you use @samp{prompt} as the argument, @@ -943,7 +938,7 @@ index 221064b..960e5f3 100644 root of the supplied file system. If @var{device} is just a number, then it will be treated as a partition -@@ -6554,10 +6554,10 @@ Print verbose messages. +@@ -6753,10 +6770,10 @@ Print verbose messages. @end table @@ -957,7 +952,7 @@ index 221064b..960e5f3 100644 or device. @example -@@ -6565,7 +6565,7 @@ grub-probe --target=fs /boot/grub +@@ -6764,7 +6781,7 @@ grub-probe --target=fs /boot/grub grub-probe --target=drive --device /dev/sda1 @end example @@ -966,7 +961,7 @@ index 221064b..960e5f3 100644 argument, and also accepts the following options: @table @option -@@ -6578,16 +6578,16 @@ Print the version number of GRUB and exit. +@@ -6777,16 +6794,16 @@ Print the version number of GRUB and exit. @item -d @itemx --device If this option is given, then the non-option argument is a system device @@ -986,7 +981,7 @@ index 221064b..960e5f3 100644 @item -t @var{target} @itemx --target=@var{target} -@@ -6640,19 +6640,19 @@ Print verbose messages. +@@ -6839,19 +6856,19 @@ Print verbose messages. @end table @@ -1011,6 +1006,3 @@ index 221064b..960e5f3 100644 @table @option @item --help --- -1.8.3.1 - diff --git a/0042-Use-the-standard-margin-for-the-timeout-string.patch b/0042-Use-the-standard-margin-for-the-timeout-string.patch deleted file mode 100644 index 315c176f77facf92d2d25b6188160e6a528b4014..0000000000000000000000000000000000000000 --- a/0042-Use-the-standard-margin-for-the-timeout-string.patch +++ /dev/null @@ -1,43 +0,0 @@ -From ead897508b29261ccf87aa46e778863a351737b2 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Fri, 7 Jun 2013 10:52:32 -0400 -Subject: [PATCH 042/220] Use the standard margin for the timeout string - -So that it aligns with the other messages ---- - grub-core/normal/menu_text.c | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index 1ed2bd9..7681f7d 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -372,7 +372,7 @@ grub_menu_init_page (int nested, int edit, - if (bottom_message) - { - grub_term_gotoxy (term, -- (struct grub_term_coordinate) { GRUB_TERM_MARGIN, -+ (struct grub_term_coordinate) { STANDARD_MARGIN, - geo->timeout_y }); - - print_message (nested, edit, term, 0); -@@ -407,14 +407,14 @@ menu_text_print_timeout (int timeout, void *dataptr) - if (data->timeout_msg == TIMEOUT_UNKNOWN) - { - data->timeout_msg = grub_print_message_indented_real (msg_translated, -- 3, 1, data->term, 1) -+ STANDARD_MARGIN, 1, data->term, 1) - <= data->geo.timeout_lines ? TIMEOUT_NORMAL : TIMEOUT_TERSE; - if (data->timeout_msg == TIMEOUT_TERSE) - { - grub_free (msg_translated); - msg_translated = grub_xasprintf (_("%ds"), timeout); - if (grub_term_width (data->term) < 10) -- data->timeout_msg = TIMEOUT_TERSE_NO_MARGIN; -+ data->timeout_msg = STANDARD_MARGIN; - } - } - --- -1.8.3.1 - diff --git a/0073-macos-just-build-chainloader-entries-don-t-try-any-x.patch b/0043-macos-just-build-chainloader-entries-don-t-try-any-x.patch similarity index 95% rename from 0073-macos-just-build-chainloader-entries-don-t-try-any-x.patch rename to 0043-macos-just-build-chainloader-entries-don-t-try-any-x.patch index daf186ff0e980061c056bda45fe300bd72f4a82a..574d1173538c9cd600aab0751594eb65a20ad5dd 100644 --- a/0073-macos-just-build-chainloader-entries-don-t-try-any-x.patch +++ b/0043-macos-just-build-chainloader-entries-don-t-try-any-x.patch @@ -1,8 +1,7 @@ -From 86b5e0f596cd6266c48dd1829d97f0debb5dc5c6 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 24 May 2017 12:42:32 -0400 -Subject: [PATCH 073/220] macos: just build chainloader entries, don't try any - xnu xnu. +Subject: [PATCH] macos: just build chainloader entries, don't try any xnu xnu. Since our bugs tell us that the xnu boot entries really just don't work most of the time, and they create piles of extra boot entries, because @@ -21,7 +20,7 @@ Signed-off-by: Peter Jones 1 file changed, 18 insertions(+), 60 deletions(-) diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in -index 9b8f596..13a3a6b 100644 +index 1b91c102f35..4b27bd20153 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -42,68 +42,25 @@ if [ -z "${OSPROBED}" ] ; then @@ -105,7 +104,7 @@ index 9b8f596..13a3a6b 100644 } EOF } -@@ -284,11 +241,12 @@ EOF +@@ -292,11 +249,12 @@ EOF echo "$title_correction_code" ;; macosx) @@ -123,6 +122,3 @@ index 9b8f596..13a3a6b 100644 ;; hurd) onstr="$(gettext_printf "(on %s)" "${DEVICE}")" --- -1.8.3.1 - diff --git a/0044-Don-t-munge-raw-spaces-when-we-re-doing-our-cmdline-.patch b/0044-Don-t-munge-raw-spaces-when-we-re-doing-our-cmdline-.patch deleted file mode 100644 index 5e886d4fc8f3e6996d02d6ac950117d187c240c3..0000000000000000000000000000000000000000 --- a/0044-Don-t-munge-raw-spaces-when-we-re-doing-our-cmdline-.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 6fa778275c0765f9d2535118ba0a37065dded86f Mon Sep 17 00:00:00 2001 -From: Hans de Goede -Date: Mon, 30 Jun 2014 14:16:46 -0400 -Subject: [PATCH 044/220] Don't munge raw spaces when we're doing our cmdline - escaping (#923374) - -Signed-off-by: Peter Jones ---- - grub-core/lib/cmdline.c | 11 +---------- - 1 file changed, 1 insertion(+), 10 deletions(-) - -diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c -index e0fb0a9..8e2294d 100644 ---- a/grub-core/lib/cmdline.c -+++ b/grub-core/lib/cmdline.c -@@ -98,16 +98,7 @@ grub_create_loader_cmdline (int argc, char *argv[], char *buf, - - while (*c) - { -- if (*c == ' ') -- { -- *buf++ = '\\'; -- *buf++ = 'x'; -- *buf++ = '2'; -- *buf++ = '0'; -- c++; -- continue; -- } -- else if (*c == '\\' && *(c+1) == 'x' && -+ if (*c == '\\' && *(c+1) == 'x' && - is_hex(*(c+2)) && is_hex(*(c+3))) - { - *buf++ = *c++; --- -1.8.3.1 - diff --git a/0074-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch b/0044-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch similarity index 89% rename from 0074-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch rename to 0044-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch index fecc1f65dff91e817982dda0242e93693c246b7a..68dfc1dc9badcb84c1357847b730a724afb39785 100644 --- a/0074-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch +++ b/0044-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch @@ -1,7 +1,7 @@ -From 4f25cd0b089dadc0be92e9226fd1eb9e2dda594f Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jeff Mahoney Date: Tue, 9 Jul 2019 13:39:45 +0200 -Subject: [PATCH 074/220] grub2/btrfs: Add ability to boot from subvolumes +Subject: [PATCH] grub2/btrfs: Add ability to boot from subvolumes This patch adds the ability to specify a different root on a btrfs filesystem too boot from other than the default one. @@ -19,12 +19,12 @@ variable and loading the config file from the subvolume. Signed-off-by: Jeff Mahoney --- - grub-core/fs/btrfs.c | 548 +++++++++++++++++++++++++++++++++++++++++++++++++-- + grub-core/fs/btrfs.c | 552 +++++++++++++++++++++++++++++++++++++++++++++++++-- include/grub/btrfs.h | 1 + - 2 files changed, 531 insertions(+), 18 deletions(-) + 2 files changed, 533 insertions(+), 20 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index 48bd3d0..6823d97 100644 +index 63203034dfc..f1fff7385b5 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -38,6 +38,9 @@ @@ -36,8 +36,8 @@ index 48bd3d0..6823d97 100644 +#include #include #include - -@@ -78,9 +81,11 @@ struct grub_btrfs_superblock + #include +@@ -79,9 +82,11 @@ struct grub_btrfs_superblock grub_uint64_t generation; grub_uint64_t root_tree; grub_uint64_t chunk_tree; @@ -51,7 +51,7 @@ index 48bd3d0..6823d97 100644 struct grub_btrfs_device this_device; char label[0x100]; grub_uint8_t dummy4[0x100]; -@@ -120,6 +125,7 @@ struct grub_btrfs_data +@@ -121,6 +126,7 @@ struct grub_btrfs_data grub_uint64_t exttree; grub_size_t extsize; struct grub_btrfs_extent_data *extent; @@ -59,7 +59,7 @@ index 48bd3d0..6823d97 100644 }; struct grub_btrfs_chunk_item -@@ -188,6 +194,14 @@ struct grub_btrfs_leaf_descriptor +@@ -191,6 +197,14 @@ struct grub_btrfs_leaf_descriptor } *data; }; @@ -74,7 +74,7 @@ index 48bd3d0..6823d97 100644 struct grub_btrfs_time { grub_int64_t sec; -@@ -233,6 +247,14 @@ struct grub_btrfs_extent_data +@@ -236,6 +250,14 @@ struct grub_btrfs_extent_data #define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100 @@ -89,7 +89,7 @@ index 48bd3d0..6823d97 100644 static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2, 256 * 1048576 * 2, 1048576ULL * 1048576ULL * 2 }; -@@ -1153,6 +1175,62 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, +@@ -1173,6 +1195,62 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, return GRUB_ERR_NONE; } @@ -152,7 +152,7 @@ index 48bd3d0..6823d97 100644 static struct grub_btrfs_data * grub_btrfs_mount (grub_device_t dev) { -@@ -1188,6 +1266,13 @@ grub_btrfs_mount (grub_device_t dev) +@@ -1208,6 +1286,13 @@ grub_btrfs_mount (grub_device_t dev) data->devices_attached[0].dev = dev; data->devices_attached[0].id = data->sblock.this_device.device_id; @@ -166,10 +166,11 @@ index 48bd3d0..6823d97 100644 return data; } -@@ -1654,6 +1739,91 @@ get_root (struct grub_btrfs_data *data, struct grub_btrfs_key *key, +@@ -1673,6 +1758,91 @@ get_root (struct grub_btrfs_data *data, struct grub_btrfs_key *key, + return GRUB_ERR_NONE; } - static grub_err_t ++static grub_err_t +find_pathname(struct grub_btrfs_data *data, grub_uint64_t objectid, + grub_uint64_t fs_root, const char *name, char **pathname) +{ @@ -254,11 +255,10 @@ index 48bd3d0..6823d97 100644 + return 0; +} + -+static grub_err_t + static grub_err_t find_path (struct grub_btrfs_data *data, const char *path, struct grub_btrfs_key *key, - grub_uint64_t *tree, grub_uint8_t *type) -@@ -1671,14 +1841,26 @@ find_path (struct grub_btrfs_data *data, +@@ -1691,14 +1861,26 @@ find_path (struct grub_btrfs_data *data, char *origpath = NULL; unsigned symlinks_max = 32; @@ -289,7 +289,7 @@ index 48bd3d0..6823d97 100644 while (1) { while (path[0] == '/') -@@ -1851,9 +2033,21 @@ find_path (struct grub_btrfs_data *data, +@@ -1871,9 +2053,21 @@ find_path (struct grub_btrfs_data *data, path = path_alloc = tmp; if (path[0] == '/') { @@ -314,45 +314,50 @@ index 48bd3d0..6823d97 100644 } continue; } -@@ -2094,6 +2288,20 @@ grub_btrfs_read (grub_file_t file, char *buf, grub_size_t len) +@@ -2114,18 +2308,10 @@ grub_btrfs_read (grub_file_t file, char *buf, grub_size_t len) data->tree, file->offset, buf, len); } +-static grub_err_t +-grub_btrfs_uuid (grub_device_t device, char **uuid) +static char * +btrfs_unparse_uuid(struct grub_btrfs_data *data) -+{ + { +- struct grub_btrfs_data *data; +- +- *uuid = NULL; +- +- data = grub_btrfs_mount (device); +- if (!data) +- return grub_errno; +- +- *uuid = grub_xasprintf ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x", + return grub_xasprintf ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x", -+ grub_be_to_cpu16 (data->sblock.uuid[0]), -+ grub_be_to_cpu16 (data->sblock.uuid[1]), -+ grub_be_to_cpu16 (data->sblock.uuid[2]), -+ grub_be_to_cpu16 (data->sblock.uuid[3]), -+ grub_be_to_cpu16 (data->sblock.uuid[4]), -+ grub_be_to_cpu16 (data->sblock.uuid[5]), -+ grub_be_to_cpu16 (data->sblock.uuid[6]), -+ grub_be_to_cpu16 (data->sblock.uuid[7])); + grub_be_to_cpu16 (data->sblock.uuid[0]), + grub_be_to_cpu16 (data->sblock.uuid[1]), + grub_be_to_cpu16 (data->sblock.uuid[2]), +@@ -2134,6 +2320,20 @@ grub_btrfs_uuid (grub_device_t device, char **uuid) + grub_be_to_cpu16 (data->sblock.uuid[5]), + grub_be_to_cpu16 (data->sblock.uuid[6]), + grub_be_to_cpu16 (data->sblock.uuid[7])); +} + - static grub_err_t - grub_btrfs_uuid (grub_device_t device, char **uuid) - { -@@ -2105,15 +2313,7 @@ grub_btrfs_uuid (grub_device_t device, char **uuid) - if (!data) - return grub_errno; - -- *uuid = grub_xasprintf ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x", -- grub_be_to_cpu16 (data->sblock.uuid[0]), -- grub_be_to_cpu16 (data->sblock.uuid[1]), -- grub_be_to_cpu16 (data->sblock.uuid[2]), -- grub_be_to_cpu16 (data->sblock.uuid[3]), -- grub_be_to_cpu16 (data->sblock.uuid[4]), -- grub_be_to_cpu16 (data->sblock.uuid[5]), -- grub_be_to_cpu16 (data->sblock.uuid[6]), -- grub_be_to_cpu16 (data->sblock.uuid[7])); ++static grub_err_t ++grub_btrfs_uuid (grub_device_t device, char **uuid) ++{ ++ struct grub_btrfs_data *data; ++ ++ *uuid = NULL; ++ ++ data = grub_btrfs_mount (device); ++ if (!data) ++ return grub_errno; ++ + *uuid = btrfs_unparse_uuid(data); grub_btrfs_unmount (data); -@@ -2170,6 +2370,242 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), +@@ -2190,6 +2390,242 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), } #endif @@ -595,7 +600,7 @@ index 48bd3d0..6823d97 100644 static struct grub_fs grub_btrfs_fs = { .name = "btrfs", .fs_dir = grub_btrfs_dir, -@@ -2185,12 +2621,88 @@ static struct grub_fs grub_btrfs_fs = { +@@ -2205,12 +2641,88 @@ static struct grub_fs grub_btrfs_fs = { #endif }; @@ -685,7 +690,7 @@ index 48bd3d0..6823d97 100644 + +// vim: si et sw=2: diff --git a/include/grub/btrfs.h b/include/grub/btrfs.h -index 9d93fb6..234ad97 100644 +index 9d93fb6c182..234ad976771 100644 --- a/include/grub/btrfs.h +++ b/include/grub/btrfs.h @@ -29,6 +29,7 @@ enum @@ -696,6 +701,3 @@ index 9d93fb6..234ad97 100644 GRUB_BTRFS_ITEM_TYPE_CHUNK = 0xe4 }; --- -1.8.3.1 - diff --git a/0075-export-btrfs_subvol-and-btrfs_subvolid.patch b/0045-export-btrfs_subvol-and-btrfs_subvolid.patch similarity index 76% rename from 0075-export-btrfs_subvol-and-btrfs_subvolid.patch rename to 0045-export-btrfs_subvol-and-btrfs_subvolid.patch index 29258015b6f3f0ce89335bbf6b2095404fc7409f..d38a6b878db3366d4236c37971d1561dd6b846e4 100644 --- a/0075-export-btrfs_subvol-and-btrfs_subvolid.patch +++ b/0045-export-btrfs_subvol-and-btrfs_subvolid.patch @@ -1,7 +1,7 @@ -From 2f9525397b30997f24ff1e9fd508839b6d149da5 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Wed, 18 Dec 2013 09:57:04 +0000 -Subject: [PATCH 075/220] export btrfs_subvol and btrfs_subvolid +Subject: [PATCH] export btrfs_subvol and btrfs_subvolid We should export btrfs_subvol and btrfs_subvolid to have both visible to subsidiary configuration files loaded using configfile. @@ -12,10 +12,10 @@ Signed-off-by: Michael Chang 1 file changed, 2 insertions(+) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index 6823d97..2d099b1 100644 +index f1fff7385b5..ad1b56b716d 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c -@@ -2694,6 +2694,8 @@ GRUB_MOD_INIT (btrfs) +@@ -2714,6 +2714,8 @@ GRUB_MOD_INIT (btrfs) subvol_set_env); grub_register_variable_hook ("btrfs_subvolid", subvolid_get_env, subvolid_set_env); @@ -24,6 +24,3 @@ index 6823d97..2d099b1 100644 } GRUB_MOD_FINI (btrfs) --- -1.8.3.1 - diff --git a/0046-Don-t-emit-Booting-.-message.patch b/0046-Don-t-emit-Booting-.-message.patch deleted file mode 100644 index 0eef6ad6f9a038e72f484891d43af76c9f762964..0000000000000000000000000000000000000000 --- a/0046-Don-t-emit-Booting-.-message.patch +++ /dev/null @@ -1,52 +0,0 @@ -From a71ee9f8f976cc09c301c8c1ceb8ca0859880130 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 18 Feb 2014 09:37:49 -0500 -Subject: [PATCH 046/220] Don't emit "Booting ..." message. - -UI team still hates this stuff, so we're disabling it for RHEL 7. - -Resolves: rhbz#1023142 - -Signed-off-by: Peter Jones ---- - grub-core/normal/menu.c | 4 +++- - grub-core/normal/menu_entry.c | 3 --- - 2 files changed, 3 insertions(+), 4 deletions(-) - -diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c -index 9175ad2..783bde5 100644 ---- a/grub-core/normal/menu.c -+++ b/grub-core/normal/menu.c -@@ -839,12 +839,14 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) - - /* Callback invoked immediately before a menu entry is executed. */ - static void --notify_booting (grub_menu_entry_t entry, -+notify_booting (grub_menu_entry_t __attribute__((unused)) entry, - void *userdata __attribute__((unused))) - { -+#if 0 - grub_printf (" "); - grub_printf_ (N_("Booting `%s'"), entry->title); - grub_printf ("\n\n"); -+#endif - } - - /* Callback invoked when a default menu entry executed because of a timeout -diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c -index cdf3590..5785f67 100644 ---- a/grub-core/normal/menu_entry.c -+++ b/grub-core/normal/menu_entry.c -@@ -1167,9 +1167,6 @@ run (struct screen *screen) - char *dummy[1] = { NULL }; - - grub_cls (); -- grub_printf (" "); -- grub_printf_ (N_("Booting a command list")); -- grub_printf ("\n\n"); - - errs_before = grub_err_printed_errors; - --- -1.8.3.1 - diff --git a/0076-grub2-btrfs-03-follow_default.patch b/0046-grub2-btrfs-03-follow_default.patch similarity index 86% rename from 0076-grub2-btrfs-03-follow_default.patch rename to 0046-grub2-btrfs-03-follow_default.patch index 63ce94294ccd4b68aaccc3a54a9140d3af2c77fe..ca203f4a423d9f2bedbf85d8fbd3337b723eed5c 100644 --- a/0076-grub2-btrfs-03-follow_default.patch +++ b/0046-grub2-btrfs-03-follow_default.patch @@ -1,17 +1,19 @@ -From 698e60b157eaa58d81150e74a3402a38047a9314 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Thu, 21 Aug 2014 03:39:11 +0000 -Subject: [PATCH 076/220] grub2-btrfs-03-follow_default +Subject: [PATCH] grub2-btrfs-03-follow_default +Signed-off-by: Michael Chang +Signed-off-by: Robbie Harwood --- grub-core/fs/btrfs.c | 107 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 76 insertions(+), 31 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index 2d099b1..2db89f7 100644 +index ad1b56b716d..113c1f746c9 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c -@@ -1236,6 +1236,7 @@ grub_btrfs_mount (grub_device_t dev) +@@ -1256,6 +1256,7 @@ grub_btrfs_mount (grub_device_t dev) { struct grub_btrfs_data *data; grub_err_t err; @@ -19,7 +21,7 @@ index 2d099b1..2db89f7 100644 if (!dev->disk) { -@@ -1266,11 +1267,14 @@ grub_btrfs_mount (grub_device_t dev) +@@ -1286,11 +1287,14 @@ grub_btrfs_mount (grub_device_t dev) data->devices_attached[0].dev = dev; data->devices_attached[0].id = data->sblock.this_device.device_id; @@ -38,7 +40,7 @@ index 2d099b1..2db89f7 100644 } return data; -@@ -1835,24 +1839,39 @@ find_path (struct grub_btrfs_data *data, +@@ -1855,24 +1859,39 @@ find_path (struct grub_btrfs_data *data, grub_size_t allocated = 0; struct grub_btrfs_dir_item *direl = NULL; struct grub_btrfs_key key_out; @@ -85,7 +87,7 @@ index 2d099b1..2db89f7 100644 } else { -@@ -1863,15 +1882,23 @@ find_path (struct grub_btrfs_data *data, +@@ -1883,15 +1902,23 @@ find_path (struct grub_btrfs_data *data, while (1) { @@ -118,7 +120,7 @@ index 2d099b1..2db89f7 100644 if (*type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY) { -@@ -1882,7 +1909,9 @@ find_path (struct grub_btrfs_data *data, +@@ -1902,7 +1929,9 @@ find_path (struct grub_btrfs_data *data, if (ctokenlen == 1 && ctoken[0] == '.') { @@ -129,7 +131,7 @@ index 2d099b1..2db89f7 100644 continue; } if (ctokenlen == 2 && ctoken[0] == '.' && ctoken[1] == '.') -@@ -1913,8 +1942,9 @@ find_path (struct grub_btrfs_data *data, +@@ -1933,8 +1962,9 @@ find_path (struct grub_btrfs_data *data, *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY; key->object_id = key_out.offset; @@ -141,7 +143,7 @@ index 2d099b1..2db89f7 100644 continue; } -@@ -1983,7 +2013,9 @@ find_path (struct grub_btrfs_data *data, +@@ -2003,7 +2033,9 @@ find_path (struct grub_btrfs_data *data, return err; } @@ -152,7 +154,7 @@ index 2d099b1..2db89f7 100644 if (cdirel->type == GRUB_BTRFS_DIR_ITEM_TYPE_SYMLINK) { struct grub_btrfs_inode inode; -@@ -2033,14 +2065,26 @@ find_path (struct grub_btrfs_data *data, +@@ -2053,14 +2085,26 @@ find_path (struct grub_btrfs_data *data, path = path_alloc = tmp; if (path[0] == '/') { @@ -186,7 +188,7 @@ index 2d099b1..2db89f7 100644 } else { -@@ -2696,6 +2740,7 @@ GRUB_MOD_INIT (btrfs) +@@ -2716,6 +2760,7 @@ GRUB_MOD_INIT (btrfs) subvolid_set_env); grub_env_export ("btrfs_subvol"); grub_env_export ("btrfs_subvolid"); @@ -194,6 +196,3 @@ index 2d099b1..2db89f7 100644 } GRUB_MOD_FINI (btrfs) --- -1.8.3.1 - diff --git a/0077-grub2-btrfs-04-grub2-install.patch b/0047-grub2-btrfs-04-grub2-install.patch similarity index 88% rename from 0077-grub2-btrfs-04-grub2-install.patch rename to 0047-grub2-btrfs-04-grub2-install.patch index 3431a85f3b257034497d02bbe7765543917bc420..451f61d780cd7dfa8976bf4b7ae4611937b0f140 100644 --- a/0077-grub2-btrfs-04-grub2-install.patch +++ b/0047-grub2-btrfs-04-grub2-install.patch @@ -1,19 +1,21 @@ -From d88b2fed5b13498999a6a186cf5a707ce0819f67 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Thu, 21 Aug 2014 03:39:11 +0000 -Subject: [PATCH 077/220] grub2-btrfs-04-grub2-install +Subject: [PATCH] grub2-btrfs-04-grub2-install +Signed-off-by: Michael Chang +Signed-off-by: Robbie Harwood --- grub-core/osdep/linux/getroot.c | 7 +++++++ grub-core/osdep/unix/config.c | 17 +++++++++++++++-- - include/grub/emu/config.h | 1 + util/config.c | 10 ++++++++++ util/grub-install.c | 15 +++++++++++++++ util/grub-mkrelpath.c | 6 ++++++ + include/grub/emu/config.h | 1 + 6 files changed, 54 insertions(+), 2 deletions(-) diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c -index 6d9f4e5..5d50dd6 100644 +index 001b818fe58..caf9b1ccd3f 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c @@ -376,6 +376,7 @@ get_btrfs_fs_prefix (const char *mount_path) @@ -38,7 +40,7 @@ index 6d9f4e5..5d50dd6 100644 else if (!retry && grub_strcmp (entries[i].fstype, "autofs") == 0) { diff --git a/grub-core/osdep/unix/config.c b/grub-core/osdep/unix/config.c -index 65effa9..b637c58 100644 +index 7d6325138ce..46a881530c0 100644 --- a/grub-core/osdep/unix/config.c +++ b/grub-core/osdep/unix/config.c @@ -82,6 +82,19 @@ grub_util_load_config (struct grub_util_config *cfg) @@ -72,20 +74,8 @@ index 65effa9..b637c58 100644 argv[2] = script; argv[3] = '\0'; -diff --git a/include/grub/emu/config.h b/include/grub/emu/config.h -index 875d589..c9a7e5f 100644 ---- a/include/grub/emu/config.h -+++ b/include/grub/emu/config.h -@@ -37,6 +37,7 @@ struct grub_util_config - { - int is_cryptodisk_enabled; - char *grub_distributor; -+ int is_suse_btrfs_snapshot_enabled; - }; - - void diff --git a/util/config.c b/util/config.c -index ebcdd8f..f044a88 100644 +index ebcdd8f5e22..f044a880a76 100644 --- a/util/config.c +++ b/util/config.c @@ -42,6 +42,16 @@ grub_util_parse_config (FILE *f, struct grub_util_config *cfg, int simple) @@ -106,10 +96,10 @@ index ebcdd8f..f044a88 100644 sizeof ("GRUB_DISTRIBUTOR=") - 1) == 0) { diff --git a/util/grub-install.c b/util/grub-install.c -index 8a55ad4..0e807b0 100644 +index 0fbe7f78c6d..0f66f36d23a 100644 --- a/util/grub-install.c +++ b/util/grub-install.c -@@ -819,6 +819,8 @@ fill_core_services (const char *core_services) +@@ -827,6 +827,8 @@ fill_core_services (const char *core_services) free (sysv_plist); } @@ -118,7 +108,7 @@ index 8a55ad4..0e807b0 100644 int main (int argc, char *argv[]) { -@@ -852,6 +854,9 @@ main (int argc, char *argv[]) +@@ -860,6 +862,9 @@ main (int argc, char *argv[]) grub_util_load_config (&config); @@ -128,7 +118,7 @@ index 8a55ad4..0e807b0 100644 if (!bootloader_id && config.grub_distributor) { char *ptr; -@@ -1344,6 +1349,16 @@ main (int argc, char *argv[]) +@@ -1352,6 +1357,16 @@ main (int argc, char *argv[]) fprintf (load_cfg_f, "set debug='%s'\n", debug_image); } @@ -146,7 +136,7 @@ index 8a55ad4..0e807b0 100644 char *install_drive = NULL; diff --git a/util/grub-mkrelpath.c b/util/grub-mkrelpath.c -index 47a241a..5db7a9a 100644 +index 47a241a391b..5db7a9a7d97 100644 --- a/util/grub-mkrelpath.c +++ b/util/grub-mkrelpath.c @@ -40,9 +40,12 @@ struct arguments @@ -172,6 +162,15 @@ index 47a241a..5db7a9a 100644 case ARGP_KEY_ARG: if (state->arg_num == 0) arguments->pathname = xstrdup (arg); --- -1.8.3.1 - +diff --git a/include/grub/emu/config.h b/include/grub/emu/config.h +index 875d5896ce1..c9a7e5f4ade 100644 +--- a/include/grub/emu/config.h ++++ b/include/grub/emu/config.h +@@ -37,6 +37,7 @@ struct grub_util_config + { + int is_cryptodisk_enabled; + char *grub_distributor; ++ int is_suse_btrfs_snapshot_enabled; + }; + + void diff --git a/0078-grub2-btrfs-05-grub2-mkconfig.patch b/0048-grub2-btrfs-05-grub2-mkconfig.patch similarity index 91% rename from 0078-grub2-btrfs-05-grub2-mkconfig.patch rename to 0048-grub2-btrfs-05-grub2-mkconfig.patch index 02b7a84b87959ef95723ac05398b290ad9978eb1..5afd183c44202ee43274d1dbd83bc6d1f8396b45 100644 --- a/0078-grub2-btrfs-05-grub2-mkconfig.patch +++ b/0048-grub2-btrfs-05-grub2-mkconfig.patch @@ -1,7 +1,7 @@ -From 62438d289c38a88cd0d3d1efad8a52f0de44b6b3 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Thu, 21 Aug 2014 03:39:11 +0000 -Subject: [PATCH 078/220] grub2-btrfs-05-grub2-mkconfig +Subject: [PATCH] grub2-btrfs-05-grub2-mkconfig Signed-off-by: Michael Chang --- @@ -13,10 +13,10 @@ Signed-off-by: Michael Chang 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index 6247a0b..4649e92 100644 +index 005f093809b..535c0f02499 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in -@@ -258,7 +258,8 @@ export GRUB_DEFAULT \ +@@ -252,7 +252,8 @@ export GRUB_DEFAULT \ GRUB_BADRAM \ GRUB_OS_PROBER_SKIP_LIST \ GRUB_DISABLE_SUBMENU \ @@ -27,7 +27,7 @@ index 6247a0b..4649e92 100644 if test "x${grub_cfg}" != "x"; then rm -f "${grub_cfg}.new" diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in -index 113a41f..b3aae53 100644 +index 42c2ea9ba50..fafeac95061 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -52,7 +52,11 @@ grub_warn () @@ -43,7 +43,7 @@ index 113a41f..b3aae53 100644 is_path_readable_by_grub () diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in -index 858b526..de727e6 100644 +index 858b526c925..de727e6ee6b 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -27,6 +27,14 @@ export TEXTDOMAINDIR="@localedir@" @@ -90,7 +90,7 @@ index 858b526..de727e6 100644 +EOF +fi diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 55f4aa7..5cab299 100644 +index 292e333324b..7bb3a211a7c 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -66,10 +66,14 @@ fi @@ -109,7 +109,7 @@ index 55f4aa7..5cab299 100644 xzfs) rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in -index 47e0d3f..1519ec6 100644 +index ada20775a14..e9e73b815fb 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -73,10 +73,14 @@ fi @@ -127,6 +127,3 @@ index 47e0d3f..1519ec6 100644 fi;; xzfs) rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` --- -1.8.3.1 - diff --git a/0079-grub2-btrfs-06-subvol-mount.patch b/0049-grub2-btrfs-06-subvol-mount.patch similarity index 93% rename from 0079-grub2-btrfs-06-subvol-mount.patch rename to 0049-grub2-btrfs-06-subvol-mount.patch index 5ba4bf87e4c8fc9ec61bf67b6a3525f69d383025..14117ab41c518ee2c2e4ab2e159ea004c568904e 100644 --- a/0079-grub2-btrfs-06-subvol-mount.patch +++ b/0049-grub2-btrfs-06-subvol-mount.patch @@ -1,17 +1,19 @@ -From 226e9d1f9fde6c6ccf711ba7112135bfa1c01868 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Tue, 9 Jul 2019 13:56:16 +0200 -Subject: [PATCH 079/220] grub2-btrfs-06-subvol-mount +Subject: [PATCH] grub2-btrfs-06-subvol-mount +Signed-off-by: Michael Chang +Signed-off-by: Robbie Harwood --- grub-core/fs/btrfs.c | 195 +++++++++++++++++++++++++++++++++++++++- grub-core/osdep/linux/getroot.c | 148 +++++++++++++++++++++++++++++- - include/grub/emu/getroot.h | 5 ++ util/grub-install.c | 49 ++++++++++ + include/grub/emu/getroot.h | 5 ++ 4 files changed, 392 insertions(+), 5 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index 2db89f7..1627234 100644 +index 113c1f746c9..d323746ecfa 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -41,6 +41,7 @@ @@ -21,8 +23,8 @@ index 2db89f7..1627234 100644 +#include #include #include - -@@ -263,6 +264,12 @@ static grub_err_t + #include +@@ -266,6 +267,12 @@ static grub_err_t grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, void *buf, grub_size_t size, int recursion_depth); @@ -35,7 +37,7 @@ index 2db89f7..1627234 100644 static grub_err_t read_sblock (grub_disk_t disk, struct grub_btrfs_superblock *sb) -@@ -1203,9 +1210,26 @@ lookup_root_by_name(struct grub_btrfs_data *data, const char *path) +@@ -1223,9 +1230,26 @@ lookup_root_by_name(struct grub_btrfs_data *data, const char *path) grub_err_t err; grub_uint64_t tree = 0; grub_uint8_t type; @@ -62,7 +64,7 @@ index 2db89f7..1627234 100644 if (err) return grub_error(GRUB_ERR_FILE_NOT_FOUND, "couldn't locate %s\n", path); -@@ -2179,11 +2203,20 @@ grub_btrfs_dir (grub_device_t device, const char *path, +@@ -2199,11 +2223,20 @@ grub_btrfs_dir (grub_device_t device, const char *path, int r = 0; grub_uint64_t tree; grub_uint8_t type; @@ -84,7 +86,7 @@ index 2db89f7..1627234 100644 if (err) { grub_btrfs_unmount (data); -@@ -2285,11 +2318,21 @@ grub_btrfs_open (struct grub_file *file, const char *name) +@@ -2305,11 +2338,21 @@ grub_btrfs_open (struct grub_file *file, const char *name) struct grub_btrfs_inode inode; grub_uint8_t type; struct grub_btrfs_key key_in; @@ -107,7 +109,7 @@ index 2db89f7..1627234 100644 if (err) { grub_btrfs_unmount (data); -@@ -2460,6 +2503,150 @@ grub_cmd_btrfs_info (grub_command_t cmd __attribute__ ((unused)), int argc, +@@ -2480,6 +2523,150 @@ grub_cmd_btrfs_info (grub_command_t cmd __attribute__ ((unused)), int argc, return 0; } @@ -258,7 +260,7 @@ index 2db89f7..1627234 100644 static grub_err_t get_fs_root(struct grub_btrfs_data *data, grub_uint64_t tree, grub_uint64_t objectid, grub_uint64_t offset, -@@ -2666,6 +2853,7 @@ static struct grub_fs grub_btrfs_fs = { +@@ -2686,6 +2873,7 @@ static struct grub_fs grub_btrfs_fs = { }; static grub_command_t cmd_info; @@ -266,7 +268,7 @@ index 2db89f7..1627234 100644 static grub_extcmd_t cmd_list_subvols; static char * -@@ -2729,6 +2917,9 @@ GRUB_MOD_INIT (btrfs) +@@ -2749,6 +2937,9 @@ GRUB_MOD_INIT (btrfs) cmd_info = grub_register_command("btrfs-info", grub_cmd_btrfs_info, "DEVICE", "Print BtrFS info about DEVICE."); @@ -277,7 +279,7 @@ index 2db89f7..1627234 100644 grub_cmd_btrfs_list_subvols, 0, "[-p|-n] [-o var] DEVICE", diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c -index 5d50dd6..4c5a130 100644 +index caf9b1ccd3f..28790307e00 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c @@ -107,6 +107,14 @@ struct btrfs_ioctl_search_key @@ -459,27 +461,11 @@ index 5d50dd6..4c5a130 100644 char * grub_make_system_path_relative_to_its_root_os (const char *path) { -diff --git a/include/grub/emu/getroot.h b/include/grub/emu/getroot.h -index 73fa2d3..9c642ae 100644 ---- a/include/grub/emu/getroot.h -+++ b/include/grub/emu/getroot.h -@@ -53,6 +53,11 @@ char ** - grub_find_root_devices_from_mountinfo (const char *dir, char **relroot); - #endif - -+#ifdef __linux__ -+char * -+grub_util_get_btrfs_subvol (const char *path, char **mount_path); -+#endif -+ - /* Devmapper functions provided by getroot_devmapper.c. */ - void - grub_util_pull_devmapper (const char *os_dev); diff --git a/util/grub-install.c b/util/grub-install.c -index 0e807b0..3e718b9 100644 +index 0f66f36d23a..84ed6e88ecb 100644 --- a/util/grub-install.c +++ b/util/grub-install.c -@@ -1561,6 +1561,55 @@ main (int argc, char *argv[]) +@@ -1569,6 +1569,55 @@ main (int argc, char *argv[]) prefix_drive = xasprintf ("(%s)", grub_drives[0]); } @@ -535,6 +521,19 @@ index 0e807b0..3e718b9 100644 char mkimage_target[200]; const char *core_name = NULL; --- -1.8.3.1 - +diff --git a/include/grub/emu/getroot.h b/include/grub/emu/getroot.h +index 73fa2d34abb..9c642ae3fe3 100644 +--- a/include/grub/emu/getroot.h ++++ b/include/grub/emu/getroot.h +@@ -53,6 +53,11 @@ char ** + grub_find_root_devices_from_mountinfo (const char *dir, char **relroot); + #endif + ++#ifdef __linux__ ++char * ++grub_util_get_btrfs_subvol (const char *path, char **mount_path); ++#endif ++ + /* Devmapper functions provided by getroot_devmapper.c. */ + void + grub_util_pull_devmapper (const char *os_dev); diff --git a/0080-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch b/0050-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch similarity index 84% rename from 0080-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch rename to 0050-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch index c56e7bb6777aaa5c586cda96de050dc7e1a52f8a..b02ab53fe8d4baa00e6eafc71f181591ec0c7cbd 100644 --- a/0080-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch +++ b/0050-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch @@ -1,8 +1,8 @@ -From dea875db30d83eeed6b53c3fc72a0dbb178abb94 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Andrei Borzenkov Date: Tue, 21 Jun 2016 16:44:17 +0000 -Subject: [PATCH 080/220] Fallback to old subvol name scheme to support old - snapshot config +Subject: [PATCH] Fallback to old subvol name scheme to support old snapshot + config Ref: bsc#953538 --- @@ -10,13 +10,14 @@ Ref: bsc#953538 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index 1627234..69c30e6 100644 +index d323746ecfa..673ded03522 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c -@@ -1241,10 +1241,40 @@ lookup_root_by_name(struct grub_btrfs_data *data, const char *path) +@@ -1260,11 +1260,41 @@ lookup_root_by_name(struct grub_btrfs_data *data, const char *path) + return GRUB_ERR_NONE; } - static grub_err_t ++static grub_err_t +lookup_root_by_name_fallback(struct grub_btrfs_data *data, const char *path) +{ + grub_err_t err; @@ -35,7 +36,7 @@ index 1627234..69c30e6 100644 + return GRUB_ERR_NONE; +} + -+static grub_err_t + static grub_err_t btrfs_handle_subvol(struct grub_btrfs_data *data __attribute__ ((unused))) { if (btrfs_default_subvol) @@ -55,6 +56,3 @@ index 1627234..69c30e6 100644 if (btrfs_default_subvolid) return lookup_root_by_id(data, btrfs_default_subvolid); --- -1.8.3.1 - diff --git a/0050-Fix-convert-function-to-support-NVMe-devices.patch b/0050-Fix-convert-function-to-support-NVMe-devices.patch deleted file mode 100644 index f9b998273e23126f53d4bbd77540684baa93fd15..0000000000000000000000000000000000000000 --- a/0050-Fix-convert-function-to-support-NVMe-devices.patch +++ /dev/null @@ -1,59 +0,0 @@ -From d876203ac9bfea1f5f0cea015dfa70ba3988d08a Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 18 Feb 2014 11:34:00 -0500 -Subject: [PATCH 050/220] Fix convert function to support NVMe devices - -This is adapted from the patch at -https://bugzilla.redhat.com/show_bug.cgi?id=1019660 , which is against -the now very old version of convert_system_partition_to_system_disk(). - -As such, it certainly not the right thing for upstream, but should -function for now. - -Resolves: rhbz#1019660 - -Signed-off-by: Peter Jones ---- - util/getroot.c | 19 +++++++++++++++++++ - 1 file changed, 19 insertions(+) - -diff --git a/util/getroot.c b/util/getroot.c -index 847406f..fa3460d 100644 ---- a/util/getroot.c -+++ b/util/getroot.c -@@ -153,6 +153,7 @@ convert_system_partition_to_system_disk (const char *os_dev, int *is_part) - { - #if GRUB_UTIL_FD_STAT_IS_FUNCTIONAL - struct stat st; -+ char *path = xmalloc(PATH_MAX); - - if (stat (os_dev, &st) < 0) - { -@@ -165,6 +166,24 @@ convert_system_partition_to_system_disk (const char *os_dev, int *is_part) - - *is_part = 0; - -+ if (realpath(os_dev, path)) -+ { -+ if ((strncmp ("/dev/nvme", path, 9) == 0)) -+ { -+ char *p = path + 5; -+ p = strchr(p, 'p'); -+ if (p) -+ { -+ *is_part = 1; -+ *p = '\0'; -+ } -+ return path; -+ } -+ } -+ -+ grub_free (path); -+ *is_part = 0; -+ - if (grub_util_device_is_mapped_stat (&st)) - return grub_util_devmapper_part_to_disk (&st, is_part, os_dev); - --- -1.8.3.1 - diff --git a/0051-Add-grub_util_readlink.patch b/0051-Add-grub_util_readlink.patch deleted file mode 100644 index e73c6c8123bf7bc8b413ba73ca2aa6f3fdbb5b2a..0000000000000000000000000000000000000000 --- a/0051-Add-grub_util_readlink.patch +++ /dev/null @@ -1,85 +0,0 @@ -From a2099170d2f7e9cca6a743c15b6cb649b88fd873 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 8 Jul 2019 21:46:52 +0200 -Subject: [PATCH 051/220] Add grub_util_readlink() - -Add grub_util_readlink(). This requires pulling in stat and readlink from -gnulib, which pulls in stat and related headers, but after that the -implementation is straightforward. - -Signed-off-by: Peter Jones -Reviewed-by: Adam Jackson ---- - grub-core/osdep/windows/hostdisk.c | 6 ++++++ - include/grub/osdep/hostfile_aros.h | 6 ++++++ - include/grub/osdep/hostfile_unix.h | 6 ++++++ - include/grub/osdep/hostfile_windows.h | 2 ++ - 4 files changed, 20 insertions(+) - -diff --git a/grub-core/osdep/windows/hostdisk.c b/grub-core/osdep/windows/hostdisk.c -index 3551007..87a106c 100644 ---- a/grub-core/osdep/windows/hostdisk.c -+++ b/grub-core/osdep/windows/hostdisk.c -@@ -365,6 +365,12 @@ grub_util_mkdir (const char *dir) - free (windows_name); - } - -+ssize_t -+grub_util_readlink (const char *name, char *buf, size_t bufsize) -+{ -+ return readlink(name, buf, bufsize); -+} -+ - int - grub_util_rename (const char *from, const char *to) - { -diff --git a/include/grub/osdep/hostfile_aros.h b/include/grub/osdep/hostfile_aros.h -index a059c0f..161fbb7 100644 ---- a/include/grub/osdep/hostfile_aros.h -+++ b/include/grub/osdep/hostfile_aros.h -@@ -68,6 +68,12 @@ grub_util_rename (const char *from, const char *to) - return rename (from, to); - } - -+static inline ssize_t -+grub_util_readlink (const char *name, char *buf, size_t bufsize) -+{ -+ return readlink(name, buf, bufsize); -+} -+ - #define grub_util_mkdir(a) mkdir ((a), 0755) - - struct grub_util_fd -diff --git a/include/grub/osdep/hostfile_unix.h b/include/grub/osdep/hostfile_unix.h -index 9ffe46f..17cd3aa 100644 ---- a/include/grub/osdep/hostfile_unix.h -+++ b/include/grub/osdep/hostfile_unix.h -@@ -71,6 +71,12 @@ grub_util_rename (const char *from, const char *to) - return rename (from, to); - } - -+static inline ssize_t -+grub_util_readlink (const char *name, char *buf, size_t bufsize) -+{ -+ return readlink(name, buf, bufsize); -+} -+ - #define grub_util_mkdir(a) mkdir ((a), 0755) - - #if defined (__NetBSD__) -diff --git a/include/grub/osdep/hostfile_windows.h b/include/grub/osdep/hostfile_windows.h -index bf6451b..8c92d05 100644 ---- a/include/grub/osdep/hostfile_windows.h -+++ b/include/grub/osdep/hostfile_windows.h -@@ -41,6 +41,8 @@ typedef struct grub_util_fd_dir *grub_util_fd_dir_t; - - int - grub_util_rename (const char *from, const char *to); -+ssize_t -+grub_util_readlink (const char *name, char *buf, size_t bufsize); - int - grub_util_unlink (const char *name); - void --- -1.8.3.1 - diff --git a/0081-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch b/0051-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch similarity index 94% rename from 0081-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch rename to 0051-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch index b0342ae51a879f72da586fdf9438290bc6f54858..b54b1960f4b8bcf4dabb0af37c969abc0f6bba5f 100644 --- a/0081-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch +++ b/0051-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch @@ -1,18 +1,19 @@ -From 0a31b397d0d3bc28e19401abe9b675fe7d3bb526 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Thu, 11 May 2017 08:56:57 +0000 -Subject: [PATCH 081/220] Grub not working correctly with btrfs snapshots - (bsc#1026511) +Subject: [PATCH] Grub not working correctly with btrfs snapshots (bsc#1026511) +Signed-off-by: Michael Chang +Signed-off-by: Robbie Harwood --- grub-core/fs/btrfs.c | 238 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index 69c30e6..ba99d04 100644 +index 673ded03522..2b21cbaa67e 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c -@@ -2867,6 +2867,238 @@ out: +@@ -2887,6 +2887,238 @@ out: return 0; } @@ -251,7 +252,7 @@ index 69c30e6..ba99d04 100644 static struct grub_fs grub_btrfs_fs = { .name = "btrfs", .fs_dir = grub_btrfs_dir, -@@ -2885,6 +3117,7 @@ static struct grub_fs grub_btrfs_fs = { +@@ -2905,6 +3137,7 @@ static struct grub_fs grub_btrfs_fs = { static grub_command_t cmd_info; static grub_command_t cmd_mount_subvol; static grub_extcmd_t cmd_list_subvols; @@ -259,7 +260,7 @@ index 69c30e6..ba99d04 100644 static char * subvolid_set_env (struct grub_env_var *var __attribute__ ((unused)), -@@ -2955,6 +3188,11 @@ GRUB_MOD_INIT (btrfs) +@@ -2975,6 +3208,11 @@ GRUB_MOD_INIT (btrfs) "[-p|-n] [-o var] DEVICE", "Print list of BtrFS subvolumes on " "DEVICE.", options); @@ -271,6 +272,3 @@ index 69c30e6..ba99d04 100644 grub_register_variable_hook ("btrfs_subvol", subvol_get_env, subvol_set_env); grub_register_variable_hook ("btrfs_subvolid", subvolid_get_env, --- -1.8.3.1 - diff --git a/0082-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch b/0052-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch similarity index 90% rename from 0082-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch rename to 0052-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch index 051c7bacafe4d8e4b35e31446157a72a7e17d663..bde70969087d1b5d1951eb0fc631af3ec7caeca9 100644 --- a/0082-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch +++ b/0052-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch @@ -1,7 +1,7 @@ -From 67fceb3fe4d6a167f26478fa2c3fdbac9a9bc871 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 1 Jun 2017 09:59:56 -0400 -Subject: [PATCH 082/220] Add grub_efi_allocate_pool() and grub_efi_free_pool() +Subject: [PATCH] Add grub_efi_allocate_pool() and grub_efi_free_pool() wrappers. Signed-off-by: Peter Jones @@ -10,7 +10,7 @@ Signed-off-by: Peter Jones 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h -index 090c862..5e2b479 100644 +index 585fa6662b6..03f9a9d0118 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -24,6 +24,10 @@ @@ -58,7 +58,7 @@ index 090c862..5e2b479 100644 grub_efi_loaded_image_t *EXPORT_FUNC(grub_efi_get_loaded_image) (grub_efi_handle_t image_handle); void EXPORT_FUNC(grub_efi_print_device_path) (grub_efi_device_path_t *dp); char *EXPORT_FUNC(grub_efi_get_filename) (grub_efi_device_path_t *dp); -@@ -109,10 +140,7 @@ void grub_efi_init (void); +@@ -115,10 +146,7 @@ void grub_efi_init (void); void grub_efi_fini (void); void grub_efi_set_prefix (void); @@ -70,6 +70,3 @@ index 090c862..5e2b479 100644 extern int EXPORT_VAR(grub_efi_is_finished); struct grub_net_card; --- -1.8.3.1 - diff --git a/0052-Make-editenv-chase-symlinks-including-those-across-d.patch b/0052-Make-editenv-chase-symlinks-including-those-across-d.patch deleted file mode 100644 index b00645570340b775504f4895fd6aae202b553066..0000000000000000000000000000000000000000 --- a/0052-Make-editenv-chase-symlinks-including-those-across-d.patch +++ /dev/null @@ -1,108 +0,0 @@ -From 33c5ef791304cd9c320dd0e6ec67e2bd5e7e8d30 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 3 Sep 2014 10:38:00 -0400 -Subject: [PATCH 052/220] Make editenv chase symlinks including those across - devices. - -This lets us make /boot/grub2/grubenv a symlink to -/boot/efi/EFI/fedora/grubenv even though they're different mount points, -which allows /usr/bin/grub2-editenv to be the same across platforms -(i.e. UEFI vs BIOS). - -Signed-off-by: Peter Jones -Reviewed-by: Adam Jackson ---- - Makefile.util.def | 11 +++++++++++ - util/editenv.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- - 2 files changed, 55 insertions(+), 2 deletions(-) - -diff --git a/Makefile.util.def b/Makefile.util.def -index 8717774..1f298d0 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -240,8 +240,19 @@ program = { - - common = util/grub-editenv.c; - common = util/editenv.c; -+ common = util/grub-install-common.c; - common = grub-core/osdep/init.c; -+ common = grub-core/osdep/compress.c; -+ extra_dist = grub-core/osdep/unix/compress.c; -+ extra_dist = grub-core/osdep/basic/compress.c; -+ common = util/mkimage.c; -+ common = util/grub-mkimage32.c; -+ common = util/grub-mkimage64.c; -+ common = grub-core/osdep/config.c; -+ common = util/config.c; -+ common = util/resolve.c; - -+ ldadd = '$(LIBLZMA)'; - ldadd = libgrubmods.a; - ldadd = libgrubgcry.a; - ldadd = libgrubkern.a; -diff --git a/util/editenv.c b/util/editenv.c -index eb2d0c0..e61dc12 100644 ---- a/util/editenv.c -+++ b/util/editenv.c -@@ -37,6 +37,7 @@ grub_util_create_envblk_file (const char *name) - FILE *fp; - char *buf; - char *namenew; -+ char *rename_target = xstrdup(name); - - buf = xmalloc (DEFAULT_ENVBLK_SIZE); - -@@ -60,7 +61,48 @@ grub_util_create_envblk_file (const char *name) - free (buf); - fclose (fp); - -- if (grub_util_rename (namenew, name) < 0) -- grub_util_error (_("cannot rename the file %s to %s"), namenew, name); -+ ssize_t size = 1; -+ while (1) -+ { -+ char *linkbuf; -+ ssize_t retsize; -+ -+ linkbuf = xmalloc(size+1); -+ retsize = grub_util_readlink (rename_target, linkbuf, size); -+ if (retsize < 0 && (errno == ENOENT || errno == EINVAL)) -+ { -+ free (linkbuf); -+ break; -+ } -+ else if (retsize < 0) -+ { -+ grub_util_error (_("cannot rename the file %s to %s: %m"), namenew, name); -+ free (linkbuf); -+ free (namenew); -+ return; -+ } -+ else if (retsize == size) -+ { -+ free(linkbuf); -+ size += 128; -+ continue; -+ } -+ -+ free (rename_target); -+ linkbuf[retsize] = '\0'; -+ rename_target = linkbuf; -+ } -+ -+ int rc = grub_util_rename (namenew, rename_target); -+ if (rc < 0 && errno == EXDEV) -+ { -+ rc = grub_install_copy_file (namenew, rename_target, 1); -+ grub_util_unlink (namenew); -+ } -+ -+ if (rc < 0) -+ grub_util_error (_("cannot rename the file %s to %s: %m"), namenew, name); -+ - free (namenew); -+ free (rename_target); - } --- -1.8.3.1 - diff --git a/0083-Use-grub_efi_.-memory-helpers-where-reasonable.patch b/0053-Use-grub_efi_.-memory-helpers-where-reasonable.patch similarity index 85% rename from 0083-Use-grub_efi_.-memory-helpers-where-reasonable.patch rename to 0053-Use-grub_efi_.-memory-helpers-where-reasonable.patch index f65956a10b6afa30fa4706d50d71dc90721ed12f..ccdf28298823bdb8e9f280bcdbdf052c7c88d256 100644 --- a/0083-Use-grub_efi_.-memory-helpers-where-reasonable.patch +++ b/0053-Use-grub_efi_.-memory-helpers-where-reasonable.patch @@ -1,7 +1,7 @@ -From 2a70ee4ec02463e5eda6137de9e3e7d9f1b2021a Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 1 Jun 2017 10:06:38 -0400 -Subject: [PATCH 083/220] Use grub_efi_...() memory helpers where reasonable. +Subject: [PATCH] Use grub_efi_...() memory helpers where reasonable. This uses grub_efi_allocate_pool(), grub_efi_free_pool(), and grub_efi_free_pages() instead of open-coded efi_call_N() calls, so we @@ -13,7 +13,7 @@ Signed-off-by: Peter Jones 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index 5aa3a5d..3a724a9 100644 +index 07c4937898d..89ac84cc663 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -65,7 +65,7 @@ grub_chainloader_unload (void) @@ -34,7 +34,7 @@ index 5aa3a5d..3a724a9 100644 grub_loader_unset (); -@@ -506,10 +506,9 @@ grub_efi_get_media_file_path (grub_efi_device_path_t *dp) +@@ -527,10 +527,9 @@ grub_efi_get_media_file_path (grub_efi_device_path_t *dp) static grub_efi_boolean_t handle_image (void *data, grub_efi_uint32_t datasize) { @@ -46,7 +46,7 @@ index 5aa3a5d..3a724a9 100644 char *buffer_aligned = NULL; grub_efi_uint32_t i; struct grub_pe32_section_table *section; -@@ -520,8 +519,6 @@ handle_image (void *data, grub_efi_uint32_t datasize) +@@ -541,8 +540,6 @@ handle_image (void *data, grub_efi_uint32_t datasize) int found_entry_point = 0; int rc; @@ -55,7 +55,7 @@ index 5aa3a5d..3a724a9 100644 rc = read_header (data, datasize, &context); if (rc < 0) { -@@ -561,8 +558,8 @@ handle_image (void *data, grub_efi_uint32_t datasize) +@@ -582,8 +579,8 @@ handle_image (void *data, grub_efi_uint32_t datasize) grub_dprintf ("chain", "image size is %08"PRIxGRUB_UINT64_T", datasize is %08x\n", context.image_size, datasize); @@ -66,7 +66,7 @@ index 5aa3a5d..3a724a9 100644 if (efi_status != GRUB_EFI_SUCCESS) { -@@ -794,14 +791,14 @@ handle_image (void *data, grub_efi_uint32_t datasize) +@@ -815,14 +812,14 @@ handle_image (void *data, grub_efi_uint32_t datasize) grub_dprintf ("chain", "entry_point returned %ld\n", efi_status); grub_memcpy (li, &li_bak, sizeof (grub_efi_loaded_image_t)); @@ -83,7 +83,7 @@ index 5aa3a5d..3a724a9 100644 return 0; } -@@ -809,10 +806,7 @@ error_exit: +@@ -830,10 +827,7 @@ error_exit: static grub_err_t grub_secureboot_chainloader_unload (void) { @@ -95,7 +95,7 @@ index 5aa3a5d..3a724a9 100644 grub_free (file_path); grub_free (cmdline); cmdline = 0; -@@ -1079,7 +1073,7 @@ fail: +@@ -1100,7 +1094,7 @@ fail: grub_free (file_path); if (address) @@ -104,6 +104,3 @@ index 5aa3a5d..3a724a9 100644 if (cmdline) grub_free (cmdline); --- -1.8.3.1 - diff --git a/0084-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch b/0054-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch similarity index 72% rename from 0084-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch rename to 0054-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch index 8ebf61b50428b5d8ac741c769a1675b7811fd4bf..ef41fe1a5afed98119c2bafc069736ab5d58a87a 100644 --- a/0084-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch +++ b/0054-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch @@ -1,21 +1,21 @@ -From aa6edc58113ecb1ff34417fa4702ff10b4e32ded Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 1 Jun 2017 10:07:50 -0400 -Subject: [PATCH 084/220] Add PRIxGRUB_EFI_STATUS and use it. +Subject: [PATCH] Add PRIxGRUB_EFI_STATUS and use it. This avoids syntax checkers getting confused about if it's llx or lx. Signed-off-by: Peter Jones --- grub-core/loader/efi/chainloader.c | 3 ++- - include/grub/efi/api.h | 8 ++++++++ - 2 files changed, 10 insertions(+), 1 deletion(-) + include/grub/efi/api.h | 9 +++++++++ + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index 3a724a9..f4ddbed 100644 +index 89ac84cc663..ac8dfd40c61 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c -@@ -789,7 +789,8 @@ handle_image (void *data, grub_efi_uint32_t datasize) +@@ -810,7 +810,8 @@ handle_image (void *data, grub_efi_uint32_t datasize) efi_status = efi_call_2 (entry_point, grub_efi_image_handle, grub_efi_system_table); @@ -26,13 +26,15 @@ index 3a724a9..f4ddbed 100644 efi_status = grub_efi_free_pool (buffer); diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index d97cdf9..955973e 100644 +index 117469450d3..99628801478 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h -@@ -527,6 +527,14 @@ typedef grub_uint8_t grub_efi_char8_t; +@@ -546,7 +546,16 @@ typedef grub_uint64_t grub_efi_uint64_t; + typedef grub_uint8_t grub_efi_char8_t; typedef grub_uint16_t grub_efi_char16_t; - typedef grub_efi_intn_t grub_efi_status_t; ++ + typedef grub_efi_uintn_t grub_efi_status_t; +/* Make grub_efi_status_t reasonably printable. */ +#if GRUB_CPU_SIZEOF_VOID_P == 8 +#define PRIxGRUB_EFI_STATUS "lx" @@ -44,6 +46,3 @@ index d97cdf9..955973e 100644 #define GRUB_EFI_ERROR_CODE(value) \ ((((grub_efi_status_t) 1) << (sizeof (grub_efi_status_t) * 8 - 1)) | (value)) --- -1.8.3.1 - diff --git a/0087-don-t-use-int-for-efi-status.patch b/0055-don-t-use-int-for-efi-status.patch similarity index 69% rename from 0087-don-t-use-int-for-efi-status.patch rename to 0055-don-t-use-int-for-efi-status.patch index 80782f56587454208cef377695f81398825c95a4..44d35554082705d6f432b9c42ad5499090816d71 100644 --- a/0087-don-t-use-int-for-efi-status.patch +++ b/0055-don-t-use-int-for-efi-status.patch @@ -1,17 +1,17 @@ -From 7fba6daaf2d9cc2c96176020212dadad593c340f Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 26 Jun 2017 12:44:59 -0400 -Subject: [PATCH 087/220] don't use int for efi status +Subject: [PATCH] don't use int for efi status --- grub-core/kern/efi/efi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index a1af9b4..2cf6a5a 100644 +index 05d8237a9b2..ae9885edb84 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c -@@ -166,7 +166,7 @@ grub_reboot (void) +@@ -167,7 +167,7 @@ grub_reboot (void) void grub_exit (int retval) { @@ -20,6 +20,3 @@ index a1af9b4..2cf6a5a 100644 if (retval == 0) rc = GRUB_EFI_SUCCESS; --- -1.8.3.1 - diff --git a/0056-Update-info-with-grub.cfg-netboot-selection-order-11.patch b/0056-Update-info-with-grub.cfg-netboot-selection-order-11.patch deleted file mode 100644 index d5421e8bc19705d542c6a4fed3de3b2344e2659f..0000000000000000000000000000000000000000 --- a/0056-Update-info-with-grub.cfg-netboot-selection-order-11.patch +++ /dev/null @@ -1,70 +0,0 @@ -From c2361e2d8c4b0d15eb78605097a9d2fa38c06d76 Mon Sep 17 00:00:00 2001 -From: Robert Marshall -Date: Mon, 16 Mar 2015 16:34:51 -0400 -Subject: [PATCH 056/220] Update info with grub.cfg netboot selection order - (#1148650) - -Added documentation to the grub info page that specifies the order -netboot clients will use to select a grub configuration file. - -Resolves rhbz#1148650 ---- - docs/grub.texi | 42 ++++++++++++++++++++++++++++++++++++++++++ - 1 file changed, 42 insertions(+) - -diff --git a/docs/grub.texi b/docs/grub.texi -index 6f52430..221064b 100644 ---- a/docs/grub.texi -+++ b/docs/grub.texi -@@ -2493,6 +2493,48 @@ grub-mknetdir --net-directory=/srv/tftp --subdir=/boot/grub -d /usr/lib/grub/i38 - Then follow instructions printed out by grub-mknetdir on configuring your DHCP - server. - -+The grub.cfg file is placed in the same directory as the path output by -+grub-mknetdir hereafter referred to as FWPATH. GRUB will search for its -+configuration files in order using the following rules where the appended -+value corresponds to a value on the client machine. -+ -+@example -+@group -+@samp{(FWPATH)}/grub.cfg-@samp{(UUID OF NIC)} -+@samp{(FWPATH)}/grub.cfg-@samp{(MAC ADDRESS OF NIC)} -+@samp{(FWPATH)}/grub.cfg-@samp{(IPv4 OR IPv6 ADDRESS)} -+@samp{(FWPATH)}/grub.cfg -+@end group -+@end example -+ -+The client will only attempt to look up an IPv6 address config once, however, -+it will try the IPv4 multiple times. The concrete example below shows what -+would happen under the IPv4 case. -+ -+@example -+@group -+UUID: 7726a678-7fc0-4853-a4f6-c85ac36a120a -+MAC: 52:54:00:ec:33:81 -+IPV4: 10.0.0.130 (0A000082) -+@end group -+@end example -+ -+@example -+@group -+@samp{(FWPATH)}/grub.cfg-7726a678-7fc0-4853-a4f6-c85ac36a120a -+@samp{(FWPATH)}/grub.cfg-52-54-00-ec-33-81 -+@samp{(FWPATH)}/grub.cfg-0A000082 -+@samp{(FWPATH)}/grub.cfg-0A00008 -+@samp{(FWPATH)}/grub.cfg-0A0000 -+@samp{(FWPATH)}/grub.cfg-0A000 -+@samp{(FWPATH)}/grub.cfg-0A00 -+@samp{(FWPATH)}/grub.cfg-0A0 -+@samp{(FWPATH)}/grub.cfg-0A -+@samp{(FWPATH)}/grub.cfg-0 -+@samp{(FWPATH)}/grub.cfg -+@end group -+@end example -+ - After GRUB has started, files on the TFTP server will be accessible via the - @samp{(tftp)} device. - --- -1.8.3.1 - diff --git a/0088-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch b/0056-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch similarity index 81% rename from 0088-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch rename to 0056-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch index 3d4575e945c55f7282e0b924f598fd42f68e95f5..1014900c932c971116862e046ee81d379ad8355d 100644 --- a/0088-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch +++ b/0056-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch @@ -1,14 +1,14 @@ -From c0d5d9ca9964f2d634a25014821199e1f4ea7be1 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 26 Jun 2017 12:46:23 -0400 -Subject: [PATCH 088/220] make GRUB_MOD_INIT() declare its function prototypes. +Subject: [PATCH] make GRUB_MOD_INIT() declare its function prototypes. --- include/grub/dl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/grub/dl.h b/include/grub/dl.h -index f03c035..90dc9bb 100644 +index b3753c9ca26..91933b85f2c 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -54,6 +54,7 @@ grub_mod_fini (void) @@ -27,6 +27,3 @@ index f03c035..90dc9bb 100644 void \ grub_##name##_fini (void) { grub_mod_fini (); } \ static void \ --- -1.8.3.1 - diff --git a/0091-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch b/0057-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch similarity index 81% rename from 0091-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch rename to 0057-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch index e33528eb6cb3d39cec312c27385421b15c87bad9..890aa34ce7905671c3ac931471ff05205e630c91 100644 --- a/0091-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch +++ b/0057-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch @@ -1,7 +1,7 @@ -From 36ceae144ede50b60f1256e0b57ceb7ed5be8eee Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 20 Apr 2017 13:29:06 -0400 -Subject: [PATCH 091/220] Don't guess /boot/efi/ as HFS+ on ppc machines in +Subject: [PATCH] Don't guess /boot/efi/ as HFS+ on ppc machines in grub-install This should never be trying this, and since we've consolidated the @@ -16,10 +16,10 @@ Signed-off-by: Peter Jones 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/util/grub-install.c b/util/grub-install.c -index 3e718b9..37fcdac 100644 +index 84ed6e88ecb..a2bec7446cb 100644 --- a/util/grub-install.c +++ b/util/grub-install.c -@@ -1182,18 +1182,8 @@ main (int argc, char *argv[]) +@@ -1190,18 +1190,8 @@ main (int argc, char *argv[]) char *d; is_guess = 1; @@ -39,6 +39,3 @@ index 3e718b9..37fcdac 100644 if (!grub_util_is_directory (d)) { free (d); --- -1.8.3.1 - diff --git a/0092-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch b/0058-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch similarity index 42% rename from 0092-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch rename to 0058-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch index 7d31e7759ca02d181f33cb863dc95a7ca50a32cd..3fd779f7dfbb5c6705302df146f71804afa79037 100644 --- a/0092-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch +++ b/0058-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch @@ -1,35 +1,47 @@ -From aef6341482706bc7a6620324795006e7209df380 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 9 Jul 2019 14:31:19 +0200 -Subject: [PATCH 092/220] 20_linux_xen: load xen or multiboot{,2} modules as - needed. +Subject: [PATCH] 20_linux_xen: load xen or multiboot{,2} modules as needed. Signed-off-by: Peter Jones --- - util/grub.d/20_linux_xen.in | 3 +++ - 1 file changed, 3 insertions(+) + util/grub.d/20_linux_xen.in | 5 +++++ + 1 file changed, 5 insertions(+) diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in -index 1519ec6..9aa23bc 100644 +index e9e73b815fb..c23b064be6c 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in -@@ -136,6 +136,8 @@ linux_entry () +@@ -153,6 +153,7 @@ linux_entry_xsm () else xen_rm_opts="no-real-mode edd=off" fi -+ insmod ${module_loader} -+ insmod ${xen_loader} ++ insmod ${xen_module} ${xen_loader} ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} \${xen_rm_opts} echo '$(echo "$lmessage" | grub_quote)' ${module_loader} ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args} -@@ -149,6 +151,7 @@ EOF +@@ -166,6 +167,7 @@ EOF done sed "s/^/$submenu_indentation/" << EOF echo '$(echo "$message" | grub_quote)' -+ insmod ${module_loader} ++ insmod ${xen_module} ${module_loader} --nounzip $(echo $initrd_path) EOF fi --- -1.8.3.1 - +@@ -253,13 +255,16 @@ while [ "x${xen_list}" != "x" ] ; do + echo " submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {" + fi + if ($grub_file --is-arm64-efi $current_xen); then ++ xen_module="xen_boot" + xen_loader="xen_hypervisor" + module_loader="xen_module" + else + if ($grub_file --is-x86-multiboot2 $current_xen); then ++ xen_module="multiboot2" + xen_loader="multiboot2" + module_loader="module2" + else ++ xen_module="multiboot" + xen_loader="multiboot" + module_loader="module" + fi diff --git a/0058-Handle-rssd-storage-devices.patch b/0058-Handle-rssd-storage-devices.patch deleted file mode 100644 index 600655506f791d614a1764801676bb96d844f6e2..0000000000000000000000000000000000000000 --- a/0058-Handle-rssd-storage-devices.patch +++ /dev/null @@ -1,39 +0,0 @@ -From 186a94f0f82bbebcbf607573ba792647acebf9cd Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 30 Jun 2015 15:50:41 -0400 -Subject: [PATCH 058/220] Handle rssd storage devices. - -Resolves: rhbz#1087962 - -Signed-off-by: Peter Jones ---- - grub-core/osdep/linux/getroot.c | 13 +++++++++++++ - 1 file changed, 13 insertions(+) - -diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c -index 90d92d3..6d9f4e5 100644 ---- a/grub-core/osdep/linux/getroot.c -+++ b/grub-core/osdep/linux/getroot.c -@@ -921,6 +921,19 @@ grub_util_part_to_disk (const char *os_dev, struct stat *st, - return path; - } - -+ /* If this is an rssd device. */ -+ if ((strncmp ("rssd", p, 4) == 0) && p[4] >= 'a' && p[4] <= 'z') -+ { -+ char *pp = p + 4; -+ while (*pp >= 'a' && *pp <= 'z') -+ pp++; -+ if (*pp) -+ *is_part = 1; -+ /* /dev/rssd[a-z]+[0-9]* */ -+ *pp = '\0'; -+ return path; -+ } -+ - /* If this is a loop device */ - if ((strncmp ("loop", p, 4) == 0) && p[4] >= '0' && p[4] <= '9') - { --- -1.8.3.1 - diff --git a/0093-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch b/0059-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch similarity index 97% rename from 0093-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch rename to 0059-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch index 95358a03a50110edfb0af73eb2ee9663fb063396..acfb116d74f35d92a98eea43dca2cf73ed2797ff 100644 --- a/0093-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch +++ b/0059-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch @@ -1,8 +1,7 @@ -From 1742890ed8ea75a898f2bc7a47c61d6acacf4128 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 7 Nov 2017 17:12:17 -0500 -Subject: [PATCH 093/220] Make pmtimer tsc calibration not take 51 seconds to - fail. +Subject: [PATCH] Make pmtimer tsc calibration not take 51 seconds to fail. On my laptop running at 2.4GHz, if I run a VM where tsc calibration using pmtimer will fail presuming a broken pmtimer, it takes ~51 seconds @@ -64,7 +63,7 @@ Signed-off-by: Peter Jones 1 file changed, 89 insertions(+), 20 deletions(-) diff --git a/grub-core/kern/i386/tsc_pmtimer.c b/grub-core/kern/i386/tsc_pmtimer.c -index c9c3616..ca15c3a 100644 +index c9c36169978..ca15c3aacd7 100644 --- a/grub-core/kern/i386/tsc_pmtimer.c +++ b/grub-core/kern/i386/tsc_pmtimer.c @@ -28,40 +28,101 @@ @@ -210,6 +209,3 @@ index c9c3616..ca15c3a 100644 tsc_diff = grub_pmtimer_wait_count_tsc (pmtimer, 3580); if (tsc_diff == 0) return 0; --- -1.8.3.1 - diff --git a/0094-align-struct-efi_variable-better.patch b/0060-align-struct-efi_variable-better.patch similarity index 81% rename from 0094-align-struct-efi_variable-better.patch rename to 0060-align-struct-efi_variable-better.patch index 6ecad784bb5ec5fba9754041029f1b0776f46ac9..ec26def52ed83b41947f594e209637e647ecb852 100644 --- a/0094-align-struct-efi_variable-better.patch +++ b/0060-align-struct-efi_variable-better.patch @@ -1,7 +1,7 @@ -From d49469ac1d2173db50595517e4bb8d5fe8f2a68b Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 27 Feb 2018 13:55:35 -0500 -Subject: [PATCH 094/220] align struct efi_variable better... +Subject: [PATCH] align struct efi_variable better... --- include/grub/efiemu/runtime.h | 2 +- @@ -9,7 +9,7 @@ Subject: [PATCH 094/220] align struct efi_variable better... 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/grub/efiemu/runtime.h b/include/grub/efiemu/runtime.h -index 36d2ded..9d93ba8 100644 +index 36d2dedf47e..9d93ba88bac 100644 --- a/include/grub/efiemu/runtime.h +++ b/include/grub/efiemu/runtime.h @@ -33,5 +33,5 @@ struct efi_variable @@ -20,7 +20,7 @@ index 36d2ded..9d93ba8 100644 +} GRUB_PACKED GRUB_ALIGNED(8); #endif /* ! GRUB_EFI_EMU_RUNTIME_HEADER */ diff --git a/include/grub/types.h b/include/grub/types.h -index 035a4b5..2fc4be4 100644 +index 0a3ff159136..ba446d99040 100644 --- a/include/grub/types.h +++ b/include/grub/types.h @@ -29,6 +29,7 @@ @@ -31,6 +31,3 @@ index 035a4b5..2fc4be4 100644 #ifdef GRUB_BUILD # define GRUB_CPU_SIZEOF_VOID_P BUILD_SIZEOF_VOID_P --- -1.8.3.1 - diff --git a/0095-Add-BLS-support-to-grub-mkconfig.patch b/0061-Add-BLS-support-to-grub-mkconfig.patch similarity index 32% rename from 0095-Add-BLS-support-to-grub-mkconfig.patch rename to 0061-Add-BLS-support-to-grub-mkconfig.patch index 75b0884d5ce8fd99b5d4654407fc082ba7ccb060..f7c8064e3608c74438280b810d9b3507fa95a16b 100644 --- a/0095-Add-BLS-support-to-grub-mkconfig.patch +++ b/0061-Add-BLS-support-to-grub-mkconfig.patch @@ -1,7 +1,7 @@ -From 9a2531c2784e9d86e4f15d549dc82b37243d46e4 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Fri, 9 Dec 2016 15:40:29 -0500 -Subject: [PATCH 095/220] Add BLS support to grub-mkconfig +Subject: [PATCH] Add BLS support to grub-mkconfig GRUB now has BootLoaderSpec support, the user can choose to use this by setting GRUB_ENABLE_BLSCFG to true in /etc/default/grub. On this setup, @@ -20,37 +20,18 @@ kernels are found in the boot directory were proposed by Yclept Nemo and Tom Gundersen respectively. Signed-off-by: Peter Jones +[javierm: remove outdated URL for BLS document] Signed-off-by: Javier Martinez Canillas +Signed-off-by: Robbie Harwood --- - Makefile.util.def | 7 + - util/grub-mkconfig.8 | 4 + - util/grub-mkconfig.in | 9 +- - util/grub-mkconfig_lib.in | 20 +- - util/grub.d/10_linux.in | 67 ++++++- - util/grub.d/10_linux_bls.in | 478 ++++++++++++++++++++++++++++++++++++++++++++ - 6 files changed, 580 insertions(+), 5 deletions(-) - create mode 100644 util/grub.d/10_linux_bls.in + util/grub-mkconfig.8 | 4 + + util/grub-mkconfig.in | 9 +- + util/grub-mkconfig_lib.in | 22 ++++- + util/grub.d/10_linux.in | 223 +++++++++++++++++++++++++++++++++++++++++++++- + 4 files changed, 252 insertions(+), 6 deletions(-) -diff --git a/Makefile.util.def b/Makefile.util.def -index 2215cc7..a616136 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -500,6 +500,13 @@ script = { - }; - - script = { -+ name = '10_linux_bls'; -+ common = util/grub.d/10_linux_bls.in; -+ installdir = grubconf; -+ condition = COND_HOST_LINUX; -+}; -+ -+script = { - name = '10_xnu'; - common = util/grub.d/10_xnu.in; - installdir = grubconf; diff --git a/util/grub-mkconfig.8 b/util/grub-mkconfig.8 -index a2d1f57..434fa4d 100644 +index a2d1f577b9b..434fa4deda4 100644 --- a/util/grub-mkconfig.8 +++ b/util/grub-mkconfig.8 @@ -13,5 +13,9 @@ @@ -64,7 +45,7 @@ index a2d1f57..434fa4d 100644 .SH SEE ALSO .BR "info grub" diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index 4649e92..2601bdc 100644 +index 535c0f02499..f55339a3f64 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -50,6 +50,8 @@ grub_get_kernel_settings="${sbindir}/@grub_get_kernel_settings@" @@ -82,7 +63,7 @@ index 4649e92..2601bdc 100644 print_option_help "-o, --output=$(gettext FILE)" "$(gettext "output generated config to FILE [default=stdout]")" + print_option_help "--no-grubenv-update" "$(gettext "do not update variables in the grubenv file")" print_option_help "-h, --help" "$(gettext "print this message and exit")" - print_option_help "-v, --version" "$(gettext "print the version information and exit")" + print_option_help "-V, --version" "$(gettext "print the version information and exit")" echo @@ -94,6 +97,9 @@ do --output=*) @@ -94,7 +75,7 @@ index 4649e92..2601bdc 100644 -*) gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2 usage -@@ -259,7 +265,8 @@ export GRUB_DEFAULT \ +@@ -253,7 +259,8 @@ export GRUB_DEFAULT \ GRUB_OS_PROBER_SKIP_LIST \ GRUB_DISABLE_SUBMENU \ GRUB_DEFAULT_DTB \ @@ -105,7 +86,7 @@ index 4649e92..2601bdc 100644 if test "x${grub_cfg}" != "x"; then rm -f "${grub_cfg}.new" diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in -index b3aae53..bc11df2 100644 +index fafeac95061..d8bb4069360 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -30,6 +30,9 @@ fi @@ -138,247 +119,52 @@ index b3aae53..bc11df2 100644 old_ifs="$IFS" IFS=' ' -@@ -161,14 +175,14 @@ prepare_grub_to_access_device () +@@ -161,18 +175,18 @@ prepare_grub_to_access_device () # otherwise set root as per value in device.map. fs_hint="`"${grub_probe}" --device $@ --target=compatibility_hint`" if [ "x$fs_hint" != x ]; then - echo "set root='$fs_hint'" + echo "set ${device_variable}='$fs_hint'" fi - if [ "x$GRUB_DISABLE_UUID" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then + if [ "x${GRUB_DISABLE_UUID}" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then hints="`"${grub_probe}" --device $@ --target=hints_string 2> /dev/null`" || hints= - echo "if [ x\$feature_platform_search_hint = xy ]; then" -- echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}" -+ echo " search --no-floppy --fs-uuid --set=${device_variable} ${hints} ${fs_uuid}" - echo "else" -- echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}" -+ echo " search --no-floppy --fs-uuid --set=${device_variable} ${fs_uuid}" - echo "fi" + if [ "x$hints" != x ]; then + echo "if [ x\$feature_platform_search_hint = xy ]; then" +- echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}" ++ echo " search --no-floppy --fs-uuid --set=${device_variable} ${hints} ${fs_uuid}" + echo "else" +- echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}" ++ echo " search --no-floppy --fs-uuid --set=${device_variable} ${fs_uuid}" + echo "fi" + else +- echo "search --no-floppy --fs-uuid --set=root ${fs_uuid}" ++ echo "search --no-floppy --fs-uuid --set=${device_variable} ${fs_uuid}" + fi fi IFS="$old_ifs" diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 5cab299..301594a 100644 +index 7bb3a211a7c..6bceabf3dc9 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in -@@ -82,6 +82,67 @@ case x"$GRUB_FS" in +@@ -82,6 +82,223 @@ case x"$GRUB_FS" in ;; esac +populate_header_warn() +{ -+cat <$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then -@@ -224,6 +286,7 @@ is_top_level=true - while [ "x$list" != "x" ] ; do - linux=`version_find_latest $list` - gettext_printf "Found linux image: %s\n" "$linux" >&2 -+ - basename=`basename $linux` - dirname=`dirname $linux` - rel_dirname=`make_system_path_relative_to_its_root $dirname` -@@ -262,7 +325,9 @@ while [ "x$list" != "x" ] ; do - for i in ${initrd}; do - initrd_display="${initrd_display} ${dirname}/${i}" - done -- gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 -+ if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then -+ gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 -+ fi - fi - - fdt= -diff --git a/util/grub.d/10_linux_bls.in b/util/grub.d/10_linux_bls.in -new file mode 100644 -index 0000000..1b75364 ---- /dev/null -+++ b/util/grub.d/10_linux_bls.in -@@ -0,0 +1,478 @@ -+#! /bin/sh -+set -e -+ -+# grub-mkconfig helper script. -+# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. -+# -+# GRUB is free software: you can redistribute it and/or modify -+# it under the terms of the GNU General Public License as published by -+# the Free Software Foundation, either version 3 of the License, or -+# (at your option) any later version. -+# -+# GRUB is distributed in the hope that it will be useful, -+# but WITHOUT ANY WARRANTY; without even the implied warranty of -+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+# GNU General Public License for more details. -+# -+# You should have received a copy of the GNU General Public License -+# along with GRUB. If not, see . -+ -+prefix="@prefix@" -+exec_prefix="@exec_prefix@" -+datarootdir="@datarootdir@" -+ -+. "$pkgdatadir/grub-mkconfig_lib" -+ -+export TEXTDOMAIN=@PACKAGE@ -+export TEXTDOMAINDIR="@localedir@" -+ -+CLASS="--class gnu-linux --class gnu --class os --unrestricted" -+ -+if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then -+ OS="$(eval $(grep PRETTY_NAME /etc/os-release) ; echo ${PRETTY_NAME})" -+ CLASS="--class $(eval $(grep '^ID_LIKE=\|^ID=' /etc/os-release) ; [ -n "${ID_LIKE}" ] && echo ${ID_LIKE} || echo ${ID}) ${CLASS}" -+else -+ OS="${GRUB_DISTRIBUTOR}" -+ CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" -+fi -+ -+# loop-AES arranges things so that /dev/loop/X can be our root device, but -+# the initrds that Linux uses don't like that. -+case ${GRUB_DEVICE} in -+ /dev/loop/*|/dev/loop[0-9]) -+ GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"` -+ ;; -+esac -+ -+# Default to disabling partition uuid support to maintian compatibility with -+# older kernels. -+GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true} -+ -+# btrfs may reside on multiple devices. We cannot pass them as value of root= parameter -+# and mounting btrfs requires user space scanning, so force UUID in this case. -+if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \ -+ || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ -+ && [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \ -+ || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ -+ && ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \ -+ || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then -+ LINUX_ROOT_DEVICE=${GRUB_DEVICE} -+elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \ -+ || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then -+ LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID} ++if [ "x${BLS_POPULATE_MENU}" = "xtrue" ]; then ++ bls_parser="10_linux script" +else -+ LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} ++ bls_parser="blscfg command" +fi -+ -+case x"$GRUB_FS" in -+ xbtrfs) -+ if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then -+ GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}" -+ else -+ rootsubvol="`make_system_path_relative_to_its_root /`" -+ rootsubvol="${rootsubvol#/}" -+ if [ "x${rootsubvol}" != x ]; then -+ GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" -+ fi -+ fi;; -+ xzfs) -+ rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` -+ bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`" -+ LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}" -+ ;; -+esac -+ -+mktitle () -+{ -+ local title_type -+ local version -+ local OS_NAME -+ local OS_VERS -+ -+ title_type=$1 && shift -+ version=$1 && shift -+ -+ OS_NAME="$(eval $(grep ^NAME= /etc/os-release) ; echo ${NAME})" -+ OS_VERS="$(eval $(grep ^VERSION= /etc/os-release) ; echo ${VERSION})" -+ -+ case $title_type in -+ recovery) -+ title=$(printf '%s (%s) %s (recovery mode)' \ -+ "${OS_NAME}" "${version}" "${OS_VERS}") -+ ;; -+ *) -+ title=$(printf '%s (%s) %s' \ -+ "${OS_NAME}" "${version}" "${OS_VERS}") -+ ;; -+ esac -+ echo -n ${title} -+} -+ -+title_correction_code= -+ -+populate_header_warn() -+{ +cat <&2 + -+ files=($(for bls in ${blsdir}/*.conf ; do ++ files=($(for bls in ${blsdir}/${machine_id}-*.conf; do + if ! [[ -e "${bls}" ]] ; then + continue + fi + bls="${bls%.conf}" + bls="${bls##*/}" + echo "${bls}" -+ done | ${kernel_sort} | tac)) || : ++ done | ${kernel_sort} 2>/dev/null | tac)) || : ++ ++ echo "${files[@]}" ++} + -+ for bls in "${files[@]}" ; do ++update_bls_cmdline() ++{ ++ local cmdline="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" ++ local -a files=($(get_sorted_bls)) ++ ++ for bls in "${files[@]}"; do ++ local options="${cmdline}" ++ if [ -z "${bls##*debug*}" ]; then ++ options="${options} ${GRUB_CMDLINE_LINUX_DEBUG}" ++ fi ++ options="$(echo "${options}" | sed -e 's/\//\\\//g')" ++ sed -i -e "s/^options.*/options ${options}/" "${blsdir}/${bls}.conf" ++ done ++} ++ ++populate_menu() ++{ ++ local -a files=($(get_sorted_bls)) ++ ++ gettext_printf "Generating boot entries from BLS files...\n" >&2 ++ ++ for bls in "${files[@]}"; do + read_config "${blsdir}/${bls}.conf" + -+ menu="${menu}menuentry '${title}' --class ${grub_class} ${grub_arg} --id=${bls} {\n" ++ menu="${menu}menuentry '${title}' ${grub_arg} --id=${bls} {\n" + menu="${menu}\t linux ${linux} ${options}\n" + if [ -n "${initrd}" ] ; then + menu="${menu}\t initrd ${boot_prefix}${initrd}\n" @@ -454,291 +264,136 @@ index 0000000..1b75364 + printf "$menu" +} + -+linux_entry () -+{ -+ os="$1" -+ version="$2" -+ type="$3" -+ isdebug="$4" -+ args="$5" -+ -+ if [ -z "$boot_device_id" ]; then -+ boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" -+ fi -+ -+ if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then -+ if [ x$dirname = x/ ]; then -+ if [ -z "${prepare_root_cache}" ]; then -+ prepare_grub_to_access_device ${GRUB_DEVICE} -+ fi -+ else -+ if [ -z "${prepare_boot_cache}" ]; then -+ prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} -+ fi -+ fi -+ -+ if [ -d /sys/firmware/efi ]; then -+ bootefi_device="`${grub_probe} --target=device /boot/efi/`" -+ prepare_grub_to_access_device_with_variable boot ${bootefi_device} -+ else -+ boot_device="`${grub_probe} --target=device /boot/`" -+ prepare_grub_to_access_device_with_variable boot ${boot_device} -+ fi -+ -+ populate_header_warn -+ populate_menu -+ -+ if [ "x${GRUB_GRUBENV_UPDATE}" = "xyes" ]; then -+ blsdir="/boot/loader/entries" -+ [ -d "${blsdir}" ] && GRUB_BLS_FS="$(${grub_probe} --target=fs ${blsdir})" -+ if [ "x${GRUB_BLS_FS}" = "xbtrfs" ] || [ "x${GRUB_BLS_FS}" = "xzfs" ]; then -+ blsdir=$(make_system_path_relative_to_its_root "${blsdir}") -+ if [ "x${blsdir}" != "x/loader/entries" ] && [ "x${blsdir}" != "x/boot/loader/entries" ]; then -+ ${grub_editenv} - set blsdir="${blsdir}" -+ fi -+ fi -+ -+ ${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}" -+ if [ -n "${GRUB_EARLY_INITRD_LINUX_CUSTOM}" ]; then -+ ${grub_editenv} - set early_initrd="${GRUB_EARLY_INITRD_LINUX_CUSTOM}" -+ fi -+ fi -+ -+ exit 0 -+ fi -+ -+ if [ x$type != xsimple ] ; then -+ title=$(mktitle "$type" "$version") -+ if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then -+ replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')" -+ quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)" -+ title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;" -+ fi -+ if [ x$isdebug = xdebug ]; then -+ title="$title${GRUB_LINUX_DEBUG_TITLE_POSTFIX}" -+ fi -+ echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/" -+ else -+ echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/" -+ fi -+ if [ x$type != xrecovery ] ; then -+ save_default_entry | grub_add_tab -+ fi -+ -+ # Use ELILO's generic "efifb" when it's known to be available. -+ # FIXME: We need an interface to select vesafb in case efifb can't be used. -+ if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then -+ echo " load_video" | sed "s/^/$submenu_indentation/" -+ if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \ -+ && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then -+ echo " set gfxpayload=keep" | sed "s/^/$submenu_indentation/" -+ fi -+ else -+ if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then -+ echo " load_video" | sed "s/^/$submenu_indentation/" -+ fi -+ echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/" -+ fi -+ -+ echo " insmod gzio" | sed "s/^/$submenu_indentation/" ++# Make BLS the default if GRUB_ENABLE_BLSCFG was not set and grubby is not installed. ++if [ -z "${GRUB_ENABLE_BLSCFG}" ] && [ -z "$(which new-kernel-pkg 2> /dev/null)" ]; then ++ GRUB_ENABLE_BLSCFG="true" ++fi + ++if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then + if [ x$dirname = x/ ]; then + if [ -z "${prepare_root_cache}" ]; then -+ prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)" ++ prepare_grub_to_access_device ${GRUB_DEVICE} + fi -+ printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/" + else + if [ -z "${prepare_boot_cache}" ]; then -+ prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)" ++ prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} + fi -+ printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" -+ fi -+ sed "s/^/$submenu_indentation/" << EOF -+ linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} -+EOF -+ if test -n "${initrd}" ; then -+ initrd_path= -+ for i in ${initrd}; do -+ initrd_path="${initrd_path} ${rel_dirname}/${i}" -+ done -+ sed "s/^/$submenu_indentation/" << EOF -+ initrd $(echo $initrd_path) -+EOF -+ fi -+ if test -n "${fdt}" ; then -+ sed "s/^/$submenu_indentation/" << EOF -+ devicetree ${rel_dirname}/${fdt} -+EOF + fi -+ sed "s/^/$submenu_indentation/" << EOF -+} -+EOF -+} + -+machine=`uname -m` -+case "x$machine" in -+ xi?86 | xx86_64) -+ list= -+ for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do -+ if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi -+ done ;; -+ *) -+ list= -+ for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do -+ if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi -+ done ;; -+esac ++ if [ -d /sys/firmware/efi ]; then ++ bootefi_device="`${grub_probe} --target=device /boot/efi/`" ++ prepare_grub_to_access_device_with_variable boot ${bootefi_device} ++ else ++ boot_device="`${grub_probe} --target=device /boot/`" ++ prepare_grub_to_access_device_with_variable boot ${boot_device} ++ fi + -+if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then -+ for i in /boot/ostree/*/vmlinuz-* ; do -+ if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi -+ done -+fi ++ arch="$(uname -m)" ++ if [ "x${arch}" = "xppc64le" ] && [ -d /sys/firmware/opal ]; then + -+case "$machine" in -+ i?86) GENKERNEL_ARCH="x86" ;; -+ mips|mips64) GENKERNEL_ARCH="mips" ;; -+ mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;; -+ arm*) GENKERNEL_ARCH="arm" ;; -+ *) GENKERNEL_ARCH="$machine" ;; -+esac -+ -+prepare_boot_cache= -+prepare_root_cache= -+boot_device_id= -+title_correction_code= -+ -+# Extra indentation to add to menu entries in a submenu. We're not in a submenu -+# yet, so it's empty. In a submenu it will be equal to '\t' (one tab). -+submenu_indentation="" -+ -+is_top_level=true -+while [ "x$list" != "x" ] ; do -+ linux=`version_find_latest $list` -+ if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then -+ gettext_printf "Found linux image: %s\n" "$linux" >&2 -+ fi ++ BLS_POPULATE_MENU="true" ++ petitboot_path="/sys/firmware/devicetree/base/ibm,firmware-versions/petitboot" + -+ basename=`basename $linux` -+ dirname=`dirname $linux` -+ rel_dirname=`make_system_path_relative_to_its_root $dirname` -+ version=`echo $basename | sed -e "s,^[^0-9]*-,,g"` -+ alt_version=`echo $version | sed -e "s,\.old$,,g"` -+ linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" -+ -+ initrd_early= -+ for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \ -+ ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do -+ if test -e "${dirname}/${i}" ; then -+ initrd_early="${initrd_early} ${i}" -+ fi -+ done -+ -+ initrd_real= -+ for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \ -+ "initrd-${version}" "initramfs-${version}.img" \ -+ "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ -+ "initrd-${alt_version}" "initramfs-${alt_version}.img" \ -+ "initramfs-genkernel-${version}" \ -+ "initramfs-genkernel-${alt_version}" \ -+ "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \ -+ "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do -+ if test -e "${dirname}/${i}" ; then -+ initrd_real="${i}" -+ break -+ fi -+ done ++ if test -e ${petitboot_path}; then ++ read -r -d '' petitboot_version < ${petitboot_path} ++ petitboot_version="$(echo ${petitboot_version//v})" + -+ initrd= -+ if test -n "${initrd_early}" || test -n "${initrd_real}"; then -+ initrd="${initrd_early} ${initrd_real}" ++ if test -n ${petitboot_version}; then ++ major_version="$(echo ${petitboot_version} | cut -d . -f1)" ++ minor_version="$(echo ${petitboot_version} | cut -d . -f2)" + -+ initrd_display= -+ for i in ${initrd}; do -+ initrd_display="${initrd_display} ${dirname}/${i}" -+ done -+ if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then -+ gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 -+ fi ++ re='^[0-9]+$' ++ if [[ $major_version =~ $re ]] && [[ $minor_version =~ $re ]] && ++ ([[ ${major_version} -gt 1 ]] || ++ [[ ${major_version} -eq 1 && ++ ${minor_version} -ge 8 ]]); then ++ BLS_POPULATE_MENU="false" ++ fi ++ fi ++ fi + fi + -+ fdt= -+ for i in "dtb-${version}" "dtb-${alt_version}"; do -+ if test -f "${dirname}/${i}/${GRUB_DEFAULT_DTB}" ; then -+ fdt="${i}/${GRUB_DEFAULT_DTB}" -+ break -+ fi -+ done -+ -+ config= -+ for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do -+ if test -e "${i}" ; then -+ config="${i}" -+ break -+ fi -+ done ++ populate_header_warn + -+ initramfs= -+ if test -n "${config}" ; then -+ initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"` -+ fi ++ cat << EOF ++# The kernelopts variable should be defined in the grubenv file. But to ensure that menu ++# entries populated from BootLoaderSpec files that use this variable work correctly even ++# without a grubenv file, define a fallback kernelopts variable if this has not been set. ++# ++# The kernelopts variable in the grubenv file can be modified using the grubby tool or by ++# executing the grub2-mkconfig tool. For the latter, the values of the GRUB_CMDLINE_LINUX ++# and GRUB_CMDLINE_LINUX_DEFAULT options from /etc/default/grub file are used to set both ++# the kernelopts variable in the grubenv file and the fallback kernelopts variable. ++if [ -z "\${kernelopts}" ]; then ++ set kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" ++fi ++EOF + -+ if test -z "${initramfs}" && test -z "${initrd_real}" ; then -+ # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's -+ # no initrd or builtin initramfs, it can't work here. -+ if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \ -+ || [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then ++ update_bls_cmdline + -+ linux_root_device_thisversion=${GRUB_DEVICE} -+ else -+ linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID} -+ fi -+ fi ++ if [ "x${BLS_POPULATE_MENU}" = "xtrue" ]; then ++ populate_menu ++ else ++ cat << EOF + -+ if [ "x${GRUB_DISABLE_SUBMENU}" = "xyes" ] || [ "x${GRUB_DISABLE_SUBMENU}" = "xy" ]; then -+ GRUB_DISABLE_SUBMENU="true" ++insmod blscfg ++blscfg ++EOF + fi + -+ if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then -+ linux_entry "${OS}" "${version}" simple standard \ -+ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" -+ if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then -+ linux_entry "${OS}" "${version}" simple debug \ -+ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}" -+ fi ++ if [ "x${GRUB_GRUBENV_UPDATE}" = "xyes" ]; then ++ blsdir="/boot/loader/entries" ++ [ -d "${blsdir}" ] && GRUB_BLS_FS="$(${grub_probe} --target=fs ${blsdir})" ++ if [ "x${GRUB_BLS_FS}" = "xbtrfs" ] || [ "x${GRUB_BLS_FS}" = "xzfs" ]; then ++ blsdir=$(make_system_path_relative_to_its_root "${blsdir}") ++ if [ "x${blsdir}" != "x/loader/entries" ] && [ "x${blsdir}" != "x/boot/loader/entries" ]; then ++ ${grub_editenv} - set blsdir="${blsdir}" ++ fi ++ fi + -+ submenu_indentation="$grub_tab" ++ if [ -n "${GRUB_EARLY_INITRD_LINUX_CUSTOM}" ]; then ++ ${grub_editenv} - set early_initrd="${GRUB_EARLY_INITRD_LINUX_CUSTOM}" ++ fi + -+ if [ -z "$boot_device_id" ]; then -+ boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" -+ fi -+ # TRANSLATORS: %s is replaced with an OS name -+ echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {" -+ is_top_level=false -+ fi ++ if [ -n "${GRUB_DEFAULT_DTB}" ]; then ++ ${grub_editenv} - set devicetree="${GRUB_DEFAULT_DTB}" ++ fi + -+ linux_entry "${OS}" "${version}" advanced standard \ -+ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" -+ if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then -+ linux_entry "${OS}" "${version}" advanced debug \ -+ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}" ++ if [ -n "${GRUB_SAVEDEFAULT}" ]; then ++ ${grub_editenv} - set save_default="${GRUB_SAVEDEFAULT}" ++ fi + fi + -+ if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then -+ linux_entry "${OS}" "${version}" recovery standard \ -+ "single ${GRUB_CMDLINE_LINUX}" -+ fi ++ exit 0 ++fi + -+ list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '` -+done + mktitle () + { + local title_type +@@ -121,6 +338,7 @@ linux_entry () + if [ -z "$boot_device_id" ]; then + boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" + fi + -+# If at least one kernel was found, then we need to -+# add a closing '}' for the submenu command. -+if [ x"$is_top_level" != xtrue ]; then -+ echo '}' -+fi + if [ x$type != xsimple ] ; then + title=$(mktitle "$type" "$version") + if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then +@@ -231,6 +449,7 @@ is_top_level=true + while [ "x$list" != "x" ] ; do + linux=`version_find_latest $list` + gettext_printf "Found linux image: %s\n" "$linux" >&2 + -+echo "$title_correction_code" --- -1.8.3.1 - + basename=`basename $linux` + dirname=`dirname $linux` + rel_dirname=`make_system_path_relative_to_its_root $dirname` +@@ -269,7 +488,9 @@ while [ "x$list" != "x" ] ; do + for i in ${initrd}; do + initrd_display="${initrd_display} ${dirname}/${i}" + done +- gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 ++ if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then ++ gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 ++ fi + fi + + fdt= diff --git a/0096-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch b/0062-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch similarity index 73% rename from 0096-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch rename to 0062-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch index d5a0d7ff885d1242da0640af6520b90927d5e8c4..9ff4c8b8694add91b6fde9d7e6355acb80b57919 100644 --- a/0096-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch +++ b/0062-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch @@ -1,8 +1,7 @@ -From 141eaab0d63830598e4304451e407289468968cb Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Tue, 6 Feb 2018 11:16:28 +0100 -Subject: [PATCH 096/220] Don't attempt to backtrace on grub_abort() for - grub-emu +Subject: [PATCH] Don't attempt to backtrace on grub_abort() for grub-emu The emu platform doesn't have a grub_backtrace() implementation, so this causes a build error. Don't attempt to call this when building grub-emu. @@ -13,10 +12,10 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 04371ac..636f97e 100644 +index a3e215155bd..c60601b699d 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c -@@ -1103,7 +1103,7 @@ static void __attribute__ ((noreturn)) +@@ -1201,7 +1201,7 @@ static void __attribute__ ((noreturn)) grub_abort (void) { #ifndef GRUB_UTIL @@ -25,6 +24,3 @@ index 04371ac..636f97e 100644 grub_backtrace(); #endif #endif --- -1.8.3.1 - diff --git a/0062-Fix-security-issue-when-reading-username-and-passwor.patch b/0062-Fix-security-issue-when-reading-username-and-passwor.patch deleted file mode 100644 index 489d4908f0019cda5eb709b48c1eb7aa8944585f..0000000000000000000000000000000000000000 --- a/0062-Fix-security-issue-when-reading-username-and-passwor.patch +++ /dev/null @@ -1,47 +0,0 @@ -From 8483464867a872744a2c40a3b4016d3b81033a5d Mon Sep 17 00:00:00 2001 -From: Hector Marco-Gisbert -Date: Fri, 13 Nov 2015 16:21:09 +0100 -Subject: [PATCH 062/220] Fix security issue when reading username and password - - This patch fixes two integer underflows at: - * grub-core/lib/crypto.c - * grub-core/normal/auth.c - -Resolves: CVE-2015-8370 - -Signed-off-by: Hector Marco-Gisbert -Signed-off-by: Ismael Ripoll-Ripoll ---- - grub-core/lib/crypto.c | 2 +- - grub-core/normal/auth.c | 2 +- - 2 files changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/lib/crypto.c b/grub-core/lib/crypto.c -index ca334d5..e6c78d1 100644 ---- a/grub-core/lib/crypto.c -+++ b/grub-core/lib/crypto.c -@@ -468,7 +468,7 @@ grub_password_get (char buf[], unsigned buf_size) - break; - } - -- if (key == '\b') -+ if (key == '\b' && cur_len) - { - if (cur_len) - cur_len--; -diff --git a/grub-core/normal/auth.c b/grub-core/normal/auth.c -index 6be678c..c35ce97 100644 ---- a/grub-core/normal/auth.c -+++ b/grub-core/normal/auth.c -@@ -172,7 +172,7 @@ grub_username_get (char buf[], unsigned buf_size) - break; - } - -- if (key == GRUB_TERM_BACKSPACE) -+ if (key == GRUB_TERM_BACKSPACE && cur_len) - { - if (cur_len) - { --- -1.8.3.1 - diff --git a/0063-Add-a-url-parser.patch b/0063-Add-a-url-parser.patch deleted file mode 100644 index ec773a7d399b62f5e4c3cde3cbd90e0de7a8ef0d..0000000000000000000000000000000000000000 --- a/0063-Add-a-url-parser.patch +++ /dev/null @@ -1,1024 +0,0 @@ -From eb8bcbb4845d6b87f16774ee62de3e5a11ccd6f1 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 14 Jun 2016 16:18:44 -0400 -Subject: [PATCH 063/220] Add a url parser. - -This patch adds a url parser that can parse http, https, tftp, and tftps -urls, and is easily extensible to handle more types. - -It's a little ugly in terms of the arguments it takes. - -Signed-off-by: Peter Jones ---- - grub-core/Makefile.core.def | 1 + - grub-core/kern/misc.c | 13 + - grub-core/net/url.c | 861 ++++++++++++++++++++++++++++++++++++++++++++ - include/grub/misc.h | 45 +++ - include/grub/net/url.h | 28 ++ - 5 files changed, 948 insertions(+) - create mode 100644 grub-core/net/url.c - create mode 100644 include/grub/net/url.h - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 57e253a..99466b1 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -2284,6 +2284,7 @@ module = { - common = net/ethernet.c; - common = net/arp.c; - common = net/netbuff.c; -+ common = net/url.c; - }; - - module = { -diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 2656a67..1c560ea 100644 ---- a/grub-core/kern/misc.c -+++ b/grub-core/kern/misc.c -@@ -296,6 +296,19 @@ grub_strrchr (const char *s, int c) - return p; - } - -+char * -+grub_strchrnul (const char *s, int c) -+{ -+ do -+ { -+ if (*s == c) -+ break; -+ } -+ while (*s++); -+ -+ return (char *) s; -+} -+ - int - grub_strword (const char *haystack, const char *needle) - { -diff --git a/grub-core/net/url.c b/grub-core/net/url.c -new file mode 100644 -index 0000000..1468582 ---- /dev/null -+++ b/grub-core/net/url.c -@@ -0,0 +1,861 @@ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2016 Free Software Foundation, Inc. -+ * -+ * GRUB is free software: you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation, either version 3 of the License, or -+ * (at your option) any later version. -+ * -+ * GRUB is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with GRUB. If not, see . -+ */ -+ -+#ifdef URL_TEST -+ -+#define _GNU_SOURCE 1 -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#define N_(x) x -+ -+#define grub_malloc(x) malloc(x) -+#define grub_free(x) ({if (x) free(x);}) -+#define grub_error(a, fmt, args...) printf(fmt "\n", ## args) -+#define grub_dprintf(a, fmt, args...) printf(a ": " fmt, ## args) -+#define grub_strlen(x) strlen(x) -+#define grub_strdup(x) strdup(x) -+#define grub_strstr(x,y) strstr(x,y) -+#define grub_memcpy(x,y,z) memcpy(x,y,z) -+#define grub_strcmp(x,y) strcmp(x,y) -+#define grub_strncmp(x,y,z) strncmp(x,y,z) -+#define grub_strcasecmp(x,y) strcasecmp(x,y) -+#define grub_strchrnul(x,y) strchrnul(x,y) -+#define grub_strchr(x,y) strchr(x,y) -+#define grub_strndup(x,y) strndup(x,y) -+#define grub_strtoul(x,y,z) strtoul(x,y,z) -+#define grub_memmove(x,y,z) memmove(x,y,z) -+#define grub_size_t size_t -+#define grub_errno errno -+ -+#else -+#include -+#include -+#include -+#include -+#endif -+ -+static char * -+translate_slashes(char *str) -+{ -+ int i, j; -+ if (str == NULL) -+ return str; -+ -+ for (i = 0, j = 0; str[i] != '\0'; i++, j++) -+ { -+ if (str[i] == '\\') -+ { -+ str[j] = '/'; -+ if (str[i+1] == '\\') -+ i++; -+ } -+ } -+ -+ return str; -+} -+ -+static inline int -+hex2int (char c) -+{ -+ if (c >= '0' && c <= '9') -+ return c - '0'; -+ c |= 0x20; -+ if (c >= 'a' && c <= 'f') -+ return c - 'a' + 10; -+ return -1; -+} -+ -+static int -+url_unescape (char *buf, grub_size_t len) -+{ -+ int c, rc; -+ unsigned int i; -+ -+ -+ if (len < 3) -+ { -+ for (i = 0; i < len; i++) -+ if (buf[i] == '%') -+ return -1; -+ return 0; -+ } -+ -+ for (i = 0; len > 2 && i < len - 2; i++) -+ { -+ if (buf[i] == '%') -+ { -+ unsigned int j; -+ for (j = i+1; j < i+3; j++) -+ { -+ if (!(buf[j] >= '0' && buf[j] <= '9') && -+ !(buf[j] >= 'a' && buf[j] <= 'f') && -+ !(buf[j] >= 'A' && buf[j] <= 'F')) -+ return -1; -+ } -+ i += 2; -+ } -+ } -+ if (i == len - 2) -+ { -+ if (buf[i+1] == '%' || buf[i+2] == '%') -+ return -1; -+ } -+ for (i = 0; i < len - 2; i++) -+ { -+ if (buf[i] == '%') -+ { -+ rc = hex2int (buf[i+1]); -+ if (rc < 0) -+ return -1; -+ c = (rc & 0xf) << 4; -+ rc = hex2int (buf[i+2]); -+ if (rc < 0) -+ return -1; -+ c |= (rc & 0xf); -+ -+ buf[i] = c; -+ grub_memmove (buf+i+1, buf+i+3, len-(i+2)); -+ len -= 2; -+ } -+ } -+ return 0; -+} -+ -+static int -+extract_http_url_info (char *url, int ssl, -+ char **userinfo, char **host, int *port, -+ char **file) -+{ -+ char *colon, *slash, *query, *at = NULL, *separator, *auth_end; -+ -+ char *userinfo_off = NULL; -+ char *userinfo_end; -+ char *host_off = NULL; -+ char *host_end; -+ char *port_off = NULL; -+ char *port_end; -+ char *file_off = NULL; -+ -+ grub_size_t l; -+ int c; -+ -+ if (!url || !userinfo || !host || !port || !file) -+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid argument"); -+ -+ *userinfo = *host = *file = NULL; -+ *port = -1; -+ -+ userinfo_off = url; -+ -+ slash = grub_strchrnul (userinfo_off, '/'); -+ query = grub_strchrnul (userinfo_off, '?'); -+ auth_end = slash < query ? slash : query; -+ /* auth_end here is one /past/ the last character in the auth section, i.e. -+ * it's the : or / or NUL */ -+ -+ separator = grub_strchrnul (userinfo_off, '@'); -+ if (separator > auth_end) -+ { -+ host_off = userinfo_off; -+ userinfo_off = NULL; -+ userinfo_end = NULL; -+ } -+ else -+ { -+ at = separator; -+ *separator = '\0'; -+ userinfo_end = separator; -+ host_off = separator + 1; -+ } -+ -+ if (*host_off == '[') -+ { -+ separator = grub_strchrnul (host_off, ']'); -+ if (separator >= auth_end) -+ goto fail; -+ -+ separator += 1; -+ host_end = separator; -+ } -+ else -+ { -+ host_end = separator = colon = grub_strchrnul (host_off, ':'); -+ -+ if (colon > auth_end) -+ { -+ separator = NULL; -+ host_end = auth_end; -+ } -+ } -+ -+ if (separator && separator < auth_end) -+ { -+ if (*separator == ':') -+ { -+ port_off = separator + 1; -+ port_end = auth_end; -+ -+ if (auth_end - port_end > 0) -+ goto fail; -+ if (port_end - port_off < 1) -+ goto fail; -+ } -+ else -+ goto fail; -+ } -+ -+ file_off = auth_end; -+ if (port_off) -+ { -+ unsigned long portul; -+ -+ separator = NULL; -+ c = *port_end; -+ *port_end = '\0'; -+ -+ portul = grub_strtoul (port_off, &separator, 10); -+ *port_end = c; -+#ifdef URL_TEST -+ if (portul == ULONG_MAX && errno == ERANGE) -+ goto fail; -+#else -+ if (grub_errno == GRUB_ERR_OUT_OF_RANGE) -+ goto fail; -+#endif -+ if (portul & ~0xfffful) -+ goto fail; -+ if (separator != port_end) -+ goto fail; -+ -+ *port = portul & 0xfffful; -+ } -+ else if (ssl) -+ *port = 443; -+ else -+ *port = 80; -+ -+ if (userinfo_off && *userinfo_off) -+ { -+ l = userinfo_end - userinfo_off + 1; -+ -+ *userinfo = grub_strndup (userinfo_off, l); -+ if (!*userinfo) -+ goto fail; -+ (*userinfo)[l-1]= '\0'; -+ } -+ -+ l = host_end - host_off; -+ -+ if (host_end == NULL) -+ goto fail; -+ else -+ c = *host_end; -+ -+ *host_end = '\0'; -+ *host = grub_strndup (host_off, l); -+ *host_end = c; -+ if (!*host) -+ goto fail; -+ (*host)[l] = '\0'; -+ -+ *file = grub_strdup (file_off); -+ if (!*file) -+ goto fail; -+ -+ if (at) -+ *at = '@'; -+ return 0; -+fail: -+ if (at) -+ *at = '@'; -+ grub_free (*userinfo); -+ grub_free (*host); -+ grub_free (*file); -+ -+ return -1; -+} -+ -+static int -+extract_tftp_url_info (char *url, int ssl, char **host, char **file, int *port) -+{ -+ char *slash, *semi; -+ -+ char *host_off = url; -+ char *host_end; -+ char *file_off; -+ -+ int c; -+ -+ if (!url || !host || !file || !port) -+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid argument"); -+ -+ if (ssl) -+ *port = 3713; -+ else -+ *port = 69; -+ -+ slash = grub_strchr (url, '/'); -+ if (!slash) -+ return -1; -+ -+ host_end = file_off = slash; -+ -+ semi = grub_strchrnul (slash, ';'); -+ if (!grub_strncmp (semi, ";mode=", 6) && grub_strcmp (semi+6, "octet")) -+ { -+ grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, -+ N_("TFTP mode `%s' is not implemented."), semi+6); -+ return -1; -+ } -+ -+ /* -+ * Maybe somebody added a new method, I dunno. Anyway, semi is a reserved -+ * character, so if it's there, it's the start of the mode block or it's -+ * invalid. So set it to \0 unconditionally, not just for ;mode=octet -+ */ -+ *semi = '\0'; -+ -+ c = *host_end; -+ *host_end = '\0'; -+ *host = grub_strdup (host_off); -+ *host_end = c; -+ -+ *file = grub_strdup (file_off); -+ -+ if (!*file || !*host) -+ { -+ grub_free (*file); -+ grub_free (*host); -+ return -1; -+ } -+ -+ return 0; -+} -+ -+int -+extract_url_info (const char *urlbuf, grub_size_t buflen, -+ char **scheme, char **userinfo, -+ char **host, int *port, char **file) -+{ -+ char *url; -+ char *colon; -+ -+ char *scheme_off; -+ char *specific_off; -+ -+ int rc; -+ int c; -+ -+ int https; -+ -+ if (!urlbuf || !buflen || !scheme || !userinfo || !host || !port || !file) -+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid argument"); -+ -+ *scheme = *userinfo = *host = *file = NULL; -+ *port = -1; -+ -+ /* make sure we have our own coherent grub_string. */ -+ url = grub_malloc (buflen + 1); -+ if (!url) -+ return -1; -+ -+ grub_memcpy (url, urlbuf, buflen); -+ url[buflen] = '\0'; -+ -+ grub_dprintf ("net", "dhcpv6 boot-file-url: `%s'\n", url); -+ -+ /* get rid of any backslashes */ -+ url = translate_slashes (url); -+ -+ /* find the constituent parts */ -+ colon = grub_strstr (url, "://"); -+ if (!colon) -+ goto fail; -+ -+ scheme_off = url; -+ c = *colon; -+ *colon = '\0'; -+ specific_off = colon + 3; -+ -+ https = !grub_strcasecmp (scheme_off, "https"); -+ -+ rc = 0; -+ if (!grub_strcasecmp (scheme_off, "tftp")) -+ { -+ rc = extract_tftp_url_info (specific_off, 0, host, file, port); -+ } -+#ifdef URL_TEST -+ else if (!grub_strcasecmp (scheme_off, "http") || https) -+#else -+ else if (!grub_strcasecmp (scheme_off, "http")) -+#endif -+ { -+ rc = extract_http_url_info (specific_off, -+ https, userinfo, host, port, file); -+ } -+#ifdef URL_TEST -+ else if (!grub_strcasecmp (scheme_off, "iscsi")) -+ { -+ grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, -+ N_("Unimplemented URL scheme `%s'"), scheme_off); -+ *colon = c; -+ goto fail; -+ } -+ else if (!grub_strcasecmp (scheme_off, "tftps")) -+ { -+ rc = extract_tftp_url_info (specific_off, 1, host, file, port); -+ } -+#endif -+ else -+ { -+ grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, -+ N_("Unimplemented URL scheme `%s'"), scheme_off); -+ *colon = c; -+ goto fail; -+ } -+ -+ if (rc < 0) -+ { -+ *colon = c; -+ goto fail; -+ } -+ -+ *scheme = grub_strdup (scheme_off); -+ *colon = c; -+ if (!*scheme) -+ goto fail; -+ -+ if (*userinfo) -+ { -+ rc = url_unescape (*userinfo, grub_strlen (*userinfo)); -+ if (rc < 0) -+ goto fail; -+ } -+ -+ if (*host) -+ { -+ rc = url_unescape (*host, grub_strlen (*host)); -+ if (rc < 0) -+ goto fail; -+ } -+ -+ if (*file) -+ { -+ rc = url_unescape (*file, grub_strlen (*file)); -+ if (rc < 0) -+ goto fail; -+ } -+ -+ grub_free (url); -+ return 0; -+fail: -+ grub_free (*scheme); -+ grub_free (*userinfo); -+ grub_free (*host); -+ grub_free (*file); -+ -+ if (!grub_errno) -+ grub_error (GRUB_ERR_NET_BAD_ADDRESS, N_("Invalid boot-file-url `%s'"), -+ url); -+ grub_free (url); -+ return -1; -+} -+ -+#ifdef URL_TEST -+ -+struct test { -+ char *url; -+ int rc; -+ char *scheme; -+ char *userinfo; -+ char *host; -+ int port; -+ char *file; -+} tests[] = { -+ {.url = "http://foo.example.com/", -+ .rc = 0, -+ .scheme = "http", -+ .host = "foo.example.com", -+ .port = 80, -+ .file = "/", -+ }, -+ {.url = "http://foo.example.com/?foobar", -+ .rc = 0, -+ .scheme = "http", -+ .host = "foo.example.com", -+ .port = 80, -+ .file = "/?foobar", -+ }, -+ {.url = "http://[foo.example.com/", -+ .rc = -1, -+ }, -+ {.url = "http://[foo.example.com/?foobar", -+ .rc = -1, -+ }, -+ {.url = "http://foo.example.com:/", -+ .rc = -1, -+ }, -+ {.url = "http://foo.example.com:81/", -+ .rc = 0, -+ .scheme = "http", -+ .host = "foo.example.com", -+ .port = 81, -+ .file = "/", -+ }, -+ {.url = "http://foo.example.com:81/?foobar", -+ .rc = 0, -+ .scheme = "http", -+ .host = "foo.example.com", -+ .port = 81, -+ .file = "/?foobar", -+ }, -+ {.url = "http://[1234::1]/", -+ .rc = 0, -+ .scheme = "http", -+ .host = "[1234::1]", -+ .port = 80, -+ .file = "/", -+ }, -+ {.url = "http://[1234::1]/?foobar", -+ .rc = 0, -+ .scheme = "http", -+ .host = "[1234::1]", -+ .port = 80, -+ .file = "/?foobar", -+ }, -+ {.url = "http://[1234::1]:81/", -+ .rc = 0, -+ .scheme = "http", -+ .host = "[1234::1]", -+ .port = 81, -+ .file = "/", -+ }, -+ {.url = "http://[1234::1]:81/?foobar", -+ .rc = 0, -+ .scheme = "http", -+ .host = "[1234::1]", -+ .port = 81, -+ .file = "/?foobar", -+ }, -+ {.url = "http://foo@foo.example.com/", -+ .rc = 0, -+ .scheme = "http", -+ .userinfo = "foo", -+ .host = "foo.example.com", -+ .port = 80, -+ .file = "/", -+ }, -+ {.url = "http://foo@foo.example.com/?foobar", -+ .rc = 0, -+ .scheme = "http", -+ .userinfo = "foo", -+ .host = "foo.example.com", -+ .port = 80, -+ .file = "/?foobar", -+ }, -+ {.url = "http://foo@[foo.example.com/", -+ .rc = -1, -+ }, -+ {.url = "http://foo@[foo.example.com/?foobar", -+ .rc = -1, -+ }, -+ {.url = "http://foo@foo.example.com:81/", -+ .rc = 0, -+ .scheme = "http", -+ .userinfo = "foo", -+ .host = "foo.example.com", -+ .port = 81, -+ .file = "/", -+ }, -+ {.url = "http://foo@foo.example.com:81/?foobar", -+ .rc = 0, -+ .scheme = "http", -+ .userinfo = "foo", -+ .host = "foo.example.com", -+ .port = 81, -+ .file = "/?foobar", -+ }, -+ {.url = "http://foo@[1234::1]/", -+ .rc = 0, -+ .scheme = "http", -+ .userinfo = "foo", -+ .host = "[1234::1]", -+ .port = 80, -+ .file = "/", -+ }, -+ {.url = "http://foo@[1234::1]/?foobar", -+ .rc = 0, -+ .scheme = "http", -+ .userinfo = "foo", -+ .host = "[1234::1]", -+ .port = 80, -+ .file = "/?foobar", -+ }, -+ {.url = "http://foo@[1234::1]:81/", -+ .rc = 0, -+ .scheme = "http", -+ .userinfo = "foo", -+ .host = "[1234::1]", -+ .port = 81, -+ .file = "/", -+ }, -+ {.url = "http://foo@[1234::1]:81/?foobar", -+ .rc = 0, -+ .scheme = "http", -+ .userinfo = "foo", -+ .host = "[1234::1]", -+ .port = 81, -+ .file = "/?foobar", -+ }, -+ {.url = "https://foo.example.com/", -+ .rc = 0, -+ .scheme = "https", -+ .host = "foo.example.com", -+ .port = 443, -+ .file = "/", -+ }, -+ {.url = "https://foo.example.com/?foobar", -+ .rc = 0, -+ .scheme = "https", -+ .host = "foo.example.com", -+ .port = 443, -+ .file = "/?foobar", -+ }, -+ {.url = "https://[foo.example.com/", -+ .rc = -1, -+ }, -+ {.url = "https://[foo.example.com/?foobar", -+ .rc = -1, -+ }, -+ {.url = "https://foo.example.com:81/", -+ .rc = 0, -+ .scheme = "https", -+ .host = "foo.example.com", -+ .port = 81, -+ .file = "/", -+ }, -+ {.url = "https://foo.example.com:81/?foobar", -+ .rc = 0, -+ .scheme = "https", -+ .host = "foo.example.com", -+ .port = 81, -+ .file = "/?foobar", -+ }, -+ {.url = "https://[1234::1]/", -+ .rc = 0, -+ .scheme = "https", -+ .host = "[1234::1]", -+ .port = 443, -+ .file = "/", -+ }, -+ {.url = "https://[1234::1]/?foobar", -+ .rc = 0, -+ .scheme = "https", -+ .host = "[1234::1]", -+ .port = 443, -+ .file = "/?foobar", -+ }, -+ {.url = "https://[1234::1]:81/", -+ .rc = 0, -+ .scheme = "https", -+ .host = "[1234::1]", -+ .port = 81, -+ .file = "/", -+ }, -+ {.url = "https://[1234::1]:81/?foobar", -+ .rc = 0, -+ .scheme = "https", -+ .host = "[1234::1]", -+ .port = 81, -+ .file = "/?foobar", -+ }, -+ {.url = "https://foo@foo.example.com/", -+ .rc = 0, -+ .scheme = "https", -+ .userinfo = "foo", -+ .host = "foo.example.com", -+ .port = 443, -+ .file = "/", -+ }, -+ {.url = "https://foo@foo.example.com/?foobar", -+ .rc = 0, -+ .scheme = "https", -+ .userinfo = "foo", -+ .host = "foo.example.com", -+ .port = 443, -+ .file = "/?foobar", -+ }, -+ {.url = "https://foo@[foo.example.com/", -+ .rc = -1, -+ }, -+ {.url = "https://f%6fo@[foo.example.com/?fooba%72", -+ .rc = -1, -+ }, -+ {.url = "https://foo@foo.example.com:81/", -+ .rc = 0, -+ .scheme = "https", -+ .userinfo = "foo", -+ .host = "foo.example.com", -+ .port = 81, -+ .file = "/", -+ }, -+ {.url = "https://foo@foo.example.com:81/?foobar", -+ .rc = 0, -+ .scheme = "https", -+ .userinfo = "foo", -+ .host = "foo.example.com", -+ .port = 81, -+ .file = "/?foobar", -+ }, -+ {.url = "https://foo@[1234::1]/", -+ .rc = 0, -+ .scheme = "https", -+ .userinfo = "foo", -+ .host = "[1234::1]", -+ .port = 443, -+ .file = "/", -+ }, -+ {.url = "https://foo@[1234::1]/?foobar", -+ .rc = 0, -+ .scheme = "https", -+ .userinfo = "foo", -+ .host = "[1234::1]", -+ .port = 443, -+ .file = "/?foobar", -+ }, -+ {.url = "https://f%6fo@[12%334::1]:81/", -+ .rc = 0, -+ .scheme = "https", -+ .userinfo = "foo", -+ .host = "[1234::1]", -+ .port = 81, -+ .file = "/", -+ }, -+ {.url = "https://foo@[1234::1]:81/?foobar", -+ .rc = 0, -+ .scheme = "https", -+ .userinfo = "foo", -+ .host = "[1234::1]", -+ .port = 81, -+ .file = "/?foobar", -+ }, -+ {.url = "tftp://foo.e%78ample.com/foo/bar/b%61%7a", -+ .rc = 0, -+ .scheme = "tftp", -+ .host = "foo.example.com", -+ .port = 69, -+ .file = "/foo/bar/baz", -+ }, -+ {.url = "tftp://foo.example.com/foo/bar/baz", -+ .rc = 0, -+ .scheme = "tftp", -+ .host = "foo.example.com", -+ .port = 69, -+ .file = "/foo/bar/baz", -+ }, -+ {.url = "tftps://foo.example.com/foo/bar/baz", -+ .rc = 0, -+ .scheme = "tftps", -+ .host = "foo.example.com", -+ .port = 3713, -+ .file = "/foo/bar/baz", -+ }, -+ {.url = "tftps://foo.example.com/foo/bar/baz;mode=netascii", -+ .rc = -1, -+ }, -+ {.url = "tftps://foo.example.com/foo/bar/baz;mode=octet", -+ .rc = 0, -+ .scheme = "tftps", -+ .host = "foo.example.com", -+ .port = 3713, -+ .file = "/foo/bar/baz", -+ }, -+ {.url = "tftps://foo.example.com/foo/bar/baz;mode=invalid", -+ .rc = -1, -+ }, -+ {.url = "", -+ }, -+}; -+ -+static int -+string_test (char *name, char *a, char *b) -+{ -+ if ((a && !b) || (!a && b)) -+ { -+ printf("expected %s \"%s\", got \"%s\"\n", name, a, b); -+ return -1; -+ } -+ if (a && b && strcmp(a, b)) -+ { -+ printf("expected %s \"%s\", got \"%s\"\n", name, a, b); -+ return -1; -+ } -+ return 0; -+} -+ -+int -+main(void) -+{ -+ unsigned int i; -+ int rc; -+ -+ for (i = 0; tests[i].url[0] != '\0'; i++) -+ { -+ char *scheme, *userinfo, *host, *file; -+ int port; -+ -+ printf("======= url: \"%s\"\n", tests[i].url); -+ rc = extract_url_info(tests[i].url, strlen(tests[i].url) + 1, -+ &scheme, &userinfo, &host, &port, &file); -+ if (tests[i].rc != rc) -+ { -+ printf(" extract_url_info(...) = %d\n", rc); -+ exit(1); -+ } -+ else if (rc >= 0) -+ { -+ if (string_test("scheme", tests[i].scheme, scheme) < 0) -+ exit(1); -+ if (string_test("userinfo", tests[i].userinfo, userinfo) < 0) -+ exit(1); -+ if (string_test("host", tests[i].host, host) < 0) -+ exit(1); -+ if (port != tests[i].port) -+ { -+ printf(" bad port \"%d\" should have been \"%d\"\n", -+ port, tests[i].port); -+ exit(1); -+ } -+ if (string_test("file", tests[i].file, file) < 0) -+ exit(1); -+ } -+ free(scheme); -+ free(userinfo); -+ free(host); -+ free(file); -+ } -+ printf("everything worked?!?\n"); -+} -+#endif -diff --git a/include/grub/misc.h b/include/grub/misc.h -index f9135b6..b433922 100644 ---- a/include/grub/misc.h -+++ b/include/grub/misc.h -@@ -85,6 +85,7 @@ int EXPORT_FUNC(grub_strncmp) (const char *s1, const char *s2, grub_size_t n); - - char *EXPORT_FUNC(grub_strchr) (const char *s, int c); - char *EXPORT_FUNC(grub_strrchr) (const char *s, int c); -+char *EXPORT_FUNC(grub_strchrnul) (const char *s, int c); - int EXPORT_FUNC(grub_strword) (const char *s, const char *w); - - /* Copied from gnulib. -@@ -207,6 +208,50 @@ grub_toupper (int c) - return c; - } - -+static inline char * -+grub_strcasestr (const char *haystack, const char *needle) -+{ -+ /* Be careful not to look at the entire extent of haystack or needle -+ until needed. This is useful because of these two cases: -+ - haystack may be very long, and a match of needle found early, -+ - needle may be very long, and not even a short initial segment of -+ needle may be found in haystack. */ -+ if (*needle != '\0') -+ { -+ /* Speed up the following searches of needle by caching its first -+ character. */ -+ char b = *needle++; -+ -+ for (;; haystack++) -+ { -+ if (*haystack == '\0') -+ /* No match. */ -+ return 0; -+ if (grub_tolower(*haystack) == grub_tolower(b)) -+ /* The first character matches. */ -+ { -+ const char *rhaystack = haystack + 1; -+ const char *rneedle = needle; -+ -+ for (;; rhaystack++, rneedle++) -+ { -+ if (*rneedle == '\0') -+ /* Found a match. */ -+ return (char *) haystack; -+ if (*rhaystack == '\0') -+ /* No match. */ -+ return 0; -+ if (grub_tolower(*rhaystack) != grub_tolower(*rneedle)) -+ /* Nothing in this round. */ -+ break; -+ } -+ } -+ } -+ } -+ else -+ return (char *) haystack; -+} -+ - static inline int - grub_strcasecmp (const char *s1, const char *s2) - { -diff --git a/include/grub/net/url.h b/include/grub/net/url.h -new file mode 100644 -index 0000000..a215fa2 ---- /dev/null -+++ b/include/grub/net/url.h -@@ -0,0 +1,28 @@ -+/* url.h - prototypes for url parsing functions */ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2016 Free Software Foundation, Inc. -+ * -+ * GRUB is free software: you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation, either version 3 of the License, or -+ * (at your option) any later version. -+ * -+ * GRUB is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with GRUB. If not, see . -+ */ -+ -+#ifndef GRUB_URL_HEADER -+#define GRUB_URL_HEADER 1 -+ -+int -+EXPORT_FUNC(extract_url_info) (const char *urlbuf, grub_size_t buflen, -+ char **scheme, char **userinfo, -+ char **host, int *port, char **file); -+ -+#endif /* GRUB_URL_HEADER */ --- -1.8.3.1 - diff --git a/0097-Add-linux-and-initrd-commands-for-grub-emu.patch b/0063-Add-linux-and-initrd-commands-for-grub-emu.patch similarity index 92% rename from 0097-Add-linux-and-initrd-commands-for-grub-emu.patch rename to 0063-Add-linux-and-initrd-commands-for-grub-emu.patch index ac026152e7bf7096a3772c4fc6376eca648bd55b..2431a4d782e87a599c87b3609c3cab2037f5a41f 100644 --- a/0097-Add-linux-and-initrd-commands-for-grub-emu.patch +++ b/0063-Add-linux-and-initrd-commands-for-grub-emu.patch @@ -1,12 +1,14 @@ -From 5dbb03ccd67da4cb9e775c429d3b933bc257194f Mon Sep 17 00:00:00 2001 -From: Michael Chang +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Raymund Will Date: Tue, 6 Feb 2018 09:09:00 +0100 -Subject: [PATCH 097/220] Add linux and initrd commands for grub-emu +Subject: [PATCH] Add linux and initrd commands for grub-emu When using grub-emu, the linux and initrd commands are used as arguments to the kexec command line tool, to allow booting the selected menu entry. + +Signed-off-by: Raymund Will +Signed-off-by: Robbie Harwood --- - grub-core/Makefile.am | 1 + grub-core/Makefile.core.def | 1 - grub-core/kern/emu/main.c | 4 + grub-core/kern/emu/misc.c | 18 ++++- @@ -14,26 +16,15 @@ to the kexec command line tool, to allow booting the selected menu entry. include/grub/emu/exec.h | 4 +- include/grub/emu/hostfile.h | 3 +- include/grub/emu/misc.h | 3 + + grub-core/Makefile.am | 1 + 8 files changed, 202 insertions(+), 4 deletions(-) create mode 100644 grub-core/loader/emu/linux.c -diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am -index c6ba5b2..5ff3afd 100644 ---- a/grub-core/Makefile.am -+++ b/grub-core/Makefile.am -@@ -304,6 +304,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/net.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostdisk.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostfile.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h -+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/exec.h - if COND_GRUB_EMU_SDL - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h - endif diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index ebc5580..528f76a 100644 +index 058c88ac3af..5354f9613d3 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -1802,7 +1802,6 @@ module = { +@@ -1826,7 +1826,6 @@ module = { common = loader/linux.c; common = lib/cmdline.c; @@ -42,7 +33,7 @@ index ebc5580..528f76a 100644 efi = loader/efi/linux.c; }; diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c -index 55ea5a1..846fe97 100644 +index 55ea5a11ccd..846fe9715ec 100644 --- a/grub-core/kern/emu/main.c +++ b/grub-core/kern/emu/main.c @@ -107,6 +107,7 @@ static struct argp_option options[] = { @@ -64,7 +55,7 @@ index 55ea5a1..846fe97 100644 case ARGP_KEY_ARG: { diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c -index 19cd007..245b69c 100644 +index 0ff13bcaf8c..eeea092752d 100644 --- a/grub-core/kern/emu/misc.c +++ b/grub-core/kern/emu/misc.c @@ -39,6 +39,7 @@ @@ -84,7 +75,7 @@ index 19cd007..245b69c 100644 } void * -@@ -142,6 +143,9 @@ void +@@ -154,6 +155,9 @@ void __attribute__ ((noreturn)) grub_exit (int rc) { @@ -94,7 +85,7 @@ index 19cd007..245b69c 100644 exit (rc < 0 ? 1 : rc); } #endif -@@ -203,3 +207,15 @@ grub_util_load_image (const char *path, char *buf) +@@ -215,3 +219,15 @@ grub_util_load_image (const char *path, char *buf) fclose (fp); } @@ -112,7 +103,7 @@ index 19cd007..245b69c 100644 +} diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c new file mode 100644 -index 0000000..fda9e00 +index 00000000000..fda9e00d24c --- /dev/null +++ b/grub-core/loader/emu/linux.c @@ -0,0 +1,172 @@ @@ -289,7 +280,7 @@ index 0000000..fda9e00 + grub_unregister_command (cmd_initrd); +} diff --git a/include/grub/emu/exec.h b/include/grub/emu/exec.h -index d1073ef..1b61b4a 100644 +index d1073ef86af..1b61b4a2e5d 100644 --- a/include/grub/emu/exec.h +++ b/include/grub/emu/exec.h @@ -23,6 +23,8 @@ @@ -311,7 +302,7 @@ index d1073ef..1b61b4a 100644 grub_util_exec_redirect (const char *const *argv, const char *stdin_file, const char *stdout_file); diff --git a/include/grub/emu/hostfile.h b/include/grub/emu/hostfile.h -index cfb1e2b..a61568e 100644 +index cfb1e2b5661..a61568e36e9 100644 --- a/include/grub/emu/hostfile.h +++ b/include/grub/emu/hostfile.h @@ -22,6 +22,7 @@ @@ -332,10 +323,10 @@ index cfb1e2b..a61568e 100644 char * grub_util_path_concat (size_t n, ...); diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h -index ce464cf..5ef4f79 100644 +index ff9c48a6490..01056954b96 100644 --- a/include/grub/emu/misc.h +++ b/include/grub/emu/misc.h -@@ -56,6 +56,9 @@ void EXPORT_FUNC(grub_util_warn) (const char *fmt, ...) __attribute__ ((format ( +@@ -57,6 +57,9 @@ void EXPORT_FUNC(grub_util_warn) (const char *fmt, ...) __attribute__ ((format ( void EXPORT_FUNC(grub_util_info) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))); void EXPORT_FUNC(grub_util_error) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2), noreturn)); @@ -345,6 +336,15 @@ index ce464cf..5ef4f79 100644 grub_uint64_t EXPORT_FUNC (grub_util_get_cpu_time_ms) (void); #ifdef HAVE_DEVICE_MAPPER --- -1.8.3.1 - +diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am +index ee88e44e97a..80e7a83edf9 100644 +--- a/grub-core/Makefile.am ++++ b/grub-core/Makefile.am +@@ -307,6 +307,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/net.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostdisk.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostfile.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h ++KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/exec.h + if COND_GRUB_EMU_SDL + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h + endif diff --git a/0098-Add-grub2-switch-to-blscfg.patch b/0064-Add-grub2-switch-to-blscfg.patch similarity index 85% rename from 0098-Add-grub2-switch-to-blscfg.patch rename to 0064-Add-grub2-switch-to-blscfg.patch index 8f7f4e639a98dc54d18a685fe5d826ecf5e6816b..ac30490f0e37fcd9434a9b926d7e48e1f28f67e1 100644 --- a/0098-Add-grub2-switch-to-blscfg.patch +++ b/0064-Add-grub2-switch-to-blscfg.patch @@ -1,7 +1,7 @@ -From 2e187d17d3ffeb9a9bf4bfa3e079be7e335d8c80 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 15 Mar 2018 14:12:40 -0400 -Subject: [PATCH 098/220] Add grub2-switch-to-blscfg +Subject: [PATCH] Add grub2-switch-to-blscfg Signed-off-by: Peter Jones Signed-off-by: Javier Martinez Canillas @@ -11,16 +11,16 @@ Signed-off-by: Jan Hlavac Makefile.util.def | 7 + util/grub-set-password.in | 2 +- util/grub-switch-to-blscfg.8 | 33 +++++ - util/grub-switch-to-blscfg.in | 314 ++++++++++++++++++++++++++++++++++++++++++ - 4 files changed, 355 insertions(+), 1 deletion(-) + util/grub-switch-to-blscfg.in | 317 ++++++++++++++++++++++++++++++++++++++++++ + 4 files changed, 358 insertions(+), 1 deletion(-) create mode 100644 util/grub-switch-to-blscfg.8 create mode 100644 util/grub-switch-to-blscfg.in diff --git a/Makefile.util.def b/Makefile.util.def -index a616136..f55473c 100644 +index 43a1c7453b1..a90879fa9ba 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -1364,6 +1364,13 @@ program = { +@@ -1365,6 +1365,13 @@ program = { ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -35,7 +35,7 @@ index a616136..f55473c 100644 name = grub-glue-efi; mansection = 1; diff --git a/util/grub-set-password.in b/util/grub-set-password.in -index 5ebf505..c0b5ebb 100644 +index 5ebf50576d6..c0b5ebbfdc5 100644 --- a/util/grub-set-password.in +++ b/util/grub-set-password.in @@ -1,6 +1,6 @@ @@ -48,7 +48,7 @@ index 5ebf505..c0b5ebb 100644 else diff --git a/util/grub-switch-to-blscfg.8 b/util/grub-switch-to-blscfg.8 new file mode 100644 -index 0000000..9a88628 +index 00000000000..9a886282976 --- /dev/null +++ b/util/grub-switch-to-blscfg.8 @@ -0,0 +1,33 @@ @@ -87,10 +87,10 @@ index 0000000..9a88628 +.BR "info grub" diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in new file mode 100644 -index 0000000..49b3985 +index 00000000000..a851424beb2 --- /dev/null +++ b/util/grub-switch-to-blscfg.in -@@ -0,0 +1,314 @@ +@@ -0,0 +1,317 @@ +#! /bin/sh +# +# Set a default boot entry for GRUB. @@ -283,7 +283,7 @@ index 0000000..49b3985 +mkbls() { + local kernelver=$1 && shift + local datetime=$1 && shift -+ local bootprefix=$1 && shift ++ local kernelopts=$1 && shift + + local debugname="" + local debugid="" @@ -302,10 +302,9 @@ index 0000000..49b3985 + cat <"${bls_target}" -+ fi ++ mkbls "${kernelver}" \ ++ "$(date -u +%Y%m%d%H%M%S -d "$(stat -c '%y' "${kernel_dir}")")" \ ++ "${bootprefix}" "${cmdline}" >"${bls_target}" + + if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then + bls_debug="$(echo ${bls_target} | sed -e "s/${kernelver}/${kernelver}~debug/")" + cp -aT "${bls_target}" "${bls_debug}" + title="$(grep '^title[ \t]' "${bls_debug}" | sed -e 's/^title[ \t]*//')" -+ blsid="$(grep '^id[ \t]' "${bls_debug}" | sed -e "s/\.${ARCH}/-debug.${arch}/")" ++ options="$(echo "${cmdline} ${GRUB_CMDLINE_LINUX_DEBUG}" | sed -e 's/\//\\\//g')" + sed -i -e "s/^title.*/title ${title}${GRUB_LINUX_DEBUG_TITLE_POSTFIX}/" "${bls_debug}" -+ sed -i -e "s/^id.*/${blsid}/" "${bls_debug}" -+ sed -i -e "s/^options.*/options \$kernelopts ${GRUB_CMDLINE_LINUX_DEBUG}/" "${bls_debug}" ++ sed -i -e "s/^options.*/options ${options}/" "${bls_debug}" + fi + done + @@ -359,6 +349,19 @@ index 0000000..49b3985 + fi +} + ++# The grub2 EFI binary is not copied to the ESP as a part of an ostree ++# transaction. Make sure a grub2 version with BLS support is installed ++# but only do this if the blsdir is not set, to make sure that the BLS ++# parsing module will search for the BLS snippets in the default path. ++if test -f /run/ostree-booted && test -d /sys/firmware/efi/efivars && \ ++ ! ${grub_editenv} - list | grep -q blsdir && \ ++ mountpoint -q /boot; then ++ grub_binary="$(find /usr/lib/ostree-boot/efi/EFI/${EFIDIR}/ -name grub*.efi)" ++ install -m 700 ${grub_binary} ${grubdir} || exit 1 ++ # Create a hidden file to indicate that grub2 now has BLS support. ++ touch /boot/grub2/.grub2-blscfg-supported ++fi ++ +GENERATE=0 +if grep '^GRUB_ENABLE_BLSCFG=.*' "${etcdefaultgrub}" \ + | grep -vq '^GRUB_ENABLE_BLSCFG="*true"*\s*$' ; then @@ -388,13 +391,13 @@ index 0000000..49b3985 + + if [ -n "${mod_dir}" ]; then + for mod in blscfg increment; do -+ cp ${prefix}/lib/grub/${mod_dir}/${mod}.mod ${grubdir}/$mod_dir/ || exit 1 ++ install -m 700 ${prefix}/lib/grub/${mod_dir}/${mod}.mod ${grubdir}/$mod_dir/ || exit 1 + done + fi + + cp -af "${GRUB_CONFIG_FILE}" "${GRUB_CONFIG_FILE}${backupsuffix}" + if ! grub2-mkconfig -o "${GRUB_CONFIG_FILE}" ; then -+ cp -af "${GRUB_CONFIG_FILE}${backupsuffix}" "${GRUB_CONFIG_FILE}" ++ install -m 700 "${GRUB_CONFIG_FILE}${backupsuffix}" "${GRUB_CONFIG_FILE}" + sed -i"${backupsuffix}" \ + -e 's,^GRUB_ENABLE_BLSCFG=.*,GRUB_ENABLE_BLSCFG=false,' \ + "${etcdefaultgrub}" @@ -405,6 +408,3 @@ index 0000000..49b3985 + +# Bye. +exit 0 --- -1.8.3.1 - diff --git a/0100-make-better-backtraces.patch b/0065-make-better-backtraces.patch similarity index 76% rename from 0100-make-better-backtraces.patch rename to 0065-make-better-backtraces.patch index d76b4fe091067df2a5a2ecf4e3b4ab7192187455..637656719b92e0b946b0eb0431ca4ee4a800e823 100644 --- a/0100-make-better-backtraces.patch +++ b/0065-make-better-backtraces.patch @@ -1,49 +1,47 @@ -From 69fbc18e0758e780236f713b579a951551d7e829 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 9 Jul 2019 17:05:03 +0200 -Subject: [PATCH 100/220] make better backtraces +Subject: [PATCH] make better backtraces Signed-off-by: Peter Jones --- - Makefile.util.def | 6 ++ - grub-core/Makefile.am | 1 + - grub-core/Makefile.core.def | 16 ++--- - grub-core/commands/backtrace.c | 72 +++++++++++++++++++ - grub-core/gdb/cstub.c | 1 - - grub-core/kern/arm/efi/startup.S | 2 + - grub-core/kern/arm/startup.S | 2 + - grub-core/kern/arm64/backtrace.c | 94 +++++++++++++++++++++++++ - grub-core/kern/arm64/efi/startup.S | 2 + - grub-core/kern/backtrace.c | 97 +++++++++++++++++++++++++ - grub-core/kern/dl.c | 45 ++++++++++++ - grub-core/kern/i386/backtrace.c | 125 +++++++++++++++++++++++++++++++++ - grub-core/kern/i386/pc/init.c | 4 +- - grub-core/kern/i386/qemu/startup.S | 3 +- - grub-core/kern/ia64/efi/startup.S | 3 +- - grub-core/kern/ieee1275/init.c | 1 - - grub-core/kern/misc.c | 13 ++-- - grub-core/kern/mm.c | 6 +- - grub-core/kern/sparc64/ieee1275/crt0.S | 3 +- - grub-core/lib/arm64/backtrace.c | 62 ---------------- - grub-core/lib/backtrace.c | 72 ------------------- - grub-core/lib/i386/backtrace.c | 78 -------------------- - include/grub/backtrace.h | 10 ++- - include/grub/dl.h | 2 + - include/grub/kernel.h | 3 + - 25 files changed, 485 insertions(+), 238 deletions(-) - create mode 100644 grub-core/commands/backtrace.c + Makefile.util.def | 6 ++ + grub-core/Makefile.core.def | 16 ++-- + grub-core/{lib => commands}/backtrace.c | 2 +- + grub-core/gdb/cstub.c | 1 - + grub-core/kern/arm64/backtrace.c | 94 ++++++++++++++++++++++++ + grub-core/kern/backtrace.c | 97 +++++++++++++++++++++++++ + grub-core/kern/dl.c | 45 ++++++++++++ + grub-core/kern/i386/backtrace.c | 125 ++++++++++++++++++++++++++++++++ + grub-core/kern/i386/pc/init.c | 4 +- + grub-core/kern/ieee1275/init.c | 1 - + grub-core/kern/misc.c | 13 ++-- + grub-core/kern/mm.c | 6 +- + grub-core/lib/arm64/backtrace.c | 62 ---------------- + grub-core/lib/i386/backtrace.c | 78 -------------------- + include/grub/backtrace.h | 10 ++- + include/grub/dl.h | 2 + + include/grub/kernel.h | 3 + + grub-core/kern/arm/efi/startup.S | 2 + + grub-core/kern/arm/startup.S | 2 + + grub-core/kern/arm64/efi/startup.S | 2 + + grub-core/kern/i386/qemu/startup.S | 3 +- + grub-core/kern/ia64/efi/startup.S | 3 +- + grub-core/kern/sparc64/ieee1275/crt0.S | 3 +- + grub-core/Makefile.am | 1 + + 24 files changed, 414 insertions(+), 167 deletions(-) + rename grub-core/{lib => commands}/backtrace.c (98%) create mode 100644 grub-core/kern/arm64/backtrace.c create mode 100644 grub-core/kern/backtrace.c create mode 100644 grub-core/kern/i386/backtrace.c delete mode 100644 grub-core/lib/arm64/backtrace.c - delete mode 100644 grub-core/lib/backtrace.c delete mode 100644 grub-core/lib/i386/backtrace.c diff --git a/Makefile.util.def b/Makefile.util.def -index f55473c..c13ca68 100644 +index a90879fa9ba..48512bc6311 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -49,6 +49,12 @@ library = { +@@ -51,6 +51,12 @@ library = { common = grub-core/partmap/msdos.c; common = grub-core/fs/proc.c; common = grub-core/fs/archelp.c; @@ -56,26 +54,14 @@ index f55473c..c13ca68 100644 }; library = { -diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am -index 5ff3afd..d9ad300 100644 ---- a/grub-core/Makefile.am -+++ b/grub-core/Makefile.am -@@ -66,6 +66,7 @@ CLEANFILES += grub_script.yy.c grub_script.yy.h - - include $(srcdir)/Makefile.core.am - -+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/backtrace.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cache.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/command.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/device.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 528f76a..49c5dc4 100644 +index 5354f9613d3..4b7c45a7b06 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -140,6 +140,12 @@ kernel = { - common = kern/rescue_parser.c; +@@ -142,6 +142,12 @@ kernel = { common = kern/rescue_reader.c; common = kern/term.c; + common = kern/verifiers.c; + common = kern/backtrace.c; + + x86 = kern/i386/backtrace.c; @@ -85,7 +71,7 @@ index 528f76a..49c5dc4 100644 noemu = kern/compiler-rt.c; noemu = kern/mm.c; -@@ -186,9 +192,6 @@ kernel = { +@@ -188,9 +194,6 @@ kernel = { softdiv = lib/division.c; @@ -95,7 +81,7 @@ index 528f76a..49c5dc4 100644 i386 = kern/i386/dl.c; i386_xen = kern/i386/dl.c; i386_xen_pvh = kern/i386/dl.c; -@@ -2376,15 +2379,12 @@ module = { +@@ -2398,15 +2401,12 @@ module = { module = { name = backtrace; @@ -113,86 +99,24 @@ index 528f76a..49c5dc4 100644 }; module = { -diff --git a/grub-core/commands/backtrace.c b/grub-core/commands/backtrace.c -new file mode 100644 -index 0000000..8b5ec39 ---- /dev/null +diff --git a/grub-core/lib/backtrace.c b/grub-core/commands/backtrace.c +similarity index 98% +rename from grub-core/lib/backtrace.c +rename to grub-core/commands/backtrace.c +index c0ad6ab8be1..8b5ec3913b5 100644 +--- a/grub-core/lib/backtrace.c +++ b/grub-core/commands/backtrace.c -@@ -0,0 +1,72 @@ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2009 Free Software Foundation, Inc. -+ * -+ * GRUB is free software: you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation, either version 3 of the License, or -+ * (at your option) any later version. -+ * -+ * GRUB is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with GRUB. If not, see . -+ */ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+GRUB_MOD_LICENSE ("GPLv3+"); -+ -+void -+grub_backtrace_print_address (void *addr) -+{ -+#ifndef GRUB_UTIL -+ grub_dl_t mod; -+ -+ FOR_DL_MODULES (mod) -+ { -+ grub_dl_segment_t segment; -+ for (segment = mod->segment; segment; segment = segment->next) -+ if (segment->addr <= addr && (grub_uint8_t *) segment->addr -+ + segment->size > (grub_uint8_t *) addr) -+ { -+ grub_printf ("%s.%x+%" PRIxGRUB_SIZE, mod->name, segment->section, -+ (grub_size_t) ((grub_uint8_t *) addr - (grub_uint8_t *) segment->addr)); -+ return; -+ } -+ } -+ -+#endif -+ grub_printf ("%p", addr); -+} -+ -+static grub_err_t -+grub_cmd_backtrace (grub_command_t cmd __attribute__ ((unused)), -+ int argc __attribute__ ((unused)), -+ char **args __attribute__ ((unused))) -+{ +@@ -54,7 +54,7 @@ grub_cmd_backtrace (grub_command_t cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) + { +- grub_backtrace (); + grub_backtrace (1); -+ return 0; -+} -+ -+static grub_command_t cmd; -+ -+GRUB_MOD_INIT(backtrace) -+{ -+ cmd = grub_register_command ("backtrace", grub_cmd_backtrace, -+ 0, N_("Print backtrace.")); -+} -+ -+GRUB_MOD_FINI(backtrace) -+{ -+ grub_unregister_command (cmd); -+} + return 0; + } + diff --git a/grub-core/gdb/cstub.c b/grub-core/gdb/cstub.c -index b64acd7..9928147 100644 +index b64acd70fee..99281472d36 100644 --- a/grub-core/gdb/cstub.c +++ b/grub-core/gdb/cstub.c @@ -215,7 +215,6 @@ grub_gdb_trap (int trap_no) @@ -203,35 +127,9 @@ index b64acd7..9928147 100644 grub_fatal ("Unhandled exception"); } -diff --git a/grub-core/kern/arm/efi/startup.S b/grub-core/kern/arm/efi/startup.S -index 9f82653..f3bc41f 100644 ---- a/grub-core/kern/arm/efi/startup.S -+++ b/grub-core/kern/arm/efi/startup.S -@@ -23,6 +23,8 @@ - .file "startup.S" - .text - .arm -+ .globl start, _start -+FUNCTION(start) - FUNCTION(_start) - /* - * EFI_SYSTEM_TABLE and EFI_HANDLE are passed in r1/r0. -diff --git a/grub-core/kern/arm/startup.S b/grub-core/kern/arm/startup.S -index 3946fe8..5679a1d 100644 ---- a/grub-core/kern/arm/startup.S -+++ b/grub-core/kern/arm/startup.S -@@ -48,6 +48,8 @@ - - .text - .arm -+ .globl start, _start -+FUNCTION(start) - FUNCTION(_start) - b codestart - diff --git a/grub-core/kern/arm64/backtrace.c b/grub-core/kern/arm64/backtrace.c new file mode 100644 -index 0000000..019c6fd +index 00000000000..019c6fdfef2 --- /dev/null +++ b/grub-core/kern/arm64/backtrace.c @@ -0,0 +1,94 @@ @@ -329,23 +227,9 @@ index 0000000..019c6fd + skip += 1; + grub_backtrace_pointer(__builtin_frame_address(0), skip); +} -diff --git a/grub-core/kern/arm64/efi/startup.S b/grub-core/kern/arm64/efi/startup.S -index 666a7ee..41676bd 100644 ---- a/grub-core/kern/arm64/efi/startup.S -+++ b/grub-core/kern/arm64/efi/startup.S -@@ -19,7 +19,9 @@ - #include - - .file "startup.S" -+ .globl start, _start - .text -+FUNCTION(start) - FUNCTION(_start) - /* - * EFI_SYSTEM_TABLE and EFI_HANDLE are passed in x1/x0. diff --git a/grub-core/kern/backtrace.c b/grub-core/kern/backtrace.c new file mode 100644 -index 0000000..4a82e86 +index 00000000000..4a82e865cc6 --- /dev/null +++ b/grub-core/kern/backtrace.c @@ -0,0 +1,97 @@ @@ -447,7 +331,7 @@ index 0000000..4a82e86 + grub_backtrace (skip + 1); +} diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index d7718d2..2e57e5e 100644 +index 7afb9e6f724..88d2077709e 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -124,6 +124,50 @@ grub_dl_resolve_symbol (const char *name) @@ -511,7 +395,7 @@ index d7718d2..2e57e5e 100644 i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) diff --git a/grub-core/kern/i386/backtrace.c b/grub-core/kern/i386/backtrace.c new file mode 100644 -index 0000000..2413f9a +index 00000000000..2413f9a57db --- /dev/null +++ b/grub-core/kern/i386/backtrace.c @@ -0,0 +1,125 @@ @@ -641,7 +525,7 @@ index 0000000..2413f9a +#endif +} diff --git a/grub-core/kern/i386/pc/init.c b/grub-core/kern/i386/pc/init.c -index 27bc68b..b51d0ab 100644 +index 27bc68b8a53..b51d0abfa6e 100644 --- a/grub-core/kern/i386/pc/init.c +++ b/grub-core/kern/i386/pc/init.c @@ -153,7 +153,7 @@ compact_mem_regions (void) @@ -662,37 +546,8 @@ index 27bc68b..b51d0ab 100644 /* Initialize the console as early as possible. */ grub_console_init (); -diff --git a/grub-core/kern/i386/qemu/startup.S b/grub-core/kern/i386/qemu/startup.S -index 0d89858..939f182 100644 ---- a/grub-core/kern/i386/qemu/startup.S -+++ b/grub-core/kern/i386/qemu/startup.S -@@ -24,7 +24,8 @@ - - .text - .code32 -- .globl _start -+ .globl start, _start -+start: - _start: - jmp codestart - -diff --git a/grub-core/kern/ia64/efi/startup.S b/grub-core/kern/ia64/efi/startup.S -index d75c6d7..8f2a593 100644 ---- a/grub-core/kern/ia64/efi/startup.S -+++ b/grub-core/kern/ia64/efi/startup.S -@@ -24,8 +24,9 @@ - .psr lsb - .lsb - -- .global _start -+ .global start, _start - .proc _start -+start: - _start: - alloc loc0=ar.pfs,2,4,0,0 - mov loc1=rp diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c -index 0cd2a62..937c1bc 100644 +index 0cd2a627231..937c1bc44cb 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c @@ -63,7 +63,6 @@ @@ -704,11 +559,11 @@ index 0cd2a62..937c1bc 100644 #ifdef __sparc__ diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index e758ab3..5c2d203 100644 +index c60601b699d..a432a6be54a 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c -@@ -1110,15 +1110,15 @@ grub_xasprintf (const char *fmt, ...) - } +@@ -1197,15 +1197,15 @@ grub_printf_fmt_check (const char *fmt, const char *fmt_expected) + /* Abort GRUB. This function does not return. */ -static void __attribute__ ((noreturn)) @@ -718,18 +573,18 @@ index e758ab3..5c2d203 100644 -#ifndef GRUB_UTIL -#if (defined(__i386__) || defined(__x86_64__)) && !defined(GRUB_MACHINE_EMU) - grub_backtrace(); --#endif +#if !defined(GRUB_MACHINE_EMU) && !defined(GRUB_UTIL) + grub_backtrace (1); +#else + grub_printf ("\n"); #endif +-#endif - grub_printf ("\nAborted."); + grub_printf ("Aborted."); #ifndef GRUB_UTIL if (grub_term_inputs) -@@ -1145,6 +1145,7 @@ grub_fatal (const char *fmt, ...) +@@ -1232,6 +1232,7 @@ grub_fatal (const char *fmt, ...) { va_list ap; @@ -738,10 +593,10 @@ index e758ab3..5c2d203 100644 grub_vprintf (_(fmt), ap); va_end (ap); diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c -index ee88ff6..002cbfa 100644 +index c070afc621f..d8c8377578b 100644 --- a/grub-core/kern/mm.c +++ b/grub-core/kern/mm.c -@@ -95,13 +95,13 @@ get_header_from_pointer (void *ptr, grub_mm_header_t *p, grub_mm_region_t *r) +@@ -97,13 +97,13 @@ get_header_from_pointer (void *ptr, grub_mm_header_t *p, grub_mm_region_t *r) break; if (! *r) @@ -758,23 +613,9 @@ index ee88ff6..002cbfa 100644 (unsigned long) (*p)->magic); } -diff --git a/grub-core/kern/sparc64/ieee1275/crt0.S b/grub-core/kern/sparc64/ieee1275/crt0.S -index 03b916f..701bf63 100644 ---- a/grub-core/kern/sparc64/ieee1275/crt0.S -+++ b/grub-core/kern/sparc64/ieee1275/crt0.S -@@ -22,7 +22,8 @@ - - .text - .align 4 -- .globl _start -+ .globl start, _start -+start: - _start: - ba codestart - mov %o4, %o0 diff --git a/grub-core/lib/arm64/backtrace.c b/grub-core/lib/arm64/backtrace.c deleted file mode 100644 -index 1079b53..0000000 +index 1079b5380e1..00000000000 --- a/grub-core/lib/arm64/backtrace.c +++ /dev/null @@ -1,62 +0,0 @@ @@ -840,87 +681,9 @@ index 1079b53..0000000 - grub_backtrace_pointer (1); -} - -diff --git a/grub-core/lib/backtrace.c b/grub-core/lib/backtrace.c -deleted file mode 100644 -index c0ad6ab..0000000 ---- a/grub-core/lib/backtrace.c -+++ /dev/null -@@ -1,72 +0,0 @@ --/* -- * GRUB -- GRand Unified Bootloader -- * Copyright (C) 2009 Free Software Foundation, Inc. -- * -- * GRUB is free software: you can redistribute it and/or modify -- * it under the terms of the GNU General Public License as published by -- * the Free Software Foundation, either version 3 of the License, or -- * (at your option) any later version. -- * -- * GRUB is distributed in the hope that it will be useful, -- * but WITHOUT ANY WARRANTY; without even the implied warranty of -- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- * GNU General Public License for more details. -- * -- * You should have received a copy of the GNU General Public License -- * along with GRUB. If not, see . -- */ -- --#include --#include --#include --#include --#include --#include --#include -- --GRUB_MOD_LICENSE ("GPLv3+"); -- --void --grub_backtrace_print_address (void *addr) --{ --#ifndef GRUB_UTIL -- grub_dl_t mod; -- -- FOR_DL_MODULES (mod) -- { -- grub_dl_segment_t segment; -- for (segment = mod->segment; segment; segment = segment->next) -- if (segment->addr <= addr && (grub_uint8_t *) segment->addr -- + segment->size > (grub_uint8_t *) addr) -- { -- grub_printf ("%s.%x+%" PRIxGRUB_SIZE, mod->name, segment->section, -- (grub_size_t) ((grub_uint8_t *) addr - (grub_uint8_t *) segment->addr)); -- return; -- } -- } -- --#endif -- grub_printf ("%p", addr); --} -- --static grub_err_t --grub_cmd_backtrace (grub_command_t cmd __attribute__ ((unused)), -- int argc __attribute__ ((unused)), -- char **args __attribute__ ((unused))) --{ -- grub_backtrace (); -- return 0; --} -- --static grub_command_t cmd; -- --GRUB_MOD_INIT(backtrace) --{ -- cmd = grub_register_command ("backtrace", grub_cmd_backtrace, -- 0, N_("Print backtrace.")); --} -- --GRUB_MOD_FINI(backtrace) --{ -- grub_unregister_command (cmd); --} diff --git a/grub-core/lib/i386/backtrace.c b/grub-core/lib/i386/backtrace.c deleted file mode 100644 -index c67273d..0000000 +index c67273db3ae..00000000000 --- a/grub-core/lib/i386/backtrace.c +++ /dev/null @@ -1,78 +0,0 @@ @@ -1003,7 +766,7 @@ index c67273d..0000000 -} - diff --git a/include/grub/backtrace.h b/include/grub/backtrace.h -index 3955197..275cf85 100644 +index 395519762f0..275cf85e2d3 100644 --- a/include/grub/backtrace.h +++ b/include/grub/backtrace.h @@ -19,8 +19,14 @@ @@ -1024,10 +787,10 @@ index 3955197..275cf85 100644 #endif diff --git a/include/grub/dl.h b/include/grub/dl.h -index 90dc9bb..4fe2b52 100644 +index 91933b85f2c..2f76e6b0437 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h -@@ -257,6 +257,8 @@ grub_dl_is_persistent (grub_dl_t mod) +@@ -259,6 +259,8 @@ grub_dl_is_persistent (grub_dl_t mod) #endif @@ -1037,10 +800,10 @@ index 90dc9bb..4fe2b52 100644 int isfunc, grub_dl_t mod); diff --git a/include/grub/kernel.h b/include/grub/kernel.h -index 133a37c..e5a5f43 100644 +index abbca5ea335..300a9766cda 100644 --- a/include/grub/kernel.h +++ b/include/grub/kernel.h -@@ -110,6 +110,9 @@ grub_addr_t grub_modules_get_end (void); +@@ -111,6 +111,9 @@ grub_addr_t grub_modules_get_end (void); #endif @@ -1050,6 +813,98 @@ index 133a37c..e5a5f43 100644 /* The start point of the C code. */ void grub_main (void) __attribute__ ((noreturn)); --- -1.8.3.1 - +diff --git a/grub-core/kern/arm/efi/startup.S b/grub-core/kern/arm/efi/startup.S +index 9f8265315a9..f3bc41f9d0f 100644 +--- a/grub-core/kern/arm/efi/startup.S ++++ b/grub-core/kern/arm/efi/startup.S +@@ -23,6 +23,8 @@ + .file "startup.S" + .text + .arm ++ .globl start, _start ++FUNCTION(start) + FUNCTION(_start) + /* + * EFI_SYSTEM_TABLE and EFI_HANDLE are passed in r1/r0. +diff --git a/grub-core/kern/arm/startup.S b/grub-core/kern/arm/startup.S +index 3946fe8e183..5679a1d00ad 100644 +--- a/grub-core/kern/arm/startup.S ++++ b/grub-core/kern/arm/startup.S +@@ -48,6 +48,8 @@ + + .text + .arm ++ .globl start, _start ++FUNCTION(start) + FUNCTION(_start) + b codestart + +diff --git a/grub-core/kern/arm64/efi/startup.S b/grub-core/kern/arm64/efi/startup.S +index 666a7ee3c92..41676bdb2b8 100644 +--- a/grub-core/kern/arm64/efi/startup.S ++++ b/grub-core/kern/arm64/efi/startup.S +@@ -19,7 +19,9 @@ + #include + + .file "startup.S" ++ .globl start, _start + .text ++FUNCTION(start) + FUNCTION(_start) + /* + * EFI_SYSTEM_TABLE and EFI_HANDLE are passed in x1/x0. +diff --git a/grub-core/kern/i386/qemu/startup.S b/grub-core/kern/i386/qemu/startup.S +index 0d89858d9b3..939f182fc74 100644 +--- a/grub-core/kern/i386/qemu/startup.S ++++ b/grub-core/kern/i386/qemu/startup.S +@@ -24,7 +24,8 @@ + + .text + .code32 +- .globl _start ++ .globl start, _start ++start: + _start: + jmp codestart + +diff --git a/grub-core/kern/ia64/efi/startup.S b/grub-core/kern/ia64/efi/startup.S +index d75c6d7cc74..8f2a593e529 100644 +--- a/grub-core/kern/ia64/efi/startup.S ++++ b/grub-core/kern/ia64/efi/startup.S +@@ -24,8 +24,9 @@ + .psr lsb + .lsb + +- .global _start ++ .global start, _start + .proc _start ++start: + _start: + alloc loc0=ar.pfs,2,4,0,0 + mov loc1=rp +diff --git a/grub-core/kern/sparc64/ieee1275/crt0.S b/grub-core/kern/sparc64/ieee1275/crt0.S +index 03b916f0534..701bf63abcf 100644 +--- a/grub-core/kern/sparc64/ieee1275/crt0.S ++++ b/grub-core/kern/sparc64/ieee1275/crt0.S +@@ -22,7 +22,8 @@ + + .text + .align 4 +- .globl _start ++ .globl start, _start ++start: + _start: + ba codestart + mov %o4, %o0 +diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am +index 80e7a83edf9..f512573c0da 100644 +--- a/grub-core/Makefile.am ++++ b/grub-core/Makefile.am +@@ -66,6 +66,7 @@ CLEANFILES += grub_script.yy.c grub_script.yy.h + + include $(srcdir)/Makefile.core.am + ++KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/backtrace.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cache.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/command.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/device.h diff --git a/0066-Normalize-slashes-in-tftp-paths.patch b/0066-Normalize-slashes-in-tftp-paths.patch deleted file mode 100644 index 4c4c84e5d31871482b05e4099dc7ff68d9f99925..0000000000000000000000000000000000000000 --- a/0066-Normalize-slashes-in-tftp-paths.patch +++ /dev/null @@ -1,64 +0,0 @@ -From be6b7ff630f73fe21b797d5396a29944262d3805 Mon Sep 17 00:00:00 2001 -From: Lenny Szubowicz -Date: Mon, 29 Aug 2016 11:04:48 -0400 -Subject: [PATCH 066/220] Normalize slashes in tftp paths. - -Some tftp servers do not handle multiple consecutive slashes correctly; -this patch avoids sending tftp requests with non-normalized paths. - -Signed-off-by: Lenny Szubowicz -[msalter: fix malformed tftp packets] -Signed-off-by: Mark Salter ---- - grub-core/net/tftp.c | 28 +++++++++++++++++++++++++--- - 1 file changed, 25 insertions(+), 3 deletions(-) - -diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c -index 1157524..dcd8249 100644 ---- a/grub-core/net/tftp.c -+++ b/grub-core/net/tftp.c -@@ -300,6 +300,25 @@ destroy_pq (tftp_data_t data) - grub_priority_queue_destroy (data->pq); - } - -+/* Create a normalized copy of the filename. -+ Compress any string of consecutive forward slashes to a single forward -+ slash. */ -+static void -+grub_normalize_filename (char *normalized, const char *filename) -+{ -+ char *dest = normalized; -+ char *src = filename; -+ -+ while (*src != '\0') -+ { -+ if (src[0] == '/' && src[1] == '/') -+ src++; -+ else -+ *dest++ = *src++; -+ } -+ *dest = '\0'; -+} -+ - static grub_err_t - tftp_open (struct grub_file *file, const char *filename) - { -@@ -337,9 +356,12 @@ tftp_open (struct grub_file *file, const char *filename) - rrqlen = 0; - - tftph->opcode = grub_cpu_to_be16_compile_time (TFTP_RRQ); -- grub_strcpy (rrq, filename); -- rrqlen += grub_strlen (filename) + 1; -- rrq += grub_strlen (filename) + 1; -+ -+ /* Copy and normalize the filename to work-around issues on some tftp -+ servers when file names are being matched for remapping. */ -+ grub_normalize_filename (rrq, filename); -+ rrqlen += grub_strlen (rrq) + 1; -+ rrq += grub_strlen (rrq) + 1; - - grub_strcpy (rrq, "octet"); - rrqlen += grub_strlen ("octet") + 1; --- -1.8.3.1 - diff --git a/0101-normal-don-t-draw-our-startup-message-if-debug-is-se.patch b/0066-normal-don-t-draw-our-startup-message-if-debug-is-se.patch similarity index 72% rename from 0101-normal-don-t-draw-our-startup-message-if-debug-is-se.patch rename to 0066-normal-don-t-draw-our-startup-message-if-debug-is-se.patch index 555227baf975e7445f0abf57d484af56bcc17342..9ebfc7ae01e3d4057d5879b7faf3f5e52bf176d4 100644 --- a/0101-normal-don-t-draw-our-startup-message-if-debug-is-se.patch +++ b/0066-normal-don-t-draw-our-startup-message-if-debug-is-se.patch @@ -1,18 +1,17 @@ -From e215e2c09bc7d7e970f4b644c30a1a3818829bfb Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 9 Nov 2017 15:58:52 -0500 -Subject: [PATCH 101/220] normal: don't draw our startup message if debug is - set +Subject: [PATCH] normal: don't draw our startup message if debug is set --- grub-core/normal/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index 2fe6743..f7ee912 100644 +index d5df4f815b0..1970e4816a8 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c -@@ -425,6 +425,9 @@ grub_normal_reader_init (int nested) +@@ -430,6 +430,9 @@ grub_normal_reader_init (int nested) const char *msg_esc = _("ESC at any time exits."); char *msg_formatted; @@ -22,6 +21,3 @@ index 2fe6743..f7ee912 100644 msg_formatted = grub_xasprintf (_("Minimal BASH-like line editing is supported. For " "the first word, TAB lists possible command completions. Anywhere " "else TAB lists possible device or file completions. %s"), --- -1.8.3.1 - diff --git a/0102-Work-around-some-minor-include-path-weirdnesses.patch b/0067-Work-around-some-minor-include-path-weirdnesses.patch similarity index 95% rename from 0102-Work-around-some-minor-include-path-weirdnesses.patch rename to 0067-Work-around-some-minor-include-path-weirdnesses.patch index 7a999873beab15a735c3ae8fa1e16822460e709f..460d792707723c4de647d169db2f2316a995b5ce 100644 --- a/0102-Work-around-some-minor-include-path-weirdnesses.patch +++ b/0067-Work-around-some-minor-include-path-weirdnesses.patch @@ -1,7 +1,7 @@ -From 5327dd96cf5e2323a3aaac3f191ed72ad3d7294b Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Fri, 16 Mar 2018 13:28:57 -0400 -Subject: [PATCH 102/220] Work around some minor include path weirdnesses +Subject: [PATCH] Work around some minor include path weirdnesses Signed-off-by: Peter Jones --- @@ -17,7 +17,7 @@ Signed-off-by: Peter Jones diff --git a/include/grub/arm/efi/console.h b/include/grub/arm/efi/console.h new file mode 100644 -index 0000000..1592f6f +index 00000000000..1592f6f76b5 --- /dev/null +++ b/include/grub/arm/efi/console.h @@ -0,0 +1,24 @@ @@ -47,7 +47,7 @@ index 0000000..1592f6f +#endif /* ! GRUB_ARM_EFI_CONSOLE_H */ diff --git a/include/grub/arm64/efi/console.h b/include/grub/arm64/efi/console.h new file mode 100644 -index 0000000..9568933 +index 00000000000..95689339384 --- /dev/null +++ b/include/grub/arm64/efi/console.h @@ -0,0 +1,24 @@ @@ -77,7 +77,7 @@ index 0000000..9568933 +#endif /* ! GRUB_ARM64_EFI_CONSOLE_H */ diff --git a/include/grub/i386/efi/console.h b/include/grub/i386/efi/console.h new file mode 100644 -index 0000000..9231375 +index 00000000000..9231375cb07 --- /dev/null +++ b/include/grub/i386/efi/console.h @@ -0,0 +1,24 @@ @@ -107,7 +107,7 @@ index 0000000..9231375 +#endif /* ! GRUB_I386_EFI_CONSOLE_H */ diff --git a/include/grub/x86_64/efi/console.h b/include/grub/x86_64/efi/console.h new file mode 100644 -index 0000000..dba9d86 +index 00000000000..dba9d8678d0 --- /dev/null +++ b/include/grub/x86_64/efi/console.h @@ -0,0 +1,24 @@ @@ -135,6 +135,3 @@ index 0000000..dba9d86 +#include + +#endif /* ! GRUB_X86_64_EFI_CONSOLE_H */ --- -1.8.3.1 - diff --git a/0103-Make-it-possible-to-enabled-build-id-sha1.patch b/0068-Make-it-possible-to-enabled-build-id-sha1.patch similarity index 87% rename from 0103-Make-it-possible-to-enabled-build-id-sha1.patch rename to 0068-Make-it-possible-to-enabled-build-id-sha1.patch index 9873991baacf5b565b24518883d95d656b64bd2d..f68fc58b8f4fa084d624f50f52dfca042084562f 100644 --- a/0103-Make-it-possible-to-enabled-build-id-sha1.patch +++ b/0068-Make-it-possible-to-enabled-build-id-sha1.patch @@ -1,16 +1,36 @@ -From cc30961c213539793d723cd1ce0c61b8a5553c12 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 25 Jun 2015 15:41:06 -0400 -Subject: [PATCH 103/220] Make it possible to enabled --build-id=sha1 +Subject: [PATCH] Make it possible to enabled --build-id=sha1 Signed-off-by: Peter Jones --- - acinclude.m4 | 19 +++++++++++++++++++ configure.ac | 8 ++++++++ + acinclude.m4 | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) +diff --git a/configure.ac b/configure.ac +index a0030632220..b50fb2e9897 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1470,7 +1470,15 @@ grub_PROG_TARGET_CC + if test "x$TARGET_APPLE_LINKER" != x1 ; then + grub_PROG_OBJCOPY_ABSOLUTE + fi ++ ++AC_ARG_ENABLE([build-id], ++ [AS_HELP_STRING([--enable-build-id], ++ [ask the linker to supply build-id notes (default=no)])]) ++if test x$enable_build_id = xyes; then ++grub_PROG_LD_BUILD_ID_SHA1 ++else + grub_PROG_LD_BUILD_ID_NONE ++fi + if test "x$target_cpu" = xi386; then + if test "$platform" != emu && test "x$TARGET_APPLE_LINKER" != x1 ; then + if test ! -z "$TARGET_IMG_LDSCRIPT"; then diff --git a/acinclude.m4 b/acinclude.m4 -index 78cdf6e..242e829 100644 +index 6e14bb553c6..21238fcfd03 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -136,6 +136,25 @@ if test "x$grub_cv_prog_ld_build_id_none" = xyes; then @@ -39,26 +59,3 @@ index 78cdf6e..242e829 100644 dnl Check nm AC_DEFUN([grub_PROG_NM_WORKS], [AC_MSG_CHECKING([whether nm works]) -diff --git a/configure.ac b/configure.ac -index eb851b8..8ee18ba 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -1414,7 +1414,15 @@ grub_PROG_TARGET_CC - if test "x$TARGET_APPLE_LINKER" != x1 ; then - grub_PROG_OBJCOPY_ABSOLUTE - fi -+ -+AC_ARG_ENABLE([build-id], -+ [AS_HELP_STRING([--enable-build-id], -+ [ask the linker to supply build-id notes (default=no)])]) -+if test x$enable_build_id = xyes; then -+grub_PROG_LD_BUILD_ID_SHA1 -+else - grub_PROG_LD_BUILD_ID_NONE -+fi - if test "x$target_cpu" = xi386; then - if test "$platform" != emu && test "x$TARGET_APPLE_LINKER" != x1 ; then - if test ! -z "$TARGET_IMG_LDSCRIPT"; then --- -1.8.3.1 - diff --git a/0104-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch b/0069-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch similarity index 81% rename from 0104-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch rename to 0069-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch index d609304781ab6cefc45c9348d8dbf92251a2ec83..a8a757e5f5b9d178564c4471ae656e909532290a 100644 --- a/0104-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch +++ b/0069-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch @@ -1,8 +1,8 @@ -From 550772dbfbe9a0bc144d3d90ed0c2e87663a318b Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Sun, 28 Jun 2015 13:09:58 -0400 -Subject: [PATCH 104/220] Add grub_qdprintf() - grub_dprintf() without the - file+line number. +Subject: [PATCH] Add grub_qdprintf() - grub_dprintf() without the file+line + number. This just makes copy+paste of our debug loading info easier. @@ -13,10 +13,10 @@ Signed-off-by: Peter Jones 2 files changed, 20 insertions(+) diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 5c2d203..0e89c48 100644 +index a432a6be54a..9a2fae6398e 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c -@@ -190,6 +190,24 @@ grub_real_dprintf (const char *file, const int line, const char *condition, +@@ -191,6 +191,24 @@ grub_real_dprintf (const char *file, const int line, const char *condition, } } @@ -42,10 +42,10 @@ index 5c2d203..0e89c48 100644 int diff --git a/include/grub/misc.h b/include/grub/misc.h -index 4a4f485..960097f 100644 +index fd18e6320b8..3adc4036e3b 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h -@@ -372,6 +372,8 @@ void EXPORT_FUNC(grub_real_dprintf) (const char *file, +@@ -345,6 +345,8 @@ void EXPORT_FUNC(grub_real_dprintf) (const char *file, const int line, const char *condition, const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 4, 5))); @@ -54,6 +54,3 @@ index 4a4f485..960097f 100644 int EXPORT_FUNC(grub_vprintf) (const char *fmt, va_list args); int EXPORT_FUNC(grub_snprintf) (char *str, grub_size_t n, const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 3, 4))); --- -1.8.3.1 - diff --git a/0105-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch b/0070-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch similarity index 87% rename from 0105-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch rename to 0070-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch index 5f44b93e12f252f7df53e10ae2dfffc17dfb67d9..75de764ad4103b03e338d9ec8baa9189668e285b 100644 --- a/0105-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch +++ b/0070-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch @@ -1,7 +1,7 @@ -From 0439dd373f4c7fe346fd3e2b4680e21135f5a00b Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 25 Jun 2015 15:11:36 -0400 -Subject: [PATCH 105/220] Make a "gdb" dprintf that tells us load addresses. +Subject: [PATCH] Make a "gdb" dprintf that tells us load addresses. This makes a grub_dprintf() call during platform init and during module loading that tells us the virtual addresses of the .text and .data @@ -20,7 +20,7 @@ Signed-off-by: Peter Jones 4 files changed, 78 insertions(+), 4 deletions(-) diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index 2e57e5e..6a5e770 100644 +index 88d2077709e..9557254035e 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -501,6 +501,23 @@ grub_dl_find_section (Elf_Ehdr *e, const char *name) @@ -47,7 +47,7 @@ index 2e57e5e..6a5e770 100644 /* Me, Vladimir Serbinenko, hereby I add this module check as per new GNU module policy. Note that this license check is informative only. -@@ -644,6 +661,37 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) +@@ -653,6 +670,37 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) return GRUB_ERR_NONE; } @@ -85,7 +85,7 @@ index 2e57e5e..6a5e770 100644 /* Load a module from core memory. */ grub_dl_t -@@ -703,6 +751,8 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size) +@@ -712,6 +760,8 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size) grub_dprintf ("modules", "module name: %s\n", mod->name); grub_dprintf ("modules", "init function: %p\n", mod->init); @@ -95,10 +95,10 @@ index 2e57e5e..6a5e770 100644 { grub_dl_unload (mod); diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index 2cf6a5a..19054b1 100644 +index ae9885edb84..d6a2fb57789 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c -@@ -283,7 +283,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, +@@ -296,7 +296,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, /* Search the mods section from the PE32/PE32+ image. This code uses a PE32 header, but should work with PE32+ as well. */ grub_addr_t @@ -107,7 +107,7 @@ index 2cf6a5a..19054b1 100644 { grub_efi_loaded_image_t *image; struct grub_pe32_header *header; -@@ -308,7 +308,7 @@ grub_efi_modules_addr (void) +@@ -321,7 +321,7 @@ grub_efi_modules_addr (void) i < coff_header->num_sections; i++, section++) { @@ -117,10 +117,10 @@ index 2cf6a5a..19054b1 100644 } diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c -index 71d2279..e6183a4 100644 +index 6d39bd3ad29..2d12e6188fd 100644 --- a/grub-core/kern/efi/init.c +++ b/grub-core/kern/efi/init.c -@@ -59,10 +59,33 @@ grub_efi_env_init (void) +@@ -115,10 +115,33 @@ grub_efi_env_init (void) grub_free (envblk_s.buf); } @@ -155,7 +155,7 @@ index 71d2279..e6183a4 100644 /* First of all, initialize the console so that GRUB can display messages. */ grub_console_init (); -@@ -74,6 +97,7 @@ grub_efi_init (void) +@@ -142,6 +165,7 @@ grub_efi_init (void) 0, 0, 0, NULL); grub_efi_env_init (); @@ -164,10 +164,10 @@ index 71d2279..e6183a4 100644 } diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h -index 5e2b479..8ca3981 100644 +index 03f9a9d0118..2e0691454b1 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h -@@ -132,7 +132,7 @@ grub_err_t grub_arch_efi_linux_check_image(struct linux_arch_kernel_header *lh); +@@ -138,7 +138,7 @@ grub_err_t grub_arch_efi_linux_check_image(struct linux_arch_kernel_header *lh); grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, char *args); #endif @@ -176,6 +176,3 @@ index 5e2b479..8ca3981 100644 void grub_efi_mm_init (void); void grub_efi_mm_fini (void); --- -1.8.3.1 - diff --git a/0070-arm64-make-sure-fdt-has-address-cells-and-size-cells.patch b/0070-arm64-make-sure-fdt-has-address-cells-and-size-cells.patch deleted file mode 100644 index 1bbd05c262fd3a3cf54981fa58287fa9ba1e2762..0000000000000000000000000000000000000000 --- a/0070-arm64-make-sure-fdt-has-address-cells-and-size-cells.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 32025dc603bdf22bdb60ebbd881a4b43b587a1a0 Mon Sep 17 00:00:00 2001 -From: Mark Salter -Date: Mon, 17 Apr 2017 08:44:29 -0400 -Subject: [PATCH 070/220] arm64: make sure fdt has #address-cells and - #size-cells properties - -Recent upstream changes to kexec-tools relies on #address-cells -and #size-cells properties in the FDT. If grub2 needs to create -a chosen node, it is likely because firmware did not provide one. -In that case, set #address-cells and #size-cells properties to -make sure they exist. ---- - grub-core/loader/arm64/linux.c | 16 +++++++++++++++- - 1 file changed, 15 insertions(+), 1 deletion(-) - -diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c -index 04994d5..4c0a09c 100644 ---- a/grub-core/loader/arm64/linux.c -+++ b/grub-core/loader/arm64/linux.c -@@ -81,7 +81,21 @@ finalize_params_linux (void) - - node = grub_fdt_find_subnode (fdt, 0, "chosen"); - if (node < 0) -- node = grub_fdt_add_subnode (fdt, 0, "chosen"); -+ { -+ /* -+ * If we have to create a chosen node, Make sure we -+ * have #address-cells and #size-cells properties. -+ */ -+ retval = grub_fdt_set_prop32(fdt, 0, "#address-cells", 2); -+ if (retval) -+ goto failure; -+ -+ retval = grub_fdt_set_prop32(fdt, 0, "#size-cells", 2); -+ if (retval) -+ goto failure; -+ -+ node = grub_fdt_add_subnode (fdt, 0, "chosen"); -+ } - - if (node < 1) - goto failure; --- -1.8.3.1 - diff --git a/0106-Fixup-for-newer-compiler.patch b/0071-Fixup-for-newer-compiler.patch similarity index 79% rename from 0106-Fixup-for-newer-compiler.patch rename to 0071-Fixup-for-newer-compiler.patch index cc830c752d2502fa181f915504774fb22c6b824b..12dd193e612d4eb766eca7f309ad1f8234db1a1d 100644 --- a/0106-Fixup-for-newer-compiler.patch +++ b/0071-Fixup-for-newer-compiler.patch @@ -1,7 +1,7 @@ -From d274cc00ea92dc4aa9c7b4b63e230e37186d31c6 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 10 May 2018 13:40:19 -0400 -Subject: [PATCH 106/220] Fixup for newer compiler +Subject: [PATCH] Fixup for newer compiler --- grub-core/fs/btrfs.c | 2 +- @@ -9,10 +9,10 @@ Subject: [PATCH 106/220] Fixup for newer compiler 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index ba99d04..9cd7f4b 100644 +index 2b21cbaa67e..4cc86e9b79e 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c -@@ -215,7 +215,7 @@ struct grub_btrfs_inode +@@ -218,7 +218,7 @@ struct grub_btrfs_inode grub_uint64_t size; grub_uint8_t dummy2[0x70]; struct grub_btrfs_time mtime; @@ -22,7 +22,7 @@ index ba99d04..9cd7f4b 100644 struct grub_btrfs_extent_data { diff --git a/include/grub/gpt_partition.h b/include/grub/gpt_partition.h -index 7a93f43..8212697 100644 +index 7a93f43291c..8212697bf6b 100644 --- a/include/grub/gpt_partition.h +++ b/include/grub/gpt_partition.h @@ -76,7 +76,7 @@ struct grub_gpt_partentry @@ -34,6 +34,3 @@ index 7a93f43..8212697 100644 grub_err_t grub_gpt_partition_map_iterate (grub_disk_t disk, --- -1.8.3.1 - diff --git a/0107-Don-t-attempt-to-export-the-start-and-_start-symbols.patch b/0072-Don-t-attempt-to-export-the-start-and-_start-symbols.patch similarity index 84% rename from 0107-Don-t-attempt-to-export-the-start-and-_start-symbols.patch rename to 0072-Don-t-attempt-to-export-the-start-and-_start-symbols.patch index db380c1e5fa4e400c2de986eb0c3e8cd0d1dce5a..0e925eef827e59cf9bd0f20211e89a626925b4f4 100644 --- a/0107-Don-t-attempt-to-export-the-start-and-_start-symbols.patch +++ b/0072-Don-t-attempt-to-export-the-start-and-_start-symbols.patch @@ -1,8 +1,8 @@ -From c6522389c9a795007a54aedeb10f8c3afd9dab24 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Sat, 12 May 2018 11:29:07 +0200 -Subject: [PATCH 107/220] Don't attempt to export the start and _start symbols - for grub-emu +Subject: [PATCH] Don't attempt to export the start and _start symbols for + grub-emu Commit 318ee04aadc ("make better backtraces") reworked the backtrace logic but the changes lead to the following build error on the grub-emu platform: @@ -26,10 +26,10 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 2 insertions(+) diff --git a/include/grub/kernel.h b/include/grub/kernel.h -index e5a5f43..de48cd4 100644 +index 300a9766cda..55849777eaa 100644 --- a/include/grub/kernel.h +++ b/include/grub/kernel.h -@@ -110,8 +110,10 @@ grub_addr_t grub_modules_get_end (void); +@@ -111,8 +111,10 @@ grub_addr_t grub_modules_get_end (void); #endif @@ -40,6 +40,3 @@ index e5a5f43..de48cd4 100644 /* The start point of the C code. */ void grub_main (void) __attribute__ ((noreturn)); --- -1.8.3.1 - diff --git a/0072-print-more-debug-info-in-our-module-loader.patch b/0072-print-more-debug-info-in-our-module-loader.patch deleted file mode 100644 index 2c2a738709e405b4b6b2b2af8abcd69b92ed4467..0000000000000000000000000000000000000000 --- a/0072-print-more-debug-info-in-our-module-loader.patch +++ /dev/null @@ -1,44 +0,0 @@ -From 2b61111bf5f5fa076faa6c7ad1066823b16b1474 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 1 May 2017 11:19:40 -0400 -Subject: [PATCH 072/220] print more debug info in our module loader. - -Signed-off-by: Peter Jones ---- - grub-core/kern/efi/efi.c | 16 +++++++++++++--- - 1 file changed, 13 insertions(+), 3 deletions(-) - -diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index 370ce03..a1af9b4 100644 ---- a/grub-core/kern/efi/efi.c -+++ b/grub-core/kern/efi/efi.c -@@ -313,13 +313,23 @@ grub_efi_modules_addr (void) - } - - if (i == coff_header->num_sections) -- return 0; -+ { -+ grub_dprintf("sections", "section %d is last section; invalid.\n", i); -+ return 0; -+ } - - info = (struct grub_module_info *) ((char *) image->image_base - + section->virtual_address); -- if (info->magic != GRUB_MODULE_MAGIC) -- return 0; -+ if (section->name[0] != '.' && info->magic != GRUB_MODULE_MAGIC) -+ { -+ grub_dprintf("sections", -+ "section %d has bad magic %08x, should be %08x\n", -+ i, info->magic, GRUB_MODULE_MAGIC); -+ return 0; -+ } - -+ grub_dprintf("sections", "returning section info for section %d: \"%s\"\n", -+ i, section->name); - return (grub_addr_t) info; - } - --- -1.8.3.1 - diff --git a/0108-Fixup-for-newer-compiler.patch b/0073-Fixup-for-newer-compiler.patch similarity index 86% rename from 0108-Fixup-for-newer-compiler.patch rename to 0073-Fixup-for-newer-compiler.patch index f6b78d256c8b30db3e98f817152d3cf0121173ba..11ed6e52167e392c7d228ebf360e186ed7f5eb7f 100644 --- a/0108-Fixup-for-newer-compiler.patch +++ b/0073-Fixup-for-newer-compiler.patch @@ -1,14 +1,14 @@ -From 433752e769b2a31d94b7e70fba2a73be509e8510 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 10 May 2018 13:40:19 -0400 -Subject: [PATCH 108/220] Fixup for newer compiler +Subject: [PATCH] Fixup for newer compiler --- conf/Makefile.common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/Makefile.common b/conf/Makefile.common -index 4ba729e..5e8ba2a 100644 +index 191b1a70c6b..5f0ef969857 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common @@ -38,7 +38,7 @@ CFLAGS_KERNEL = $(CFLAGS_PLATFORM) -ffreestanding @@ -20,6 +20,3 @@ index 4ba729e..5e8ba2a 100644 CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d --- -1.8.3.1 - diff --git a/0109-Add-support-for-non-Ethernet-network-cards.patch b/0074-Add-support-for-non-Ethernet-network-cards.patch similarity index 94% rename from 0109-Add-support-for-non-Ethernet-network-cards.patch rename to 0074-Add-support-for-non-Ethernet-network-cards.patch index c66ef7d8bd3c5bfcb797aad6b183cc01f32c6093..02fb951f4750f649ad8dce02d39efa2df94b2df0 100644 --- a/0109-Add-support-for-non-Ethernet-network-cards.patch +++ b/0074-Add-support-for-non-Ethernet-network-cards.patch @@ -1,7 +1,7 @@ -From e8e2d019246798865075a3577619ac89ac34eee6 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Andrzej Kacprowski Date: Wed, 10 Jul 2019 15:22:29 +0200 -Subject: [PATCH 109/220] Add support for non-Ethernet network cards +Subject: [PATCH] Add support for non-Ethernet network cards This patch replaces fixed 6-byte link layer address with up to 32-byte variable sized address. @@ -23,22 +23,22 @@ Signed-off-by: Andrzej Kacprowski [msalter: Fix max string calculation in grub_net_hwaddr_to_str] Signed-off-by: Mark Salter --- - grub-core/net/arp.c | 157 +++++++++++++++++++++------------ + grub-core/net/arp.c | 155 ++++++++++++++++++++++----------- grub-core/net/bootp.c | 15 ++-- grub-core/net/drivers/efi/efinet.c | 8 +- grub-core/net/drivers/emu/emunet.c | 1 + grub-core/net/drivers/i386/pc/pxe.c | 13 +-- grub-core/net/drivers/ieee1275/ofnet.c | 2 + grub-core/net/drivers/uboot/ubootnet.c | 1 + - grub-core/net/ethernet.c | 88 +++++++++--------- + grub-core/net/ethernet.c | 88 +++++++++---------- grub-core/net/icmp6.c | 15 ++-- grub-core/net/ip.c | 4 +- grub-core/net/net.c | 50 ++++++----- include/grub/net.h | 19 ++-- - 12 files changed, 220 insertions(+), 153 deletions(-) + 12 files changed, 219 insertions(+), 152 deletions(-) diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c -index 54306e3..67b409a 100644 +index 54306e3b16d..67b409a8acc 100644 --- a/grub-core/net/arp.c +++ b/grub-core/net/arp.c @@ -31,22 +31,12 @@ enum @@ -146,16 +146,15 @@ index 54306e3..67b409a 100644 grub_net_network_level_address_t sender_addr, target_addr; grub_net_link_level_address_t sender_mac_addr; struct grub_net_network_level_interface *inf; -- -- if (arp_packet->pro != grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP) -- || arp_packet->pln != 4 || arp_packet->hln != 6 -- || nb->tail - nb->data < (int) sizeof (*arp_packet)) + grub_uint16_t hw_type; + grub_uint8_t hln; + grub_uint8_t pln; + grub_uint8_t arp_packet_len; + grub_uint8_t *tmp_ptr; -+ + +- if (arp_packet->pro != grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP) +- || arp_packet->pln != 4 || arp_packet->hln != 6 +- || nb->tail - nb->data < (int) sizeof (*arp_packet)) + hw_type = card->default_address.type; + hln = card->default_address.len; + pln = sizeof(sender_addr.ipv4); @@ -178,29 +177,29 @@ index 54306e3..67b409a 100644 + + /* The source protocol address. */ sender_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; -- target_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; -- sender_addr.ipv4 = arp_packet->sender_ip; -- target_addr.ipv4 = arp_packet->recv_ip; -- if (arp_packet->sender_ip == pending_req) -- have_pending = 1; + grub_memcpy(&sender_addr.ipv4, tmp_ptr, pln); + tmp_ptr += pln; - -- sender_mac_addr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; -- grub_memcpy (sender_mac_addr.mac, arp_packet->sender_mac, -- sizeof (sender_mac_addr.mac)); - grub_net_link_layer_add_address (card, &sender_addr, &sender_mac_addr, 1); - ++ ++ grub_net_link_layer_add_address (card, &sender_addr, &sender_mac_addr, 1); ++ + /* The target hardware address. */ + tmp_ptr += hln; + + /* The target protocol address. */ -+ target_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; +- sender_addr.ipv4 = arp_packet->sender_ip; +- target_addr.ipv4 = arp_packet->recv_ip; +- if (arp_packet->sender_ip == pending_req) + grub_memcpy(&target_addr.ipv4, tmp_ptr, pln); + + if (sender_addr.ipv4 == pending_req) -+ have_pending = 1; -+ + have_pending = 1; + +- sender_mac_addr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; +- grub_memcpy (sender_mac_addr.mac, arp_packet->sender_mac, +- sizeof (sender_mac_addr.mac)); +- grub_net_link_layer_add_address (card, &sender_addr, &sender_mac_addr, 1); +- FOR_NET_NETWORK_LEVEL_INTERFACES (inf) { /* Verify vlantag id */ @@ -272,10 +271,10 @@ index 54306e3..67b409a 100644 /* Change operation to REPLY and send packet */ send_ethernet_packet (inf, &nb_reply, target, GRUB_NET_ETHERTYPE_ARP); diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index 8c96959..3cf6dbf 100644 +index e28fb6a09f9..08b6b2b5d6c 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c -@@ -269,7 +269,6 @@ grub_net_configure_by_dhcp_ack (const char *name, +@@ -233,7 +233,6 @@ grub_net_configure_by_dhcp_ack (const char *name, int is_def, char **device, char **path) { grub_net_network_level_address_t addr; @@ -283,7 +282,7 @@ index 8c96959..3cf6dbf 100644 struct grub_net_network_level_interface *inter; int mask = -1; char server_ip[sizeof ("xxx.xxx.xxx.xxx")]; -@@ -286,12 +285,8 @@ grub_net_configure_by_dhcp_ack (const char *name, +@@ -250,12 +249,8 @@ grub_net_configure_by_dhcp_ack (const char *name, if (path) *path = 0; @@ -298,7 +297,7 @@ index 8c96959..3cf6dbf 100644 if (!inter) return 0; -@@ -601,7 +596,9 @@ send_dhcp_packet (struct grub_net_network_level_interface *iface) +@@ -567,7 +562,9 @@ send_dhcp_packet (struct grub_net_network_level_interface *iface) grub_memset (pack, 0, sizeof (*pack)); pack->opcode = 1; pack->hw_type = 1; @@ -309,7 +308,7 @@ index 8c96959..3cf6dbf 100644 err = grub_get_datetime (&date); if (err || !grub_datetime2unixtime (&date, &t)) { -@@ -614,7 +611,7 @@ send_dhcp_packet (struct grub_net_network_level_interface *iface) +@@ -580,7 +577,7 @@ send_dhcp_packet (struct grub_net_network_level_interface *iface) else pack->ident = iface->xid; @@ -319,10 +318,10 @@ index 8c96959..3cf6dbf 100644 grub_netbuff_push (nb, sizeof (*udph)); diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index a57189e..4444e8e 100644 +index 173fb63153c..a673bea807a 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c -@@ -280,6 +280,9 @@ grub_efinet_findcards (void) +@@ -279,6 +279,9 @@ grub_efinet_findcards (void) /* This should not happen... Why? */ continue; @@ -332,7 +331,7 @@ index a57189e..4444e8e 100644 if (net->mode->state == GRUB_EFI_NETWORK_STOPPED && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS) continue; -@@ -316,10 +319,11 @@ grub_efinet_findcards (void) +@@ -315,10 +318,11 @@ grub_efinet_findcards (void) card->name = grub_xasprintf ("efinet%d", i++); card->driver = &efidriver; card->flags = 0; @@ -347,7 +346,7 @@ index a57189e..4444e8e 100644 card->efi_handle = *handle; diff --git a/grub-core/net/drivers/emu/emunet.c b/grub-core/net/drivers/emu/emunet.c -index b194920..5b6c5e1 100644 +index b194920861f..5b6c5e16a6d 100644 --- a/grub-core/net/drivers/emu/emunet.c +++ b/grub-core/net/drivers/emu/emunet.c @@ -46,6 +46,7 @@ static struct grub_net_card emucard = @@ -359,7 +358,7 @@ index b194920..5b6c5e1 100644 }, .flags = 0 diff --git a/grub-core/net/drivers/i386/pc/pxe.c b/grub-core/net/drivers/i386/pc/pxe.c -index 3f4152d..9f8fb4b 100644 +index 3f4152d036c..9f8fb4b6d2b 100644 --- a/grub-core/net/drivers/i386/pc/pxe.c +++ b/grub-core/net/drivers/i386/pc/pxe.c @@ -386,20 +386,21 @@ GRUB_MOD_INIT(pxe) @@ -391,7 +390,7 @@ index 3f4152d..9f8fb4b 100644 grub_pxe_card.default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c -index 3860b6f..bcb3f9e 100644 +index 3860b6f78d8..bcb3f9ea02d 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -160,6 +160,7 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath, @@ -411,7 +410,7 @@ index 3860b6f..bcb3f9e 100644 card->txbufsize = ALIGN_UP (card->mtu, 64) + 256; diff --git a/grub-core/net/drivers/uboot/ubootnet.c b/grub-core/net/drivers/uboot/ubootnet.c -index 056052e..22ebcbf 100644 +index 056052e40d5..22ebcbf211e 100644 --- a/grub-core/net/drivers/uboot/ubootnet.c +++ b/grub-core/net/drivers/uboot/ubootnet.c @@ -131,6 +131,7 @@ GRUB_MOD_INIT (ubootnet) @@ -423,7 +422,7 @@ index 056052e..22ebcbf 100644 card->txbufsize = ALIGN_UP (card->mtu, 64) + 256; card->txbuf = grub_zalloc (card->txbufsize); diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c -index 4d7ceed..9aae83a 100644 +index 4d7ceed6f93..9aae83a5eb4 100644 --- a/grub-core/net/ethernet.c +++ b/grub-core/net/ethernet.c @@ -29,13 +29,6 @@ @@ -573,7 +572,7 @@ index 4d7ceed..9aae83a 100644 { /* ARP packet. */ diff --git a/grub-core/net/icmp6.c b/grub-core/net/icmp6.c -index 2cbd95d..56a3ec5 100644 +index 2cbd95dce25..56a3ec5c8e8 100644 --- a/grub-core/net/icmp6.c +++ b/grub-core/net/icmp6.c @@ -231,8 +231,9 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *nb, @@ -613,7 +612,7 @@ index 2cbd95d..56a3ec5 100644 } if (ohdr->type == OPTION_PREFIX && ohdr->len == 4) diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c -index ea5edf8..a5896f6 100644 +index ea5edf8f1f6..a5896f6dc26 100644 --- a/grub-core/net/ip.c +++ b/grub-core/net/ip.c @@ -276,8 +276,8 @@ handle_dgram (struct grub_net_buff *nb, @@ -628,10 +627,10 @@ index ea5edf8..a5896f6 100644 grub_net_process_dhcp (nb, inf); grub_netbuff_free (nb); diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index 5366e44..6468eb2 100644 +index 22f2689aaeb..a46f82362ed 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c -@@ -128,8 +128,9 @@ grub_net_link_layer_resolve (struct grub_net_network_level_interface *inf, +@@ -133,8 +133,9 @@ grub_net_link_layer_resolve (struct grub_net_network_level_interface *inf, << 48) && proto_addr->ipv6[1] == (grub_be_to_cpu64_compile_time (1)))) { @@ -643,7 +642,7 @@ index 5366e44..6468eb2 100644 return GRUB_ERR_NONE; } -@@ -137,6 +138,7 @@ grub_net_link_layer_resolve (struct grub_net_network_level_interface *inf, +@@ -142,6 +143,7 @@ grub_net_link_layer_resolve (struct grub_net_network_level_interface *inf, && ((grub_be_to_cpu64 (proto_addr->ipv6[0]) >> 56) == 0xff)) { hw_addr->type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; @@ -651,7 +650,7 @@ index 5366e44..6468eb2 100644 hw_addr->mac[0] = 0x33; hw_addr->mac[1] = 0x33; hw_addr->mac[2] = ((grub_be_to_cpu64 (proto_addr->ipv6[1]) >> 24) & 0xff); -@@ -757,23 +759,23 @@ grub_net_addr_to_str (const grub_net_network_level_address_t *target, char *buf) +@@ -762,23 +764,23 @@ grub_net_addr_to_str (const grub_net_network_level_address_t *target, char *buf) void grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str) { @@ -690,7 +689,7 @@ index 5366e44..6468eb2 100644 } int -@@ -784,13 +786,17 @@ grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a, +@@ -789,13 +791,17 @@ grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a, return -1; if (a->type > b->type) return +1; @@ -714,7 +713,7 @@ index 5366e44..6468eb2 100644 int diff --git a/include/grub/net.h b/include/grub/net.h -index 3647012..fc1fc44 100644 +index 8a05ec4fe7a..af0404db7e3 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -29,7 +29,8 @@ @@ -765,6 +764,3 @@ index 3647012..fc1fc44 100644 void grub_net_addr_to_str (const grub_net_network_level_address_t *target, --- -1.8.3.1 - diff --git a/0111-net-read-bracketed-ipv6-addrs-and-port-numbers.patch b/0075-net-read-bracketed-ipv6-addrs-and-port-numbers.patch similarity index 86% rename from 0111-net-read-bracketed-ipv6-addrs-and-port-numbers.patch rename to 0075-net-read-bracketed-ipv6-addrs-and-port-numbers.patch index fef7bf81ceecf3dea92b65ee29fa62ea9f67bec7..834b96e28a7c14d92f80c7258b9a17cbb5b983cd 100644 --- a/0111-net-read-bracketed-ipv6-addrs-and-port-numbers.patch +++ b/0075-net-read-bracketed-ipv6-addrs-and-port-numbers.patch @@ -1,7 +1,7 @@ -From 4a61dd01be61bb37b64866659e357558535b8b56 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aaron Miller Date: Fri, 29 Jul 2016 17:41:38 +0800 -Subject: [PATCH 111/220] net: read bracketed ipv6 addrs and port numbers +Subject: [PATCH] net: read bracketed ipv6 addrs and port numbers Allow specifying port numbers for http and tftp paths, and allow ipv6 addresses to be recognized with brackets around them, which is required to specify a port @@ -11,14 +11,14 @@ Signed-off-by: Aaron Miller [pjones: various bug fixes] Signed-off-by: Peter Jones --- - grub-core/net/http.c | 27 ++++++++++++---- + grub-core/net/http.c | 25 ++++++++++++--- grub-core/net/net.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++--- grub-core/net/tftp.c | 8 +++-- include/grub/net.h | 1 + - 4 files changed, 110 insertions(+), 13 deletions(-) + 4 files changed, 109 insertions(+), 12 deletions(-) diff --git a/grub-core/net/http.c b/grub-core/net/http.c -index 5aa4ad3..00737c5 100644 +index b616cf40b1e..12a2632ea55 100644 --- a/grub-core/net/http.c +++ b/grub-core/net/http.c @@ -289,7 +289,9 @@ http_receive (grub_net_tcp_socket_t sock __attribute__ ((unused)), @@ -73,26 +73,24 @@ index 5aa4ad3..00737c5 100644 ptr = nb->tail; err = grub_netbuff_put (nb, sizeof ("\r\nUser-Agent: " PACKAGE_STRING "\r\n") -@@ -390,9 +403,11 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) +@@ -390,8 +403,10 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) grub_netbuff_put (nb, 2); grub_memcpy (ptr, "\r\n", 2); - data->sock = grub_net_tcp_open (file->device->net->server, - HTTP_PORT, http_receive, -- http_err, http_err, + grub_dprintf ("http", "opening path %s on host %s TCP port %d\n", + data->filename, server, port ? port : HTTP_PORT); + data->sock = grub_net_tcp_open (server, + port ? port : HTTP_PORT, http_receive, -+ http_err, NULL, + http_err, NULL, file); if (!data->sock) - { diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index 6468eb2..2734f70 100644 +index a46f82362ed..0ce5e675ed7 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c -@@ -439,6 +439,13 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) +@@ -444,6 +444,13 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) grub_uint16_t newip[8]; const char *ptr = val; int word, quaddot = -1; @@ -106,7 +104,7 @@ index 6468eb2..2734f70 100644 if (ptr[0] == ':' && ptr[1] != ':') return 0; -@@ -477,6 +484,8 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) +@@ -482,6 +489,8 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) grub_memset (&newip[quaddot], 0, (7 - word) * sizeof (newip[0])); } grub_memcpy (ip, newip, 16); @@ -115,7 +113,7 @@ index 6468eb2..2734f70 100644 if (rest) *rest = ptr; return 1; -@@ -1338,8 +1347,10 @@ grub_net_open_real (const char *name) +@@ -1343,8 +1352,10 @@ grub_net_open_real (const char *name) { grub_net_app_level_t proto; const char *protname, *server; @@ -126,7 +124,7 @@ index 6468eb2..2734f70 100644 if (grub_strncmp (name, "pxe:", sizeof ("pxe:") - 1) == 0) { -@@ -1377,6 +1388,72 @@ grub_net_open_real (const char *name) +@@ -1382,6 +1393,72 @@ grub_net_open_real (const char *name) return NULL; } @@ -199,7 +197,7 @@ index 6468eb2..2734f70 100644 for (try = 0; try < 2; try++) { FOR_NET_APP_LEVEL (proto) -@@ -1386,14 +1463,13 @@ grub_net_open_real (const char *name) +@@ -1391,14 +1468,13 @@ grub_net_open_real (const char *name) { grub_net_t ret = grub_zalloc (sizeof (*ret)); if (!ret) @@ -218,7 +216,7 @@ index 6468eb2..2734f70 100644 ret->fs = &grub_net_fs; return ret; } -@@ -1468,6 +1544,7 @@ grub_net_open_real (const char *name) +@@ -1473,6 +1549,7 @@ grub_net_open_real (const char *name) grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("disk `%s' not found"), name); @@ -227,10 +225,10 @@ index 6468eb2..2734f70 100644 } diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c -index f900713..e267af3 100644 +index 4ab2f5c7357..d54b13f09ff 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c -@@ -333,6 +333,7 @@ tftp_open (struct grub_file *file, const char *filename) +@@ -295,6 +295,7 @@ tftp_open (struct grub_file *file, const char *filename) grub_err_t err; grub_uint8_t *nbd; grub_net_network_level_address_t addr; @@ -238,7 +236,7 @@ index f900713..e267af3 100644 data = grub_zalloc (sizeof (*data)); if (!data) -@@ -405,7 +406,10 @@ tftp_open (struct grub_file *file, const char *filename) +@@ -362,14 +363,17 @@ tftp_open (struct grub_file *file, const char *filename) err = grub_net_resolve_address (file->device->net->server, &addr); if (err) { @@ -247,10 +245,9 @@ index f900713..e267af3 100644 + grub_dprintf ("tftp", "file_size is %llu, block_size is %llu\n", + (unsigned long long)data->file_size, + (unsigned long long)data->block_size); - destroy_pq (data); grub_free (data); return err; -@@ -413,7 +417,7 @@ tftp_open (struct grub_file *file, const char *filename) + } grub_dprintf("tftp", "opening connection\n"); data->sock = grub_net_udp_open (addr, @@ -260,7 +257,7 @@ index f900713..e267af3 100644 if (!data->sock) { diff --git a/include/grub/net.h b/include/grub/net.h -index fc1fc44..fa7a8c3 100644 +index af0404db7e3..d55d505a03a 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -273,6 +273,7 @@ typedef struct grub_net @@ -271,6 +268,3 @@ index fc1fc44..fa7a8c3 100644 grub_net_app_level_t protocol; grub_net_packets_t packs; grub_off_t offset; --- -1.8.3.1 - diff --git a/0112-bootp-New-net_bootp6-command.patch b/0076-bootp-New-net_bootp6-command.patch similarity index 98% rename from 0112-bootp-New-net_bootp6-command.patch rename to 0076-bootp-New-net_bootp6-command.patch index 1f8d22939f907ef480c967ec5b49422c3dd4065c..21b3871bf51e027c408a1cd9f8ac6f31ef70a71a 100644 --- a/0112-bootp-New-net_bootp6-command.patch +++ b/0076-bootp-New-net_bootp6-command.patch @@ -1,7 +1,7 @@ -From c8eb4df74d416a4d94c364f2d361c7cc3f9b2cac Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Wed, 10 Jul 2019 15:42:36 +0200 -Subject: [PATCH 112/220] bootp: New net_bootp6 command +Subject: [PATCH] bootp: New net_bootp6 command Implement new net_bootp6 command for IPv6 network auto configuration via the DHCPv6 protocol (RFC3315). @@ -19,12 +19,12 @@ Signed-off-by: Peter Jones 5 files changed, 1002 insertions(+), 209 deletions(-) diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index 3cf6dbf..85adc9c 100644 +index 08b6b2b5d6c..fe93b80f1cf 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c -@@ -25,6 +25,98 @@ +@@ -24,6 +24,98 @@ + #include #include - #include #include +#include +#include @@ -121,7 +121,7 @@ index 3cf6dbf..85adc9c 100644 struct grub_dhcp_discover_options { -@@ -638,6 +730,584 @@ out: +@@ -604,6 +696,584 @@ out: return err; } @@ -706,7 +706,7 @@ index 3cf6dbf..85adc9c 100644 /* * This is called directly from net/ip.c:handle_dgram(), because those * BOOTP/DHCP packets are a bit special due to their improper -@@ -706,6 +1376,77 @@ grub_net_process_dhcp (struct grub_net_buff *nb, +@@ -672,6 +1342,77 @@ grub_net_process_dhcp (struct grub_net_buff *nb, } } @@ -784,7 +784,7 @@ index 3cf6dbf..85adc9c 100644 static grub_err_t grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), int argc, char **args) -@@ -931,180 +1672,174 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), +@@ -897,180 +1638,174 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), return err; } @@ -805,22 +805,43 @@ index 3cf6dbf..85adc9c 100644 - struct grub_net_network_level_interface *inter = NULL; - struct grub_net_network_level_address addr; - int mask = -1; -- ++ struct grub_net_card *card; ++ grub_uint32_t iaid = 0; ++ int interval; ++ grub_err_t err; ++ grub_dhcp6_session_t se; + - if (!device || !path) - return NULL; -- ++ err = GRUB_ERR_NONE; + - *device = 0; - *path = 0; -- ++ FOR_NET_CARDS (card) ++ { ++ struct grub_net_network_level_interface *iface; + - grub_dprintf ("net", "mac address is %02x:%02x:%02x:%02x:%02x:%02x\n", - hwaddr->mac[0], hwaddr->mac[1], hwaddr->mac[2], - hwaddr->mac[3], hwaddr->mac[4], hwaddr->mac[5]); -- ++ if (argc > 0 && grub_strcmp (card->name, args[0]) != 0) ++ continue; + - if (is_def) - grub_net_default_server = 0; -- ++ iface = grub_net_ipv6_get_link_local (card, &card->default_address); ++ if (!iface) ++ { ++ grub_dhcp6_session_remove_all (); ++ return grub_errno; ++ } + - if (is_def && !grub_net_default_server && packet) -- { ++ grub_dhcp6_session_add (iface, iaid++); ++ } ++ ++ for (interval = 200; interval < 10000; interval *= 2) + { - const grub_uint8_t *options = packet->dhcp_options; - unsigned int option_max = 1024 - OFFSET_OF (dhcp_options, packet); - unsigned int i; @@ -833,26 +854,15 @@ index 3cf6dbf..85adc9c 100644 - - num = grub_be_to_cpu16(opt->option_num); - len = grub_be_to_cpu16(opt->option_len); -+ struct grub_net_card *card; -+ grub_uint32_t iaid = 0; -+ int interval; -+ grub_err_t err; -+ grub_dhcp6_session_t se; - +- - grub_dprintf ("net", "got dhcpv6 option %d len %d\n", num, len); -+ err = GRUB_ERR_NONE; - +- - if (len == 0) - break; -+ FOR_NET_CARDS (card) -+ { -+ struct grub_net_network_level_interface *iface; - +- - if (len + i > 1024) - break; -+ if (argc > 0 && grub_strcmp (card->name, args[0]) != 0) -+ continue; - +- - if (num == GRUB_NET_DHCP6_BOOTFILE_URL) - { - char *scheme, *userinfo, *host, *file; @@ -958,21 +968,11 @@ index 3cf6dbf..85adc9c 100644 - left -= ia_na_opt_len; - } - } -+ iface = grub_net_ipv6_get_link_local (card, &card->default_address); -+ if (!iface) -+ { -+ grub_dhcp6_session_remove_all (); -+ return grub_errno; -+ } - +- - i += len + 4; - } -+ grub_dhcp6_session_add (iface, iaid++); -+ } - +- - grub_print_error (); -+ for (interval = 200; interval < 10000; interval *= 2) -+ { + int done = 1; + + FOR_DHCP6_SESSIONS (se) @@ -1119,7 +1119,7 @@ index 3cf6dbf..85adc9c 100644 void grub_bootp_init (void) -@@ -1118,11 +1853,15 @@ grub_bootp_init (void) +@@ -1084,11 +1819,15 @@ grub_bootp_init (void) cmd_getdhcp = grub_register_command ("net_get_dhcp_option", grub_cmd_dhcpopt, N_("VAR INTERFACE NUMBER DESCRIPTION"), N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value.")); @@ -1136,10 +1136,10 @@ index 3cf6dbf..85adc9c 100644 grub_unregister_command (cmd_bootp); grub_unregister_command (cmd_dhcp); diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index 4444e8e..00d7d37 100644 +index a673bea807a..8e25680db0c 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c -@@ -394,9 +394,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -393,9 +393,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, pxe_mode = pxe->mode; if (pxe_mode->using_ipv6) { @@ -1149,7 +1149,7 @@ index 4444e8e..00d7d37 100644 grub_dprintf ("efinet", "using ipv6 and dhcpv6\n"); grub_dprintf ("efinet", "dhcp_ack_received: %s%s\n", pxe_mode->dhcp_ack_received ? "yes" : "no", -@@ -404,15 +401,14 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -403,15 +400,14 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, if (!pxe_mode->dhcp_ack_received) continue; @@ -1174,7 +1174,7 @@ index 4444e8e..00d7d37 100644 } else diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c -index a5896f6..ce6bdc7 100644 +index a5896f6dc26..ce6bdc75c6d 100644 --- a/grub-core/net/ip.c +++ b/grub-core/net/ip.c @@ -239,6 +239,45 @@ handle_dgram (struct grub_net_buff *nb, @@ -1224,10 +1224,10 @@ index a5896f6..ce6bdc7 100644 { const struct grub_net_bootp_packet *bootp; diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index 955973e..71d972a 100644 +index 99628801478..7614b58dca8 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h -@@ -1507,7 +1507,7 @@ typedef struct grub_efi_pxe_ip_filter +@@ -1532,7 +1532,7 @@ typedef struct grub_efi_pxe_ip_filter { grub_efi_uint8_t filters; grub_efi_uint8_t ip_count; @@ -1237,7 +1237,7 @@ index 955973e..71d972a 100644 } grub_efi_pxe_ip_filter_t; diff --git a/include/grub/net.h b/include/grub/net.h -index fa7a8c3..aedf4b5 100644 +index d55d505a03a..543251f7273 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -451,50 +451,65 @@ struct grub_net_bootp_packet @@ -1366,6 +1366,3 @@ index fa7a8c3..aedf4b5 100644 int grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a, const grub_net_link_level_address_t *b); --- -1.8.3.1 - diff --git a/0113-efinet-UEFI-IPv6-PXE-support.patch b/0077-efinet-UEFI-IPv6-PXE-support.patch similarity index 89% rename from 0113-efinet-UEFI-IPv6-PXE-support.patch rename to 0077-efinet-UEFI-IPv6-PXE-support.patch index daf647609cddf2cf0257e168c8fe936c1325edab..d8b22b8c94a3535b1782a86f62c0955971b7d2a1 100644 --- a/0113-efinet-UEFI-IPv6-PXE-support.patch +++ b/0077-efinet-UEFI-IPv6-PXE-support.patch @@ -1,7 +1,7 @@ -From 31d0e54b21a9dde2cfe4eefcab5371fc1454e373 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Wed, 15 Apr 2015 14:48:30 +0800 -Subject: [PATCH 113/220] efinet: UEFI IPv6 PXE support +Subject: [PATCH] efinet: UEFI IPv6 PXE support When grub2 image is booted from UEFI IPv6 PXE, the DHCPv6 Reply packet is cached in firmware buffer which can be obtained by PXE Base Code protocol. The @@ -15,10 +15,10 @@ Signed-off-by: Ken Lin 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index 00d7d37..c3db328 100644 +index 8e25680db0c..014e5bf9802 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c -@@ -410,6 +410,8 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -409,6 +409,8 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, grub_print_error (); if (device && path) grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path); @@ -28,10 +28,10 @@ index 00d7d37..c3db328 100644 else { diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index 71d972a..186cf39 100644 +index 7614b58dca8..91ab528e4d0 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h -@@ -1499,31 +1499,6 @@ typedef union +@@ -1524,31 +1524,6 @@ typedef union grub_efi_pxe_dhcpv6_packet_t dhcpv6; } grub_efi_pxe_packet_t; @@ -63,7 +63,7 @@ index 71d972a..186cf39 100644 typedef struct grub_efi_pxe_icmp_error { grub_efi_uint8_t type; -@@ -1549,6 +1524,48 @@ typedef struct grub_efi_pxe_tftp_error +@@ -1574,6 +1549,48 @@ typedef struct grub_efi_pxe_tftp_error grub_efi_char8_t error_string[127]; } grub_efi_pxe_tftp_error_t; @@ -112,7 +112,7 @@ index 71d972a..186cf39 100644 typedef struct grub_efi_pxe_mode { grub_efi_boolean_t started; -@@ -1580,9 +1597,9 @@ typedef struct grub_efi_pxe_mode +@@ -1605,9 +1622,9 @@ typedef struct grub_efi_pxe_mode grub_efi_pxe_packet_t pxe_bis_reply; grub_efi_pxe_ip_filter_t ip_filter; grub_efi_uint32_t arp_cache_entries; @@ -124,6 +124,3 @@ index 71d972a..186cf39 100644 grub_efi_pxe_icmp_error_t icmp_error; grub_efi_pxe_tftp_error_t tftp_error; } grub_efi_pxe_mode_t; --- -1.8.3.1 - diff --git a/0114-grub.texi-Add-net_bootp6-doument.patch b/0078-grub.texi-Add-net_bootp6-doument.patch similarity index 73% rename from 0114-grub.texi-Add-net_bootp6-doument.patch rename to 0078-grub.texi-Add-net_bootp6-doument.patch index acd465c82e41f18c304b066359a3864bac24e76a..3f8ec97a685181b0e3489e5c97d998349d1b6421 100644 --- a/0114-grub.texi-Add-net_bootp6-doument.patch +++ b/0078-grub.texi-Add-net_bootp6-doument.patch @@ -1,7 +1,7 @@ -From 5d9e28b3bf21eebf915b4519d6bac521f87815d3 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Tue, 5 May 2015 14:19:24 +0800 -Subject: [PATCH 114/220] grub.texi: Add net_bootp6 doument +Subject: [PATCH] grub.texi: Add net_bootp6 doument Update grub documentation for net_bootp6 command. @@ -12,18 +12,18 @@ Signed-off-by: Ken Lin 1 file changed, 17 insertions(+) diff --git a/docs/grub.texi b/docs/grub.texi -index 960e5f3..495462b 100644 +index 0615d0ed97e..04ed6ac1f07 100644 --- a/docs/grub.texi +++ b/docs/grub.texi -@@ -5338,6 +5338,7 @@ This command is only available on AArch64 systems. +@@ -5487,6 +5487,7 @@ This command is only available on AArch64 systems. * net_add_dns:: Add a DNS server * net_add_route:: Add routing entry - * net_bootp:: Perform a bootp autoconfiguration + * net_bootp:: Perform a bootp/DHCP autoconfiguration +* net_bootp6:: Perform a DHCPv6 autoconfiguration * net_del_addr:: Remove IP address from interface * net_del_dns:: Remove a DNS server * net_del_route:: Remove a route entry -@@ -5419,6 +5420,22 @@ Sets environment variable @samp{net_}@var{}@samp{_dhcp_extensionspath} +@@ -5611,6 +5612,22 @@ Sets environment variable @samp{net_}@var{}@samp{_boot_file} @end deffn @@ -44,8 +44,5 @@ index 960e5f3..495462b 100644 + +@end deffn - @node net_del_addr - @subsection net_del_addr --- -1.8.3.1 - + @node net_get_dhcp_option + @subsection net_get_dhcp_option diff --git a/0115-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch b/0079-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch similarity index 85% rename from 0115-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch rename to 0079-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch index a28b33b69baa2e86bc23473accb59d207d6927d4..e800dd236d9dede4e0c16f65ac307475a9df2f60 100644 --- a/0115-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch +++ b/0079-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch @@ -1,7 +1,7 @@ -From 03bca00dc93a92f9f5ae5194b2c86a40b6281766 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Wed, 10 Jul 2019 23:58:28 +0200 -Subject: [PATCH 115/220] bootp: Add processing DHCPACK packet from HTTP Boot +Subject: [PATCH] bootp: Add processing DHCPACK packet from HTTP Boot The vendor class identifier with the string "HTTPClient" is used to denote the packet as responding to HTTP boot request. In DHCP4 config, the filename for @@ -22,7 +22,7 @@ Signed-off-by: Ken Lin 2 files changed, 56 insertions(+) diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index 85adc9c..2e46842 100644 +index fe93b80f1cf..8fb8918ae7e 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c @@ -20,6 +20,7 @@ @@ -33,7 +33,7 @@ index 85adc9c..2e46842 100644 #include #include #include -@@ -567,6 +568,60 @@ grub_net_configure_by_dhcp_ack (const char *name, +@@ -500,6 +501,60 @@ grub_net_configure_by_dhcp_ack (const char *name, if (opt && opt_len) grub_env_set_net_property (name, "rootpath", (const char *) opt, opt_len); @@ -95,17 +95,14 @@ index 85adc9c..2e46842 100644 if (opt && opt_len) grub_env_set_net_property (name, "extensionspath", (const char *) opt, opt_len); diff --git a/include/grub/net.h b/include/grub/net.h -index aedf4b5..ebb569b 100644 +index 543251f7273..42af7de250a 100644 --- a/include/grub/net.h +++ b/include/grub/net.h -@@ -526,6 +526,7 @@ enum - GRUB_NET_BOOTP_DOMAIN = 0x0f, - GRUB_NET_BOOTP_ROOT_PATH = 0x11, - GRUB_NET_BOOTP_EXTENSIONS_PATH = 0x12, -+ GRUB_NET_BOOTP_VENDOR_CLASS_IDENTIFIER = 0x3C, - GRUB_NET_BOOTP_CLIENT_ID = 0x3d, - GRUB_NET_BOOTP_CLIENT_UUID = 0x61, - GRUB_NET_DHCP_REQUESTED_IP_ADDRESS = 50, --- -1.8.3.1 - +@@ -531,6 +531,7 @@ enum + GRUB_NET_DHCP_MESSAGE_TYPE = 53, + GRUB_NET_DHCP_SERVER_IDENTIFIER = 54, + GRUB_NET_DHCP_PARAMETER_REQUEST_LIST = 55, ++ GRUB_NET_BOOTP_VENDOR_CLASS_IDENTIFIER = 60, + GRUB_NET_BOOTP_CLIENT_ID = 61, + GRUB_NET_DHCP_TFTP_SERVER_NAME = 66, + GRUB_NET_DHCP_BOOTFILE_NAME = 67, diff --git a/0116-efinet-Setting-network-from-UEFI-device-path.patch b/0080-efinet-Setting-network-from-UEFI-device-path.patch similarity index 94% rename from 0116-efinet-Setting-network-from-UEFI-device-path.patch rename to 0080-efinet-Setting-network-from-UEFI-device-path.patch index 6a766bc9de182dc200483cc62929408400e080f0..11b2a724d656dc1c48f639f75e85239308c835b0 100644 --- a/0116-efinet-Setting-network-from-UEFI-device-path.patch +++ b/0080-efinet-Setting-network-from-UEFI-device-path.patch @@ -1,7 +1,7 @@ -From b412d2074f75951680962af0f64b1467cd485821 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Sun, 10 Jul 2016 23:46:31 +0800 -Subject: [PATCH 116/220] efinet: Setting network from UEFI device path +Subject: [PATCH] efinet: Setting network from UEFI device path The PXE Base Code protocol used to obtain cached PXE DHCPACK packet is no longer provided for HTTP Boot. Instead, we have to get the HTTP boot @@ -32,10 +32,10 @@ Signed-off-by: Ken Lin 2 files changed, 280 insertions(+), 15 deletions(-) diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index c3db328..2817b6f 100644 +index 014e5bf9802..8171ecaa5e4 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c -@@ -27,6 +27,7 @@ +@@ -26,6 +26,7 @@ #include #include #include @@ -43,7 +43,7 @@ index c3db328..2817b6f 100644 GRUB_MOD_LICENSE ("GPLv3+"); -@@ -332,6 +333,227 @@ grub_efinet_findcards (void) +@@ -331,6 +332,227 @@ grub_efinet_findcards (void) grub_free (handles); } @@ -271,7 +271,7 @@ index c3db328..2817b6f 100644 static void grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, char **path) -@@ -347,7 +569,11 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -346,7 +568,11 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, { grub_efi_device_path_t *cdp; struct grub_efi_pxe *pxe; @@ -284,7 +284,7 @@ index c3db328..2817b6f 100644 if (card->driver != &efidriver) continue; -@@ -371,11 +597,21 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -370,11 +596,21 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, */ if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE @@ -307,7 +307,7 @@ index c3db328..2817b6f 100644 dup_ldp = grub_efi_find_last_device_path (dup_dp); dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; -@@ -388,23 +624,37 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -387,23 +623,37 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, pxe = grub_efi_open_protocol (hnd, &pxe_io_guid, GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); @@ -356,7 +356,7 @@ index c3db328..2817b6f 100644 1, device, path); if (grub_errno) grub_print_error (); -@@ -418,11 +668,15 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -417,11 +667,15 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, grub_dprintf ("efinet", "using ipv4 and dhcp\n"); grub_net_configure_by_dhcp_ack (card->name, card, 0, (struct grub_net_bootp_packet *) @@ -375,10 +375,10 @@ index c3db328..2817b6f 100644 } } diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index 186cf39..0d4839a 100644 +index 91ab528e4d0..4a51667adb1 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h -@@ -839,6 +839,8 @@ struct grub_efi_ipv4_device_path +@@ -864,6 +864,8 @@ struct grub_efi_ipv4_device_path grub_efi_uint16_t remote_port; grub_efi_uint16_t protocol; grub_efi_uint8_t static_ip_address; @@ -387,7 +387,7 @@ index 186cf39..0d4839a 100644 } GRUB_PACKED; typedef struct grub_efi_ipv4_device_path grub_efi_ipv4_device_path_t; -@@ -893,6 +895,15 @@ struct grub_efi_sata_device_path +@@ -918,6 +920,15 @@ struct grub_efi_sata_device_path } GRUB_PACKED; typedef struct grub_efi_sata_device_path grub_efi_sata_device_path_t; @@ -403,6 +403,3 @@ index 186cf39..0d4839a 100644 #define GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE 10 /* Media Device Path. */ --- -1.8.3.1 - diff --git a/0117-efinet-Setting-DNS-server-from-UEFI-protocol.patch b/0081-efinet-Setting-DNS-server-from-UEFI-protocol.patch similarity index 91% rename from 0117-efinet-Setting-DNS-server-from-UEFI-protocol.patch rename to 0081-efinet-Setting-DNS-server-from-UEFI-protocol.patch index 75d786b87552ec4092635af76be53afbc9a7af0d..1460c8a6f8617c05976451fbe99325b136a33de7 100644 --- a/0117-efinet-Setting-DNS-server-from-UEFI-protocol.patch +++ b/0081-efinet-Setting-DNS-server-from-UEFI-protocol.patch @@ -1,7 +1,7 @@ -From 8bccd41162bf0172c30934330b71983706d796f4 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Thu, 14 Jul 2016 17:48:45 +0800 -Subject: [PATCH 117/220] efinet: Setting DNS server from UEFI protocol +Subject: [PATCH] efinet: Setting DNS server from UEFI protocol In the URI device path node, any name rahter than address can be used for looking up the resources so that DNS service become needed to get answer of the @@ -29,14 +29,14 @@ Signed-off-by: Michael Chang Signed-off-by: Ken Lin --- grub-core/net/drivers/efi/efinet.c | 163 +++++++++++++++++++++++++++++++++++++ - include/grub/efi/api.h | 76 +++++++++++++++++ - 2 files changed, 239 insertions(+) + include/grub/efi/api.h | 75 +++++++++++++++++ + 2 files changed, 238 insertions(+) diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index 2817b6f..c843654 100644 +index 8171ecaa5e4..715a6168d77 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c -@@ -34,6 +34,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); +@@ -33,6 +33,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); /* GUID. */ static grub_efi_guid_t net_io_guid = GRUB_EFI_SIMPLE_NETWORK_GUID; static grub_efi_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID; @@ -45,7 +45,7 @@ index 2817b6f..c843654 100644 static grub_err_t send_card_buffer (struct grub_net_card *dev, -@@ -333,6 +335,125 @@ grub_efinet_findcards (void) +@@ -332,6 +334,125 @@ grub_efinet_findcards (void) grub_free (handles); } @@ -171,7 +171,7 @@ index 2817b6f..c843654 100644 static struct grub_net_buff * grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *use_ipv6) { -@@ -391,6 +512,8 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u +@@ -390,6 +511,8 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u grub_efi_ipv4_device_path_t *ipv4 = (grub_efi_ipv4_device_path_t *) ldp; struct grub_net_bootp_packet *bp; grub_uint8_t *ptr; @@ -180,7 +180,7 @@ index 2817b6f..c843654 100644 bp = (struct grub_net_bootp_packet *) nb->tail; err = grub_netbuff_put (nb, sizeof (*bp) + 4); -@@ -452,6 +575,25 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u +@@ -451,6 +574,25 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u *ptr++ = sizeof ("HTTPClient") - 1; grub_memcpy (ptr, "HTTPClient", sizeof ("HTTPClient") - 1); @@ -206,7 +206,7 @@ index 2817b6f..c843654 100644 ptr = nb->tail; err = grub_netbuff_put (nb, 1); if (err) -@@ -484,6 +626,8 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u +@@ -483,6 +625,8 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u struct grub_net_dhcp6_option *opt; struct grub_net_dhcp6_option_iana *iana; struct grub_net_dhcp6_option_iaaddr *iaaddr; @@ -215,7 +215,7 @@ index 2817b6f..c843654 100644 d6p = (struct grub_net_dhcp6_packet *)nb->tail; err = grub_netbuff_put (nb, sizeof(*d6p)); -@@ -547,6 +691,25 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u +@@ -546,6 +690,25 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u opt->len = grub_cpu_to_be16 (uri_len); grub_memcpy (opt->data, uri_dp->uri, uri_len); @@ -242,13 +242,14 @@ index 2817b6f..c843654 100644 } diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index 0d4839a..716f121 100644 +index 4a51667adb1..0b490195ad9 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h -@@ -334,6 +334,16 @@ - { 0x8B, 0x8C, 0xE2, 0x1B, 0x01, 0xAE, 0xF2, 0xB7 } \ - } - +@@ -352,6 +352,15 @@ + #define GRUB_EFI_RNG_PROTOCOL_GUID \ + { 0x3152bca5, 0xeade, 0x433d, \ + { 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44 } \ ++ +#define GRUB_EFI_IP4_CONFIG2_PROTOCOL_GUID \ + { 0x5b446ed1, 0xe30b, 0x4faa, \ + { 0x87, 0x1a, 0x36, 0x54, 0xec, 0xa3, 0x60, 0x80 } \ @@ -257,14 +258,12 @@ index 0d4839a..716f121 100644 +#define GRUB_EFI_IP6_CONFIG_PROTOCOL_GUID \ + { 0x937fe521, 0x95ae, 0x4d1a, \ + { 0x89, 0x29, 0x48, 0xbc, 0xd9, 0x0a, 0xd3, 0x1a } \ -+ } -+ + } + struct grub_efi_sal_system_table - { - grub_uint32_t signature; -@@ -1838,6 +1848,72 @@ struct grub_efi_block_io +@@ -1883,6 +1892,72 @@ struct grub_efi_rng_protocol }; - typedef struct grub_efi_block_io grub_efi_block_io_t; + typedef struct grub_efi_rng_protocol grub_efi_rng_protocol_t; +enum grub_efi_ip4_config2_data_type { + GRUB_EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO, @@ -335,6 +334,3 @@ index 0d4839a..716f121 100644 #if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \ || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) \ || defined(__riscv) --- -1.8.3.1 - diff --git a/0119-Support-UEFI-networking-protocols.patch b/0082-Support-UEFI-networking-protocols.patch similarity index 98% rename from 0119-Support-UEFI-networking-protocols.patch rename to 0082-Support-UEFI-networking-protocols.patch index 38414496768f8188c3c806c369d301292b571180..fb143862d55710f868b5a325fa61b231e2369592 100644 --- a/0119-Support-UEFI-networking-protocols.patch +++ b/0082-Support-UEFI-networking-protocols.patch @@ -1,7 +1,7 @@ -From 52cf36ce649fc8a5f915b143ccc680cf4a2ebbda Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Wed, 22 Feb 2017 14:27:50 +0800 -Subject: [PATCH 119/220] Support UEFI networking protocols +Subject: [PATCH] Support UEFI networking protocols References: fate#320130, bsc#1015589, bsc#1076132 Patch-Mainline: no @@ -39,11 +39,11 @@ Signed-off-by: Peter Jones grub-core/net/efi/net.c | 1428 ++++++++++++++++++++++++++++++++++++ grub-core/net/efi/pxe.c | 424 +++++++++++ grub-core/net/net.c | 74 ++ + util/grub-mknetdir.c | 23 +- include/grub/efi/api.h | 180 ++++- include/grub/efi/dhcp.h | 343 +++++++++ include/grub/efi/http.h | 215 ++++++ include/grub/net/efi.h | 144 ++++ - util/grub-mknetdir.c | 23 +- 17 files changed, 4620 insertions(+), 41 deletions(-) create mode 100644 grub-core/net/efi/dhcp.c create mode 100644 grub-core/net/efi/efi_netfs.c @@ -57,26 +57,26 @@ Signed-off-by: Peter Jones create mode 100644 include/grub/net/efi.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 49c5dc4..48491b5 100644 +index 4b7c45a7b06..c40170f2dd2 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -2277,6 +2277,12 @@ module = { +@@ -2299,6 +2299,12 @@ module = { + common = hook/datehook.c; }; - module = { ++module = { + name = efi_netfs; + common = net/efi/efi_netfs.c; + enable = efi; +}; + -+module = { + module = { name = net; common = net/net.c; - common = net/dns.c; -@@ -2290,6 +2296,12 @@ module = { +@@ -2312,6 +2318,12 @@ module = { + common = net/ethernet.c; common = net/arp.c; common = net/netbuff.c; - common = net/url.c; + efi = net/efi/net.c; + efi = net/efi/http.c; + efi = net/efi/pxe.c; @@ -87,7 +87,7 @@ index 49c5dc4..48491b5 100644 module = { diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c -index a458c3a..1637731 100644 +index a458c3aca78..1637731535e 100644 --- a/grub-core/io/bufio.c +++ b/grub-core/io/bufio.c @@ -139,7 +139,7 @@ grub_bufio_read (grub_file_t file, char *buf, grub_size_t len) @@ -100,10 +100,10 @@ index a458c3a..1637731 100644 if (file->offset + res < next_buf) { diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index 19054b1..ada3004 100644 +index d6a2fb57789..2a446f5031b 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c -@@ -709,7 +709,7 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) +@@ -755,7 +755,7 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) { grub_efi_ipv4_device_path_t *ipv4 = (grub_efi_ipv4_device_path_t *) dp; @@ -112,7 +112,7 @@ index 19054b1..ada3004 100644 (unsigned) ipv4->local_ip_address[0], (unsigned) ipv4->local_ip_address[1], (unsigned) ipv4->local_ip_address[2], -@@ -722,33 +722,60 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) +@@ -768,33 +768,60 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) (unsigned) ipv4->remote_port, (unsigned) ipv4->protocol, (unsigned) ipv4->static_ip_address); @@ -190,7 +190,7 @@ index 19054b1..ada3004 100644 } break; case GRUB_EFI_INFINIBAND_DEVICE_PATH_SUBTYPE: -@@ -788,6 +815,39 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) +@@ -834,6 +861,39 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) dump_vendor_path ("Messaging", (grub_efi_vendor_device_path_t *) dp); break; @@ -231,10 +231,10 @@ index 19054b1..ada3004 100644 grub_printf ("/UnknownMessaging(%x)", (unsigned) subtype); break; diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index c843654..ca8bd3c 100644 +index 715a6168d77..e11d759f19a 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c -@@ -28,6 +28,7 @@ +@@ -27,6 +27,7 @@ #include #include #include @@ -242,7 +242,7 @@ index c843654..ca8bd3c 100644 GRUB_MOD_LICENSE ("GPLv3+"); -@@ -492,6 +493,17 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u +@@ -491,6 +492,17 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u ldp = grub_efi_find_last_device_path (ddp); @@ -260,7 +260,7 @@ index c843654..ca8bd3c 100644 if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE)) -@@ -761,6 +773,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -760,6 +772,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE @@ -268,10 +268,11 @@ index c843654..ca8bd3c 100644 && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_URI_DEVICE_PATH_SUBTYPE)) continue; dup_dp = grub_efi_duplicate_device_path (dp); -@@ -776,6 +789,15 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -774,6 +787,15 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + dup_ldp->length = sizeof (*dup_ldp); } - dup_ldp = grub_efi_find_last_device_path (dup_dp); ++ dup_ldp = grub_efi_find_last_device_path (dup_dp); + if (GRUB_EFI_DEVICE_PATH_SUBTYPE (dup_ldp) == GRUB_EFI_DNS_DEVICE_PATH_SUBTYPE) + { + dup_ldp = grub_efi_find_last_device_path (dup_dp); @@ -280,11 +281,10 @@ index c843654..ca8bd3c 100644 + dup_ldp->length = sizeof (*dup_ldp); + } + -+ dup_ldp = grub_efi_find_last_device_path (dup_dp); + dup_ldp = grub_efi_find_last_device_path (dup_dp); dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; - dup_ldp->length = sizeof (*dup_ldp); -@@ -846,6 +868,9 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -845,6 +867,9 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, GRUB_MOD_INIT(efinet) { @@ -294,7 +294,7 @@ index c843654..ca8bd3c 100644 grub_efinet_findcards (); grub_efi_net_config = grub_efi_net_config_real; } -@@ -857,5 +882,7 @@ GRUB_MOD_FINI(efinet) +@@ -856,5 +881,7 @@ GRUB_MOD_FINI(efinet) FOR_NET_CARDS_SAFE (card, next) if (card->driver == &efidriver) grub_net_card_unregister (card); @@ -304,7 +304,7 @@ index c843654..ca8bd3c 100644 diff --git a/grub-core/net/efi/dhcp.c b/grub-core/net/efi/dhcp.c new file mode 100644 -index 0000000..dbef63d +index 00000000000..dbef63d8c08 --- /dev/null +++ b/grub-core/net/efi/dhcp.c @@ -0,0 +1,397 @@ @@ -707,7 +707,7 @@ index 0000000..dbef63d +grub_command_func_t grub_efi_net_bootp6 = grub_cmd_efi_bootp6; diff --git a/grub-core/net/efi/efi_netfs.c b/grub-core/net/efi/efi_netfs.c new file mode 100644 -index 0000000..ef371d8 +index 00000000000..ef371d885ea --- /dev/null +++ b/grub-core/net/efi/efi_netfs.c @@ -0,0 +1,57 @@ @@ -770,7 +770,7 @@ index 0000000..ef371d8 +} diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c new file mode 100644 -index 0000000..3f61fd2 +index 00000000000..3f61fd2fa5b --- /dev/null +++ b/grub-core/net/efi/http.c @@ -0,0 +1,419 @@ @@ -1195,7 +1195,7 @@ index 0000000..3f61fd2 + }; diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c new file mode 100644 -index 0000000..b711a5d +index 00000000000..b711a5d9457 --- /dev/null +++ b/grub-core/net/efi/ip4_config.c @@ -0,0 +1,398 @@ @@ -1599,7 +1599,7 @@ index 0000000..b711a5d + }; diff --git a/grub-core/net/efi/ip6_config.c b/grub-core/net/efi/ip6_config.c new file mode 100644 -index 0000000..017c4d0 +index 00000000000..017c4d05bc7 --- /dev/null +++ b/grub-core/net/efi/ip6_config.c @@ -0,0 +1,422 @@ @@ -2027,7 +2027,7 @@ index 0000000..017c4d0 + }; diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c new file mode 100644 -index 0000000..86bce65 +index 00000000000..86bce6535d3 --- /dev/null +++ b/grub-core/net/efi/net.c @@ -0,0 +1,1428 @@ @@ -3461,7 +3461,7 @@ index 0000000..86bce65 +} diff --git a/grub-core/net/efi/pxe.c b/grub-core/net/efi/pxe.c new file mode 100644 -index 0000000..531949c +index 00000000000..531949cba5c --- /dev/null +++ b/grub-core/net/efi/pxe.c @@ -0,0 +1,424 @@ @@ -3890,7 +3890,7 @@ index 0000000..531949c + }; + diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index 2734f70..27a0a1d 100644 +index 0ce5e675ed7..55aed92722c 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -32,6 +32,9 @@ @@ -3903,7 +3903,7 @@ index 2734f70..27a0a1d 100644 GRUB_MOD_LICENSE ("GPLv3+"); -@@ -2025,8 +2028,49 @@ static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; +@@ -2033,8 +2036,49 @@ static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; static grub_command_t cmd_lsroutes, cmd_lscards; static grub_command_t cmd_lsaddr, cmd_slaac; @@ -3953,7 +3953,7 @@ index 2734f70..27a0a1d 100644 grub_register_variable_hook ("net_default_server", defserver_get_env, defserver_set_env); grub_env_export ("net_default_server"); -@@ -2074,10 +2118,37 @@ GRUB_MOD_INIT(net) +@@ -2082,10 +2126,37 @@ GRUB_MOD_INIT(net) grub_net_restore_hw, GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK); grub_net_poll_cards_idle = grub_net_poll_cards_idle_real; @@ -3991,7 +3991,7 @@ index 2734f70..27a0a1d 100644 grub_register_variable_hook ("net_default_server", 0, 0); grub_register_variable_hook ("pxe_default_server", 0, 0); -@@ -2096,4 +2167,7 @@ GRUB_MOD_FINI(net) +@@ -2104,4 +2175,7 @@ GRUB_MOD_FINI(net) grub_net_fini_hw (0); grub_loader_unregister_preboot_hook (fini_hnd); grub_net_poll_cards_idle = grub_net_poll_cards_idle_real; @@ -3999,11 +3999,93 @@ index 2734f70..27a0a1d 100644 + init_mode = INIT_MODE_NONE; +#endif } +diff --git a/util/grub-mknetdir.c b/util/grub-mknetdir.c +index a2461cda1c4..77958dd9dd5 100644 +--- a/util/grub-mknetdir.c ++++ b/util/grub-mknetdir.c +@@ -32,13 +32,15 @@ + + static char *rootdir = NULL, *subdir = NULL; + static char *debug_image = NULL; ++static char efi_netfs = 0; + + enum + { + OPTION_NET_DIRECTORY = 0x301, + OPTION_SUBDIR, + OPTION_DEBUG, +- OPTION_DEBUG_IMAGE ++ OPTION_DEBUG_IMAGE, ++ OPTION_DEBUG_EFI_NETFS + }; + + static struct argp_option options[] = { +@@ -49,6 +51,7 @@ static struct argp_option options[] = { + 0, N_("relative subdirectory on network server"), 2}, + {"debug", OPTION_DEBUG, 0, OPTION_HIDDEN, 0, 2}, + {"debug-image", OPTION_DEBUG_IMAGE, N_("STRING"), OPTION_HIDDEN, 0, 2}, ++ {"debug-efi-netfs", OPTION_DEBUG_EFI_NETFS, 0, OPTION_HIDDEN, 0, 2}, + {0, 0, 0, 0, 0, 0} + }; + +@@ -67,6 +70,9 @@ argp_parser (int key, char *arg, struct argp_state *state) + free (subdir); + subdir = xstrdup (arg); + return 0; ++ case OPTION_DEBUG_EFI_NETFS: ++ efi_netfs = 1; ++ return 0; + /* This is an undocumented feature... */ + case OPTION_DEBUG: + verbosity++; +@@ -82,7 +88,6 @@ argp_parser (int key, char *arg, struct argp_state *state) + } + } + +- + struct argp argp = { + options, argp_parser, NULL, + "\v"N_("Prepares GRUB network boot images at net_directory/subdir " +@@ -92,7 +97,7 @@ struct argp argp = { + + static char *base; + +-static const struct ++static struct + { + const char *mkimage_target; + const char *netmodule; +@@ -156,6 +161,7 @@ process_input_dir (const char *input_dir, enum grub_install_plat platform) + grub_install_push_module (targets[platform].netmodule); + + output = grub_util_path_concat_ext (2, grubdir, "core", targets[platform].ext); ++ + grub_install_make_image_wrap (input_dir, prefix, output, + 0, load_cfg, + targets[platform].mkimage_target, 0); +@@ -195,7 +201,16 @@ main (int argc, char *argv[]) + + grub_install_mkdir_p (base); + +- grub_install_push_module ("tftp"); ++ if (!efi_netfs) ++ { ++ grub_install_push_module ("tftp"); ++ grub_install_push_module ("http"); ++ } ++ else ++ { ++ targets[GRUB_INSTALL_PLATFORM_I386_EFI].netmodule = "efi_netfs"; ++ targets[GRUB_INSTALL_PLATFORM_X86_64_EFI].netmodule = "efi_netfs"; ++ } + + if (!grub_install_source_directory) + { diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index 716f121..2ed9c26 100644 +index 0b490195ad9..f431f49973e 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h -@@ -602,6 +602,23 @@ typedef union +@@ -622,6 +622,23 @@ typedef union typedef grub_efi_uint64_t grub_efi_physical_address_t; typedef grub_efi_uint64_t grub_efi_virtual_address_t; @@ -4027,7 +4109,7 @@ index 716f121..2ed9c26 100644 struct grub_efi_guid { -@@ -865,6 +882,8 @@ struct grub_efi_ipv6_device_path +@@ -889,6 +906,8 @@ struct grub_efi_ipv6_device_path grub_efi_uint16_t remote_port; grub_efi_uint16_t protocol; grub_efi_uint8_t static_ip_address; @@ -4036,7 +4118,7 @@ index 716f121..2ed9c26 100644 } GRUB_PACKED; typedef struct grub_efi_ipv6_device_path grub_efi_ipv6_device_path_t; -@@ -914,6 +933,15 @@ struct grub_efi_uri_device_path +@@ -938,6 +957,15 @@ struct grub_efi_uri_device_path } GRUB_PACKED; typedef struct grub_efi_uri_device_path grub_efi_uri_device_path_t; @@ -4052,7 +4134,7 @@ index 716f121..2ed9c26 100644 #define GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE 10 /* Media Device Path. */ -@@ -996,6 +1024,23 @@ struct grub_efi_bios_device_path +@@ -1020,6 +1048,23 @@ struct grub_efi_bios_device_path } GRUB_PACKED; typedef struct grub_efi_bios_device_path grub_efi_bios_device_path_t; @@ -4076,7 +4158,7 @@ index 716f121..2ed9c26 100644 struct grub_efi_open_protocol_information_entry { grub_efi_handle_t agent_handle; -@@ -1545,23 +1590,27 @@ typedef struct grub_efi_pxe_tftp_error +@@ -1569,23 +1614,27 @@ typedef struct grub_efi_pxe_tftp_error grub_efi_char8_t error_string[127]; } grub_efi_pxe_tftp_error_t; @@ -4118,7 +4200,7 @@ index 716f121..2ed9c26 100644 #define GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT 8 typedef struct grub_efi_pxe_ip_filter -@@ -1628,17 +1677,31 @@ typedef struct grub_efi_pxe_mode +@@ -1652,17 +1701,31 @@ typedef struct grub_efi_pxe_mode typedef struct grub_efi_pxe { grub_uint64_t rev; @@ -4154,7 +4236,7 @@ index 716f121..2ed9c26 100644 void (*setpackets) (void); struct grub_efi_pxe_mode *mode; } grub_efi_pxe_t; -@@ -1880,6 +1943,44 @@ struct grub_efi_ip4_config2_protocol +@@ -1924,6 +1987,44 @@ struct grub_efi_ip4_config2_protocol }; typedef struct grub_efi_ip4_config2_protocol grub_efi_ip4_config2_protocol_t; @@ -4199,7 +4281,7 @@ index 716f121..2ed9c26 100644 enum grub_efi_ip6_config_data_type { GRUB_EFI_IP6_CONFIG_DATA_TYPE_INTERFACEINFO, GRUB_EFI_IP6_CONFIG_DATA_TYPE_ALT_INTERFACEID, -@@ -1914,6 +2015,49 @@ struct grub_efi_ip6_config_protocol +@@ -1958,6 +2059,49 @@ struct grub_efi_ip6_config_protocol }; typedef struct grub_efi_ip6_config_protocol grub_efi_ip6_config_protocol_t; @@ -4251,7 +4333,7 @@ index 716f121..2ed9c26 100644 || defined(__riscv) diff --git a/include/grub/efi/dhcp.h b/include/grub/efi/dhcp.h new file mode 100644 -index 0000000..fdb88eb +index 00000000000..fdb88eb810e --- /dev/null +++ b/include/grub/efi/dhcp.h @@ -0,0 +1,343 @@ @@ -4600,7 +4682,7 @@ index 0000000..fdb88eb +#endif /* ! GRUB_EFI_DHCP_HEADER */ diff --git a/include/grub/efi/http.h b/include/grub/efi/http.h new file mode 100644 -index 0000000..c5e9a89 +index 00000000000..c5e9a89f505 --- /dev/null +++ b/include/grub/efi/http.h @@ -0,0 +1,215 @@ @@ -4821,7 +4903,7 @@ index 0000000..c5e9a89 +#endif /* !GRUB_EFI_HTTP_HEADER */ diff --git a/include/grub/net/efi.h b/include/grub/net/efi.h new file mode 100644 -index 0000000..de90d22 +index 00000000000..de90d223e8e --- /dev/null +++ b/include/grub/net/efi.h @@ -0,0 +1,144 @@ @@ -4969,88 +5051,3 @@ index 0000000..de90d22 +extern grub_command_func_t grub_efi_net_bootp6; + +#endif /* ! GRUB_NET_EFI_HEADER */ -diff --git a/util/grub-mknetdir.c b/util/grub-mknetdir.c -index 602574d..1a61e05 100644 ---- a/util/grub-mknetdir.c -+++ b/util/grub-mknetdir.c -@@ -32,13 +32,15 @@ - - static char *rootdir = NULL, *subdir = NULL; - static char *debug_image = NULL; -+static char efi_netfs = 0; - - enum - { - OPTION_NET_DIRECTORY = 0x301, - OPTION_SUBDIR, - OPTION_DEBUG, -- OPTION_DEBUG_IMAGE -+ OPTION_DEBUG_IMAGE, -+ OPTION_DEBUG_EFI_NETFS - }; - - static struct argp_option options[] = { -@@ -49,6 +51,7 @@ static struct argp_option options[] = { - 0, N_("relative subdirectory on network server"), 2}, - {"debug", OPTION_DEBUG, 0, OPTION_HIDDEN, 0, 2}, - {"debug-image", OPTION_DEBUG_IMAGE, N_("STRING"), OPTION_HIDDEN, 0, 2}, -+ {"debug-efi-netfs", OPTION_DEBUG_EFI_NETFS, 0, OPTION_HIDDEN, 0, 2}, - {0, 0, 0, 0, 0, 0} - }; - -@@ -67,6 +70,9 @@ argp_parser (int key, char *arg, struct argp_state *state) - free (subdir); - subdir = xstrdup (arg); - return 0; -+ case OPTION_DEBUG_EFI_NETFS: -+ efi_netfs = 1; -+ return 0; - /* This is an undocumented feature... */ - case OPTION_DEBUG: - verbosity++; -@@ -82,7 +88,6 @@ argp_parser (int key, char *arg, struct argp_state *state) - } - } - -- - struct argp argp = { - options, argp_parser, NULL, - "\v"N_("Prepares GRUB network boot images at net_directory/subdir " -@@ -92,7 +97,7 @@ struct argp argp = { - - static char *base; - --static const struct -+static struct - { - const char *mkimage_target; - const char *netmodule; -@@ -156,6 +161,7 @@ process_input_dir (const char *input_dir, enum grub_install_plat platform) - grub_install_push_module (targets[platform].netmodule); - - output = grub_util_path_concat_ext (2, grubdir, "core", targets[platform].ext); -+ - grub_install_make_image_wrap (input_dir, prefix, output, - 0, load_cfg, - targets[platform].mkimage_target, 0); -@@ -192,7 +198,16 @@ main (int argc, char *argv[]) - - grub_install_mkdir_p (base); - -- grub_install_push_module ("tftp"); -+ if (!efi_netfs) -+ { -+ grub_install_push_module ("tftp"); -+ grub_install_push_module ("http"); -+ } -+ else -+ { -+ targets[GRUB_INSTALL_PLATFORM_I386_EFI].netmodule = "efi_netfs"; -+ targets[GRUB_INSTALL_PLATFORM_X86_64_EFI].netmodule = "efi_netfs"; -+ } - - if (!grub_install_source_directory) - { --- -1.8.3.1 - diff --git a/0120-AUDIT-0-http-boot-tracker-bug.patch b/0083-AUDIT-0-http-boot-tracker-bug.patch similarity index 90% rename from 0120-AUDIT-0-http-boot-tracker-bug.patch rename to 0083-AUDIT-0-http-boot-tracker-bug.patch index 1bc19bcca6b1287dd69079e70cd4598151373deb..ef3e67b7f3ae4483fccfcd9707bee1f794b9c013 100644 --- a/0120-AUDIT-0-http-boot-tracker-bug.patch +++ b/0083-AUDIT-0-http-boot-tracker-bug.patch @@ -1,7 +1,7 @@ -From c5fa5fa521644d4f41ba0f436826d0b0345645b2 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Sebastian Krahmer Date: Tue, 28 Nov 2017 17:24:38 +0800 -Subject: [PATCH 120/220] AUDIT-0: http boot tracker bug +Subject: [PATCH] AUDIT-0: http boot tracker bug Fixing a memory leak in case of error, and a integer overflow, leading to a heap overflow due to overly large chunk sizes. @@ -22,7 +22,7 @@ Signed-off-by: Michael Chang 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c -index 86bce65..4bb3080 100644 +index 86bce6535d3..4bb308026ce 100644 --- a/grub-core/net/efi/net.c +++ b/grub-core/net/efi/net.c @@ -645,8 +645,10 @@ grub_efihttp_chunk_read (grub_file_t file, char *buf, @@ -38,7 +38,7 @@ index 86bce65..4bb3080 100644 if (buf) { diff --git a/grub-core/net/http.c b/grub-core/net/http.c -index 00737c5..c9c5969 100644 +index 12a2632ea55..b52b558d631 100644 --- a/grub-core/net/http.c +++ b/grub-core/net/http.c @@ -31,7 +31,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); @@ -60,6 +60,3 @@ index 00737c5..c9c5969 100644 grub_errno = GRUB_ERR_NONE; if (data->chunk_rem == 0) { --- -1.8.3.1 - diff --git a/0128-grub-editenv-Add-incr-command-to-increment-integer-v.patch b/0084-grub-editenv-Add-incr-command-to-increment-integer-v.patch similarity index 89% rename from 0128-grub-editenv-Add-incr-command-to-increment-integer-v.patch rename to 0084-grub-editenv-Add-incr-command-to-increment-integer-v.patch index 7d1d531488add286b2d5db212761915410203611..f8de42a3d0c810726fc5888c41b7ba01b9849c46 100644 --- a/0128-grub-editenv-Add-incr-command-to-increment-integer-v.patch +++ b/0084-grub-editenv-Add-incr-command-to-increment-integer-v.patch @@ -1,8 +1,8 @@ -From 379558c0a9affaef66eea173f58952e2848b654c Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Mon, 4 Jun 2018 19:49:47 +0200 -Subject: [PATCH 128/220] grub-editenv: Add "incr" command to increment integer - value env. variables +Subject: [PATCH] grub-editenv: Add "incr" command to increment integer value + env. variables To be able to automatically detect if the last boot was successful, We want to keep count of succesful / failed boots in some integer @@ -17,7 +17,7 @@ Signed-off-by: Hans de Goede 1 file changed, 50 insertions(+) diff --git a/util/grub-editenv.c b/util/grub-editenv.c -index f3662c9..d848038 100644 +index db6f187cc63..948eec8a114 100644 --- a/util/grub-editenv.c +++ b/util/grub-editenv.c @@ -53,6 +53,9 @@ static struct argp_option options[] = { @@ -30,7 +30,7 @@ index f3662c9..d848038 100644 {0, 0, 0, OPTION_DOC, N_("Options:"), -1}, {"verbose", 'v', 0, 0, N_("print verbose messages."), 0}, -@@ -247,6 +250,51 @@ unset_variables (const char *name, int argc, char *argv[]) +@@ -253,6 +256,51 @@ unset_variables (const char *name, int argc, char *argv[]) grub_envblk_close (envblk); } @@ -82,7 +82,7 @@ index f3662c9..d848038 100644 int main (int argc, char *argv[]) { -@@ -286,6 +334,8 @@ main (int argc, char *argv[]) +@@ -292,6 +340,8 @@ main (int argc, char *argv[]) set_variables (filename, argc - curindex, argv + curindex); else if (strcmp (command, "unset") == 0) unset_variables (filename, argc - curindex, argv + curindex); @@ -91,6 +91,3 @@ index f3662c9..d848038 100644 else { char *program = xstrdup(program_name); --- -1.8.3.1 - diff --git a/0129-Add-auto-hide-menu-support.patch b/0085-Add-auto-hide-menu-support.patch similarity index 90% rename from 0129-Add-auto-hide-menu-support.patch rename to 0085-Add-auto-hide-menu-support.patch index 83ea2232963a109d7d8c7c2b421922932134659f..863cd053e0e69e31971e9e7dd55cd3ce6e64cd5a 100644 --- a/0129-Add-auto-hide-menu-support.patch +++ b/0085-Add-auto-hide-menu-support.patch @@ -1,7 +1,7 @@ -From 07f39734261c2c98ed3e0486558de362e7294d1f Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Wed, 6 Jun 2018 08:44:11 +0200 -Subject: [PATCH 129/220] Add auto-hide menu support +Subject: [PATCH] Add auto-hide menu support On single-os systems we do not want to show the menu, unless something went wrong with the previous boot, in which case the user may need the @@ -35,6 +35,12 @@ fastboot If set to "1" and the conditions for auto-hiding the menu https://git.launchpad.net/~ubuntu-core-dev/grub/+git/ubuntu/tree/debian/patches/quick_boot.patch Signed-off-by: Hans de Goede +--- +Changes in v2: +-Drop shutdown_success tests, there is no meaningful way for systemd to set + this flag (by the time it knows all filesystems are unmounted or read-only +-Drop fwsetup_once support, systemd already supports booting directly into + the fwsetup by doing "systemctl reboot --firmware" --- Makefile.util.def | 6 +++++ util/grub.d/01_menu_auto_hide.in | 48 ++++++++++++++++++++++++++++++++++++++++ @@ -43,25 +49,25 @@ Signed-off-by: Hans de Goede create mode 100644 util/grub.d/01_menu_auto_hide.in diff --git a/Makefile.util.def b/Makefile.util.def -index c13ca68..026b458 100644 +index 48512bc6311..314e6f2acf8 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -458,6 +458,12 @@ script = { + installdir = grubconf; }; - script = { ++script = { + name = '01_menu_auto_hide'; + common = util/grub.d/01_menu_auto_hide.in; + installdir = grubconf; +}; + -+script = { + script = { name = '01_users'; common = util/grub.d/01_users.in; - installdir = grubconf; diff --git a/util/grub.d/01_menu_auto_hide.in b/util/grub.d/01_menu_auto_hide.in new file mode 100644 -index 0000000..ad17587 +index 00000000000..ad175870a54 --- /dev/null +++ b/util/grub.d/01_menu_auto_hide.in @@ -0,0 +1,48 @@ @@ -114,7 +120,7 @@ index 0000000..ad17587 +fi +EOF diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in -index 13a3a6b..ab63439 100644 +index 4b27bd20153..3c9431cfcfb 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -42,6 +42,7 @@ if [ -z "${OSPROBED}" ] ; then @@ -149,7 +155,7 @@ index 13a3a6b..ab63439 100644 onstr="$(gettext_printf "(on %s)" "${DEVICE}")" recovery_params="$(echo "${LPARAMS}" | grep single)" || true counter=1 -@@ -249,6 +253,7 @@ EOF +@@ -257,6 +261,7 @@ EOF done ;; hurd) @@ -157,7 +163,7 @@ index 13a3a6b..ab63439 100644 onstr="$(gettext_printf "(on %s)" "${DEVICE}")" cat << EOF menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class hurd --class gnu --class os \$menuentry_id_option 'osprober-gnuhurd-/boot/gnumach.gz-false-$(grub_get_device_id "${DEVICE}")' { -@@ -275,6 +280,7 @@ EOF +@@ -283,6 +288,7 @@ EOF EOF ;; minix) @@ -165,8 +171,8 @@ index 13a3a6b..ab63439 100644 cat << EOF menuentry "${LONGNAME} (on ${DEVICE}, Multiboot)" { EOF -@@ -306,3 +312,15 @@ EOF - esac +@@ -299,3 +305,15 @@ EOF + ;; esac done + @@ -181,6 +187,3 @@ index 13a3a6b..ab63439 100644 +fi +EOF +fi --- -1.8.3.1 - diff --git a/0085-Don-t-use-dynamic-sized-arrays-since-we-don-t-build-.patch b/0085-Don-t-use-dynamic-sized-arrays-since-we-don-t-build-.patch deleted file mode 100644 index d57c5c378cf9ce7595ef90d9c9ace84f9733672e..0000000000000000000000000000000000000000 --- a/0085-Don-t-use-dynamic-sized-arrays-since-we-don-t-build-.patch +++ /dev/null @@ -1,46 +0,0 @@ -From a7fba153297429ab5124366aba482a462c239a3e Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 26 Jun 2017 12:42:57 -0400 -Subject: [PATCH 085/220] Don't use dynamic sized arrays since we don't build - with -std=c99 - ---- - grub-core/net/net.c | 17 ++++++++++++++--- - 1 file changed, 14 insertions(+), 3 deletions(-) - -diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index f24f1fd..5366e44 100644 ---- a/grub-core/net/net.c -+++ b/grub-core/net/net.c -@@ -1853,14 +1853,25 @@ grub_net_search_configfile (char *config) - { - /* By the Client UUID. */ - -- char client_uuid_var[sizeof ("net_") + grub_strlen (inf->name) + -- sizeof ("_clientuuid") + 1]; -- grub_snprintf (client_uuid_var, sizeof (client_uuid_var), -+ char *client_uuid_var; -+ grub_size_t client_uuid_var_size; -+ -+ client_uuid_var_size = grub_snprintf (NULL, 0, -+ "net_%s_clientuuid", inf->name); -+ if (client_uuid_var_size <= 0) -+ continue; -+ client_uuid_var_size += 1; -+ client_uuid_var = grub_malloc(client_uuid_var_size); -+ if (!client_uuid_var) -+ continue; -+ grub_snprintf (client_uuid_var, client_uuid_var_size, - "net_%s_clientuuid", inf->name); - - const char *client_uuid; - client_uuid = grub_env_get (client_uuid_var); - -+ grub_free(client_uuid_var); -+ - if (client_uuid) - { - grub_strcpy (suffix, client_uuid); --- -1.8.3.1 - diff --git a/0131-Add-grub-set-bootflag-utility.patch b/0086-Add-grub-set-bootflag-utility.patch similarity index 92% rename from 0131-Add-grub-set-bootflag-utility.patch rename to 0086-Add-grub-set-bootflag-utility.patch index af4acd2dba2792e5af322a720412c088e2f4dbb3..e39f8bebb496a3315ab10090c10ecf7b3339fac0 100644 --- a/0131-Add-grub-set-bootflag-utility.patch +++ b/0086-Add-grub-set-bootflag-utility.patch @@ -1,7 +1,7 @@ -From 07c1dfb9df01d3be4bbb9219fbe8a25b5d7dc0d9 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 12 Jun 2018 13:25:16 +0200 -Subject: [PATCH 131/220] Add grub-set-bootflag utility +Subject: [PATCH] Add grub-set-bootflag utility This commit adds a new grub-set-bootflag utility, which can be used to set known bootflags in the grubenv: boot_success or menu_show_once. @@ -31,24 +31,27 @@ and a symlink to grub-boot-success.timer should be added to /lib/systemd/user/timers.target.wants. Signed-off-by: Hans de Goede +[makhomed: grub-boot-success.timer: Only run if not in a container] +Signed-off-by: Gena Makhomed +Signed-off-by: Robbie Harwood --- Makefile.util.def | 7 ++ + util/grub-set-bootflag.c | 160 +++++++++++++++++++++++++++++++++++++++++ conf/Makefile.extra-dist | 3 + docs/grub-boot-success.service | 6 ++ - docs/grub-boot-success.timer | 6 ++ + docs/grub-boot-success.timer | 7 ++ util/grub-set-bootflag.1 | 20 ++++++ - util/grub-set-bootflag.c | 160 +++++++++++++++++++++++++++++++++++++++++ - 6 files changed, 202 insertions(+) + 6 files changed, 203 insertions(+) + create mode 100644 util/grub-set-bootflag.c create mode 100644 docs/grub-boot-success.service create mode 100644 docs/grub-boot-success.timer create mode 100644 util/grub-set-bootflag.1 - create mode 100644 util/grub-set-bootflag.c diff --git a/Makefile.util.def b/Makefile.util.def -index 89a9da1..125ad62 100644 +index 314e6f2acf8..0b85a7fce4a 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -1451,3 +1451,10 @@ program = { +@@ -1446,3 +1446,10 @@ program = { ldadd = grub-core/lib/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -59,73 +62,9 @@ index 89a9da1..125ad62 100644 + mansection = 1; + common = util/grub-set-bootflag.c; +}; -diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist -index 58d7d95..375b1bf 100644 ---- a/conf/Makefile.extra-dist -+++ b/conf/Makefile.extra-dist -@@ -14,6 +14,9 @@ EXTRA_DIST += util/import_unicode.py - EXTRA_DIST += docs/autoiso.cfg - EXTRA_DIST += docs/grub.cfg - EXTRA_DIST += docs/osdetect.cfg -+EXTRA_DIST += docs/org.gnu.grub.policy -+EXTRA_DIST += docs/grub-boot-success.service -+EXTRA_DIST += docs/grub-boot-success.timer - - EXTRA_DIST += conf/i386-cygwin-img-ld.sc - -diff --git a/docs/grub-boot-success.service b/docs/grub-boot-success.service -new file mode 100644 -index 0000000..80e7958 ---- /dev/null -+++ b/docs/grub-boot-success.service -@@ -0,0 +1,6 @@ -+[Unit] -+Description=Mark boot as successful -+ -+[Service] -+Type=oneshot -+ExecStart=/usr/sbin/grub2-set-bootflag boot_success -diff --git a/docs/grub-boot-success.timer b/docs/grub-boot-success.timer -new file mode 100644 -index 0000000..5d8fcba ---- /dev/null -+++ b/docs/grub-boot-success.timer -@@ -0,0 +1,6 @@ -+[Unit] -+Description=Mark boot as successful after the user session has run 2 minutes -+ConditionUser=!@system -+ -+[Timer] -+OnActiveSec=2min -diff --git a/util/grub-set-bootflag.1 b/util/grub-set-bootflag.1 -new file mode 100644 -index 0000000..57801da ---- /dev/null -+++ b/util/grub-set-bootflag.1 -@@ -0,0 +1,20 @@ -+.TH GRUB-SET-BOOTFLAG 1 "Tue Jun 12 2018" -+.SH NAME -+\fBgrub-set-bootflag\fR \(em Set a bootflag in the GRUB environment block. -+ -+.SH SYNOPSIS -+\fBgrub-set-bootflag\fR <\fIBOOTFLAG\fR> -+ -+.SH DESCRIPTION -+\fBgrub-set-bootflag\fR is a command line to set bootflags in GRUB's -+stored environment. -+ -+.SH COMMANDS -+.TP -+\fBBOOTFLAG\fR -+.RS 7 -+Bootflag to set, one of \fIboot_success\fR or \fIshow_menu_once\fR. -+.RE -+ -+.SH SEE ALSO -+.BR "info grub" diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c new file mode 100644 -index 0000000..bb198f0 +index 00000000000..bb198f02351 --- /dev/null +++ b/util/grub-set-bootflag.c @@ -0,0 +1,160 @@ @@ -289,6 +228,68 @@ index 0000000..bb198f0 + + return 0; +} --- -1.8.3.1 - +diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist +index b909f2c073a..ea58362b555 100644 +--- a/conf/Makefile.extra-dist ++++ b/conf/Makefile.extra-dist +@@ -14,6 +14,9 @@ EXTRA_DIST += util/import_unicode.py + EXTRA_DIST += docs/autoiso.cfg + EXTRA_DIST += docs/grub.cfg + EXTRA_DIST += docs/osdetect.cfg ++EXTRA_DIST += docs/org.gnu.grub.policy ++EXTRA_DIST += docs/grub-boot-success.service ++EXTRA_DIST += docs/grub-boot-success.timer + + EXTRA_DIST += conf/i386-cygwin-img-ld.sc + +diff --git a/docs/grub-boot-success.service b/docs/grub-boot-success.service +new file mode 100644 +index 00000000000..80e79584c91 +--- /dev/null ++++ b/docs/grub-boot-success.service +@@ -0,0 +1,6 @@ ++[Unit] ++Description=Mark boot as successful ++ ++[Service] ++Type=oneshot ++ExecStart=/usr/sbin/grub2-set-bootflag boot_success +diff --git a/docs/grub-boot-success.timer b/docs/grub-boot-success.timer +new file mode 100644 +index 00000000000..406f1720056 +--- /dev/null ++++ b/docs/grub-boot-success.timer +@@ -0,0 +1,7 @@ ++[Unit] ++Description=Mark boot as successful after the user session has run 2 minutes ++ConditionUser=!@system ++ConditionVirtualization=!container ++ ++[Timer] ++OnActiveSec=2min +diff --git a/util/grub-set-bootflag.1 b/util/grub-set-bootflag.1 +new file mode 100644 +index 00000000000..57801da22a0 +--- /dev/null ++++ b/util/grub-set-bootflag.1 +@@ -0,0 +1,20 @@ ++.TH GRUB-SET-BOOTFLAG 1 "Tue Jun 12 2018" ++.SH NAME ++\fBgrub-set-bootflag\fR \(em Set a bootflag in the GRUB environment block. ++ ++.SH SYNOPSIS ++\fBgrub-set-bootflag\fR <\fIBOOTFLAG\fR> ++ ++.SH DESCRIPTION ++\fBgrub-set-bootflag\fR is a command line to set bootflags in GRUB's ++stored environment. ++ ++.SH COMMANDS ++.TP ++\fBBOOTFLAG\fR ++.RS 7 ++Bootflag to set, one of \fIboot_success\fR or \fIshow_menu_once\fR. ++.RE ++ ++.SH SEE ALSO ++.BR "info grub" diff --git a/0086-don-t-ignore-const.patch b/0086-don-t-ignore-const.patch deleted file mode 100644 index c84fba85def44b52063e2fe971f4fbb8990f5586..0000000000000000000000000000000000000000 --- a/0086-don-t-ignore-const.patch +++ /dev/null @@ -1,25 +0,0 @@ -From f35f4b17be40199adb6df155f208da0a33ea95e9 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 26 Jun 2017 12:43:22 -0400 -Subject: [PATCH 086/220] don't ignore const - ---- - grub-core/net/tftp.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c -index dcd8249..f900713 100644 ---- a/grub-core/net/tftp.c -+++ b/grub-core/net/tftp.c -@@ -307,7 +307,7 @@ static void - grub_normalize_filename (char *normalized, const char *filename) - { - char *dest = normalized; -- char *src = filename; -+ const char *src = filename; - - while (*src != '\0') - { --- -1.8.3.1 - diff --git a/0132-docs-Add-grub-boot-indeterminate.service-example.patch b/0087-docs-Add-grub-boot-indeterminate.service-example.patch similarity index 83% rename from 0132-docs-Add-grub-boot-indeterminate.service-example.patch rename to 0087-docs-Add-grub-boot-indeterminate.service-example.patch index 029366414996aa0d652386567e6b42c2b67cdcd7..44f6ad3984b8dd0c9ab108d395e1a68934a831a2 100644 --- a/0132-docs-Add-grub-boot-indeterminate.service-example.patch +++ b/0087-docs-Add-grub-boot-indeterminate.service-example.patch @@ -1,7 +1,7 @@ -From 600518039d5a46d1098d28da0e352a4f92dbc145 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 19 Jun 2018 15:20:54 +0200 -Subject: [PATCH 132/220] docs: Add grub-boot-indeterminate.service example +Subject: [PATCH] docs: Add grub-boot-indeterminate.service example This is an example service file, for use from /lib/systemd/system/system-update.target.wants @@ -16,7 +16,7 @@ Signed-off-by: Hans de Goede diff --git a/docs/grub-boot-indeterminate.service b/docs/grub-boot-indeterminate.service new file mode 100644 -index 0000000..6c8dcb1 +index 00000000000..6c8dcb186b6 --- /dev/null +++ b/docs/grub-boot-indeterminate.service @@ -0,0 +1,11 @@ @@ -31,6 +31,3 @@ index 0000000..6c8dcb1 +[Service] +Type=oneshot +ExecStart=/usr/bin/grub2-editenv - incr boot_indeterminate --- -1.8.3.1 - diff --git a/0133-gentpl-add-disable-support.patch b/0088-gentpl-add-disable-support.patch similarity index 89% rename from 0133-gentpl-add-disable-support.patch rename to 0088-gentpl-add-disable-support.patch index 3f12f5fb0ba4e0c33363ab47f3ccb814b4532c3f..2c3c998f505c768ce1538d996323e754fc34a932 100644 --- a/0133-gentpl-add-disable-support.patch +++ b/0088-gentpl-add-disable-support.patch @@ -1,7 +1,7 @@ -From 5b8e719389524825b88322555030188309d88ba6 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 11 Jul 2018 13:43:15 -0400 -Subject: [PATCH 133/220] gentpl: add 'disable = ' support +Subject: [PATCH] gentpl: add 'disable = ' support Signed-off-by: Peter Jones --- @@ -9,7 +9,7 @@ Signed-off-by: Peter Jones 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gentpl.py b/gentpl.py -index f05812e..3a0c049 100644 +index 2cba0bbbd6f..628e8bec1d7 100644 --- a/gentpl.py +++ b/gentpl.py @@ -592,11 +592,21 @@ def platform_conditional(platform, closure): @@ -44,6 +44,3 @@ index f05812e..3a0c049 100644 for suffix in [ "", "_nodist" ]: template = platform_values(defn, GRUB_PLATFORMS[0], suffix) for platform in GRUB_PLATFORMS[1:]: --- -1.8.3.1 - diff --git a/0089-editenv-handle-relative-symlinks.patch b/0089-editenv-handle-relative-symlinks.patch deleted file mode 100644 index e0ccccc9447ec1b6dfca894178afd5aa658bc8d9..0000000000000000000000000000000000000000 --- a/0089-editenv-handle-relative-symlinks.patch +++ /dev/null @@ -1,53 +0,0 @@ -From aa5c3b11994dc7b3856d7f4a3671029eb7056c66 Mon Sep 17 00:00:00 2001 -From: Jonathan Lebon -Date: Mon, 14 Aug 2017 14:37:20 -0400 -Subject: [PATCH 089/220] editenv: handle relative symlinks - -Handle symlinks with targets relative to the containing dir. This -ensures that the rename operation does not depend on the cwd. - -Resolves: rhbz#1479960 - -Signed-off-by: Jonathan Lebon ---- - util/editenv.c | 16 ++++++++++++++-- - 1 file changed, 14 insertions(+), 2 deletions(-) - -diff --git a/util/editenv.c b/util/editenv.c -index e61dc12..1f7f6f3 100644 ---- a/util/editenv.c -+++ b/util/editenv.c -@@ -28,6 +28,7 @@ - - #include - #include -+#include - - #define DEFAULT_ENVBLK_SIZE 1024 - -@@ -88,9 +89,20 @@ grub_util_create_envblk_file (const char *name) - continue; - } - -- free (rename_target); - linkbuf[retsize] = '\0'; -- rename_target = linkbuf; -+ if (linkbuf[0] == '/') -+ { -+ free (rename_target); -+ rename_target = linkbuf; -+ } -+ else -+ { -+ char *dbuf = xstrdup (rename_target); -+ const char *dir = dirname (dbuf); -+ free (rename_target); -+ rename_target = xasprintf("%s/%s", dir, linkbuf); -+ free (dbuf); -+ } - } - - int rc = grub_util_rename (namenew, rename_target); --- -1.8.3.1 - diff --git a/0134-gentpl-add-pc-firmware-type.patch b/0089-gentpl-add-pc-firmware-type.patch similarity index 78% rename from 0134-gentpl-add-pc-firmware-type.patch rename to 0089-gentpl-add-pc-firmware-type.patch index 9b5a74256f9a868868f13fc7179ca301fc8ca865..96dd2b8c623287deebd1198ec49d19395f66099f 100644 --- a/0134-gentpl-add-pc-firmware-type.patch +++ b/0089-gentpl-add-pc-firmware-type.patch @@ -1,7 +1,7 @@ -From f763ca059bb527b66e2b7194e7f0bb7b6d47ccb9 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 11 Jul 2019 11:04:24 +0200 -Subject: [PATCH 134/220] gentpl: add 'pc' firmware type +Subject: [PATCH] gentpl: add 'pc' firmware type Signed-off-by: Peter Jones --- @@ -9,7 +9,7 @@ Signed-off-by: Peter Jones 1 file changed, 1 insertion(+) diff --git a/gentpl.py b/gentpl.py -index 3a0c049..1d9dda4 100644 +index 628e8bec1d7..34a4eba2b42 100644 --- a/gentpl.py +++ b/gentpl.py @@ -51,6 +51,7 @@ GROUPS["riscv32"] = [ "riscv32_efi" ] @@ -20,6 +20,3 @@ index 3a0c049..1d9dda4 100644 GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi", "riscv32_efi", "riscv64_efi" ] GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ] --- -1.8.3.1 - diff --git a/0090-Make-libgrub.pp-depend-on-config-util.h.patch b/0090-Make-libgrub.pp-depend-on-config-util.h.patch deleted file mode 100644 index 58bb475f1737c2b6c07853c04d44cd519b51d802..0000000000000000000000000000000000000000 --- a/0090-Make-libgrub.pp-depend-on-config-util.h.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 6cac349f34599ab50c3c548c1832d502ae1c17d6 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 23 Aug 2017 10:37:27 -0400 -Subject: [PATCH 090/220] Make libgrub.pp depend on config-util.h - -If you build with "make -j48" a lot, sometimes you see: - -gcc -E -DHAVE_CONFIG_H -I. -I.. -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub_script.tab.h\" -I. -I.. -I. -I.. -I../include -I./include -I../grub-core/lib/libgcrypt-grub/src/ -I../grub-core/lib/minilzo -I../grub-core/lib/xzembed -DMINILZO_HAVE_CONFIG_H -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub_script.tab.h\" -I. -I.. -I. -I.. -I../include -I./include -I../grub-core/lib/libgcrypt-grub/src/ -I./grub-core/gnulib -I../grub-core/gnulib -I/builddir/build/BUILD/grub-2.02/grub-aarch64-efi-2.02 -D_FILE_OFFSET_BITS=64 \ - -D'GRUB_MOD_INIT(x)=@MARKER@x@' grub_script.tab.h grub_script.yy.h ../grub-core/commands/blocklist.c ../grub-core/commands/macbless.c ../grub-core/commands/xnu_uuid.c ../grub-core/commands/testload.c ../grub-core/commands/ls.c ../grub-core/disk/dmraid_nvidia.c ../grub-core/disk/loopback.c ../grub-core/disk/lvm.c ../grub-core/disk/mdraid_linux.c ../grub-core/disk/mdraid_linux_be.c ../grub-core/disk/mdraid1x_linux.c ../grub-core/disk/raid5_recover.c ../grub-core/disk/raid6_recover.c ../grub-core/font/font.c ../grub-core/gfxmenu/font.c ../grub-core/normal/charset.c ../grub-core/video/fb/fbblit.c ../grub-core/video/fb/fbutil.c ../grub-core/video/fb/fbfill.c ../grub-core/video/fb/video_fb.c ../grub-core/video/video.c ../grub-core/video/capture.c ../grub-core/video/colors.c ../grub-core/unidata.c ../grub-core/io/bufio.c ../grub-core/fs/affs.c ../grub-core/fs/afs.c ../grub-core/fs/bfs.c ../grub-core/fs/btrfs.c ../grub-core/fs/cbfs.c ../grub-core/fs/cpio.c ../grub-core/fs/cpio_be.c ../grub-core/fs/odc.c ../grub-core/fs/newc.c ../grub-core/fs/ext2.c ../grub-core/fs/fat.c ../grub-core/fs/exfat.c ../grub-core/fs/fshelp.c ../grub-core/fs/hfs.c ../grub-core/fs/hfsplus.c ../grub-core/fs/hfspluscomp.c ../grub-core/fs/iso9660.c ../grub-core/fs/jfs.c ../grub-core/fs/minix.c ../grub-core/fs/minix2.c ../grub-core/fs/minix3.c ../grub-core/fs/minix_be.c ../grub-core/fs/minix2_be.c ../grub-core/fs/minix3_be.c ../grub-core/fs/nilfs2.c ../grub-core/fs/ntfs.c ../grub-core/fs/ntfscomp.c ../grub-core/fs/reiserfs.c ../grub-core/fs/romfs.c ../grub-core/fs/sfs.c ../grub-core/fs/squash4.c ../grub-core/fs/tar.c ../grub-core/fs/udf.c ../grub-core/fs/ufs2.c ../grub-core/fs/ufs.c ../grub-core/fs/ufs_be.c ../grub-core/fs/xfs.c ../grub-core/fs/zfs/zfscrypt.c ../grub-core/fs/zfs/zfs.c ../grub-core/fs/zfs/zfsinfo.c ../grub-core/fs/zfs/zfs_lzjb.c ../grub-core/fs/zfs/zfs_lz4.c ../grub-core/fs/zfs/zfs_sha256.c ../grub-core/fs/zfs/zfs_fletcher.c ../grub-core/lib/envblk.c ../grub-core/lib/hexdump.c ../grub-core/lib/LzFind.c ../grub-core/lib/LzmaEnc.c ../grub-core/lib/crc.c ../grub-core/lib/adler32.c ../grub-core/lib/crc64.c ../grub-core/normal/datetime.c ../grub-core/normal/misc.c ../grub-core/partmap/acorn.c ../grub-core/partmap/amiga.c ../grub-core/partmap/apple.c ../grub-core/partmap/sun.c ../grub-core/partmap/plan.c ../grub-core/partmap/dvh.c ../grub-core/partmap/sunpc.c ../grub-core/partmap/bsdlabel.c ../grub-core/partmap/dfly.c ../grub-core/script/function.c ../grub-core/script/lexer.c ../grub-core/script/main.c ../grub-core/script/script.c ../grub-core/script/argv.c ../grub-core/io/gzio.c ../grub-core/io/xzio.c ../grub-core/io/lzopio.c ../grub-core/kern/ia64/dl_helper.c ../grub-core/kern/arm/dl_helper.c ../grub-core/kern/arm64/dl_helper.c ../grub-core/lib/minilzo/minilzo.c ../grub-core/lib/xzembed/xz_dec_bcj.c ../grub-core/lib/xzembed/xz_dec_lzma2.c ../grub-core/lib/xzembed/xz_dec_stream.c ../util/misc.c ../grub-core/kern/command.c ../grub-core/kern/device.c ../grub-core/kern/disk.c ../grub-core/lib/disk.c ../util/getroot.c ../grub-core/osdep/unix/getroot.c ../grub-core/osdep/getroot.c ../grub-core/osdep/devmapper/getroot.c ../grub-core/osdep/relpath.c ../grub-core/kern/emu/hostdisk.c ../grub-core/osdep/devmapper/hostdisk.c ../grub-core/osdep/hostdisk.c ../grub-core/osdep/unix/hostdisk.c ../grub-core/osdep/exec.c ../grub-core/osdep/sleep.c ../grub-core/osdep/password.c ../grub-core/kern/emu/misc.c ../grub-core/kern/emu/mm.c ../grub-core/kern/env.c ../grub-core/kern/err.c ../grub-core/kern/file.c ../grub-core/kern/fs.c ../grub-core/kern/list.c ../grub-core/kern/misc.c ../grub-core/kern/partition.c ../grub-core/lib/crypto.c ../grub-core/disk/luks.c ../grub-core/disk/geli.c ../grub-core/disk/cryptodisk.c ../grub-core/disk/AFSplitter.c ../grub-core/lib/pbkdf2.c ../grub-core/commands/extcmd.c ../grub-core/lib/arg.c ../grub-core/disk/ldm.c ../grub-core/disk/diskfilter.c ../grub-core/partmap/gpt.c ../grub-core/partmap/msdos.c ../grub-core/fs/proc.c ../grub-core/fs/archelp.c > libgrub.pp || (rm -f libgrub.pp; exit 1) -rm -f stamp-h1 -touch ../config-util.h.in -cd . && /bin/sh ./config.status config-util.h -config.status: creating config-util.h -In file included from ../include/grub/mm.h:25:0, - from ../include/grub/disk.h:29, - from ../include/grub/file.h:26, - from ../grub-core/fs/btrfs.c:21: -./config.h:38:10: fatal error: ./config-util.h: No such file or directory - #include - ^~~~~~~~~~~~~~~ -compilation terminated. -make: *** [Makefile:13098: libgrub.pp] Error 1 - -This is because libgrub.pp is built with -DGRUB_UTIL=1, which means -it'll try to include config-util.h, but a parallel make is actually -building that file. I think. - -Signed-off-by: Peter Jones ---- - Makefile.am | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/Makefile.am b/Makefile.am -index 1f4bb9b..bf9c1ba 100644 ---- a/Makefile.am -+++ b/Makefile.am -@@ -37,7 +37,7 @@ grub_script.yy.c: grub_script.yy.h - CLEANFILES += grub_script.yy.c grub_script.yy.h - - # For libgrub.a --libgrub.pp: grub_script.tab.h grub_script.yy.h $(libgrubmods_a_SOURCES) $(libgrubkern_a_SOURCES) -+libgrub.pp: config-util.h grub_script.tab.h grub_script.yy.h $(libgrubmods_a_SOURCES) $(libgrubkern_a_SOURCES) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgrubmods_a_CPPFLAGS) $(libgrubkern_a_CPPFLAGS) $(CPPFLAGS) \ - -D'GRUB_MOD_INIT(x)=@MARKER@x@' $^ > $@ || (rm -f $@; exit 1) - CLEANFILES += libgrub.pp --- -1.8.3.1 - diff --git a/0135-efinet-also-use-the-firmware-acceleration-for-http.patch b/0090-efinet-also-use-the-firmware-acceleration-for-http.patch similarity index 83% rename from 0135-efinet-also-use-the-firmware-acceleration-for-http.patch rename to 0090-efinet-also-use-the-firmware-acceleration-for-http.patch index 2132bd90ea553bcf642fe3c2ed97613d8f002b48..915b5aa161164b5725011f539c6b1bd942ca79ad 100644 --- a/0135-efinet-also-use-the-firmware-acceleration-for-http.patch +++ b/0090-efinet-also-use-the-firmware-acceleration-for-http.patch @@ -1,7 +1,7 @@ -From 4b0d5c577825b4b9e4f0fc768ea57cfb941e6c45 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 30 Jul 2018 14:06:42 -0400 -Subject: [PATCH 135/220] efinet: also use the firmware acceleration for http +Subject: [PATCH] efinet: also use the firmware acceleration for http Signed-off-by: Peter Jones --- @@ -9,7 +9,7 @@ Signed-off-by: Peter Jones 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c -index 4bb3080..6603cd8 100644 +index 4bb308026ce..6603cd83edc 100644 --- a/grub-core/net/efi/net.c +++ b/grub-core/net/efi/net.c @@ -1324,7 +1324,9 @@ grub_efi_net_boot_from_https (void) @@ -23,6 +23,3 @@ index 4bb3080..6603cd8 100644 } if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp)) --- -1.8.3.1 - diff --git a/0136-efi-http-Make-root_url-reflect-the-protocol-hostname.patch b/0091-efi-http-Make-root_url-reflect-the-protocol-hostname.patch similarity index 87% rename from 0136-efi-http-Make-root_url-reflect-the-protocol-hostname.patch rename to 0091-efi-http-Make-root_url-reflect-the-protocol-hostname.patch index 43bfc60d84313f5254a59058d909703e52b4df2e..985a037828bde8390cc4d84d0b395a133fcc0338 100644 --- a/0136-efi-http-Make-root_url-reflect-the-protocol-hostname.patch +++ b/0091-efi-http-Make-root_url-reflect-the-protocol-hostname.patch @@ -1,8 +1,8 @@ -From f1173dcc353427122e640347a35df802fabd020f Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 30 Jul 2018 16:39:57 -0400 -Subject: [PATCH 136/220] efi/http: Make root_url reflect the protocol+hostname - of our boot url. +Subject: [PATCH] efi/http: Make root_url reflect the protocol+hostname of our + boot url. This lets you write config files that don't know urls. @@ -12,7 +12,7 @@ Signed-off-by: Peter Jones 1 file changed, 19 insertions(+) diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c -index 3f61fd2..243acba 100644 +index 3f61fd2fa5b..243acbaa35b 100644 --- a/grub-core/net/efi/http.c +++ b/grub-core/net/efi/http.c @@ -4,6 +4,7 @@ @@ -48,6 +48,3 @@ index 3f61fd2..243acba 100644 err = efihttp_request (dev->http, file->device->net->server, file->device->net->name, type, 1, 0); if (err != GRUB_ERR_NONE) --- -1.8.3.1 - diff --git a/0137-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch b/0092-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch similarity index 93% rename from 0137-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch rename to 0092-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch index 287dbe74ca280e9ff2f811cefb865926e6f33271..ee2216e514ec1d9db12487219790a04bf0f06ca8 100644 --- a/0137-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch +++ b/0092-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch @@ -1,8 +1,8 @@ -From 2ed3f5abf24ef7b6802aba64ecf2e3bf415f2f67 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 26 Jun 2018 17:16:06 -0400 -Subject: [PATCH 137/220] Make it so we can tell configure which cflags utils - are built with +Subject: [PATCH] Make it so we can tell configure which cflags utils are built + with This lets us have kernel.img be built with TARGET_CFLAGS but grub-mkimage and friends built with HOST_CFLAGS. That in turn lets us build with an ARM compiler @@ -11,57 +11,16 @@ float for grub.efi. Signed-off-by: Peter Jones --- - conf/Makefile.common | 23 ++++++++++++----------- configure.ac | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- + conf/Makefile.common | 23 ++++++++++++----------- gentpl.py | 8 ++++---- 3 files changed, 64 insertions(+), 16 deletions(-) -diff --git a/conf/Makefile.common b/conf/Makefile.common -index 5e8ba2a..bbf33b0 100644 ---- a/conf/Makefile.common -+++ b/conf/Makefile.common -@@ -40,24 +40,25 @@ CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1 - CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) - STRIPFLAGS_KERNEL = -R .eh_frame -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx -R .note.gnu.property -R .gnu.build.attributes - --CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding --LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d --CPPFLAGS_MODULE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) --CCASFLAGS_MODULE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) -+CFLAGS_MODULE = $(TARGET_CFLAGS) $(CFLAGS_PLATFORM) -ffreestanding -+LDFLAGS_MODULE = $(TARGET_LDFLAGS) $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d -+CPPFLAGS_MODULE = $(TARGET_CPPFLAGS) $(CPPFLAGS_DEFAULT) $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -+CCASFLAGS_MODULE = $(TARGET_CCASFLAGS) $(CCASFLAGS_DEFAULT) $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) - - CFLAGS_IMAGE = $(CFLAGS_PLATFORM) -fno-builtin - LDFLAGS_IMAGE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-S - CPPFLAGS_IMAGE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) - CCASFLAGS_IMAGE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) - --CFLAGS_PROGRAM = --LDFLAGS_PROGRAM = --CPPFLAGS_PROGRAM = --CCASFLAGS_PROGRAM = -+CFLAGS_PROGRAM = $(UTILS_CFLAGS) -+LDFLAGS_PROGRAM = $(UTILS_LDFLAGS) -+CPPFLAGS_PROGRAM = $(UTILS_CPPFLAGS) -+CCASFLAGS_PROGRAM = $(UTILS_CCASFLAGS) - --CFLAGS_LIBRARY = --CPPFLAGS_LIBRARY = --CCASFLAGS_LIBRARY = -+CFLAGS_LIBRARY = $(UTILS_CFLAGS) -+LDFLAGS_LIBRARY = $(UTILS_LDFLAGS) -+CPPFLAGS_LIBRARY = $(UTILS_CPPFLAGS) -+CCASFLAGS_LIBRARY = $(UTILS_CCASFLAGS) - - # Other variables - diff --git a/configure.ac b/configure.ac -index 8ee18ba..cf32748 100644 +index b50fb2e9897..b27573b3de5 100644 --- a/configure.ac +++ b/configure.ac -@@ -868,11 +868,23 @@ if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ) && test "x$p +@@ -877,11 +877,23 @@ if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ) && test "x$p TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow" fi @@ -86,7 +45,7 @@ index 8ee18ba..cf32748 100644 AC_CACHE_CHECK([for options to get soft-float], grub_cv_target_cc_soft_float, [ grub_cv_target_cc_soft_float=no if test "x$target_cpu" = xarm64; then -@@ -1951,6 +1963,41 @@ HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include" +@@ -2011,6 +2023,41 @@ HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include" TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_srcdir)/include" TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_builddir)/include" @@ -128,8 +87,49 @@ index 8ee18ba..cf32748 100644 GRUB_TARGET_CPU="${target_cpu}" GRUB_PLATFORM="${platform}" +diff --git a/conf/Makefile.common b/conf/Makefile.common +index 5f0ef969857..2ff9b39357c 100644 +--- a/conf/Makefile.common ++++ b/conf/Makefile.common +@@ -40,24 +40,25 @@ CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1 + CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) + STRIPFLAGS_KERNEL = -R .eh_frame -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx -R .note.gnu.property -R .gnu.build.attributes + +-CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding +-LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d +-CPPFLAGS_MODULE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) +-CCASFLAGS_MODULE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) ++CFLAGS_MODULE = $(TARGET_CFLAGS) $(CFLAGS_PLATFORM) -ffreestanding ++LDFLAGS_MODULE = $(TARGET_LDFLAGS) $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d ++CPPFLAGS_MODULE = $(TARGET_CPPFLAGS) $(CPPFLAGS_DEFAULT) $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) ++CCASFLAGS_MODULE = $(TARGET_CCASFLAGS) $(CCASFLAGS_DEFAULT) $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) + + CFLAGS_IMAGE = $(CFLAGS_PLATFORM) -fno-builtin + LDFLAGS_IMAGE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-S + CPPFLAGS_IMAGE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) + CCASFLAGS_IMAGE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) + +-CFLAGS_PROGRAM = +-LDFLAGS_PROGRAM = +-CPPFLAGS_PROGRAM = +-CCASFLAGS_PROGRAM = ++CFLAGS_PROGRAM = $(UTILS_CFLAGS) ++LDFLAGS_PROGRAM = $(UTILS_LDFLAGS) ++CPPFLAGS_PROGRAM = $(UTILS_CPPFLAGS) ++CCASFLAGS_PROGRAM = $(UTILS_CCASFLAGS) + +-CFLAGS_LIBRARY = +-CPPFLAGS_LIBRARY = +-CCASFLAGS_LIBRARY = ++CFLAGS_LIBRARY = $(UTILS_CFLAGS) ++LDFLAGS_LIBRARY = $(UTILS_LDFLAGS) ++CPPFLAGS_LIBRARY = $(UTILS_CPPFLAGS) ++CCASFLAGS_LIBRARY = $(UTILS_CCASFLAGS) + + # Other variables + diff --git a/gentpl.py b/gentpl.py -index 1d9dda4..95fe1a2 100644 +index 34a4eba2b42..59f62ef9522 100644 --- a/gentpl.py +++ b/gentpl.py @@ -697,10 +697,10 @@ def module(defn, platform): @@ -147,6 +147,3 @@ index 1d9dda4..95fe1a2 100644 var_set(cname(defn) + "_DEPENDENCIES", "$(TARGET_OBJ2ELF) " + platform_dependencies(defn, platform)) gvar_add("dist_noinst_DATA", extra_dist(defn)) --- -1.8.3.1 - diff --git a/0138-module-verifier-make-it-possible-to-run-checkers-on-.patch b/0093-module-verifier-make-it-possible-to-run-checkers-on-.patch similarity index 87% rename from 0138-module-verifier-make-it-possible-to-run-checkers-on-.patch rename to 0093-module-verifier-make-it-possible-to-run-checkers-on-.patch index 0d6301e94f511393549b6a38c51c88f505a7476a..e31b38f6c86e7b8b693b9beaefa31c7d9080a08a 100644 --- a/0138-module-verifier-make-it-possible-to-run-checkers-on-.patch +++ b/0093-module-verifier-make-it-possible-to-run-checkers-on-.patch @@ -1,7 +1,7 @@ -From cf80fb1ad8e247a4d56a9740d489bb85c447a3ca Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 1 Aug 2018 10:24:52 -0400 -Subject: [PATCH 138/220] module-verifier: make it possible to run checkers on +Subject: [PATCH] module-verifier: make it possible to run checkers on grub-module-verifierxx.c This makes it so you can treat grub-module-verifierxx.c as a file you can @@ -22,7 +22,7 @@ Signed-off-by: Peter Jones 3 files changed, 13 insertions(+) diff --git a/util/grub-module-verifier32.c b/util/grub-module-verifier32.c -index 257229f..ba7d41a 100644 +index 257229f8f08..ba7d41aafea 100644 --- a/util/grub-module-verifier32.c +++ b/util/grub-module-verifier32.c @@ -1,2 +1,4 @@ @@ -31,7 +31,7 @@ index 257229f..ba7d41a 100644 #include "grub-module-verifierXX.c" +#endif diff --git a/util/grub-module-verifier64.c b/util/grub-module-verifier64.c -index 4db6b4b..fc23ef8 100644 +index 4db6b4bedd1..fc23ef800b3 100644 --- a/util/grub-module-verifier64.c +++ b/util/grub-module-verifier64.c @@ -1,2 +1,4 @@ @@ -40,7 +40,7 @@ index 4db6b4b..fc23ef8 100644 #include "grub-module-verifierXX.c" +#endif diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c -index ceb2430..a98e2f9 100644 +index ceb24309aec..a98e2f9b1ac 100644 --- a/util/grub-module-verifierXX.c +++ b/util/grub-module-verifierXX.c @@ -1,3 +1,12 @@ @@ -56,6 +56,3 @@ index ceb2430..a98e2f9 100644 #include #include --- -1.8.3.1 - diff --git a/0139-Rework-how-the-fdt-command-builds.patch b/0094-Rework-how-the-fdt-command-builds.patch similarity index 73% rename from 0139-Rework-how-the-fdt-command-builds.patch rename to 0094-Rework-how-the-fdt-command-builds.patch index 1c42474927e59677775082dd7c5e64facc2ecc9c..e233067a3eaab09e616270c71a73d812a4c16c86 100644 --- a/0139-Rework-how-the-fdt-command-builds.patch +++ b/0094-Rework-how-the-fdt-command-builds.patch @@ -1,7 +1,7 @@ -From 849085d266f998cdcf6191194b12fdf5b52a38bd Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 11 Jul 2019 13:01:41 +0200 -Subject: [PATCH 139/220] Rework how the fdt command builds. +Subject: [PATCH] Rework how the fdt command builds. Trying to avoid all variants of: cat syminfo.lst | sort | gawk -f ../../grub-core/genmoddep.awk > moddep.lst || (rm -f moddep.lst; exit 1) @@ -13,31 +13,22 @@ grub_fdt_load in xen_boot is not defined grub_fdt_unload in xen_boot is not defined Signed-off-by: Peter Jones +[javierm: Fix build with platform emu, aarch64, and risc-v] +Signed-off-by: Javier Martinez Canillas +Signed-off-by: Robbie Harwood --- - grub-core/Makefile.am | 1 + grub-core/Makefile.core.def | 5 ++--- grub-core/lib/fdt.c | 2 -- grub-core/loader/efi/fdt.c | 2 ++ - include/grub/fdt.h | 4 ++++ - 5 files changed, 9 insertions(+), 5 deletions(-) + include/grub/fdt.h | 6 ++++++ + grub-core/Makefile.am | 1 + + 5 files changed, 11 insertions(+), 5 deletions(-) -diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am -index d9ad300..ee9c4e4 100644 ---- a/grub-core/Makefile.am -+++ b/grub-core/Makefile.am -@@ -76,6 +76,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/sb.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env_private.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/err.h -+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdt.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/file.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fs.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i18n.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 48491b5..556adca 100644 +index c40170f2dd2..84a3d89de9a 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -175,7 +175,6 @@ kernel = { +@@ -177,7 +177,6 @@ kernel = { arm_coreboot = kern/arm/coreboot/init.c; arm_coreboot = kern/arm/coreboot/timer.c; arm_coreboot = kern/arm/coreboot/coreboot.S; @@ -45,7 +36,7 @@ index 48491b5..556adca 100644 arm_coreboot = bus/fdt.c; arm_coreboot = term/ps2.c; arm_coreboot = term/arm/pl050.c; -@@ -348,6 +347,8 @@ kernel = { +@@ -351,6 +350,8 @@ kernel = { riscv64 = kern/riscv/cache_flush.S; riscv64 = kern/riscv/dl.c; @@ -54,7 +45,7 @@ index 48491b5..556adca 100644 emu = disk/host.c; emu = kern/emu/cache_s.S; emu = kern/emu/hostdisk.c; -@@ -1801,7 +1802,6 @@ module = { +@@ -1825,7 +1826,6 @@ module = { riscv32 = loader/riscv/linux.c; riscv64 = loader/riscv/linux.c; emu = loader/emu/linux.c; @@ -62,7 +53,7 @@ index 48491b5..556adca 100644 common = loader/linux.c; common = lib/cmdline.c; -@@ -1812,7 +1812,6 @@ module = { +@@ -1836,7 +1836,6 @@ module = { module = { name = fdt; efi = loader/efi/fdt.c; @@ -71,7 +62,7 @@ index 48491b5..556adca 100644 }; diff --git a/grub-core/lib/fdt.c b/grub-core/lib/fdt.c -index 0d371c5..37e04bd 100644 +index 0d371c5633e..37e04bd69e7 100644 --- a/grub-core/lib/fdt.c +++ b/grub-core/lib/fdt.c @@ -21,8 +21,6 @@ @@ -84,12 +75,12 @@ index 0d371c5..37e04bd 100644 #define FDT_BEGIN_NODE 0x00000001 diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c -index ee9c559..37ca407 100644 +index c86f283d756..c572415d38a 100644 --- a/grub-core/loader/efi/fdt.c +++ b/grub-core/loader/efi/fdt.c -@@ -26,6 +26,8 @@ - #include +@@ -27,6 +27,8 @@ #include + #include +GRUB_MOD_LICENSE ("GPLv3+"); + @@ -97,25 +88,36 @@ index ee9c559..37ca407 100644 static void *fdt; diff --git a/include/grub/fdt.h b/include/grub/fdt.h -index e609c7e..22b7c54 100644 +index e609c7e4111..3514aa4a5b6 100644 --- a/include/grub/fdt.h +++ b/include/grub/fdt.h -@@ -19,6 +19,8 @@ +@@ -19,6 +19,9 @@ #ifndef GRUB_FDT_HEADER #define GRUB_FDT_HEADER 1 -+#if defined(__arm__) || defined(__aarch64__) ++#if !defined(GRUB_MACHINE_EMU) && \ ++ (defined(__arm__) || defined(__aarch64__) || defined(__riscv)) + #include #include -@@ -144,4 +146,6 @@ int EXPORT_FUNC(grub_fdt_set_prop) (void *fdt, unsigned int nodeoffset, const ch +@@ -144,4 +147,7 @@ int EXPORT_FUNC(grub_fdt_set_prop) (void *fdt, unsigned int nodeoffset, const ch grub_fdt_set_prop ((fdt), (nodeoffset), "reg", reg_64, 16); \ }) -+#endif /* defined(__arm__) || defined(__aarch64__) */ ++#endif /* !defined(GRUB_MACHINE_EMU) && \ ++ (defined(__arm__) || defined(__aarch64__) || defined(__riscv)) */ + #endif /* ! GRUB_FDT_HEADER */ --- -1.8.3.1 - +diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am +index f512573c0da..dd49939aaa9 100644 +--- a/grub-core/Makefile.am ++++ b/grub-core/Makefile.am +@@ -76,6 +76,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/sb.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env_private.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/err.h ++KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdt.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/file.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fs.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i18n.h diff --git a/0140-Disable-non-wordsize-allocations-on-arm.patch b/0095-Disable-non-wordsize-allocations-on-arm.patch similarity index 84% rename from 0140-Disable-non-wordsize-allocations-on-arm.patch rename to 0095-Disable-non-wordsize-allocations-on-arm.patch index 6722d9c2a4310970c9375e91297d76c6a5d50279..e28041a1a38cc308d3533b787691e43746acdba2 100644 --- a/0140-Disable-non-wordsize-allocations-on-arm.patch +++ b/0095-Disable-non-wordsize-allocations-on-arm.patch @@ -1,7 +1,7 @@ -From 454da6e71b93313ce7bc1067ea173ffb709a64bb Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 2 Aug 2018 10:56:38 -0400 -Subject: [PATCH 140/220] Disable non-wordsize allocations on arm +Subject: [PATCH] Disable non-wordsize allocations on arm Signed-off-by: Peter Jones --- @@ -9,10 +9,10 @@ Signed-off-by: Peter Jones 1 file changed, 20 insertions(+) diff --git a/configure.ac b/configure.ac -index cf32748..9b0946c 100644 +index b27573b3de5..bb4e05ceef3 100644 --- a/configure.ac +++ b/configure.ac -@@ -1262,6 +1262,26 @@ if test "x$target_cpu" = xarm; then +@@ -1288,6 +1288,26 @@ if test "x$target_cpu" = xarm; then done ]) @@ -39,6 +39,3 @@ index cf32748..9b0946c 100644 if test x"$grub_cv_target_cc_mno_movt" != xno ; then # A trick so that clang doesn't see it on link stage TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_mno_movt" --- -1.8.3.1 - diff --git a/0142-Prepend-prefix-when-HTTP-path-is-relative.patch b/0096-Prepend-prefix-when-HTTP-path-is-relative.patch similarity index 90% rename from 0142-Prepend-prefix-when-HTTP-path-is-relative.patch rename to 0096-Prepend-prefix-when-HTTP-path-is-relative.patch index 3c086afd2602c0c92703a259901618a0bf0d83d7..d3e599d1a691e995b007c21e03eea4205037d11e 100644 --- a/0142-Prepend-prefix-when-HTTP-path-is-relative.patch +++ b/0096-Prepend-prefix-when-HTTP-path-is-relative.patch @@ -1,23 +1,25 @@ -From d8321112ee226889aeeedff6c83a7c0f49151cc9 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Stephen Benjamin Date: Thu, 16 Aug 2018 16:58:51 -0400 -Subject: [PATCH 142/220] Prepend prefix when HTTP path is relative +Subject: [PATCH] Prepend prefix when HTTP path is relative This sets a couple of variables. With the url http://www.example.com/foo/bar : http_path: /foo/bar http_url: http://www.example.com/foo/bar Signed-off-by: Peter Jones +Signed-off-by: Stephen Benjamin +Signed-off-by: Robbie Harwood --- grub-core/kern/main.c | 10 +++++- - grub-core/net/efi/http.c | 84 ++++++++++++++++++++++++++++++++++++------------ - 2 files changed, 72 insertions(+), 22 deletions(-) + grub-core/net/efi/http.c | 82 ++++++++++++++++++++++++++++++++++++------------ + 2 files changed, 71 insertions(+), 21 deletions(-) diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c -index da47b18..dcf4872 100644 +index d1de9fa6873..1c540fc8c26 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c -@@ -130,11 +130,19 @@ grub_set_prefix_and_root (void) +@@ -131,11 +131,19 @@ grub_set_prefix_and_root (void) if (fwdevice && fwpath) { char *fw_path; @@ -39,7 +41,7 @@ index da47b18..dcf4872 100644 } } diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c -index 243acba..de351b2 100644 +index 243acbaa35b..de351b2cd03 100644 --- a/grub-core/net/efi/http.c +++ b/grub-core/net/efi/http.c @@ -9,10 +9,52 @@ @@ -102,7 +104,9 @@ index 243acba..de351b2 100644 - char *root_url; - grub_efi_ipv6_address_t address; - const char *rest; -- ++ char *file_name = NULL; ++ const char *http_path; + - if (grub_efi_string_to_ip6_address (file->device->net->server, &address, &rest) && *rest == 0) - root_url = grub_xasprintf ("%s://[%s]", type ? "https" : "http", file->device->net->server); - else @@ -115,9 +119,6 @@ index 243acba..de351b2 100644 - } - else - { -+ char *file_name = NULL; -+ const char *http_path; -+ + /* If path is relative, prepend http_path */ + http_path = grub_env_get ("http_path"); + if (http_path && file->device->net->name[0] != '/') { @@ -149,6 +150,3 @@ index 243acba..de351b2 100644 buf = grub_malloc (size); efihttp_read (dev, buf, size); --- -1.8.3.1 - diff --git a/0144-Make-grub_error-more-verbose.patch b/0097-Make-grub_error-more-verbose.patch similarity index 47% rename from 0144-Make-grub_error-more-verbose.patch rename to 0097-Make-grub_error-more-verbose.patch index f2ed9536bea94d2a81a6129f70bd1a11cbdf9ede..2492e9f689c7c4c1dff34193317668148eba9d79 100644 --- a/0144-Make-grub_error-more-verbose.patch +++ b/0097-Make-grub_error-more-verbose.patch @@ -1,56 +1,16 @@ -From c1576dc60b66fc5219e99d8b6c817287c5f5ec4b Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 27 Aug 2018 13:14:06 -0400 -Subject: [PATCH 144/220] Make grub_error() more verbose +Subject: [PATCH] Make grub_error() more verbose Signed-off-by: Peter Jones --- - grub-core/kern/efi/mm.c | 17 ++++++++++++++--- - grub-core/kern/err.c | 13 +++++++++++-- - include/grub/err.h | 5 ++++- - 3 files changed, 29 insertions(+), 6 deletions(-) + grub-core/kern/err.c | 13 +++++++++++-- + include/grub/err.h | 8 ++++++-- + 2 files changed, 17 insertions(+), 4 deletions(-) -diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c -index a9e3710..15595a4 100644 ---- a/grub-core/kern/efi/mm.c -+++ b/grub-core/kern/efi/mm.c -@@ -157,12 +157,20 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, - - /* Limit the memory access to less than 4GB for 32-bit platforms. */ - if (address > GRUB_EFI_MAX_USABLE_ADDRESS) -- return 0; -+ { -+ grub_error (GRUB_ERR_BAD_ARGUMENT, -+ N_("invalid memory address (0x%llx > 0x%llx)"), -+ address, GRUB_EFI_MAX_USABLE_ADDRESS); -+ return NULL; -+ } - - b = grub_efi_system_table->boot_services; - status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address); - if (status != GRUB_EFI_SUCCESS) -- return 0; -+ { -+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); -+ return NULL; -+ } - - if (address == 0) - { -@@ -172,7 +180,10 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, - status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address); - grub_efi_free_pages (0, pages); - if (status != GRUB_EFI_SUCCESS) -- return 0; -+ { -+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); -+ return NULL; -+ } - } - - grub_efi_store_alloc (address, pages); diff --git a/grub-core/kern/err.c b/grub-core/kern/err.c -index 53c734d..aebfe0c 100644 +index 53c734de70e..aebfe0cf839 100644 --- a/grub-core/kern/err.c +++ b/grub-core/kern/err.c @@ -33,15 +33,24 @@ static struct grub_error_saved grub_error_stack_items[GRUB_ERROR_STACK_SIZE]; @@ -81,21 +41,21 @@ index 53c734d..aebfe0c 100644 return n; diff --git a/include/grub/err.h b/include/grub/err.h -index 24ba9f5..b68bbec 100644 +index b08d5d0de4c..c0f90ef07c8 100644 --- a/include/grub/err.h +++ b/include/grub/err.h -@@ -85,7 +85,10 @@ struct grub_error_saved +@@ -85,8 +85,12 @@ struct grub_error_saved extern grub_err_t EXPORT_VAR(grub_errno); extern char EXPORT_VAR(grub_errmsg)[GRUB_MAX_ERRMSG]; --grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *fmt, ...); -+grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *file, const int line, const char *fmt, ...); +-grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *fmt, ...) +- __attribute__ ((format (GNU_PRINTF, 2, 3))); ++grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *file, const int line, const char *fmt, ...) ++ __attribute__ ((format (GNU_PRINTF, 4, 5))); + +#define grub_error(n, fmt, ...) grub_error (n, __FILE__, __LINE__, fmt, ##__VA_ARGS__) ++ + void EXPORT_FUNC(grub_fatal) (const char *fmt, ...) __attribute__ ((noreturn)); void EXPORT_FUNC(grub_error_push) (void); int EXPORT_FUNC(grub_error_pop) (void); --- -1.8.3.1 - diff --git a/0145-Make-reset-an-alias-for-the-reboot-command.patch b/0098-Make-reset-an-alias-for-the-reboot-command.patch similarity index 86% rename from 0145-Make-reset-an-alias-for-the-reboot-command.patch rename to 0098-Make-reset-an-alias-for-the-reboot-command.patch index 6af5d06871aa017bc2cf7c9d2a23d45dd3b78aa5..c86acf18a627bd3725b89d2a816648fa252dead9 100644 --- a/0145-Make-reset-an-alias-for-the-reboot-command.patch +++ b/0098-Make-reset-an-alias-for-the-reboot-command.patch @@ -1,7 +1,7 @@ -From 0ad7fa987ac696ec412e3247e548a1e05e269537 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Fri, 31 Aug 2018 16:42:03 -0400 -Subject: [PATCH 145/220] Make "reset" an alias for the "reboot" command. +Subject: [PATCH] Make "reset" an alias for the "reboot" command. I'm really tired of half the tools I get to use having one and the other half having the other. @@ -12,7 +12,7 @@ Signed-off-by: Peter Jones 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/grub-core/commands/reboot.c b/grub-core/commands/reboot.c -index 46d364c..f5cc228 100644 +index 46d364c99a9..f5cc2283636 100644 --- a/grub-core/commands/reboot.c +++ b/grub-core/commands/reboot.c @@ -32,15 +32,18 @@ grub_cmd_reboot (grub_command_t cmd __attribute__ ((unused)), @@ -38,6 +38,3 @@ index 46d364c..f5cc228 100644 + grub_unregister_command (reboot_cmd); + grub_unregister_command (reset_cmd); } --- -1.8.3.1 - diff --git a/0147-Add-a-version-command.patch b/0099-Add-a-version-command.patch similarity index 91% rename from 0147-Add-a-version-command.patch rename to 0099-Add-a-version-command.patch index 2b4ec61f88152089af9498833e6ddcd2fee11a2d..bf3b4b80794aefacc18b53d758c3943b605ae3bc 100644 --- a/0147-Add-a-version-command.patch +++ b/0099-Add-a-version-command.patch @@ -1,7 +1,7 @@ -From 568f0094df7aeef7ec558142139c7e93a4d019f3 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 11 Sep 2018 14:20:37 -0400 -Subject: [PATCH 147/220] Add a "version" command. +Subject: [PATCH] Add a "version" command. This adds a command that shows you info about grub's version, the grub target platform, the compiler version, and if you built with @@ -9,30 +9,18 @@ platform, the compiler version, and if you built with Signed-off-by: Peter Jones --- - config.h.in | 1 + configure.ac | 13 ++++++++++ grub-core/Makefile.core.def | 5 ++++ grub-core/commands/version.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ + config.h.in | 1 + 4 files changed, 75 insertions(+) create mode 100644 grub-core/commands/version.c -diff --git a/config.h.in b/config.h.in -index 9e8f991..c7e316f 100644 ---- a/config.h.in -+++ b/config.h.in -@@ -59,6 +59,7 @@ - - #define GRUB_TARGET_CPU "@GRUB_TARGET_CPU@" - #define GRUB_PLATFORM "@GRUB_PLATFORM@" -+#define GRUB_RPM_VERSION "@GRUB_RPM_VERSION@" - - #define RE_ENABLE_I18N 1 - diff --git a/configure.ac b/configure.ac -index 9b0946c..bca7c28 100644 +index bb4e05ceef3..59ccda24475 100644 --- a/configure.ac +++ b/configure.ac -@@ -303,6 +303,19 @@ AC_SUBST(target_cpu) +@@ -312,6 +312,19 @@ AC_SUBST(target_cpu) AC_SUBST(platform) # Define default variables @@ -53,24 +41,24 @@ index 9b0946c..bca7c28 100644 have_with_bootdir=n AC_ARG_WITH([bootdir], diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 556adca..8bb1daf 100644 +index 84a3d89de9a..498ca11762a 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -577,6 +577,11 @@ image = { +@@ -579,6 +579,11 @@ image = { + enable = mips_loongson; }; - module = { ++module = { + name = version; + common = commands/version.c; +}; + -+module = { + module = { name = disk; common = lib/disk.c; - extra_dist = kern/disk_common.c; diff --git a/grub-core/commands/version.c b/grub-core/commands/version.c new file mode 100644 -index 0000000..f0966a5 +index 00000000000..f0966a518f7 --- /dev/null +++ b/grub-core/commands/version.c @@ -0,0 +1,56 @@ @@ -130,6 +118,15 @@ index 0000000..f0966a5 +{ + grub_unregister_command (cmd); +} --- -1.8.3.1 - +diff --git a/config.h.in b/config.h.in +index 9e8f9911b18..c7e316f0f1f 100644 +--- a/config.h.in ++++ b/config.h.in +@@ -59,6 +59,7 @@ + + #define GRUB_TARGET_CPU "@GRUB_TARGET_CPU@" + #define GRUB_PLATFORM "@GRUB_PLATFORM@" ++#define GRUB_RPM_VERSION "@GRUB_RPM_VERSION@" + + #define RE_ENABLE_I18N 1 + diff --git a/0148-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch b/0100-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch similarity index 83% rename from 0148-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch rename to 0100-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch index 04d9b79e7a1870e6d0d47151342b4eebd2e394c9..9afb315163fc653edba049d5855c497803351e24 100644 --- a/0148-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch +++ b/0100-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch @@ -1,7 +1,7 @@ -From 088dae49c71c95b0c354afabad3263aca9a6d8bf Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 11 Sep 2018 15:58:29 -0400 -Subject: [PATCH 148/220] Add more dprintf, and nerf dprintf in script.c +Subject: [PATCH] Add more dprintf, and nerf dprintf in script.c Signed-off-by: Peter Jones --- @@ -12,7 +12,7 @@ Signed-off-by: Peter Jones 4 files changed, 10 insertions(+) diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c -index c3b578a..1a3eb6b 100644 +index 0320115662f..7cdffe3ebd5 100644 --- a/grub-core/disk/diskfilter.c +++ b/grub-core/disk/diskfilter.c @@ -188,6 +188,8 @@ scan_disk (const char *name, int accept_diskfilter) @@ -24,16 +24,16 @@ index c3b578a..1a3eb6b 100644 if (!accept_diskfilter && is_valid_diskfilter_name (name)) return 0; -@@ -1211,6 +1213,7 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id, +@@ -1212,6 +1214,7 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id, the same. */ - if (pv->disk && grub_disk_get_size (disk) >= pv->part_size) + if (pv->disk && grub_disk_native_sectors (disk) >= pv->part_size) return GRUB_ERR_NONE; + grub_dprintf ("diskfilter", "checking %s\n", disk->name); pv->disk = grub_disk_open (disk->name); if (!pv->disk) return grub_errno; diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c -index 9e20af7..54c227b 100644 +index f077b5f5535..fe8ba6e6c93 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -855,6 +855,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) @@ -45,7 +45,7 @@ index 9e20af7..54c227b 100644 grub_free (dup_dp); diff --git a/grub-core/kern/device.c b/grub-core/kern/device.c -index 73b8ecc..f58b58c 100644 +index 73b8ecc0c09..f58b58c89d5 100644 --- a/grub-core/kern/device.c +++ b/grub-core/kern/device.c @@ -34,6 +34,7 @@ grub_device_open (const char *name) @@ -57,7 +57,7 @@ index 73b8ecc..f58b58c 100644 { name = grub_env_get ("root"); diff --git a/grub-core/script/script.c b/grub-core/script/script.c -index ec4d433..844e834 100644 +index ec4d4337c66..844e8343ca7 100644 --- a/grub-core/script/script.c +++ b/grub-core/script/script.c @@ -22,6 +22,11 @@ @@ -72,6 +72,3 @@ index ec4d433..844e834 100644 /* It is not possible to deallocate the memory when a syntax error was found. Because of that it is required to keep track of all memory allocations. The memory is freed in case of an error, or assigned --- -1.8.3.1 - diff --git a/0149-arm-arm64-loader-Better-memory-allocation-and-error-.patch b/0101-arm-arm64-loader-Better-memory-allocation-and-error-.patch similarity index 88% rename from 0149-arm-arm64-loader-Better-memory-allocation-and-error-.patch rename to 0101-arm-arm64-loader-Better-memory-allocation-and-error-.patch index 740ea2e80fa9d2fb57b604ec20f3efad52fdeed0..1fdc552897eee214fbb25892f9ee82c97765d3d0 100644 --- a/0149-arm-arm64-loader-Better-memory-allocation-and-error-.patch +++ b/0101-arm-arm64-loader-Better-memory-allocation-and-error-.patch @@ -1,7 +1,7 @@ -From 5df842469c4b53ecabeaad3edca5f31355507cee Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 11 Jul 2019 14:38:57 +0200 -Subject: [PATCH 149/220] arm/arm64 loader: Better memory allocation and error +Subject: [PATCH] arm/arm64 loader: Better memory allocation and error messages. On mustang, our memory map looks like: @@ -66,12 +66,12 @@ per-platform constraints on its given address are maintained. Signed-off-by: Peter Jones --- - grub-core/kern/efi/mm.c | 33 +++++++++++++----- - grub-core/loader/arm64/linux.c | 78 ++++++++++++++++++++++++++++++++---------- - 2 files changed, 84 insertions(+), 27 deletions(-) + grub-core/kern/efi/mm.c | 33 +++++++++++++++----- + grub-core/loader/arm64/linux.c | 68 +++++++++++++++++++++++++++++++----------- + 2 files changed, 76 insertions(+), 25 deletions(-) diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c -index 15595a4..1b14fa0 100644 +index f6aef0ef649..85ad4b4494c 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -154,6 +154,7 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, @@ -82,7 +82,7 @@ index 15595a4..1b14fa0 100644 /* Limit the memory access to less than 4GB for 32-bit platforms. */ if (address > GRUB_EFI_MAX_USABLE_ADDRESS) -@@ -165,19 +166,22 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, +@@ -170,19 +171,22 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, } b = grub_efi_system_table->boot_services; @@ -109,7 +109,7 @@ index 15595a4..1b14fa0 100644 grub_efi_free_pages (0, pages); if (status != GRUB_EFI_SUCCESS) { -@@ -186,9 +190,9 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, +@@ -191,9 +195,9 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, } } @@ -121,7 +121,7 @@ index 15595a4..1b14fa0 100644 } void * -@@ -699,8 +703,21 @@ grub_efi_get_ram_base(grub_addr_t *base_addr) +@@ -713,8 +717,21 @@ grub_efi_get_ram_base(grub_addr_t *base_addr) for (desc = memory_map, *base_addr = GRUB_EFI_MAX_USABLE_ADDRESS; (grub_addr_t) desc < ((grub_addr_t) memory_map + memory_map_size); desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) @@ -146,10 +146,10 @@ index 15595a4..1b14fa0 100644 grub_free(memory_map); diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c -index 4c0a09c..8791b35 100644 +index 04994d5c67d..70a0075ec5e 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c -@@ -71,13 +71,15 @@ finalize_params_linux (void) +@@ -71,20 +71,25 @@ finalize_params_linux (void) { grub_efi_loaded_image_t *loaded_image = NULL; int node, retval, len; @@ -168,26 +168,7 @@ index 4c0a09c..8791b35 100644 node = grub_fdt_find_subnode (fdt, 0, "chosen"); if (node < 0) -@@ -88,17 +90,26 @@ finalize_params_linux (void) - */ - retval = grub_fdt_set_prop32(fdt, 0, "#address-cells", 2); - if (retval) -- goto failure; -+ { -+ err = grub_error(retval, "Could not find #address-cells"); -+ goto failure; -+ } - - retval = grub_fdt_set_prop32(fdt, 0, "#size-cells", 2); - if (retval) -- goto failure; -+ { -+ err = grub_error(retval, "Could not find #size-cells"); -+ goto failure; -+ } - - node = grub_fdt_add_subnode (fdt, 0, "chosen"); - } + node = grub_fdt_add_subnode (fdt, 0, "chosen"); if (node < 1) - goto failure; @@ -198,7 +179,7 @@ index 4c0a09c..8791b35 100644 /* Set initrd info */ if (initrd_start && initrd_end > initrd_start) -@@ -109,15 +120,26 @@ finalize_params_linux (void) +@@ -95,15 +100,26 @@ finalize_params_linux (void) retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-start", initrd_start); if (retval) @@ -229,7 +210,7 @@ index 4c0a09c..8791b35 100644 grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n", fdt); -@@ -125,14 +147,20 @@ finalize_params_linux (void) +@@ -111,14 +127,20 @@ finalize_params_linux (void) /* Convert command line to UCS-2 */ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); if (!loaded_image) @@ -252,7 +233,7 @@ index 4c0a09c..8791b35 100644 loaded_image->load_options_size = 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, -@@ -142,7 +170,7 @@ finalize_params_linux (void) +@@ -128,7 +150,7 @@ finalize_params_linux (void) failure: grub_fdt_unload(); @@ -261,7 +242,7 @@ index 4c0a09c..8791b35 100644 } static void -@@ -226,16 +254,28 @@ grub_linux_unload (void) +@@ -212,16 +234,28 @@ grub_linux_unload (void) static void * allocate_initrd_mem (int initrd_pages) { @@ -269,16 +250,16 @@ index 4c0a09c..8791b35 100644 + grub_addr_t max_addr = 0; + grub_err_t err; + void *ret; -+ + +- if (grub_efi_get_ram_base (&max_addr) != GRUB_ERR_NONE) +- return NULL; + err = grub_efi_get_ram_base (&max_addr); + if (err != GRUB_ERR_NONE) + { + grub_error (err, "grub_efi_get_ram_base() failed"); + return NULL; + } - -- if (grub_efi_get_ram_base (&max_addr) != GRUB_ERR_NONE) -- return NULL; ++ + grub_dprintf ("linux", "max_addr: 0x%016lx, INITRD_MAX_ADDRESS_OFFSET: 0x%016llx\n", + max_addr, INITRD_MAX_ADDRESS_OFFSET); @@ -296,6 +277,3 @@ index 4c0a09c..8791b35 100644 } static grub_err_t --- -1.8.3.1 - diff --git a/0150-Try-to-pick-better-locations-for-kernel-and-initrd.patch b/0102-Try-to-pick-better-locations-for-kernel-and-initrd.patch similarity index 85% rename from 0150-Try-to-pick-better-locations-for-kernel-and-initrd.patch rename to 0102-Try-to-pick-better-locations-for-kernel-and-initrd.patch index 138a525f3feaa7dcb78a4461977e49dcc4e86f59..06329b9cf31d76e1f7181ccf1462b3481ecb57b8 100644 --- a/0150-Try-to-pick-better-locations-for-kernel-and-initrd.patch +++ b/0102-Try-to-pick-better-locations-for-kernel-and-initrd.patch @@ -1,7 +1,7 @@ -From f3626af8bf79ed7498b723f46c54312b69a429b8 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 11 Jul 2019 17:17:02 +0200 -Subject: [PATCH 150/220] Try to pick better locations for kernel and initrd +Subject: [PATCH] Try to pick better locations for kernel and initrd - Don't limit allocations on 64-bit platforms to < 0x[37f]fffffff if we're using the "large" code model ; use __UINTPTR_MAX__. @@ -23,6 +23,9 @@ Additionally, we now try to locate kernel+initrd+cmdline+etc below we try a higher address. Signed-off-by: Peter Jones +[david.abdurachmanov: fix macro for riscv64] +Signed-off-by: David Abdurachmanov +Signed-off-by: Robbie Harwood --- grub-core/kern/efi/mm.c | 8 ++++---- grub-core/loader/i386/efi/linux.c | 24 +++++++++++++++++------- @@ -30,11 +33,12 @@ Signed-off-by: Peter Jones include/grub/arm64/efi/memory.h | 1 + include/grub/i386/efi/memory.h | 1 + include/grub/ia64/efi/memory.h | 1 + + include/grub/riscv64/efi/memory.h | 1 + include/grub/x86_64/efi/memory.h | 4 +++- - 7 files changed, 28 insertions(+), 12 deletions(-) + 8 files changed, 29 insertions(+), 12 deletions(-) diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c -index 1b14fa0..d70e5b4 100644 +index 85ad4b4494c..e84961d078c 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -122,7 +122,7 @@ grub_efi_allocate_pages_max (grub_efi_physical_address_t max, @@ -46,7 +50,7 @@ index 1b14fa0..d70e5b4 100644 return 0; b = grub_efi_system_table->boot_services; -@@ -466,7 +466,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, +@@ -480,7 +480,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, { if (desc->type == GRUB_EFI_CONVENTIONAL_MEMORY #if 1 @@ -55,7 +59,7 @@ index 1b14fa0..d70e5b4 100644 #endif && desc->physical_start + PAGES_TO_BYTES (desc->num_pages) > 0x100000 && desc->num_pages != 0) -@@ -484,9 +484,9 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, +@@ -498,9 +498,9 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, #if 1 if (BYTES_TO_PAGES (filtered_desc->physical_start) + filtered_desc->num_pages @@ -68,7 +72,7 @@ index 1b14fa0..d70e5b4 100644 #endif diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 3017d0f..33e981e 100644 +index 3017d0f3e52..33e981e76e7 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -27,6 +27,7 @@ @@ -134,7 +138,7 @@ index 3017d0f..33e981e 100644 { grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate kernel")); diff --git a/include/grub/arm/efi/memory.h b/include/grub/arm/efi/memory.h -index 2c64918..a4c2ec8 100644 +index 2c64918e3f7..a4c2ec83502 100644 --- a/include/grub/arm/efi/memory.h +++ b/include/grub/arm/efi/memory.h @@ -2,5 +2,6 @@ @@ -145,7 +149,7 @@ index 2c64918..a4c2ec8 100644 #endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/include/grub/arm64/efi/memory.h b/include/grub/arm64/efi/memory.h -index c6cb324..acb61dc 100644 +index c6cb3241714..acb61dca44b 100644 --- a/include/grub/arm64/efi/memory.h +++ b/include/grub/arm64/efi/memory.h @@ -2,5 +2,6 @@ @@ -156,7 +160,7 @@ index c6cb324..acb61dc 100644 #endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/include/grub/i386/efi/memory.h b/include/grub/i386/efi/memory.h -index 2c64918..a4c2ec8 100644 +index 2c64918e3f7..a4c2ec83502 100644 --- a/include/grub/i386/efi/memory.h +++ b/include/grub/i386/efi/memory.h @@ -2,5 +2,6 @@ @@ -167,7 +171,7 @@ index 2c64918..a4c2ec8 100644 #endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/include/grub/ia64/efi/memory.h b/include/grub/ia64/efi/memory.h -index 2c64918..a4c2ec8 100644 +index 2c64918e3f7..a4c2ec83502 100644 --- a/include/grub/ia64/efi/memory.h +++ b/include/grub/ia64/efi/memory.h @@ -2,5 +2,6 @@ @@ -176,9 +180,20 @@ index 2c64918..a4c2ec8 100644 #define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffff +#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS + #endif /* ! GRUB_MEMORY_CPU_HEADER */ +diff --git a/include/grub/riscv64/efi/memory.h b/include/grub/riscv64/efi/memory.h +index c6cb3241714..acb61dca44b 100644 +--- a/include/grub/riscv64/efi/memory.h ++++ b/include/grub/riscv64/efi/memory.h +@@ -2,5 +2,6 @@ + #include + + #define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL ++#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS + #endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/include/grub/x86_64/efi/memory.h b/include/grub/x86_64/efi/memory.h -index 46e9145..e81cfb3 100644 +index 46e9145a308..e81cfb32213 100644 --- a/include/grub/x86_64/efi/memory.h +++ b/include/grub/x86_64/efi/memory.h @@ -2,9 +2,11 @@ @@ -194,6 +209,3 @@ index 46e9145..e81cfb3 100644 #endif #endif /* ! GRUB_MEMORY_CPU_HEADER */ --- -1.8.3.1 - diff --git a/0151-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch b/0103-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch similarity index 89% rename from 0151-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch rename to 0103-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch index 7c2c13f7a8470c4a8cc25c28b7b00a83f504f308..c2f2a597732335b1508213b5e158343e8d70571c 100644 --- a/0151-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch +++ b/0103-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch @@ -1,13 +1,11 @@ -From 902fb795c21608b8dd34553fe3c915cd8866b0c6 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 11 Jul 2019 18:03:25 +0200 -Subject: [PATCH 151/220] Attempt to fix up all the places -Wsign-compare=error - finds. +Subject: [PATCH] Attempt to fix up all the places -Wsign-compare=error finds. Signed-off-by: Peter Jones --- grub-core/kern/emu/misc.c | 2 +- - .../gnulib-patches/fix-sign-compare-errors.patch | 161 +++++++++++++++++++++ grub-core/lib/reed_solomon.c | 4 +- grub-core/osdep/linux/blocklist.c | 2 +- grub-core/osdep/linux/getroot.c | 2 +- @@ -18,14 +16,16 @@ Signed-off-by: Peter Jones util/grub-probe.c | 2 +- util/grub-rpm-sort.c | 2 +- util/setup.c | 2 +- - 12 files changed, 179 insertions(+), 17 deletions(-) + bootstrap.conf | 3 +- + .../gnulib-patches/fix-sign-compare-errors.patch | 161 +++++++++++++++++++++ + 13 files changed, 181 insertions(+), 18 deletions(-) create mode 100644 grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c -index 245b69c..7a8d9e6 100644 +index eeea092752d..f08a1bb8415 100644 --- a/grub-core/kern/emu/misc.c +++ b/grub-core/kern/emu/misc.c -@@ -177,7 +177,7 @@ grub_util_get_image_size (const char *path) +@@ -189,7 +189,7 @@ grub_util_get_image_size (const char *path) sz = ftello (f); if (sz < 0) grub_util_error (_("cannot open `%s': %s"), path, strerror (errno)); @@ -34,187 +34,20 @@ index 245b69c..7a8d9e6 100644 grub_util_error (_("file `%s' is too big"), path); ret = (size_t) sz; -diff --git a/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch b/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch -new file mode 100644 -index 0000000..479029c ---- /dev/null -+++ b/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch -@@ -0,0 +1,161 @@ -+diff --git a/lib/regcomp.c b/lib/regcomp.c -+index cc85f35ac58..361079d82d6 100644 -+--- a/lib/regcomp.c -++++ b/lib/regcomp.c -+@@ -322,7 +322,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, -+ *p++ = dfa->nodes[node].opr.c; -+ memset (&state, '\0', sizeof (state)); -+ if (__mbrtowc (&wc, (const char *) buf, p - buf, -+- &state) == p - buf -++ &state) == (size_t)(p - buf) -+ && (__wcrtomb ((char *) buf, __towlower (wc), &state) -+ != (size_t) -1)) -+ re_set_fastmap (fastmap, false, buf[0]); -+@@ -3778,7 +3778,7 @@ fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax) -+ num = ((token->type != CHARACTER || c < '0' || '9' < c || num == -2) -+ ? -2 -+ : num == -1 -+- ? c - '0' -++ ? (Idx)(c - '0') -+ : MIN (RE_DUP_MAX + 1, num * 10 + c - '0')); -+ } -+ return num; -+diff --git a/lib/regex_internal.c b/lib/regex_internal.c -+index 9004ce809eb..193a1e3d332 100644 -+--- a/lib/regex_internal.c -++++ b/lib/regex_internal.c -+@@ -233,7 +233,7 @@ build_wcs_buffer (re_string_t *pstr) -+ /* Apply the translation if we need. */ -+ if (__glibc_unlikely (pstr->trans != NULL)) -+ { -+- int i, ch; -++ unsigned int i, ch; -+ -+ for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) -+ { -+@@ -376,7 +376,7 @@ build_wcs_upper_buffer (re_string_t *pstr) -+ prev_st = pstr->cur_state; -+ if (__glibc_unlikely (pstr->trans != NULL)) -+ { -+- int i, ch; -++ unsigned int i, ch; -+ -+ for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) -+ { -+@@ -754,7 +754,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) -+ memset (&cur_state, 0, sizeof (cur_state)); -+ mbclen = __mbrtowc (&wc2, (const char *) pp, mlen, -+ &cur_state); -+- if (raw + offset - p <= mbclen -++ if ((size_t)(raw + offset - p) <= mbclen -+ && mbclen < (size_t) -2) -+ { -+ memset (&pstr->cur_state, '\0', -+diff --git a/lib/regex_internal.h b/lib/regex_internal.h -+index 5462419b787..e0f8292395d 100644 -+--- a/lib/regex_internal.h -++++ b/lib/regex_internal.h -+@@ -425,7 +425,7 @@ struct re_string_t -+ unsigned char offsets_needed; -+ unsigned char newline_anchor; -+ unsigned char word_ops_used; -+- int mb_cur_max; -++ unsigned int mb_cur_max; -+ }; -+ typedef struct re_string_t re_string_t; -+ -+@@ -702,7 +702,7 @@ struct re_dfa_t -+ unsigned int is_utf8 : 1; -+ unsigned int map_notascii : 1; -+ unsigned int word_ops_used : 1; -+- int mb_cur_max; -++ unsigned int mb_cur_max; -+ bitset_t word_char; -+ reg_syntax_t syntax; -+ Idx *subexp_map; -+diff --git a/lib/regexec.c b/lib/regexec.c -+index 0a7a27b772e..b57d4f9141d 100644 -+--- a/lib/regexec.c -++++ b/lib/regexec.c -+@@ -443,7 +443,7 @@ re_search_stub (struct re_pattern_buffer *bufp, const char *string, Idx length, -+ { -+ if (ret_len) -+ { -+- assert (pmatch[0].rm_so == start); -++ assert (pmatch[0].rm_so == (long)start); -+ rval = pmatch[0].rm_eo - start; -+ } -+ else -+@@ -877,11 +877,11 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, -+ if (__glibc_unlikely (mctx.input.offsets_needed != 0)) -+ { -+ pmatch[reg_idx].rm_so = -+- (pmatch[reg_idx].rm_so == mctx.input.valid_len -++ (pmatch[reg_idx].rm_so == (long)mctx.input.valid_len -+ ? mctx.input.valid_raw_len -+ : mctx.input.offsets[pmatch[reg_idx].rm_so]); -+ pmatch[reg_idx].rm_eo = -+- (pmatch[reg_idx].rm_eo == mctx.input.valid_len -++ (pmatch[reg_idx].rm_eo == (long)mctx.input.valid_len -+ ? mctx.input.valid_raw_len -+ : mctx.input.offsets[pmatch[reg_idx].rm_eo]); -+ } -+@@ -1418,11 +1418,11 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, -+ } -+ memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch); -+ -+- for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;) -++ for (idx = pmatch[0].rm_so; idx <= (long)pmatch[0].rm_eo ;) -+ { -+ update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch); -+ -+- if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node) -++ if (idx == (long)pmatch[0].rm_eo && cur_node == mctx->last_node) -+ { -+ Idx reg_idx; -+ if (fs) -+@@ -1519,7 +1519,7 @@ update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, -+ if (reg_num < nmatch) -+ { -+ /* We are at the last node of this sub expression. */ -+- if (pmatch[reg_num].rm_so < cur_idx) -++ if (pmatch[reg_num].rm_so < (long)cur_idx) -+ { -+ pmatch[reg_num].rm_eo = cur_idx; -+ /* This is a non-empty match or we are not inside an optional -+@@ -2938,7 +2938,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, -+ mctx->state_log[str_idx] = cur_state; -+ } -+ -+- for (null_cnt = 0; str_idx < last_str && null_cnt <= mctx->max_mb_elem_len;) -++ for (null_cnt = 0; str_idx < last_str && null_cnt <= (long)mctx->max_mb_elem_len;) -+ { -+ re_node_set_empty (&next_nodes); -+ if (mctx->state_log[str_idx + 1]) -+@@ -3718,7 +3718,7 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, -+ const re_string_t *input, Idx str_idx) -+ { -+ const re_token_t *node = dfa->nodes + node_idx; -+- int char_len, elem_len; -++ unsigned int char_len, elem_len; -+ Idx i; -+ -+ if (__glibc_unlikely (node->type == OP_UTF8_PERIOD)) -+@@ -4066,7 +4066,7 @@ extend_buffers (re_match_context_t *mctx, int min_len) -+ /* Double the lengths of the buffers, but allocate at least MIN_LEN. */ -+ ret = re_string_realloc_buffers (pstr, -+ MAX (min_len, -+- MIN (pstr->len, pstr->bufs_len * 2))); -++ MIN ((long)pstr->len, pstr->bufs_len * 2))); -+ if (__glibc_unlikely (ret != REG_NOERROR)) -+ return ret; -+ -+@@ -4236,7 +4236,7 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, -+ = (from == to ? -1 : 0); -+ -+ mctx->bkref_ents[mctx->nbkref_ents++].more = 0; -+- if (mctx->max_mb_elem_len < to - from) -++ if (mctx->max_mb_elem_len < (long)(to - from)) -+ mctx->max_mb_elem_len = to - from; -+ return REG_NOERROR; -+ } diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c -index ee9fa7b..19c2008 100644 +index 467305b46ab..79037c093f7 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c -@@ -156,7 +156,7 @@ static void +@@ -157,7 +157,7 @@ static void rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) { gf_single_t *rs_polynomial; - int i, j; + unsigned int i, j; gf_single_t *m; - m = xmalloc ((s + rs) * sizeof (gf_single_t)); + m = xcalloc (s + rs, sizeof (gf_single_t)); grub_memcpy (m, data, s * sizeof (gf_single_t)); -@@ -325,7 +325,7 @@ static void +@@ -324,7 +324,7 @@ static void encode_block (gf_single_t *ptr, grub_size_t s, gf_single_t *rptr, grub_size_t rs) { @@ -224,7 +57,7 @@ index ee9fa7b..19c2008 100644 { grub_size_t ds = (s + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; diff --git a/grub-core/osdep/linux/blocklist.c b/grub-core/osdep/linux/blocklist.c -index c77d608..42a3150 100644 +index c77d6085ccb..42a315031ff 100644 --- a/grub-core/osdep/linux/blocklist.c +++ b/grub-core/osdep/linux/blocklist.c @@ -109,7 +109,7 @@ grub_install_get_blocklist (grub_device_t root_dev, @@ -237,7 +70,7 @@ index c77d608..42a3150 100644 + fie1.fm_mapped_extents * sizeof (fie1.fm_extents[1])); diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c -index 4c5a130..2b7a626 100644 +index 28790307e00..9f730b35189 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c @@ -236,7 +236,7 @@ grub_find_root_devices_from_btrfs (const char *dir) @@ -250,7 +83,7 @@ index 4c5a130..2b7a626 100644 fd = open (dir, 0); diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c -index 8b92f85..370d027 100644 +index da62f924e35..7bc99ac1c1d 100644 --- a/grub-core/osdep/linux/hostdisk.c +++ b/grub-core/osdep/linux/hostdisk.c @@ -83,7 +83,7 @@ grub_util_get_fd_size_os (grub_util_fd_t fd, const char *name, unsigned *log_sec @@ -263,7 +96,7 @@ index 8b92f85..370d027 100644 if (log_secsize) diff --git a/util/grub-fstest.c b/util/grub-fstest.c -index f14e02d..88f9c5d 100644 +index 83865642009..bfcef852d83 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -323,7 +323,7 @@ cmd_cmp (char *src, char *dest) @@ -276,7 +109,7 @@ index f14e02d..88f9c5d 100644 fseek (ff, 0, SEEK_END); if (pre != ftell (ff)) diff --git a/util/grub-menulst2cfg.c b/util/grub-menulst2cfg.c -index a39f869..358d604 100644 +index a39f8693947..358d604210b 100644 --- a/util/grub-menulst2cfg.c +++ b/util/grub-menulst2cfg.c @@ -34,7 +34,7 @@ main (int argc, char **argv) @@ -289,7 +122,7 @@ index a39f869..358d604 100644 grub_util_host_init (&argc, &argv); diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c -index 0fe45a6..3e09240 100644 +index 0fe45a6103d..3e09240b99f 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -138,7 +138,8 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, @@ -343,7 +176,7 @@ index 0fe45a6..3e09240 100644 add_pixel (&data, &mask, glyph->bitmap.buffer[i / 8 + j * glyph->bitmap.pitch] & diff --git a/util/grub-probe.c b/util/grub-probe.c -index 81d27ee..7481e48 100644 +index c08e46bbb40..c6fac732b40 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -798,7 +798,7 @@ argp_parser (int key, char *arg, struct argp_state *state) @@ -356,7 +189,7 @@ index 81d27ee..7481e48 100644 for (i = PRINT_FS; i < ARRAY_SIZE (targets); i++) if (strcmp (arg, targets[i]) == 0) diff --git a/util/grub-rpm-sort.c b/util/grub-rpm-sort.c -index f33bd1e..8345944 100644 +index f33bd1ed568..8345944105f 100644 --- a/util/grub-rpm-sort.c +++ b/util/grub-rpm-sort.c @@ -232,7 +232,7 @@ main (int argc, char *argv[]) @@ -369,10 +202,10 @@ index f33bd1e..8345944 100644 grub_util_host_init (&argc, &argv); diff --git a/util/setup.c b/util/setup.c -index 6f88f3c..864094d 100644 +index da5f2c07f50..8b22bb8ccac 100644 --- a/util/setup.c +++ b/util/setup.c -@@ -402,7 +402,7 @@ SETUP (const char *dir, +@@ -406,7 +406,7 @@ SETUP (const char *dir, int is_ldm; grub_err_t err; grub_disk_addr_t *sectors; @@ -381,6 +214,184 @@ index 6f88f3c..864094d 100644 grub_fs_t fs; unsigned int nsec, maxsec; --- -1.8.3.1 - +diff --git a/bootstrap.conf b/bootstrap.conf +index 6b043fc354c..186be9c48ce 100644 +--- a/bootstrap.conf ++++ b/bootstrap.conf +@@ -80,7 +80,8 @@ cp -a INSTALL INSTALL.grub + bootstrap_post_import_hook () { + set -e + for patchname in fix-base64 fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \ +- fix-regexec-null-deref fix-uninit-structure fix-unused-value fix-width no-abort; do ++ fix-regexec-null-deref fix-uninit-structure fix-unused-value fix-width no-abort \ ++ fix-sign-compare-errors; do + patch -d grub-core/lib/gnulib -p2 \ + < "grub-core/lib/gnulib-patches/$patchname.patch" + done +diff --git a/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch b/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch +new file mode 100644 +index 00000000000..479029c0565 +--- /dev/null ++++ b/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch +@@ -0,0 +1,161 @@ ++diff --git a/lib/regcomp.c b/lib/regcomp.c ++index cc85f35ac58..361079d82d6 100644 ++--- a/lib/regcomp.c +++++ b/lib/regcomp.c ++@@ -322,7 +322,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, ++ *p++ = dfa->nodes[node].opr.c; ++ memset (&state, '\0', sizeof (state)); ++ if (__mbrtowc (&wc, (const char *) buf, p - buf, ++- &state) == p - buf +++ &state) == (size_t)(p - buf) ++ && (__wcrtomb ((char *) buf, __towlower (wc), &state) ++ != (size_t) -1)) ++ re_set_fastmap (fastmap, false, buf[0]); ++@@ -3778,7 +3778,7 @@ fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax) ++ num = ((token->type != CHARACTER || c < '0' || '9' < c || num == -2) ++ ? -2 ++ : num == -1 ++- ? c - '0' +++ ? (Idx)(c - '0') ++ : MIN (RE_DUP_MAX + 1, num * 10 + c - '0')); ++ } ++ return num; ++diff --git a/lib/regex_internal.c b/lib/regex_internal.c ++index 9004ce809eb..193a1e3d332 100644 ++--- a/lib/regex_internal.c +++++ b/lib/regex_internal.c ++@@ -233,7 +233,7 @@ build_wcs_buffer (re_string_t *pstr) ++ /* Apply the translation if we need. */ ++ if (__glibc_unlikely (pstr->trans != NULL)) ++ { ++- int i, ch; +++ unsigned int i, ch; ++ ++ for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) ++ { ++@@ -376,7 +376,7 @@ build_wcs_upper_buffer (re_string_t *pstr) ++ prev_st = pstr->cur_state; ++ if (__glibc_unlikely (pstr->trans != NULL)) ++ { ++- int i, ch; +++ unsigned int i, ch; ++ ++ for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) ++ { ++@@ -754,7 +754,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) ++ memset (&cur_state, 0, sizeof (cur_state)); ++ mbclen = __mbrtowc (&wc2, (const char *) pp, mlen, ++ &cur_state); ++- if (raw + offset - p <= mbclen +++ if ((size_t)(raw + offset - p) <= mbclen ++ && mbclen < (size_t) -2) ++ { ++ memset (&pstr->cur_state, '\0', ++diff --git a/lib/regex_internal.h b/lib/regex_internal.h ++index 5462419b787..e0f8292395d 100644 ++--- a/lib/regex_internal.h +++++ b/lib/regex_internal.h ++@@ -425,7 +425,7 @@ struct re_string_t ++ unsigned char offsets_needed; ++ unsigned char newline_anchor; ++ unsigned char word_ops_used; ++- int mb_cur_max; +++ unsigned int mb_cur_max; ++ }; ++ typedef struct re_string_t re_string_t; ++ ++@@ -702,7 +702,7 @@ struct re_dfa_t ++ unsigned int is_utf8 : 1; ++ unsigned int map_notascii : 1; ++ unsigned int word_ops_used : 1; ++- int mb_cur_max; +++ unsigned int mb_cur_max; ++ bitset_t word_char; ++ reg_syntax_t syntax; ++ Idx *subexp_map; ++diff --git a/lib/regexec.c b/lib/regexec.c ++index 0a7a27b772e..b57d4f9141d 100644 ++--- a/lib/regexec.c +++++ b/lib/regexec.c ++@@ -443,7 +443,7 @@ re_search_stub (struct re_pattern_buffer *bufp, const char *string, Idx length, ++ { ++ if (ret_len) ++ { ++- assert (pmatch[0].rm_so == start); +++ assert (pmatch[0].rm_so == (long)start); ++ rval = pmatch[0].rm_eo - start; ++ } ++ else ++@@ -877,11 +877,11 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, ++ if (__glibc_unlikely (mctx.input.offsets_needed != 0)) ++ { ++ pmatch[reg_idx].rm_so = ++- (pmatch[reg_idx].rm_so == mctx.input.valid_len +++ (pmatch[reg_idx].rm_so == (long)mctx.input.valid_len ++ ? mctx.input.valid_raw_len ++ : mctx.input.offsets[pmatch[reg_idx].rm_so]); ++ pmatch[reg_idx].rm_eo = ++- (pmatch[reg_idx].rm_eo == mctx.input.valid_len +++ (pmatch[reg_idx].rm_eo == (long)mctx.input.valid_len ++ ? mctx.input.valid_raw_len ++ : mctx.input.offsets[pmatch[reg_idx].rm_eo]); ++ } ++@@ -1418,11 +1418,11 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, ++ } ++ memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch); ++ ++- for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;) +++ for (idx = pmatch[0].rm_so; idx <= (long)pmatch[0].rm_eo ;) ++ { ++ update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch); ++ ++- if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node) +++ if (idx == (long)pmatch[0].rm_eo && cur_node == mctx->last_node) ++ { ++ Idx reg_idx; ++ if (fs) ++@@ -1519,7 +1519,7 @@ update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, ++ if (reg_num < nmatch) ++ { ++ /* We are at the last node of this sub expression. */ ++- if (pmatch[reg_num].rm_so < cur_idx) +++ if (pmatch[reg_num].rm_so < (long)cur_idx) ++ { ++ pmatch[reg_num].rm_eo = cur_idx; ++ /* This is a non-empty match or we are not inside an optional ++@@ -2938,7 +2938,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, ++ mctx->state_log[str_idx] = cur_state; ++ } ++ ++- for (null_cnt = 0; str_idx < last_str && null_cnt <= mctx->max_mb_elem_len;) +++ for (null_cnt = 0; str_idx < last_str && null_cnt <= (long)mctx->max_mb_elem_len;) ++ { ++ re_node_set_empty (&next_nodes); ++ if (mctx->state_log[str_idx + 1]) ++@@ -3718,7 +3718,7 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, ++ const re_string_t *input, Idx str_idx) ++ { ++ const re_token_t *node = dfa->nodes + node_idx; ++- int char_len, elem_len; +++ unsigned int char_len, elem_len; ++ Idx i; ++ ++ if (__glibc_unlikely (node->type == OP_UTF8_PERIOD)) ++@@ -4066,7 +4066,7 @@ extend_buffers (re_match_context_t *mctx, int min_len) ++ /* Double the lengths of the buffers, but allocate at least MIN_LEN. */ ++ ret = re_string_realloc_buffers (pstr, ++ MAX (min_len, ++- MIN (pstr->len, pstr->bufs_len * 2))); +++ MIN ((long)pstr->len, pstr->bufs_len * 2))); ++ if (__glibc_unlikely (ret != REG_NOERROR)) ++ return ret; ++ ++@@ -4236,7 +4236,7 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, ++ = (from == to ? -1 : 0); ++ ++ mctx->bkref_ents[mctx->nbkref_ents++].more = 0; ++- if (mctx->max_mb_elem_len < to - from) +++ if (mctx->max_mb_elem_len < (long)(to - from)) ++ mctx->max_mb_elem_len = to - from; ++ return REG_NOERROR; ++ } diff --git a/0152-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch b/0104-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch similarity index 84% rename from 0152-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch rename to 0104-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch index 145031da72fe29729eff1f7d1a876c04b814a505..1fa705e68c8581cc2242a39b86766c5631b8e2d7 100644 --- a/0152-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch +++ b/0104-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch @@ -1,33 +1,20 @@ -From 7a86d5c7160b12f0608fa51cd5fa2fccd9b8f596 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 11 Jul 2019 18:20:37 +0200 -Subject: [PATCH 152/220] Don't use -Wno-sign-compare -Wno-conversion - -Wno-error, do use -Wextra. +Subject: [PATCH] Don't use -Wno-sign-compare -Wno-conversion -Wno-error, do + use -Wextra. Signed-off-by: Peter Jones --- - conf/Makefile.common | 2 +- configure.ac | 14 +++++++++++--- + conf/Makefile.common | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) -diff --git a/conf/Makefile.common b/conf/Makefile.common -index bbf33b0..b867691 100644 ---- a/conf/Makefile.common -+++ b/conf/Makefile.common -@@ -66,7 +66,7 @@ grubconfdir = $(sysconfdir)/grub.d - platformdir = $(pkglibdir)/$(target_cpu)-$(platform) - starfielddir = $(pkgdatadir)/themes/starfield - --CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion -+CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code - CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib - - CFLAGS_POSIX = -fno-builtin diff --git a/configure.ac b/configure.ac -index bca7c28..38d978b 100644 +index 59ccda24475..6eb297fdbf6 100644 --- a/configure.ac +++ b/configure.ac -@@ -1424,11 +1424,11 @@ fi +@@ -1480,11 +1480,11 @@ fi # Set them to their new values for the tests below. CC="$TARGET_CC" if test x"$platform" = xemu ; then @@ -42,7 +29,7 @@ index bca7c28..38d978b 100644 fi CPPFLAGS="$TARGET_CPPFLAGS" -@@ -1987,6 +1987,14 @@ if test x"$enable_werror" != xno ; then +@@ -2047,6 +2047,14 @@ if test x"$enable_werror" != xno ; then HOST_CFLAGS="$HOST_CFLAGS -Werror" fi @@ -57,6 +44,16 @@ index bca7c28..38d978b 100644 TARGET_CPP="$TARGET_CC -E" TARGET_CCAS=$TARGET_CC --- -1.8.3.1 - +diff --git a/conf/Makefile.common b/conf/Makefile.common +index 2ff9b39357c..35e14ff017e 100644 +--- a/conf/Makefile.common ++++ b/conf/Makefile.common +@@ -66,7 +66,7 @@ grubconfdir = $(sysconfdir)/grub.d + platformdir = $(pkglibdir)/$(target_cpu)-$(platform) + starfielddir = $(pkgdatadir)/themes/starfield + +-CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion ++CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code + CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib + + CFLAGS_POSIX = -fno-builtin diff --git a/0153-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch b/0105-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch similarity index 93% rename from 0153-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch rename to 0105-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch index 6d5eaaed195100fb6f69ed7cb1e69bd4982890be..fdd3096520fc796857e08439d9f54566aee1629d 100644 --- a/0153-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch +++ b/0105-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch @@ -1,8 +1,7 @@ -From c776520796765685c405a72ecbf3ac6f5eeae1cb Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Fri, 12 Jul 2019 09:53:32 +0200 -Subject: [PATCH 153/220] x86-efi: Use bounce buffers for reading to addresses - > 4GB +Subject: [PATCH] x86-efi: Use bounce buffers for reading to addresses > 4GB Lots of machines apparently can't DMA correctly above 4GB during UEFI, so use bounce buffers for the initramfs read. @@ -13,7 +12,7 @@ Signed-off-by: Peter Jones 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 33e981e..2f03368 100644 +index 33e981e76e7..2f0336809e7 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -35,11 +35,16 @@ static grub_dl_t my_mod; @@ -100,6 +99,3 @@ index 33e981e..2f03368 100644 static grub_err_t grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) --- -1.8.3.1 - diff --git a/0154-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch b/0106-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch similarity index 96% rename from 0154-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch rename to 0106-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch index 056b4922d318375aa4af9290a7222eb93be87ef4..f8284ec28a87c863b555d99766a590102167ca57 100644 --- a/0154-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch +++ b/0106-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch @@ -1,7 +1,7 @@ -From da26129db9e007294b3b35dc75ef74c5e516afff Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 13 Sep 2018 14:42:34 -0400 -Subject: [PATCH 154/220] x86-efi: Re-arrange grub_cmd_linux() a little bit. +Subject: [PATCH] x86-efi: Re-arrange grub_cmd_linux() a little bit. This just helps the next patch be easier to read. @@ -11,7 +11,7 @@ Signed-off-by: Peter Jones 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 2f03368..5f48fa5 100644 +index 2f0336809e7..5f48fa55619 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -243,32 +243,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), @@ -28,13 +28,13 @@ index 2f03368..5f48fa5 100644 - grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters"); - goto fail; - } -- -- grub_dprintf ("linux", "params = %p\n", params); -- -- grub_memset (params, 0, sizeof(*params)); + lh = (struct linux_i386_kernel_header *)kernel; + grub_dprintf ("linux", "original lh is at %p\n", kernel); +- grub_dprintf ("linux", "params = %p\n", params); +- +- grub_memset (params, 0, sizeof(*params)); +- - setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201); - grub_dprintf ("linux", "copying %lu bytes from %p to %p\n", - MIN((grub_size_t)0x202+setup_header_end_offset, @@ -131,6 +131,3 @@ index 2f03368..5f48fa5 100644 if (file) grub_file_close (file); --- -1.8.3.1 - diff --git a/0155-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch b/0107-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch similarity index 97% rename from 0155-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch rename to 0107-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch index 63d419fc72661938ecefe1445782a69ed7e47852..4ad0696be43718b6e04fb3a4351e9807062020a7 100644 --- a/0155-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch +++ b/0107-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch @@ -1,7 +1,7 @@ -From 70dc54b23fb32c57a58540857c54ed3291215f28 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 12 Sep 2018 16:03:55 -0400 -Subject: [PATCH 155/220] x86-efi: Make our own allocator for kernel stuff +Subject: [PATCH] x86-efi: Make our own allocator for kernel stuff This helps enable allocations above 4GB. @@ -11,7 +11,7 @@ Signed-off-by: Peter Jones 1 file changed, 94 insertions(+), 73 deletions(-) diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 5f48fa5..075b77e 100644 +index 5f48fa55619..3e4f7ef39f4 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -47,6 +47,65 @@ static char *linux_cmdline; @@ -72,7 +72,7 @@ index 5f48fa5..075b77e 100644 + } + + if (addr == NULL) -+ grub_error (GRUB_ERR_OUT_OF_MEMORY, errmsg); ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, "%s", errmsg); + + return addr; +} @@ -238,15 +238,15 @@ index 5f48fa5..075b77e 100644 - grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t) - linux_cmdline, - BYTES_TO_PAGES(lh->cmdline_size + 1)); -- -- if (kernel_mem && !loaded) -- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, -- BYTES_TO_PAGES(kernel_size)); + if (!loaded) + { + if (lh) + kernel_free (linux_cmdline, lh->cmdline_size + 1); +- if (kernel_mem && !loaded) +- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, +- BYTES_TO_PAGES(kernel_size)); +- - if (params && !loaded) - grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params, - BYTES_TO_PAGES(16384)); @@ -256,6 +256,3 @@ index 5f48fa5..075b77e 100644 return grub_errno; } --- -1.8.3.1 - diff --git a/0156-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch b/0108-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch similarity index 95% rename from 0156-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch rename to 0108-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch index 0b33b343f2b6f2bcfa874996c6dfce3e3ac61b43..b1233ce3ca2384b80b35089d8e437058fa6df087 100644 --- a/0156-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch +++ b/0108-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch @@ -1,8 +1,7 @@ -From c2315ea6badfef590717c50b652c9d31a1156ca4 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 12 Sep 2018 16:12:27 -0400 -Subject: [PATCH 156/220] x86-efi: Allow initrd+params+cmdline allocations - above 4GB. +Subject: [PATCH] x86-efi: Allow initrd+params+cmdline allocations above 4GB. This enables everything except the kernel itself to be above 4GB. Putting the kernel up there still doesn't work, because of the way @@ -15,7 +14,7 @@ Signed-off-by: Peter Jones 2 files changed, 65 insertions(+), 8 deletions(-) diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 075b77e..50b7798 100644 +index 3e4f7ef39f4..6bc18d5aef5 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -52,13 +52,22 @@ struct allocation_choice { @@ -154,10 +153,10 @@ index 075b77e..50b7798 100644 grub_memcpy (kernel_mem, (char *)kernel + start, filelen - start); diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h -index a093679..91123b1 100644 +index 25ef52c04eb..fac22476cc5 100644 --- a/include/grub/i386/linux.h +++ b/include/grub/i386/linux.h -@@ -234,7 +234,11 @@ struct linux_kernel_params +@@ -236,7 +236,11 @@ struct linux_kernel_params grub_uint32_t ofw_cif_handler; /* b8 */ grub_uint32_t ofw_idt; /* bc */ @@ -170,6 +169,3 @@ index a093679..91123b1 100644 union { --- -1.8.3.1 - diff --git a/0157-Fix-getroot.c-s-trampolines.patch b/0109-Fix-getroot.c-s-trampolines.patch similarity index 87% rename from 0157-Fix-getroot.c-s-trampolines.patch rename to 0109-Fix-getroot.c-s-trampolines.patch index 43b559febf462ead0069c1bae270a1849edf6474..29ec44c9861955c3e1060409e2af923d4616e35c 100644 --- a/0157-Fix-getroot.c-s-trampolines.patch +++ b/0109-Fix-getroot.c-s-trampolines.patch @@ -1,7 +1,7 @@ -From 56c9e4636e9bfcdd16e8616c3b4084c12abe39d8 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Fri, 28 Sep 2018 15:42:19 -0400 -Subject: [PATCH 157/220] Fix getroot.c's trampolines. +Subject: [PATCH] Fix getroot.c's trampolines. This makes the stack executable on most of the grub utilities, which is bad, and rpmdiff complains about it. @@ -12,7 +12,7 @@ Signed-off-by: Peter Jones 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c -index 2b7a626..36429a7 100644 +index 9f730b35189..f0c503f43d3 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c @@ -1264,22 +1264,20 @@ grub_util_get_grub_dev_os (const char *os_dev) @@ -45,6 +45,3 @@ index 2b7a626..36429a7 100644 grub_free (grub_find_root_devices_from_mountinfo (path, NULL)); grub_find_root_btrfs_mount_path_hook = NULL; --- -1.8.3.1 - diff --git a/0158-Do-not-allow-stack-trampolines-anywhere.patch b/0110-Do-not-allow-stack-trampolines-anywhere.patch similarity index 81% rename from 0158-Do-not-allow-stack-trampolines-anywhere.patch rename to 0110-Do-not-allow-stack-trampolines-anywhere.patch index f4a8b6e6f7b95fa6968c395b75ca460c6a1a008d..2a3247af9705fb621e66000060a03b126dbd34d3 100644 --- a/0158-Do-not-allow-stack-trampolines-anywhere.patch +++ b/0110-Do-not-allow-stack-trampolines-anywhere.patch @@ -1,32 +1,19 @@ -From 7840cc28efc1de9777fec4e9c85dd7d2887be628 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Fri, 12 Jul 2019 10:06:50 +0200 -Subject: [PATCH 158/220] Do not allow stack trampolines, anywhere. +Subject: [PATCH] Do not allow stack trampolines, anywhere. Signed-off-by: Peter Jones --- - conf/Makefile.common | 2 +- configure.ac | 3 +++ + conf/Makefile.common | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) -diff --git a/conf/Makefile.common b/conf/Makefile.common -index b867691..87c1f0e 100644 ---- a/conf/Makefile.common -+++ b/conf/Makefile.common -@@ -66,7 +66,7 @@ grubconfdir = $(sysconfdir)/grub.d - platformdir = $(pkglibdir)/$(target_cpu)-$(platform) - starfielddir = $(pkgdatadir)/themes/starfield - --CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -+CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Werror=trampolines -fno-trampolines - CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib - - CFLAGS_POSIX = -fno-builtin diff --git a/configure.ac b/configure.ac -index 38d978b..5076d63 100644 +index 6eb297fdbf6..c6bd965f1f9 100644 --- a/configure.ac +++ b/configure.ac -@@ -1995,6 +1995,9 @@ if test x"$enable_wextra" != xno ; then +@@ -2055,6 +2055,9 @@ if test x"$enable_wextra" != xno ; then HOST_CFLAGS="$HOST_CFLAGS -Wextra" fi @@ -36,6 +23,16 @@ index 38d978b..5076d63 100644 TARGET_CPP="$TARGET_CC -E" TARGET_CCAS=$TARGET_CC --- -1.8.3.1 - +diff --git a/conf/Makefile.common b/conf/Makefile.common +index 35e14ff017e..0647c53b916 100644 +--- a/conf/Makefile.common ++++ b/conf/Makefile.common +@@ -66,7 +66,7 @@ grubconfdir = $(sysconfdir)/grub.d + platformdir = $(pkglibdir)/$(target_cpu)-$(platform) + starfielddir = $(pkgdatadir)/themes/starfield + +-CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code ++CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Werror=trampolines -fno-trampolines + CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib + + CFLAGS_POSIX = -fno-builtin diff --git a/0110-misc-fix-invalid-character-recongition-in-strto-l.patch b/0110-misc-fix-invalid-character-recongition-in-strto-l.patch deleted file mode 100644 index 110cfc9745e725a09f6c46d5fcea8cebf99960bd..0000000000000000000000000000000000000000 --- a/0110-misc-fix-invalid-character-recongition-in-strto-l.patch +++ /dev/null @@ -1,40 +0,0 @@ -From d2f8885f7d9ea9581d93541c321dd1ce564c8446 Mon Sep 17 00:00:00 2001 -From: Aaron Miller -Date: Fri, 29 Jul 2016 17:41:27 +0800 -Subject: [PATCH 110/220] misc: fix invalid character recongition in strto*l - -Would previously allow digits larger than the base and didn't check that -subtracting the difference from 0-9 to lowercase letters for characters -larger than 9 didn't result in a value lower than 9, which allowed the -parses: ` = 9, _ = 8, ^ = 7, ] = 6, \ = 5, and [ = 4 ---- - grub-core/kern/misc.c | 13 ++++++++----- - 1 file changed, 8 insertions(+), 5 deletions(-) - -diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 0e89c48..5c3899f 100644 ---- a/grub-core/kern/misc.c -+++ b/grub-core/kern/misc.c -@@ -434,11 +434,14 @@ grub_strtoull (const char *str, char **end, int base) - unsigned long digit; - - digit = grub_tolower (*str) - '0'; -- if (digit >= 'a' - '0') -- digit += '0' - 'a' + 10; -- else if (digit > 9) -- break; -- -+ if (digit > 9) -+ { -+ digit += '0' - 'a' + 10; -+ /* digit <= 9 check is needed to keep chars larger than -+ '9' but less than 'a' from being read as numbers */ -+ if (digit >= (unsigned long) base || digit <= 9) -+ break; -+ } - if (digit >= (unsigned long) base) - break; - --- -1.8.3.1 - diff --git a/0159-Reimplement-boot_counter.patch b/0111-Reimplement-boot_counter.patch similarity index 95% rename from 0159-Reimplement-boot_counter.patch rename to 0111-Reimplement-boot_counter.patch index 88b642b7aa9987634e1230eebf14439767905dbd..a203929f1a193c0119330975e4529aaef818e54c 100644 --- a/0159-Reimplement-boot_counter.patch +++ b/0111-Reimplement-boot_counter.patch @@ -1,7 +1,7 @@ -From 6a1bf02b86814f1b015bfc0a0979ecdca4106516 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 4 Oct 2018 14:22:09 -0400 -Subject: [PATCH 159/220] Reimplement boot_counter +Subject: [PATCH] Reimplement boot_counter This adds "increment" and "decrement" commands, and uses them to maintain our variables in 01_fallback_counter. It also simplifies the counter logic, so @@ -23,27 +23,27 @@ Signed-off-by: Christian Glombek create mode 100644 util/grub.d/01_fallback_counting.in diff --git a/Makefile.util.def b/Makefile.util.def -index 125ad62..2019ebd 100644 +index 0b85a7fce4a..27a13bc734e 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -458,6 +458,12 @@ script = { + installdir = grubconf; }; - script = { ++script = { + name = '01_fallback_counting'; + common = util/grub.d/01_fallback_counting.in; + installdir = grubconf; +}; + -+script = { + script = { name = '01_menu_auto_hide'; common = util/grub.d/01_menu_auto_hide.in; - installdir = grubconf; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 8bb1daf..65ca74f 100644 +index 498ca11762a..1e15345107e 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -395,6 +395,11 @@ kernel = { +@@ -398,6 +398,11 @@ kernel = { extra_dist = kern/mips/cache_flush.S; }; @@ -57,7 +57,7 @@ index 8bb1daf..65ca74f 100644 mansection = 1; diff --git a/grub-core/commands/increment.c b/grub-core/commands/increment.c new file mode 100644 -index 0000000..79cf137 +index 00000000000..79cf137656c --- /dev/null +++ b/grub-core/commands/increment.c @@ -0,0 +1,105 @@ @@ -168,7 +168,7 @@ index 0000000..79cf137 +} diff --git a/util/grub.d/01_fallback_counting.in b/util/grub.d/01_fallback_counting.in new file mode 100644 -index 0000000..be0e770 +index 00000000000..be0e770ea82 --- /dev/null +++ b/util/grub.d/01_fallback_counting.in @@ -0,0 +1,22 @@ @@ -194,6 +194,3 @@ index 0000000..be0e770 + save_env boot_counter +fi +EOF --- -1.8.3.1 - diff --git a/0161-Fix-menu-entry-selection-based-on-ID-and-title.patch b/0112-Fix-menu-entry-selection-based-on-ID-and-title.patch similarity index 96% rename from 0161-Fix-menu-entry-selection-based-on-ID-and-title.patch rename to 0112-Fix-menu-entry-selection-based-on-ID-and-title.patch index 4cbd69820bd71582c55714de8b3f927af6681184..957fda38c2fc97a96d5422873c82b84983bc47dc 100644 --- a/0161-Fix-menu-entry-selection-based-on-ID-and-title.patch +++ b/0112-Fix-menu-entry-selection-based-on-ID-and-title.patch @@ -1,7 +1,7 @@ -From 14470b5b42b1cc05979e8607fc0659418226b718 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Fri, 19 Oct 2018 10:57:52 -0400 -Subject: [PATCH 161/220] Fix menu entry selection based on ID and title +Subject: [PATCH] Fix menu entry selection based on ID and title Currently if grub_strtoul(saved_entry_value, NULL, 0) does not return an error, we assume the value it has produced is a correct index into our @@ -24,7 +24,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 71 insertions(+), 70 deletions(-) diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c -index 37d753d..ea714d2 100644 +index d7a222e681b..4a02aadb01c 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -164,12 +164,12 @@ grub_menu_set_timeout (int timeout) @@ -127,9 +127,13 @@ index 37d753d..ea714d2 100644 grub_error_push (); - entry = (int) grub_strtoul (val, &tail, 0); -- ++ entry = get_entry_number_helper(menu, val, &tail); ++ if (!(*tail == 0 || grub_isspace(*tail))) ++ entry = -1; + - if (grub_errno == GRUB_ERR_BAD_NUMBER) -- { ++ if (entry >= 0) + { - /* See if the variable matches the title of a menu entry. */ - grub_menu_entry_t e = menu->entry_list; - int i; @@ -147,10 +151,7 @@ index 37d753d..ea714d2 100644 - } - e = e->next; - } -+ entry = get_entry_number_helper(menu, val, &tail); -+ if (!(*tail == 0 || grub_isspace(*tail))) -+ entry = -1; - +- - if (sz > 0) - grub_errno = GRUB_ERR_NONE; - @@ -159,8 +160,7 @@ index 37d753d..ea714d2 100644 - } - - if (grub_errno == GRUB_ERR_NONE) -+ if (entry >= 0) - { +- { - if (sz > 0) - tail += sz; - @@ -231,6 +231,3 @@ index 37d753d..ea714d2 100644 grub_error_pop (); return entry; --- -1.8.3.1 - diff --git a/0162-Make-the-menu-entry-users-option-argument-to-be-opti.patch b/0113-Make-the-menu-entry-users-option-argument-to-be-opti.patch similarity index 90% rename from 0162-Make-the-menu-entry-users-option-argument-to-be-opti.patch rename to 0113-Make-the-menu-entry-users-option-argument-to-be-opti.patch index 3c12b5f8047b34627c4d737cb9c6bb25635a8cf7..e0d36db797811eb41c4bc2607ab588d0c985ce38 100644 --- a/0162-Make-the-menu-entry-users-option-argument-to-be-opti.patch +++ b/0113-Make-the-menu-entry-users-option-argument-to-be-opti.patch @@ -1,8 +1,7 @@ -From 5088373cfad54d6c61604cb7b266ef58aaaedb61 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Mon, 26 Nov 2018 10:06:42 +0100 -Subject: [PATCH 162/220] Make the menu entry users option argument to be - optional +Subject: [PATCH] Make the menu entry users option argument to be optional The --users option is used to restrict the access to specific menu entries only to a set of users. But the option requires an argument to either be a @@ -24,7 +23,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c -index 9faf2be..29736f5 100644 +index b194123eb67..b175a1b43b7 100644 --- a/grub-core/commands/menuentry.c +++ b/grub-core/commands/menuentry.c @@ -29,7 +29,7 @@ static const struct grub_arg_option options[] = @@ -45,6 +44,3 @@ index 9faf2be..29736f5 100644 users = ctxt->state[1].arg; else if (ctxt->state[5].set) users = NULL; --- -1.8.3.1 - diff --git a/0163-Add-efi-export-env-and-efi-load-env-commands.patch b/0114-Add-efi-export-env-and-efi-load-env-commands.patch similarity index 90% rename from 0163-Add-efi-export-env-and-efi-load-env-commands.patch rename to 0114-Add-efi-export-env-and-efi-load-env-commands.patch index d4b7ec004ea3a53fec042079f85b5b4be9023c0e..73456bc94c8a9bd9191cb7664eaf6a9754fd8ce3 100644 --- a/0163-Add-efi-export-env-and-efi-load-env-commands.patch +++ b/0114-Add-efi-export-env-and-efi-load-env-commands.patch @@ -1,7 +1,7 @@ -From cdd189ff589f11629f67198755490e93974354d1 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 16 Jan 2019 13:21:46 -0500 -Subject: [PATCH 163/220] Add efi-export-env and efi-load-env commands +Subject: [PATCH] Add efi-export-env and efi-load-env commands This adds "efi-export-env VARIABLE" and "efi-load-env", which manipulate the environment block stored in the EFI variable @@ -14,33 +14,32 @@ Signed-off-by: Peter Jones grub-core/kern/efi/efi.c | 3 + grub-core/kern/efi/init.c | 5 -- grub-core/lib/envblk.c | 43 +++++++++++ + util/grub-set-bootflag.c | 1 + include/grub/efi/efi.h | 5 ++ include/grub/lib/envblk.h | 3 + - util/editenv.c | 2 - - util/grub-set-bootflag.c | 1 + - 9 files changed, 229 insertions(+), 7 deletions(-) + 8 files changed, 229 insertions(+), 5 deletions(-) create mode 100644 grub-core/commands/efi/env.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 65ca74f..6619946 100644 +index 1e15345107e..81fc274148e 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -818,6 +818,12 @@ module = { +@@ -820,6 +820,12 @@ module = { + enable = efi; }; - module = { ++module = { + name = efienv; + common = commands/efi/env.c; + enable = efi; +}; + -+module = { + module = { name = efifwsetup; efi = commands/efi/efifwsetup.c; - enable = efi; diff --git a/grub-core/commands/efi/env.c b/grub-core/commands/efi/env.c new file mode 100644 -index 0000000..a690797 +index 00000000000..cbd13e03e81 --- /dev/null +++ b/grub-core/commands/efi/env.c @@ -0,0 +1,168 @@ @@ -96,8 +95,8 @@ index 0000000..a690797 + if (argc != 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("variable name expected")); + -+ envblk_s.buf = grub_efi_get_variable ("GRUB_ENV", &grub_env_guid, -+ &envblk_s.size); ++ grub_efi_get_variable ("GRUB_ENV", &grub_env_guid, &envblk_s.size, ++ (void **) &envblk_s.buf); + if (!envblk_s.buf || envblk_s.size < 1) + { + char *buf = grub_malloc (1025); @@ -185,8 +184,8 @@ index 0000000..a690797 + struct grub_envblk envblk_s = { NULL, 0 }; + grub_envblk_t envblk = &envblk_s; + -+ envblk_s.buf = grub_efi_get_variable ("GRUB_ENV", &grub_env_guid, -+ &envblk_s.size); ++ grub_efi_get_variable ("GRUB_ENV", &grub_env_guid, &envblk_s.size, ++ (void **) &envblk_s.buf); + if (!envblk_s.buf || envblk_s.size < 1) + return 0; + @@ -213,10 +212,10 @@ index 0000000..a690797 + grub_unregister_command (loadenv_cmd); +} diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index ada3004..279394d 100644 +index 2a446f5031b..14bc10eb564 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c -@@ -224,6 +224,9 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, +@@ -225,6 +225,9 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, if (status == GRUB_EFI_SUCCESS) return GRUB_ERR_NONE; @@ -227,10 +226,10 @@ index ada3004..279394d 100644 } diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c -index e6183a4..d1afa3a 100644 +index 2d12e6188fd..0574d8d6217 100644 --- a/grub-core/kern/efi/init.c +++ b/grub-core/kern/efi/init.c -@@ -29,11 +29,6 @@ +@@ -85,11 +85,6 @@ stack_protector_init (void) grub_addr_t grub_modbase; @@ -243,7 +242,7 @@ index e6183a4..d1afa3a 100644 static int set_var (const char *name, const char *value, diff --git a/grub-core/lib/envblk.c b/grub-core/lib/envblk.c -index 230e0e9..f89d86d 100644 +index 2e4e78b132d..874506da169 100644 --- a/grub-core/lib/envblk.c +++ b/grub-core/lib/envblk.c @@ -223,6 +223,49 @@ grub_envblk_delete (grub_envblk_t envblk, const char *name) @@ -296,8 +295,20 @@ index 230e0e9..f89d86d 100644 void grub_envblk_iterate (grub_envblk_t envblk, void *hook_data, +diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c +index bb198f02351..6a79ee67444 100644 +--- a/util/grub-set-bootflag.c ++++ b/util/grub-set-bootflag.c +@@ -25,6 +25,7 @@ + + #include /* For *_DIR_NAME defines */ + #include ++#include + #include /* For GRUB_ENVBLK_DEFCFG define */ + #include + #include diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h -index 8ca3981..d24afba 100644 +index 2e0691454b1..8dfc89a33b9 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -24,6 +24,11 @@ @@ -313,7 +324,7 @@ index 8ca3981..d24afba 100644 extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table); extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle); diff --git a/include/grub/lib/envblk.h b/include/grub/lib/envblk.h -index c3e6559..ab969af 100644 +index c3e65592170..ab969af2461 100644 --- a/include/grub/lib/envblk.h +++ b/include/grub/lib/envblk.h @@ -22,6 +22,8 @@ @@ -333,31 +344,3 @@ index c3e6559..ab969af 100644 void grub_envblk_delete (grub_envblk_t envblk, const char *name); void grub_envblk_iterate (grub_envblk_t envblk, void *hook_data, -diff --git a/util/editenv.c b/util/editenv.c -index 1f7f6f3..66f99f9 100644 ---- a/util/editenv.c -+++ b/util/editenv.c -@@ -30,8 +30,6 @@ - #include - #include - --#define DEFAULT_ENVBLK_SIZE 1024 -- - void - grub_util_create_envblk_file (const char *name) - { -diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c -index bb198f0..6a79ee6 100644 ---- a/util/grub-set-bootflag.c -+++ b/util/grub-set-bootflag.c -@@ -25,6 +25,7 @@ - - #include /* For *_DIR_NAME defines */ - #include -+#include - #include /* For GRUB_ENVBLK_DEFCFG define */ - #include - #include --- -1.8.3.1 - diff --git a/0164-Make-it-possible-to-subtract-conditions-from-debug.patch b/0115-Make-it-possible-to-subtract-conditions-from-debug.patch similarity index 84% rename from 0164-Make-it-possible-to-subtract-conditions-from-debug.patch rename to 0115-Make-it-possible-to-subtract-conditions-from-debug.patch index 9ae6b0025582f4d59027cd84f2590fd7f9bbc4a4..fce51eac8360f042579e9ff102632bfb3115d246 100644 --- a/0164-Make-it-possible-to-subtract-conditions-from-debug.patch +++ b/0115-Make-it-possible-to-subtract-conditions-from-debug.patch @@ -1,7 +1,7 @@ -From 735e69de93dc746ded8c03eed4c193b5299492cf Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 17 Jan 2019 13:10:39 -0500 -Subject: [PATCH 164/220] Make it possible to subtract conditions from debug= +Subject: [PATCH] Make it possible to subtract conditions from debug= This makes it so you can do set debug to "all,-scripting,-lexer" and get the obvious outcome. Any negation present will take preference over that @@ -14,10 +14,10 @@ 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 e21dd44..18a7dbf 100644 +index 9a2fae6398e..578bf51a5fc 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c -@@ -163,12 +163,24 @@ int +@@ -164,12 +164,24 @@ int grub_debug_enabled (const char * condition) { const char *debug; @@ -43,6 +43,3 @@ index e21dd44..18a7dbf 100644 return 1; return 0; --- -1.8.3.1 - diff --git a/0165-Export-all-variables-from-the-initial-context-when-c.patch b/0116-Export-all-variables-from-the-initial-context-when-c.patch similarity index 84% rename from 0165-Export-all-variables-from-the-initial-context-when-c.patch rename to 0116-Export-all-variables-from-the-initial-context-when-c.patch index c0c028e5c999ed5a642c5c1c128789eae73a6c07..4e32260ccada665fefa13ad61396c453217e4574 100644 --- a/0165-Export-all-variables-from-the-initial-context-when-c.patch +++ b/0116-Export-all-variables-from-the-initial-context-when-c.patch @@ -1,8 +1,8 @@ -From 7eeac73061708872cd41d3e03233d2ff8fe4167c Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Tue, 22 Jan 2019 15:40:25 +0100 -Subject: [PATCH 165/220] Export all variables from the initial context when - creating a submenu +Subject: [PATCH] Export all variables from the initial context when creating a + submenu When a submenu is created, only the exported variables are copied to the new menu context. But we want the variables to be global, so export lets @@ -17,7 +17,7 @@ Signed-off-by: Javier Martinez Canillas 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/grub-core/normal/context.c b/grub-core/normal/context.c -index ee53d4a..87edd25 100644 +index ee53d4a68e5..87edd254c44 100644 --- a/grub-core/normal/context.c +++ b/grub-core/normal/context.c @@ -99,7 +99,7 @@ grub_env_new_context (int export_all) @@ -30,7 +30,7 @@ index ee53d4a..87edd25 100644 int grub_extractor_level = 0; diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c -index ea714d2..d4832f1 100644 +index 4a02aadb01c..fe2e77a43e2 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -375,8 +375,6 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) @@ -42,6 +42,3 @@ index ea714d2..d4832f1 100644 grub_script_execute_new_scope (entry->sourcecode, entry->argc, entry->args); --- -1.8.3.1 - diff --git a/0169-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch b/0117-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch similarity index 48% rename from 0169-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch rename to 0117-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch index e4f09ce98e7f07d7401ffbfc3d0e9f4f9af59d63..92f259dc3886aabe44acfdf1fcccfdb5c5d27dd0 100644 --- a/0169-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch +++ b/0117-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch @@ -1,31 +1,30 @@ -From d371c69fed702b24a9025309c5773abddc18d3d3 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Christian Glombek Date: Tue, 2 Apr 2019 16:22:21 +0200 -Subject: [PATCH 169/220] grub.d: Split out boot success reset from menu auto - hide script +Subject: [PATCH] grub.d: Split out boot success reset from menu auto hide + script Also rename fallback and menu auto hide script to be executed before and after boot success reset script. In menu auto hide script, rename last_boot_ok var to menu_hide_ok + +Signed-off-by: Christian Glombek +Signed-off-by: Robbie Harwood --- - Makefile.util.def | 14 ++++++++--- - util/grub.d/01_fallback_counting.in | 22 ----------------- - util/grub.d/01_menu_auto_hide.in | 48 ------------------------------------ - util/grub.d/08_fallback_counting.in | 24 ++++++++++++++++++ - util/grub.d/10_reset_boot_success.in | 25 +++++++++++++++++++ - util/grub.d/12_menu_auto_hide.in | 35 ++++++++++++++++++++++++++ - 6 files changed, 94 insertions(+), 74 deletions(-) - delete mode 100644 util/grub.d/01_fallback_counting.in - delete mode 100644 util/grub.d/01_menu_auto_hide.in - create mode 100644 util/grub.d/08_fallback_counting.in + Makefile.util.def | 14 ++++++++---- + ...allback_counting.in => 08_fallback_counting.in} | 14 ++++++------ + util/grub.d/10_reset_boot_success.in | 25 ++++++++++++++++++++++ + .../{01_menu_auto_hide.in => 12_menu_auto_hide.in} | 23 +++++--------------- + 4 files changed, 48 insertions(+), 28 deletions(-) + rename util/grub.d/{01_fallback_counting.in => 08_fallback_counting.in} (65%) create mode 100644 util/grub.d/10_reset_boot_success.in - create mode 100644 util/grub.d/12_menu_auto_hide.in + rename util/grub.d/{01_menu_auto_hide.in => 12_menu_auto_hide.in} (58%) diff --git a/Makefile.util.def b/Makefile.util.def -index 2019ebd..1fa92ca 100644 +index 27a13bc734e..2e6ad979c3e 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -458,14 +458,14 @@ script = { +@@ -459,14 +459,14 @@ script = { }; script = { @@ -44,134 +43,53 @@ index 2019ebd..1fa92ca 100644 installdir = grubconf; }; -@@ -525,6 +525,12 @@ script = { +@@ -518,6 +518,12 @@ script = { + condition = COND_HOST_LINUX; }; - script = { ++script = { + name = '10_reset_boot_success'; + common = util/grub.d/10_reset_boot_success.in; + installdir = grubconf; +}; + -+script = { + script = { name = '10_xnu'; common = util/grub.d/10_xnu.in; - installdir = grubconf; -diff --git a/util/grub.d/01_fallback_counting.in b/util/grub.d/01_fallback_counting.in -deleted file mode 100644 -index be0e770..0000000 +diff --git a/util/grub.d/01_fallback_counting.in b/util/grub.d/08_fallback_counting.in +similarity index 65% +rename from util/grub.d/01_fallback_counting.in +rename to util/grub.d/08_fallback_counting.in +index be0e770ea82..2e2c3ff7d31 100644 --- a/util/grub.d/01_fallback_counting.in -+++ /dev/null -@@ -1,22 +0,0 @@ --#! /bin/sh -e ++++ b/util/grub.d/08_fallback_counting.in +@@ -1,15 +1,17 @@ + #! /bin/sh -e - -# Boot Counting --# The boot_counter env var can be used to count down boot attempts after an --# OSTree upgrade and choose the rollback deployment when 0 is reached. Both --# boot_counter and boot_success need to be (re-)set from userspace. --cat << EOF --insmod increment --# Check if boot_counter exists and boot_success=0 to activate this behaviour. --if [ -n "\${boot_counter}" -a "\${boot_success}" = "0" ]; then -- # if countdown has ended, choose to boot rollback deployment (default=1 on -- # OSTree-based systems) -- if [ "\${boot_counter}" = "0" -o "\${boot_counter}" = "-1" ]; then -- set default=1 -- set boot_counter=-1 -- # otherwise decrement boot_counter -- else -- decrement boot_counter -- fi -- save_env boot_counter --fi --EOF -diff --git a/util/grub.d/01_menu_auto_hide.in b/util/grub.d/01_menu_auto_hide.in -deleted file mode 100644 -index ad17587..0000000 ---- a/util/grub.d/01_menu_auto_hide.in -+++ /dev/null -@@ -1,48 +0,0 @@ --#! /bin/sh -- --# Disable / skip generating menu-auto-hide config parts on serial terminals --for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do -- case "$x" in -- serial*) -- exit 0 -- ;; -- esac --done -- --cat << EOF --if [ "\${boot_success}" = "1" -o "\${boot_indeterminate}" = "1" ]; then -- set last_boot_ok=1 --else -- set last_boot_ok=0 --fi -- --# Reset boot_indeterminate after a successful boot --if [ "\${boot_success}" = "1" ] ; then -- set boot_indeterminate=0 --# Avoid boot_indeterminate causing the menu to be hidden more then once --elif [ "\${boot_indeterminate}" = "1" ]; then -- set boot_indeterminate=2 --fi --set boot_success=0 --save_env boot_success boot_indeterminate -- --if [ x\$feature_timeout_style = xy ] ; then -- if [ "\${menu_show_once}" ]; then -- unset menu_show_once -- save_env menu_show_once -- set timeout_style=menu -- set timeout=60 -- elif [ "\${menu_auto_hide}" -a "\${last_boot_ok}" = "1" ]; then -- set orig_timeout_style=\${timeout_style} -- set orig_timeout=\${timeout} -- if [ "\${fastboot}" = "1" ]; then -- # timeout_style=menu + timeout=0 avoids the countdown code keypress check -- set timeout_style=menu -- set timeout=0 -- else -- set timeout_style=hidden -- set timeout=1 -- fi -- fi --fi --EOF -diff --git a/util/grub.d/08_fallback_counting.in b/util/grub.d/08_fallback_counting.in -new file mode 100644 -index 0000000..2e2c3ff ---- /dev/null -+++ b/util/grub.d/08_fallback_counting.in -@@ -0,0 +1,24 @@ -+#! /bin/sh -e +# Fallback Countdown +# +# This snippet depends on 10_reset_boot_success and needs to be kept in sync. +# -+# The boot_counter env var can be used to count down boot attempts after an + # The boot_counter env var can be used to count down boot attempts after an +-# OSTree upgrade and choose the rollback deployment when 0 is reached. Both +-# boot_counter and boot_success need to be (re-)set from userspace. +# OSTree upgrade and choose the rollback deployment when 0 is reached. +# Both boot_counter=X and boot_success=1 need to be set from userspace. -+cat << EOF -+insmod increment -+# Check if boot_counter exists and boot_success=0 to activate this behaviour. -+if [ -n "\${boot_counter}" -a "\${boot_success}" = "0" ]; then + cat << EOF + insmod increment + # Check if boot_counter exists and boot_success=0 to activate this behaviour. + if [ -n "\${boot_counter}" -a "\${boot_success}" = "0" ]; then +- # if countdown has ended, choose to boot rollback deployment (default=1 on +- # OSTree-based systems) + # if countdown has ended, choose to boot rollback deployment, + # i.e. default=1 on OSTree-based systems. -+ if [ "\${boot_counter}" = "0" -o "\${boot_counter}" = "-1" ]; then -+ set default=1 -+ set boot_counter=-1 -+ # otherwise decrement boot_counter -+ else -+ decrement boot_counter -+ fi -+ save_env boot_counter -+fi -+EOF + if [ "\${boot_counter}" = "0" -o "\${boot_counter}" = "-1" ]; then + set default=1 + set boot_counter=-1 diff --git a/util/grub.d/10_reset_boot_success.in b/util/grub.d/10_reset_boot_success.in new file mode 100644 -index 0000000..6c88d93 +index 00000000000..6c88d933dde --- /dev/null +++ b/util/grub.d/10_reset_boot_success.in @@ -0,0 +1,25 @@ @@ -200,47 +118,51 @@ index 0000000..6c88d93 +set boot_success=0 +save_env boot_success boot_indeterminate +EOF -diff --git a/util/grub.d/12_menu_auto_hide.in b/util/grub.d/12_menu_auto_hide.in -new file mode 100644 -index 0000000..6a7c0fa ---- /dev/null +diff --git a/util/grub.d/01_menu_auto_hide.in b/util/grub.d/12_menu_auto_hide.in +similarity index 58% +rename from util/grub.d/01_menu_auto_hide.in +rename to util/grub.d/12_menu_auto_hide.in +index ad175870a54..6a7c0fa0d43 100644 +--- a/util/grub.d/01_menu_auto_hide.in +++ b/util/grub.d/12_menu_auto_hide.in -@@ -0,0 +1,35 @@ -+#! /bin/sh +@@ -1,5 +1,8 @@ + #! /bin/sh +- +# Menu Auto Hide +# +# This snippet depends on 10_reset_boot_success and needs to be kept in sync. +# -+# Disable / skip generating menu-auto-hide config parts on serial terminals -+for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do -+ case "$x" in -+ serial*) -+ exit 0 -+ ;; -+ esac -+done -+ -+cat << EOF -+if [ x\$feature_timeout_style = xy ] ; then -+ if [ "\${menu_show_once}" ]; then -+ unset menu_show_once -+ save_env menu_show_once -+ set timeout_style=menu -+ set timeout=60 + # Disable / skip generating menu-auto-hide config parts on serial terminals + for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do + case "$x" in +@@ -10,29 +13,13 @@ for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do + done + + cat << EOF +-if [ "\${boot_success}" = "1" -o "\${boot_indeterminate}" = "1" ]; then +- set last_boot_ok=1 +-else +- set last_boot_ok=0 +-fi +- +-# Reset boot_indeterminate after a successful boot +-if [ "\${boot_success}" = "1" ] ; then +- set boot_indeterminate=0 +-# Avoid boot_indeterminate causing the menu to be hidden more then once +-elif [ "\${boot_indeterminate}" = "1" ]; then +- set boot_indeterminate=2 +-fi +-set boot_success=0 +-save_env boot_success boot_indeterminate +- + if [ x\$feature_timeout_style = xy ] ; then + if [ "\${menu_show_once}" ]; then + unset menu_show_once + save_env menu_show_once + set timeout_style=menu + set timeout=60 +- elif [ "\${menu_auto_hide}" -a "\${last_boot_ok}" = "1" ]; then + elif [ "\${menu_auto_hide}" -a "\${menu_hide_ok}" = "1" ]; then -+ set orig_timeout_style=\${timeout_style} -+ set orig_timeout=\${timeout} -+ if [ "\${fastboot}" = "1" ]; then -+ # timeout_style=menu + timeout=0 avoids the countdown code keypress check -+ set timeout_style=menu -+ set timeout=0 -+ else -+ set timeout_style=hidden -+ set timeout=1 -+ fi -+ fi -+fi -+EOF --- -1.8.3.1 - + set orig_timeout_style=\${timeout_style} + set orig_timeout=\${timeout} + if [ "\${fastboot}" = "1" ]; then diff --git a/0118-Fix-one-more-coverity-complaint.patch b/0118-Fix-one-more-coverity-complaint.patch deleted file mode 100644 index f8a130dc513a2dc8b4028939165d67c021295606..0000000000000000000000000000000000000000 --- a/0118-Fix-one-more-coverity-complaint.patch +++ /dev/null @@ -1,30 +0,0 @@ -From c160c16be2002a3f61b7c0432ff2759c9a5219a0 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 25 May 2017 11:27:40 -0400 -Subject: [PATCH 118/220] Fix one more coverity complaint - -No idea why covscan thinks this is an "added" bug, since the file hasn't -changed in 3 years, but... yeah. - -Signed-off-by: Peter Jones ---- - grub-core/normal/completion.c | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/grub-core/normal/completion.c b/grub-core/normal/completion.c -index 5961028..c07100a 100644 ---- a/grub-core/normal/completion.c -+++ b/grub-core/normal/completion.c -@@ -284,7 +284,8 @@ complete_file (void) - - /* Cut away the filename part. */ - dirfile = grub_strrchr (dir, '/'); -- dirfile[1] = '\0'; -+ if (dirfile) -+ dirfile[1] = '\0'; - - /* Iterate the directory. */ - (fs->fs_dir) (dev, dir, iterate_dir, NULL); --- -1.8.3.1 - diff --git a/0170-Fix-systemctl-kexec-exit-status-check.patch b/0118-Fix-systemctl-kexec-exit-status-check.patch similarity index 88% rename from 0170-Fix-systemctl-kexec-exit-status-check.patch rename to 0118-Fix-systemctl-kexec-exit-status-check.patch index afb9597afc52d1358d4ec754825263f446c426e4..74ecedccb118eb3ee9753ef02183c533c0f6e1e3 100644 --- a/0170-Fix-systemctl-kexec-exit-status-check.patch +++ b/0118-Fix-systemctl-kexec-exit-status-check.patch @@ -1,7 +1,7 @@ -From 425daec448d7ad73d0d2dc5e0918af823b4b11b3 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Tue, 9 Apr 2019 12:30:38 +0200 -Subject: [PATCH 170/220] Fix systemctl kexec exit status check +Subject: [PATCH] Fix systemctl kexec exit status check There's always an error printed even when the systemctl kexec command does succeed. That's because systemctl executes it asynchronously, but the emu @@ -19,7 +19,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c -index fda9e00..5b85b22 100644 +index fda9e00d24c..5b85b225eed 100644 --- a/grub-core/loader/emu/linux.c +++ b/grub-core/loader/emu/linux.c @@ -71,8 +71,10 @@ grub_linux_boot (void) @@ -35,6 +35,3 @@ index fda9e00..5b85b22 100644 /* need to check read-only root before resetting hard!? */ grub_printf("Performing 'kexec -e'"); --- -1.8.3.1 - diff --git a/0171-Print-grub-emu-linux-loader-messages-as-debug.patch b/0119-Print-grub-emu-linux-loader-messages-as-debug.patch similarity index 86% rename from 0171-Print-grub-emu-linux-loader-messages-as-debug.patch rename to 0119-Print-grub-emu-linux-loader-messages-as-debug.patch index 55c2bbf25f6bc523e000a93f85409cfd56c87dc1..a49ec44c4981f22752e041cf9c4ce0461e076ad8 100644 --- a/0171-Print-grub-emu-linux-loader-messages-as-debug.patch +++ b/0119-Print-grub-emu-linux-loader-messages-as-debug.patch @@ -1,7 +1,7 @@ -From d82290c42e977165ed19c02e0a548f11b50db818 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Tue, 9 Apr 2019 12:42:37 +0200 -Subject: [PATCH 171/220] Print grub-emu linux loader messages as debug +Subject: [PATCH] Print grub-emu linux loader messages as debug They just polute the output and should better be debug messages instead. @@ -11,7 +11,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c -index 5b85b22..22ab6af 100644 +index 5b85b225eed..22ab6af1727 100644 --- a/grub-core/loader/emu/linux.c +++ b/grub-core/loader/emu/linux.c @@ -50,7 +50,7 @@ grub_linux_boot (void) @@ -32,6 +32,3 @@ index 5b85b22..22ab6af 100644 (kexecute==1) ? "do-or-die" : "just-in-case"); rc = grub_util_exec (systemctl); --- -1.8.3.1 - diff --git a/0172-Don-t-assume-that-boot-commands-will-only-return-on-.patch b/0120-Don-t-assume-that-boot-commands-will-only-return-on-.patch similarity index 76% rename from 0172-Don-t-assume-that-boot-commands-will-only-return-on-.patch rename to 0120-Don-t-assume-that-boot-commands-will-only-return-on-.patch index 5ff8cb129e470e2a4fb1a48c64a1a8c51ae3b895..bd7b2c1b509e7d46b608e65e92d6fa15a9147b9c 100644 --- a/0172-Don-t-assume-that-boot-commands-will-only-return-on-.patch +++ b/0120-Don-t-assume-that-boot-commands-will-only-return-on-.patch @@ -1,8 +1,7 @@ -From 8edc8d1d8e0f4a6f4a25c85e4821fbabc8fb2232 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Tue, 9 Apr 2019 13:12:40 +0200 -Subject: [PATCH 172/220] Don't assume that boot commands will only return on - fail +Subject: [PATCH] Don't assume that boot commands will only return on fail While it's true that for most loaders the boot command never returns, it may be the case that it does. For example the GRUB emulator boot command @@ -14,11 +13,11 @@ kexec call later succeeds. Signed-off-by: Javier Martinez Canillas --- - grub-core/normal/menu.c | 19 +++++++++++-------- - 1 file changed, 11 insertions(+), 8 deletions(-) + grub-core/normal/menu.c | 23 +++++++++++++---------- + 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c -index d4832f1..9ea1f41 100644 +index fe2e77a43e2..ec0c92bade0 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -285,7 +285,7 @@ get_and_remove_first_entry_number (grub_menu_t menu, const char *name) @@ -30,6 +29,24 @@ index d4832f1..9ea1f41 100644 grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) { grub_err_t err = GRUB_ERR_NONE; +@@ -302,7 +302,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; +- return; ++ return grub_errno; + } + + errs_before = grub_err_printed_errors; +@@ -315,7 +315,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) + grub_env_context_open (); + menu = grub_zalloc (sizeof (*menu)); + if (! menu) +- return; ++ return grub_errno; + grub_env_set_menu (menu); + if (auto_boot) + grub_env_set ("timeout", "0"); @@ -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 ()) @@ -78,6 +95,3 @@ index d4832f1..9ea1f41 100644 } if (!autobooted) --- -1.8.3.1 - diff --git a/0121-Do-better-in-bootstrap.conf.patch b/0121-Do-better-in-bootstrap.conf.patch new file mode 100644 index 0000000000000000000000000000000000000000..ec9d8ecc15fa1e2b315ee081222aa64a0d02d3d3 --- /dev/null +++ b/0121-Do-better-in-bootstrap.conf.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 29 Jul 2019 10:58:52 -0400 +Subject: [PATCH] Do better in bootstrap.conf + +--- + bootstrap.conf | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/bootstrap.conf b/bootstrap.conf +index 186be9c48ce..9259526e891 100644 +--- a/bootstrap.conf ++++ b/bootstrap.conf +@@ -16,7 +16,13 @@ + # along with this program. If not, see . + + +-GNULIB_REVISION=d271f868a8df9bbec29049d01e056481b7a1a263 ++# GNULIB_REVISION=d271f868a8df9bbec29049d01e056481b7a1a263 ++if [[ -z "${GNULIB_REVISION}" ]] ;then ++ GNULIB_REVISION=fixes ++fi ++if [[ -z "${GNULIB_URL}" ]] ;then ++ GNULIB_URL=https://github.com/rhboot/gnulib.git ++fi + + # gnulib modules used by this package. + # mbswidth is used by gnulib-fix-width.diff's changes to argp rather than diff --git a/0121-grub-core-video-efi_gop.c-Add-support-for-BLT_ONLY-a.patch b/0121-grub-core-video-efi_gop.c-Add-support-for-BLT_ONLY-a.patch deleted file mode 100644 index f12a3f7f517ed2841b6457f8bddb9fb93a55cf2e..0000000000000000000000000000000000000000 --- a/0121-grub-core-video-efi_gop.c-Add-support-for-BLT_ONLY-a.patch +++ /dev/null @@ -1,60 +0,0 @@ -From dc1adda5b575712665a1e5a4d2a86232e34748a8 Mon Sep 17 00:00:00 2001 -From: Alexander Graf -Date: Wed, 1 Feb 2017 23:10:45 +0100 -Subject: [PATCH 121/220] grub-core/video/efi_gop.c: Add support for BLT_ONLY - adapters - -EFI GOP has support for multiple different bitness types of frame buffers -and for a special "BLT only" type which is always defined to be RGBx. - -Because grub2 doesn't ever directly access the frame buffer but instead -only renders graphics via the BLT interface anyway, we can easily support -these adapters. - -The reason this has come up now is the emerging support for virtio-gpu -in OVMF. That adapter does not have the notion of a memory mapped frame -buffer and thus is BLT only. - -Signed-off-by: Alexander Graf ---- - grub-core/video/efi_gop.c | 2 ++ - include/grub/efi/graphics_output.h | 3 ++- - 2 files changed, 4 insertions(+), 1 deletion(-) - -diff --git a/grub-core/video/efi_gop.c b/grub-core/video/efi_gop.c -index 7f9d1c2..c9e40e8 100644 ---- a/grub-core/video/efi_gop.c -+++ b/grub-core/video/efi_gop.c -@@ -121,6 +121,7 @@ grub_video_gop_get_bpp (struct grub_efi_gop_mode_info *in) - { - case GRUB_EFI_GOT_BGRA8: - case GRUB_EFI_GOT_RGBA8: -+ case GRUB_EFI_GOT_BLT_ONLY: - return 32; - - case GRUB_EFI_GOT_BITMASK: -@@ -187,6 +188,7 @@ grub_video_gop_fill_real_mode_info (unsigned mode, - switch (in->pixel_format) - { - case GRUB_EFI_GOT_RGBA8: -+ case GRUB_EFI_GOT_BLT_ONLY: - out->red_mask_size = 8; - out->red_field_pos = 0; - out->green_mask_size = 8; -diff --git a/include/grub/efi/graphics_output.h b/include/grub/efi/graphics_output.h -index 1297774..e438812 100644 ---- a/include/grub/efi/graphics_output.h -+++ b/include/grub/efi/graphics_output.h -@@ -28,7 +28,8 @@ typedef enum - { - GRUB_EFI_GOT_RGBA8, - GRUB_EFI_GOT_BGRA8, -- GRUB_EFI_GOT_BITMASK -+ GRUB_EFI_GOT_BITMASK, -+ GRUB_EFI_GOT_BLT_ONLY, - } - grub_efi_gop_pixel_format_t; - --- -1.8.3.1 - diff --git a/0122-Use-git-to-apply-gnulib-patches.patch b/0122-Use-git-to-apply-gnulib-patches.patch new file mode 100644 index 0000000000000000000000000000000000000000..7654648859f9928d8c4b1df6657a5fdb03bbb742 --- /dev/null +++ b/0122-Use-git-to-apply-gnulib-patches.patch @@ -0,0 +1,631 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 29 Jul 2019 11:21:27 -0400 +Subject: [PATCH] Use git to apply gnulib patches. + +Signed-off-by: Peter Jones +--- + bootstrap.conf | 6 - + conf/Makefile.extra-dist | 10 - + grub-core/lib/gnulib-patches/fix-base64.patch | 21 -- + grub-core/lib/gnulib-patches/fix-null-deref.patch | 13 -- + .../lib/gnulib-patches/fix-null-state-deref.patch | 12 -- + .../gnulib-patches/fix-regcomp-uninit-token.patch | 15 -- + .../gnulib-patches/fix-regexec-null-deref.patch | 12 -- + .../gnulib-patches/fix-sign-compare-errors.patch | 161 --------------- + .../lib/gnulib-patches/fix-uninit-structure.patch | 11 -- + .../lib/gnulib-patches/fix-unused-value.patch | 14 -- + grub-core/lib/gnulib-patches/fix-width.patch | 217 --------------------- + grub-core/lib/gnulib-patches/no-abort.patch | 26 --- + 12 files changed, 518 deletions(-) + delete mode 100644 grub-core/lib/gnulib-patches/fix-base64.patch + delete mode 100644 grub-core/lib/gnulib-patches/fix-null-deref.patch + delete mode 100644 grub-core/lib/gnulib-patches/fix-null-state-deref.patch + delete mode 100644 grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch + delete mode 100644 grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch + delete mode 100644 grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch + delete mode 100644 grub-core/lib/gnulib-patches/fix-uninit-structure.patch + delete mode 100644 grub-core/lib/gnulib-patches/fix-unused-value.patch + delete mode 100644 grub-core/lib/gnulib-patches/fix-width.patch + delete mode 100644 grub-core/lib/gnulib-patches/no-abort.patch + +diff --git a/bootstrap.conf b/bootstrap.conf +index 9259526e891..452f4d79b0d 100644 +--- a/bootstrap.conf ++++ b/bootstrap.conf +@@ -85,12 +85,6 @@ cp -a INSTALL INSTALL.grub + + bootstrap_post_import_hook () { + set -e +- for patchname in fix-base64 fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \ +- fix-regexec-null-deref fix-uninit-structure fix-unused-value fix-width no-abort \ +- fix-sign-compare-errors; do +- patch -d grub-core/lib/gnulib -p2 \ +- < "grub-core/lib/gnulib-patches/$patchname.patch" +- done + for patchname in \ + 0001-Support-POTFILES-shell \ + 0002-Handle-gettext_printf-shell-function \ +diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist +index ea58362b555..8ddf22e6c99 100644 +--- a/conf/Makefile.extra-dist ++++ b/conf/Makefile.extra-dist +@@ -30,16 +30,6 @@ EXTRA_DIST += grub-core/gensymlist.sh + EXTRA_DIST += grub-core/genemuinit.sh + EXTRA_DIST += grub-core/genemuinitheader.sh + +-EXTRA_DIST += grub-core/lib/gnulib-patches/fix-base64.patch +-EXTRA_DIST += grub-core/lib/gnulib-patches/fix-null-deref.patch +-EXTRA_DIST += grub-core/lib/gnulib-patches/fix-null-state-deref.patch +-EXTRA_DIST += grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch +-EXTRA_DIST += grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch +-EXTRA_DIST += grub-core/lib/gnulib-patches/fix-uninit-structure.patch +-EXTRA_DIST += grub-core/lib/gnulib-patches/fix-unused-value.patch +-EXTRA_DIST += grub-core/lib/gnulib-patches/fix-width.patch +-EXTRA_DIST += grub-core/lib/gnulib-patches/no-abort.patch +- + EXTRA_DIST += grub-core/lib/libgcrypt + EXTRA_DIST += grub-core/lib/libgcrypt-grub/mpi/generic + EXTRA_DIST += $(shell find $(top_srcdir)/include -name '*.h') +diff --git a/grub-core/lib/gnulib-patches/fix-base64.patch b/grub-core/lib/gnulib-patches/fix-base64.patch +deleted file mode 100644 +index 985db127971..00000000000 +--- a/grub-core/lib/gnulib-patches/fix-base64.patch ++++ /dev/null +@@ -1,21 +0,0 @@ +-diff --git a/lib/base64.h b/lib/base64.h +-index 9cd0183b8..185a2afa1 100644 +---- a/lib/base64.h +-+++ b/lib/base64.h +-@@ -21,8 +21,14 @@ +- /* Get size_t. */ +- # include +- +--/* Get bool. */ +--# include +-+#ifndef GRUB_POSIX_BOOL_DEFINED +-+typedef enum { false = 0, true = 1 } bool; +-+#define GRUB_POSIX_BOOL_DEFINED 1 +-+#endif +-+ +-+#ifndef _GL_ATTRIBUTE_CONST +-+# define _GL_ATTRIBUTE_CONST /* empty */ +-+#endif +- +- # ifdef __cplusplus +- extern "C" { +diff --git a/grub-core/lib/gnulib-patches/fix-null-deref.patch b/grub-core/lib/gnulib-patches/fix-null-deref.patch +deleted file mode 100644 +index 8fafa153a47..00000000000 +--- a/grub-core/lib/gnulib-patches/fix-null-deref.patch ++++ /dev/null +@@ -1,13 +0,0 @@ +-diff --git a/lib/argp-parse.c b/lib/argp-parse.c +-index 6dec57310..900adad54 100644 +---- a/lib/argp-parse.c +-+++ b/lib/argp-parse.c +-@@ -940,7 +940,7 @@ weak_alias (__argp_parse, argp_parse) +- void * +- __argp_input (const struct argp *argp, const struct argp_state *state) +- { +-- if (state) +-+ if (state && state->pstate) +- { +- struct group *group; +- struct parser *parser = state->pstate; +diff --git a/grub-core/lib/gnulib-patches/fix-null-state-deref.patch b/grub-core/lib/gnulib-patches/fix-null-state-deref.patch +deleted file mode 100644 +index 813ec09c8a1..00000000000 +--- a/grub-core/lib/gnulib-patches/fix-null-state-deref.patch ++++ /dev/null +@@ -1,12 +0,0 @@ +---- a/lib/argp-help.c 2020-10-28 14:32:19.189215988 +0000 +-+++ b/lib/argp-help.c 2020-10-28 14:38:21.204673940 +0000 +-@@ -145,7 +145,8 @@ +- if (*(int *)((char *)upptr + up->uparams_offs) >= upptr->rmargin) +- { +- __argp_failure (state, 0, 0, +-- dgettext (state->root_argp->argp_domain, +-+ dgettext (state == NULL ? NULL +-+ : state->root_argp->argp_domain, +- "\ +- ARGP_HELP_FMT: %s value is less than or equal to %s"), +- "rmargin", up->name); +diff --git a/grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch b/grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch +deleted file mode 100644 +index 02e06315dff..00000000000 +--- a/grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch ++++ /dev/null +@@ -1,15 +0,0 @@ +---- a/lib/regcomp.c 2020-11-24 17:06:08.159223858 +0000 +-+++ b/lib/regcomp.c 2020-11-24 17:06:15.630253923 +0000 +-@@ -3808,11 +3808,7 @@ +- create_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right, +- re_token_type_t type) +- { +-- re_token_t t; +--#if defined GCC_LINT || defined lint +-- memset (&t, 0, sizeof t); +--#endif +-- t.type = type; +-+ re_token_t t = { .type = type }; +- return create_token_tree (dfa, left, right, &t); +- } +- +diff --git a/grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch b/grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch +deleted file mode 100644 +index db6dac9c9e3..00000000000 +--- a/grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch ++++ /dev/null +@@ -1,12 +0,0 @@ +---- a/lib/regexec.c 2020-10-21 14:25:35.310195912 +0000 +-+++ b/lib/regexec.c 2020-11-05 10:55:09.621542984 +0000 +-@@ -1692,6 +1692,9 @@ +- { +- Idx top = mctx->state_log_top; +- +-+ if (mctx->state_log == NULL) +-+ return REG_NOERROR; +-+ +- if ((next_state_log_idx >= mctx->input.bufs_len +- && mctx->input.bufs_len < mctx->input.len) +- || (next_state_log_idx >= mctx->input.valid_len +diff --git a/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch b/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch +deleted file mode 100644 +index 479029c0565..00000000000 +--- a/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch ++++ /dev/null +@@ -1,161 +0,0 @@ +-diff --git a/lib/regcomp.c b/lib/regcomp.c +-index cc85f35ac58..361079d82d6 100644 +---- a/lib/regcomp.c +-+++ b/lib/regcomp.c +-@@ -322,7 +322,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, +- *p++ = dfa->nodes[node].opr.c; +- memset (&state, '\0', sizeof (state)); +- if (__mbrtowc (&wc, (const char *) buf, p - buf, +-- &state) == p - buf +-+ &state) == (size_t)(p - buf) +- && (__wcrtomb ((char *) buf, __towlower (wc), &state) +- != (size_t) -1)) +- re_set_fastmap (fastmap, false, buf[0]); +-@@ -3778,7 +3778,7 @@ fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax) +- num = ((token->type != CHARACTER || c < '0' || '9' < c || num == -2) +- ? -2 +- : num == -1 +-- ? c - '0' +-+ ? (Idx)(c - '0') +- : MIN (RE_DUP_MAX + 1, num * 10 + c - '0')); +- } +- return num; +-diff --git a/lib/regex_internal.c b/lib/regex_internal.c +-index 9004ce809eb..193a1e3d332 100644 +---- a/lib/regex_internal.c +-+++ b/lib/regex_internal.c +-@@ -233,7 +233,7 @@ build_wcs_buffer (re_string_t *pstr) +- /* Apply the translation if we need. */ +- if (__glibc_unlikely (pstr->trans != NULL)) +- { +-- int i, ch; +-+ unsigned int i, ch; +- +- for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) +- { +-@@ -376,7 +376,7 @@ build_wcs_upper_buffer (re_string_t *pstr) +- prev_st = pstr->cur_state; +- if (__glibc_unlikely (pstr->trans != NULL)) +- { +-- int i, ch; +-+ unsigned int i, ch; +- +- for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) +- { +-@@ -754,7 +754,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) +- memset (&cur_state, 0, sizeof (cur_state)); +- mbclen = __mbrtowc (&wc2, (const char *) pp, mlen, +- &cur_state); +-- if (raw + offset - p <= mbclen +-+ if ((size_t)(raw + offset - p) <= mbclen +- && mbclen < (size_t) -2) +- { +- memset (&pstr->cur_state, '\0', +-diff --git a/lib/regex_internal.h b/lib/regex_internal.h +-index 5462419b787..e0f8292395d 100644 +---- a/lib/regex_internal.h +-+++ b/lib/regex_internal.h +-@@ -425,7 +425,7 @@ struct re_string_t +- unsigned char offsets_needed; +- unsigned char newline_anchor; +- unsigned char word_ops_used; +-- int mb_cur_max; +-+ unsigned int mb_cur_max; +- }; +- typedef struct re_string_t re_string_t; +- +-@@ -702,7 +702,7 @@ struct re_dfa_t +- unsigned int is_utf8 : 1; +- unsigned int map_notascii : 1; +- unsigned int word_ops_used : 1; +-- int mb_cur_max; +-+ unsigned int mb_cur_max; +- bitset_t word_char; +- reg_syntax_t syntax; +- Idx *subexp_map; +-diff --git a/lib/regexec.c b/lib/regexec.c +-index 0a7a27b772e..b57d4f9141d 100644 +---- a/lib/regexec.c +-+++ b/lib/regexec.c +-@@ -443,7 +443,7 @@ re_search_stub (struct re_pattern_buffer *bufp, const char *string, Idx length, +- { +- if (ret_len) +- { +-- assert (pmatch[0].rm_so == start); +-+ assert (pmatch[0].rm_so == (long)start); +- rval = pmatch[0].rm_eo - start; +- } +- else +-@@ -877,11 +877,11 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, +- if (__glibc_unlikely (mctx.input.offsets_needed != 0)) +- { +- pmatch[reg_idx].rm_so = +-- (pmatch[reg_idx].rm_so == mctx.input.valid_len +-+ (pmatch[reg_idx].rm_so == (long)mctx.input.valid_len +- ? mctx.input.valid_raw_len +- : mctx.input.offsets[pmatch[reg_idx].rm_so]); +- pmatch[reg_idx].rm_eo = +-- (pmatch[reg_idx].rm_eo == mctx.input.valid_len +-+ (pmatch[reg_idx].rm_eo == (long)mctx.input.valid_len +- ? mctx.input.valid_raw_len +- : mctx.input.offsets[pmatch[reg_idx].rm_eo]); +- } +-@@ -1418,11 +1418,11 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, +- } +- memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch); +- +-- for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;) +-+ for (idx = pmatch[0].rm_so; idx <= (long)pmatch[0].rm_eo ;) +- { +- update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch); +- +-- if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node) +-+ if (idx == (long)pmatch[0].rm_eo && cur_node == mctx->last_node) +- { +- Idx reg_idx; +- if (fs) +-@@ -1519,7 +1519,7 @@ update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, +- if (reg_num < nmatch) +- { +- /* We are at the last node of this sub expression. */ +-- if (pmatch[reg_num].rm_so < cur_idx) +-+ if (pmatch[reg_num].rm_so < (long)cur_idx) +- { +- pmatch[reg_num].rm_eo = cur_idx; +- /* This is a non-empty match or we are not inside an optional +-@@ -2938,7 +2938,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, +- mctx->state_log[str_idx] = cur_state; +- } +- +-- for (null_cnt = 0; str_idx < last_str && null_cnt <= mctx->max_mb_elem_len;) +-+ for (null_cnt = 0; str_idx < last_str && null_cnt <= (long)mctx->max_mb_elem_len;) +- { +- re_node_set_empty (&next_nodes); +- if (mctx->state_log[str_idx + 1]) +-@@ -3718,7 +3718,7 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, +- const re_string_t *input, Idx str_idx) +- { +- const re_token_t *node = dfa->nodes + node_idx; +-- int char_len, elem_len; +-+ unsigned int char_len, elem_len; +- Idx i; +- +- if (__glibc_unlikely (node->type == OP_UTF8_PERIOD)) +-@@ -4066,7 +4066,7 @@ extend_buffers (re_match_context_t *mctx, int min_len) +- /* Double the lengths of the buffers, but allocate at least MIN_LEN. */ +- ret = re_string_realloc_buffers (pstr, +- MAX (min_len, +-- MIN (pstr->len, pstr->bufs_len * 2))); +-+ MIN ((long)pstr->len, pstr->bufs_len * 2))); +- if (__glibc_unlikely (ret != REG_NOERROR)) +- return ret; +- +-@@ -4236,7 +4236,7 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, +- = (from == to ? -1 : 0); +- +- mctx->bkref_ents[mctx->nbkref_ents++].more = 0; +-- if (mctx->max_mb_elem_len < to - from) +-+ if (mctx->max_mb_elem_len < (long)(to - from)) +- mctx->max_mb_elem_len = to - from; +- return REG_NOERROR; +- } +diff --git a/grub-core/lib/gnulib-patches/fix-uninit-structure.patch b/grub-core/lib/gnulib-patches/fix-uninit-structure.patch +deleted file mode 100644 +index 7b4d9f67af4..00000000000 +--- a/grub-core/lib/gnulib-patches/fix-uninit-structure.patch ++++ /dev/null +@@ -1,11 +0,0 @@ +---- a/lib/regcomp.c 2020-10-22 13:49:06.770168928 +0000 +-+++ b/lib/regcomp.c 2020-10-22 13:50:37.026528298 +0000 +-@@ -3662,7 +3662,7 @@ +- Idx alloc = 0; +- #endif /* not RE_ENABLE_I18N */ +- reg_errcode_t ret; +-- re_token_t br_token; +-+ re_token_t br_token = {0}; +- bin_tree_t *tree; +- +- sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); +diff --git a/grub-core/lib/gnulib-patches/fix-unused-value.patch b/grub-core/lib/gnulib-patches/fix-unused-value.patch +deleted file mode 100644 +index ba51f1bf223..00000000000 +--- a/grub-core/lib/gnulib-patches/fix-unused-value.patch ++++ /dev/null +@@ -1,14 +0,0 @@ +---- a/lib/regexec.c 2020-10-21 14:25:35.310195912 +0000 +-+++ b/lib/regexec.c 2020-10-21 14:32:07.961765604 +0000 +-@@ -828,7 +828,11 @@ +- break; +- if (__glibc_unlikely (err != REG_NOMATCH)) +- goto free_return; +-+#ifdef DEBUG +-+ /* Only used for assertion below when DEBUG is set, otherwise +-+ it will be over-written when we loop around. */ +- match_last = -1; +-+#endif +- } +- else +- break; /* We found a match. */ +diff --git a/grub-core/lib/gnulib-patches/fix-width.patch b/grub-core/lib/gnulib-patches/fix-width.patch +deleted file mode 100644 +index 0a208ad08b5..00000000000 +--- a/grub-core/lib/gnulib-patches/fix-width.patch ++++ /dev/null +@@ -1,217 +0,0 @@ +-diff --git a/lib/argp-fmtstream.c b/lib/argp-fmtstream.c +-index ba6a407f7..d0685b3d4 100644 +---- a/lib/argp-fmtstream.c +-+++ b/lib/argp-fmtstream.c +-@@ -28,9 +28,11 @@ +- #include +- #include +- #include +-+#include +- +- #include "argp-fmtstream.h" +- #include "argp-namefrob.h" +-+#include "mbswidth.h" +- +- #ifndef ARGP_FMTSTREAM_USE_LINEWRAP +- +-@@ -115,6 +117,51 @@ weak_alias (__argp_fmtstream_free, argp_fmtstream_free) +- #endif +- #endif +- +-+ +-+/* Return the pointer to the first character that doesn't fit in l columns. */ +-+static inline const ptrdiff_t +-+add_width (const char *ptr, const char *end, size_t l) +-+{ +-+ mbstate_t ps; +-+ const char *ptr0 = ptr; +-+ +-+ memset (&ps, 0, sizeof (ps)); +-+ +-+ while (ptr < end) +-+ { +-+ wchar_t wc; +-+ size_t s, k; +-+ +-+ s = mbrtowc (&wc, ptr, end - ptr, &ps); +-+ if (s == (size_t) -1) +-+ break; +-+ if (s == (size_t) -2) +-+ { +-+ if (1 >= l) +-+ break; +-+ l--; +-+ ptr++; +-+ continue; +-+ } +-+ +-+ if (wc == '\e' && ptr + 3 < end +-+ && ptr[1] == '[' && (ptr[2] == '0' || ptr[2] == '1') +-+ && ptr[3] == 'm') +-+ { +-+ ptr += 4; +-+ continue; +-+ } +-+ +-+ k = wcwidth (wc); +-+ +-+ if (k >= l) +-+ break; +-+ l -= k; +-+ ptr += s; +-+ } +-+ return ptr - ptr0; +-+} +-+ +- /* Process FS's buffer so that line wrapping is done from POINT_OFFS to the +- end of its buffer. This code is mostly from glibc stdio/linewrap.c. */ +- void +-@@ -168,13 +215,15 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +- if (!nl) +- { +- /* The buffer ends in a partial line. */ +-+ size_t display_width = mbsnwidth (buf, fs->p - buf, +-+ MBSW_STOP_AT_NUL); +- +-- if (fs->point_col + len < fs->rmargin) +-+ if (fs->point_col + display_width < fs->rmargin) +- { +- /* The remaining buffer text is a partial line and fits +- within the maximum line width. Advance point for the +- characters to be written and stop scanning. */ +-- fs->point_col += len; +-+ fs->point_col += display_width; +- break; +- } +- else +-@@ -182,14 +231,18 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +- the end of the buffer. */ +- nl = fs->p; +- } +-- else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin) +-- { +-- /* The buffer contains a full line that fits within the maximum +-- line width. Reset point and scan the next line. */ +-- fs->point_col = 0; +-- buf = nl + 1; +-- continue; +-- } +-+ else +-+ { +-+ size_t display_width = mbsnwidth (buf, nl - buf, MBSW_STOP_AT_NUL); +-+ if (display_width < (ssize_t) fs->rmargin) +-+ { +-+ /* The buffer contains a full line that fits within the maximum +-+ line width. Reset point and scan the next line. */ +-+ fs->point_col = 0; +-+ buf = nl + 1; +-+ continue; +-+ } +-+ } +- +- /* This line is too long. */ +- r = fs->rmargin - 1; +-@@ -225,7 +278,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +- char *p, *nextline; +- int i; +- +-- p = buf + (r + 1 - fs->point_col); +-+ p = buf + add_width (buf, fs->p, (r + 1 - fs->point_col)); +- while (p >= buf && !isblank ((unsigned char) *p)) +- --p; +- nextline = p + 1; /* This will begin the next line. */ +-@@ -243,7 +296,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +- { +- /* A single word that is greater than the maximum line width. +- Oh well. Put it on an overlong line by itself. */ +-- p = buf + (r + 1 - fs->point_col); +-+ p = buf + add_width (buf, fs->p, (r + 1 - fs->point_col)); +- /* Find the end of the long word. */ +- if (p < nl) +- do +-@@ -277,7 +330,8 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +- && fs->p > nextline) +- { +- /* The margin needs more blanks than we removed. */ +-- if (fs->end - fs->p > fs->wmargin + 1) +-+ if (mbsnwidth (fs->p, fs->end - fs->p, MBSW_STOP_AT_NUL) +-+ > fs->wmargin + 1) +- /* Make some space for them. */ +- { +- size_t mv = fs->p - nextline; +-diff --git a/lib/argp-help.c b/lib/argp-help.c +-index e5375a0f0..5d8f451ec 100644 +---- a/lib/argp-help.c +-+++ b/lib/argp-help.c +-@@ -51,6 +51,7 @@ +- #include "argp.h" +- #include "argp-fmtstream.h" +- #include "argp-namefrob.h" +-+#include "mbswidth.h" +- +- #ifndef SIZE_MAX +- # define SIZE_MAX ((size_t) -1) +-@@ -1432,7 +1433,7 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state, +- +- /* Manually do line wrapping so that it (probably) won't get wrapped at +- any embedded spaces. */ +-- space (stream, 1 + nl - cp); +-+ space (stream, 1 + mbsnwidth (cp, nl - cp, MBSW_STOP_AT_NUL)); +- +- __argp_fmtstream_write (stream, cp, nl - cp); +- } +-diff --git a/lib/mbswidth.c b/lib/mbswidth.c +-index 408a15e34..b3fb7f83a 100644 +---- a/lib/mbswidth.c +-+++ b/lib/mbswidth.c +-@@ -38,6 +38,14 @@ +- /* Get INT_MAX. */ +- #include +- +-+#ifndef FALLTHROUGH +-+# if __GNUC__ < 7 +-+# define FALLTHROUGH ((void) 0) +-+# else +-+# define FALLTHROUGH __attribute__ ((__fallthrough__)) +-+# endif +-+#endif +-+ +- /* Returns the number of columns needed to represent the multibyte +- character string pointed to by STRING. If a non-printable character +- occurs, and MBSW_REJECT_UNPRINTABLE is specified, -1 is returned. +-@@ -90,6 +98,10 @@ mbsnwidth (const char *string, size_t nbytes, int flags) +- p++; +- width++; +- break; +-+ case '\0': +-+ if (flags & MBSW_STOP_AT_NUL) +-+ return width; +-+ FALLTHROUGH; +- default: +- /* If we have a multibyte sequence, scan it up to its end. */ +- { +-@@ -168,6 +180,9 @@ mbsnwidth (const char *string, size_t nbytes, int flags) +- { +- unsigned char c = (unsigned char) *p++; +- +-+ if (c == 0 && (flags & MBSW_STOP_AT_NUL)) +-+ return width; +-+ +- if (isprint (c)) +- { +- if (width == INT_MAX) +-diff --git a/lib/mbswidth.h b/lib/mbswidth.h +-index 2b5c53c37..45a123e63 100644 +---- a/lib/mbswidth.h +-+++ b/lib/mbswidth.h +-@@ -45,6 +45,10 @@ extern "C" { +- control characters and 1 otherwise. */ +- #define MBSW_REJECT_UNPRINTABLE 2 +- +-+/* If this bit is set \0 is treated as the end of string. +-+ Otherwise it's treated as a normal one column width character. */ +-+#define MBSW_STOP_AT_NUL 4 +-+ +- +- /* Returns the number of screen columns needed for STRING. */ +- #define mbswidth gnu_mbswidth /* avoid clash with UnixWare 7.1.1 function */ +diff --git a/grub-core/lib/gnulib-patches/no-abort.patch b/grub-core/lib/gnulib-patches/no-abort.patch +deleted file mode 100644 +index e469c4762eb..00000000000 +--- a/grub-core/lib/gnulib-patches/no-abort.patch ++++ /dev/null +@@ -1,26 +0,0 @@ +-diff --git a/lib/regcomp.c b/lib/regcomp.c +-index cc85f35ac..de45ebb5c 100644 +---- a/lib/regcomp.c +-+++ b/lib/regcomp.c +-@@ -528,9 +528,9 @@ regerror (int errcode, const regex_t *__restrict preg, char *__restrict errbuf, +- to this routine. If we are given anything else, or if other regex +- code generates an invalid error code, then the program has a bug. +- Dump core so we can fix it. */ +-- abort (); +-- +-- msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]); +-+ msg = gettext ("unknown regexp error"); +-+ else +-+ msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]); +- +- msg_size = strlen (msg) + 1; /* Includes the null. */ +- +-@@ -1136,7 +1136,7 @@ optimize_utf8 (re_dfa_t *dfa) +- } +- break; +- default: +-- abort (); +-+ break; +- } +- +- if (mb_chars || has_period) diff --git a/0122-efi-uga-use-64-bit-for-fb_base.patch b/0122-efi-uga-use-64-bit-for-fb_base.patch deleted file mode 100644 index a08c153f176183e6ad211c3427e8f4adea1d7a0d..0000000000000000000000000000000000000000 --- a/0122-efi-uga-use-64-bit-for-fb_base.patch +++ /dev/null @@ -1,108 +0,0 @@ -From 0cb697c89b068b6a130150fb5f980fd7e17da387 Mon Sep 17 00:00:00 2001 -From: Andrei Borzenkov -Date: Wed, 16 May 2018 13:06:04 -0400 -Subject: [PATCH 122/220] efi/uga: use 64 bit for fb_base - -We get 64 bit from PCI BAR but then truncate by assigning to 32 bit. -Make sure to check that pointer does not overflow on 32 bit platform. - -Closes: 50931 ---- - grub-core/video/efi_uga.c | 31 ++++++++++++++++--------------- - 1 file changed, 16 insertions(+), 15 deletions(-) - -diff --git a/grub-core/video/efi_uga.c b/grub-core/video/efi_uga.c -index 044af1d..97a607c 100644 ---- a/grub-core/video/efi_uga.c -+++ b/grub-core/video/efi_uga.c -@@ -34,7 +34,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); - - static grub_efi_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID; - static struct grub_efi_uga_draw_protocol *uga; --static grub_uint32_t uga_fb; -+static grub_uint64_t uga_fb; - static grub_uint32_t uga_pitch; - - static struct -@@ -52,7 +52,7 @@ static struct - #define FBTEST_COUNT 8 - - static int --find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len) -+find_line_len (grub_uint64_t *fb_base, grub_uint32_t *line_len) - { - grub_uint32_t *base = (grub_uint32_t *) (grub_addr_t) *fb_base; - int i; -@@ -67,7 +67,7 @@ find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len) - { - if ((base[j] & RGB_MASK) == RGB_MAGIC) - { -- *fb_base = (grub_uint32_t) (grub_addr_t) base; -+ *fb_base = (grub_uint64_t) (grub_addr_t) base; - *line_len = j << 2; - - return 1; -@@ -84,7 +84,7 @@ find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len) - /* Context for find_framebuf. */ - struct find_framebuf_ctx - { -- grub_uint32_t *fb_base; -+ grub_uint64_t *fb_base; - grub_uint32_t *line_len; - int found; - }; -@@ -129,7 +129,9 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) - if (i == 5) - break; - -- old_bar2 = grub_pci_read (addr + 4); -+ i++; -+ addr += 4; -+ old_bar2 = grub_pci_read (addr); - } - else - old_bar2 = 0; -@@ -138,10 +140,15 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) - base64 <<= 32; - base64 |= (old_bar1 & GRUB_PCI_ADDR_MEM_MASK); - -- grub_dprintf ("fb", "%s(%d): 0x%llx\n", -+ grub_dprintf ("fb", "%s(%d): 0x%" PRIxGRUB_UINT64_T "\n", - ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) ? -- "VMEM" : "MMIO"), i, -- (unsigned long long) base64); -+ "VMEM" : "MMIO"), type == GRUB_PCI_ADDR_MEM_TYPE_64 ? i - 1 : i, -+ base64); -+ -+#if GRUB_CPU_SIZEOF_VOID_P == 4 -+ if (old_bar2) -+ continue; -+#endif - - if ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) && (! ctx->found)) - { -@@ -149,12 +156,6 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) - if (find_line_len (ctx->fb_base, ctx->line_len)) - ctx->found++; - } -- -- if (type == GRUB_PCI_ADDR_MEM_TYPE_64) -- { -- i++; -- addr += 4; -- } - } - } - -@@ -162,7 +163,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) - } - - static int --find_framebuf (grub_uint32_t *fb_base, grub_uint32_t *line_len) -+find_framebuf (grub_uint64_t *fb_base, grub_uint32_t *line_len) - { - struct find_framebuf_ctx ctx = { - .fb_base = fb_base, --- -1.8.3.1 - diff --git a/0123-EFI-console-Do-not-set-text-mode-until-we-actually-n.patch b/0123-EFI-console-Do-not-set-text-mode-until-we-actually-n.patch deleted file mode 100644 index 8040da5b4e40802c9217925f56dbd35a3c132c13..0000000000000000000000000000000000000000 --- a/0123-EFI-console-Do-not-set-text-mode-until-we-actually-n.patch +++ /dev/null @@ -1,188 +0,0 @@ -From de237e1a95e9526f500d7de8264a481a1cc0201a Mon Sep 17 00:00:00 2001 -From: Hans de Goede -Date: Tue, 6 Mar 2018 17:11:15 +0100 -Subject: [PATCH 123/220] EFI: console: Do not set text-mode until we actually - need it - -If we're running with a hidden menu we may never need text mode, so do not -change the video-mode to text until we actually need it. - -Signed-off-by: Hans de Goede ---- - grub-core/term/efi/console.c | 65 ++++++++++++++++++++++++++++++-------------- - 1 file changed, 44 insertions(+), 21 deletions(-) - -diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c -index 4840cc5..051633d 100644 ---- a/grub-core/term/efi/console.c -+++ b/grub-core/term/efi/console.c -@@ -24,6 +24,11 @@ - #include - #include - -+static grub_err_t grub_prepare_for_text_output(struct grub_term_output *term); -+ -+static int text_mode_available = -1; -+static int text_colorstate = -1; -+ - static grub_uint32_t - map_char (grub_uint32_t c) - { -@@ -66,14 +71,14 @@ map_char (grub_uint32_t c) - } - - static void --grub_console_putchar (struct grub_term_output *term __attribute__ ((unused)), -+grub_console_putchar (struct grub_term_output *term, - const struct grub_unicode_glyph *c) - { - grub_efi_char16_t str[2 + 30]; - grub_efi_simple_text_output_interface_t *o; - unsigned i, j; - -- if (grub_efi_is_finished) -+ if (grub_prepare_for_text_output (term)) - return; - - o = grub_efi_system_table->con_out; -@@ -223,14 +228,15 @@ grub_console_getkey (struct grub_term_input *term) - } - - static struct grub_term_coordinate --grub_console_getwh (struct grub_term_output *term __attribute__ ((unused))) -+grub_console_getwh (struct grub_term_output *term) - { - grub_efi_simple_text_output_interface_t *o; - grub_efi_uintn_t columns, rows; - - o = grub_efi_system_table->con_out; -- if (grub_efi_is_finished || efi_call_4 (o->query_mode, o, o->mode->mode, -- &columns, &rows) != GRUB_EFI_SUCCESS) -+ if (grub_prepare_for_text_output (term) != GRUB_ERR_NONE || -+ efi_call_4 (o->query_mode, o, o->mode->mode, -+ &columns, &rows) != GRUB_EFI_SUCCESS) - { - /* Why does this fail? */ - columns = 80; -@@ -245,7 +251,7 @@ grub_console_getxy (struct grub_term_output *term __attribute__ ((unused))) - { - grub_efi_simple_text_output_interface_t *o; - -- if (grub_efi_is_finished) -+ if (grub_efi_is_finished || text_mode_available != 1) - return (struct grub_term_coordinate) { 0, 0 }; - - o = grub_efi_system_table->con_out; -@@ -253,12 +259,12 @@ grub_console_getxy (struct grub_term_output *term __attribute__ ((unused))) - } - - static void --grub_console_gotoxy (struct grub_term_output *term __attribute__ ((unused)), -+grub_console_gotoxy (struct grub_term_output *term, - struct grub_term_coordinate pos) - { - grub_efi_simple_text_output_interface_t *o; - -- if (grub_efi_is_finished) -+ if (grub_prepare_for_text_output (term)) - return; - - o = grub_efi_system_table->con_out; -@@ -271,7 +277,7 @@ grub_console_cls (struct grub_term_output *term __attribute__ ((unused))) - grub_efi_simple_text_output_interface_t *o; - grub_efi_int32_t orig_attr; - -- if (grub_efi_is_finished) -+ if (grub_efi_is_finished || text_mode_available != 1) - return; - - o = grub_efi_system_table->con_out; -@@ -291,6 +297,12 @@ grub_console_setcolorstate (struct grub_term_output *term - if (grub_efi_is_finished) - return; - -+ if (text_mode_available != 1) { -+ /* Avoid "color_normal" environment writes causing a switch to textmode */ -+ text_colorstate = state; -+ return; -+ } -+ - o = grub_efi_system_table->con_out; - - switch (state) { -@@ -315,7 +327,7 @@ grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)), - { - grub_efi_simple_text_output_interface_t *o; - -- if (grub_efi_is_finished) -+ if (grub_efi_is_finished || text_mode_available != 1) - return; - - o = grub_efi_system_table->con_out; -@@ -323,18 +335,38 @@ grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)), - } - - static grub_err_t --grub_efi_console_output_init (struct grub_term_output *term) -+grub_prepare_for_text_output(struct grub_term_output *term) - { -- grub_efi_set_text_mode (1); -+ if (grub_efi_is_finished) -+ return GRUB_ERR_BAD_DEVICE; -+ -+ if (text_mode_available != -1) -+ return text_mode_available ? 0 : GRUB_ERR_BAD_DEVICE; -+ -+ if (! grub_efi_set_text_mode (1)) -+ { -+ /* This really should never happen */ -+ grub_error (GRUB_ERR_BAD_DEVICE, "cannot set text mode"); -+ text_mode_available = 0; -+ return GRUB_ERR_BAD_DEVICE; -+ } -+ - grub_console_setcursor (term, 1); -+ if (text_colorstate != -1) -+ grub_console_setcolorstate (term, text_colorstate); -+ text_mode_available = 1; - return 0; - } - - static grub_err_t - grub_efi_console_output_fini (struct grub_term_output *term) - { -+ if (text_mode_available != 1) -+ return 0; -+ - grub_console_setcursor (term, 0); - grub_efi_set_text_mode (0); -+ text_mode_available = -1; - return 0; - } - -@@ -348,7 +380,6 @@ static struct grub_term_input grub_console_term_input = - static struct grub_term_output grub_console_term_output = - { - .name = "console", -- .init = grub_efi_console_output_init, - .fini = grub_efi_console_output_fini, - .putchar = grub_console_putchar, - .getwh = grub_console_getwh, -@@ -364,14 +395,6 @@ static struct grub_term_output grub_console_term_output = - void - grub_console_init (void) - { -- /* FIXME: it is necessary to consider the case where no console control -- is present but the default is already in text mode. */ -- if (! grub_efi_set_text_mode (1)) -- { -- grub_error (GRUB_ERR_BAD_DEVICE, "cannot set text mode"); -- return; -- } -- - grub_term_register_output ("console", &grub_console_term_output); - grub_term_register_input ("console", &grub_console_term_input); - } --- -1.8.3.1 - diff --git a/0182-grub-set-bootflag-Update-comment-about-running-as-ro.patch b/0123-grub-set-bootflag-Update-comment-about-running-as-ro.patch similarity index 79% rename from 0182-grub-set-bootflag-Update-comment-about-running-as-ro.patch rename to 0123-grub-set-bootflag-Update-comment-about-running-as-ro.patch index abaf89c41b385cca272d5cac08ac6a2e51f68ed2..cd4ef77508ceaef567291cd93af9b66cfd6e6317 100644 --- a/0182-grub-set-bootflag-Update-comment-about-running-as-ro.patch +++ b/0123-grub-set-bootflag-Update-comment-about-running-as-ro.patch @@ -1,8 +1,8 @@ -From 791c8d7fcd59c406f5d61e79950cdf08bd732617 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Wed, 13 Nov 2019 12:15:43 +0100 -Subject: [PATCH 182/220] grub-set-bootflag: Update comment about running as - root through pkexec +Subject: [PATCH] grub-set-bootflag: Update comment about running as root + through pkexec We have stopped using pkexec for grub-set-bootflag, instead it is now installed suid root, update the comment accordingly. @@ -13,7 +13,7 @@ Signed-off-by: Hans de Goede 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c -index 6a79ee6..65d74ce 100644 +index 6a79ee67444..65d74ce010f 100644 --- a/util/grub-set-bootflag.c +++ b/util/grub-set-bootflag.c @@ -18,7 +18,7 @@ @@ -25,6 +25,3 @@ index 6a79ee6..65d74ce 100644 * use any grub library / util functions to allow for easy auditing. * The grub headers are only included to get certain defines. */ --- -1.8.3.1 - diff --git a/0124-EFI-console-Add-grub_console_read_key_stroke-helper-.patch b/0124-EFI-console-Add-grub_console_read_key_stroke-helper-.patch deleted file mode 100644 index bbcb6c3fa7c8b01a0a6cb5cd619beb66a1a0084c..0000000000000000000000000000000000000000 --- a/0124-EFI-console-Add-grub_console_read_key_stroke-helper-.patch +++ /dev/null @@ -1,105 +0,0 @@ -From 6662c908c594e9b6bd6d3b7102c56310002cc5af Mon Sep 17 00:00:00 2001 -From: Hans de Goede -Date: Wed, 6 Jun 2018 15:54:44 +0200 -Subject: [PATCH 124/220] EFI: console: Add grub_console_read_key_stroke() - helper function - -This is a preparation patch for adding getkeystatus() support to the -EFI console terminal input driver. - -We can get modifier status through the simple_text_input read_key_stroke -method, but if a non-modifier key is (also) pressed the read_key_stroke -call will consume that key from the firmware's queue. - -The new grub_console_read_key_stroke() helper buffers upto 1 key-stroke. -If it has a non-modifier key buffered, it will return that one, if its -buffer is empty, it will fills its buffer by getting a new key-stroke. - -If called with consume=1 it will empty its buffer after copying the -key-data to the callers buffer, this is how getkey() will use it. - -If called with consume=0 it will keep the last key-stroke buffered, this -is how getkeystatus() will call it. This means that if a non-modifier -key gets pressed, repeated getkeystatus() calls will return the modifiers -of that key-press until it is consumed by a getkey() call. - -Signed-off-by: Hans de Goede ---- - grub-core/term/efi/console.c | 51 ++++++++++++++++++++++++++++++++++---------- - 1 file changed, 40 insertions(+), 11 deletions(-) - -diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c -index 051633d..3d36c5c 100644 ---- a/grub-core/term/efi/console.c -+++ b/grub-core/term/efi/console.c -@@ -157,27 +157,56 @@ grub_console_getkey_con (struct grub_term_input *term __attribute__ ((unused))) - return grub_efi_translate_key(key); - } - -+/* -+ * When more then just modifiers are pressed, our getkeystatus() consumes a -+ * press from the queue, this function buffers the press for the regular -+ * getkey() so that it does not get lost. -+ */ - static int --grub_console_getkey_ex(struct grub_term_input *term) -+grub_console_read_key_stroke ( -+ grub_efi_simple_text_input_ex_interface_t *text_input, -+ grub_efi_key_data_t *key_data_ret, int *key_ret, -+ int consume) - { -- grub_efi_key_data_t key_data; -+ static grub_efi_key_data_t key_data; - grub_efi_status_t status; -- grub_efi_uint32_t kss; -- int key = -1; -+ int key; - -- grub_efi_simple_text_input_ex_interface_t *text_input = term->data; -+ if (!text_input) -+ return GRUB_ERR_EOF; - -- status = efi_call_2 (text_input->read_key_stroke, text_input, &key_data); -+ key = grub_efi_translate_key (key_data.key); -+ if (key == GRUB_TERM_NO_KEY) { -+ status = efi_call_2 (text_input->read_key_stroke, text_input, &key_data); -+ if (status != GRUB_EFI_SUCCESS) -+ return GRUB_ERR_EOF; - -- if (status != GRUB_EFI_SUCCESS) -- return GRUB_TERM_NO_KEY; -+ key = grub_efi_translate_key (key_data.key); -+ } - -- kss = key_data.key_state.key_shift_state; -- key = grub_efi_translate_key(key_data.key); -+ *key_data_ret = key_data; -+ *key_ret = key; -+ -+ if (consume) { -+ key_data.key.scan_code = 0; -+ key_data.key.unicode_char = 0; -+ } -+ -+ return 0; -+} -+ -+static int -+grub_console_getkey_ex(struct grub_term_input *term) -+{ -+ grub_efi_key_data_t key_data; -+ grub_efi_uint32_t kss; -+ int key = -1; - -- if (key == GRUB_TERM_NO_KEY) -+ if (grub_console_read_key_stroke (term->data, &key_data, &key, 1) || -+ key == GRUB_TERM_NO_KEY) - return GRUB_TERM_NO_KEY; - -+ kss = key_data.key_state.key_shift_state; - if (kss & GRUB_EFI_SHIFT_STATE_VALID) - { - if ((kss & GRUB_EFI_LEFT_SHIFT_PRESSED --- -1.8.3.1 - diff --git a/0183-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch b/0124-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch similarity index 95% rename from 0183-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch rename to 0124-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch index a97854dfbfc3c796fdd90ac842f87c2249d2bd9c..122bf68689a6ef1321d50c3f0b26442a50570e3e 100644 --- a/0183-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch +++ b/0124-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch @@ -1,8 +1,7 @@ -From d70d66650887f945e402dd0e1099c9d639d6dc8b Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Wed, 13 Nov 2019 13:02:01 +0100 -Subject: [PATCH 183/220] grub-set-bootflag: Write new env to tmpfile and then - rename +Subject: [PATCH] grub-set-bootflag: Write new env to tmpfile and then rename Make the grubenv writing code in grub-set-bootflag more robust by writing the modified grubenv to a tmpfile first and then renaming the @@ -14,7 +13,7 @@ Signed-off-by: Hans de Goede 1 file changed, 78 insertions(+), 9 deletions(-) diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c -index 65d74ce..d1c5e28 100644 +index 65d74ce010f..d1c5e28862b 100644 --- a/util/grub-set-bootflag.c +++ b/util/grub-set-bootflag.c @@ -28,7 +28,9 @@ @@ -151,6 +150,3 @@ index 65d74ce..d1c5e28 100644 return 0; } --- -1.8.3.1 - diff --git a/0125-EFI-console-Implement-getkeystatus-support.patch b/0125-EFI-console-Implement-getkeystatus-support.patch deleted file mode 100644 index 3410681b0cbefee3a39babf63240def43c667dcd..0000000000000000000000000000000000000000 --- a/0125-EFI-console-Implement-getkeystatus-support.patch +++ /dev/null @@ -1,75 +0,0 @@ -From 05bea373a5f88292528ed2b2fef16448f0265771 Mon Sep 17 00:00:00 2001 -From: Hans de Goede -Date: Wed, 6 Jun 2018 16:16:47 +0200 -Subject: [PATCH 125/220] EFI: console: Implement getkeystatus() support - -Implement getkeystatus() support. - -Note that if a non-modifier key gets pressed and repeated calls to -getkeystatus() are made then it will return the modifier status at the -time of the non-modifier key, until that key-press gets consumed by a -getkey() call. - -This is a side-effect of how the EFI simple-text-input protocol works -and cannot be avoided. - -Signed-off-by: Hans de Goede ---- - grub-core/term/efi/console.c | 34 ++++++++++++++++++++++++++++++++++ - 1 file changed, 34 insertions(+) - -diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c -index 3d36c5c..92dd499 100644 ---- a/grub-core/term/efi/console.c -+++ b/grub-core/term/efi/console.c -@@ -223,6 +223,39 @@ grub_console_getkey_ex(struct grub_term_input *term) - return key; - } - -+static int -+grub_console_getkeystatus(struct grub_term_input *term) -+{ -+ grub_efi_key_data_t key_data; -+ grub_efi_uint32_t kss; -+ int key, mods = 0; -+ -+ if (grub_efi_is_finished) -+ return 0; -+ -+ if (grub_console_read_key_stroke (term->data, &key_data, &key, 0)) -+ return 0; -+ -+ kss = key_data.key_state.key_shift_state; -+ if (kss & GRUB_EFI_SHIFT_STATE_VALID) -+ { -+ if (kss & GRUB_EFI_LEFT_SHIFT_PRESSED) -+ mods |= GRUB_TERM_STATUS_LSHIFT; -+ if (kss & GRUB_EFI_RIGHT_SHIFT_PRESSED) -+ mods |= GRUB_TERM_STATUS_RSHIFT; -+ if (kss & GRUB_EFI_LEFT_ALT_PRESSED) -+ mods |= GRUB_TERM_STATUS_LALT; -+ if (kss & GRUB_EFI_RIGHT_ALT_PRESSED) -+ mods |= GRUB_TERM_STATUS_RALT; -+ if (kss & GRUB_EFI_LEFT_CONTROL_PRESSED) -+ mods |= GRUB_TERM_STATUS_LCTRL; -+ if (kss & GRUB_EFI_RIGHT_CONTROL_PRESSED) -+ mods |= GRUB_TERM_STATUS_RCTRL; -+ } -+ -+ return mods; -+} -+ - static grub_err_t - grub_efi_console_input_init (struct grub_term_input *term) - { -@@ -403,6 +436,7 @@ static struct grub_term_input grub_console_term_input = - { - .name = "console", - .getkey = grub_console_getkey, -+ .getkeystatus = grub_console_getkeystatus, - .init = grub_efi_console_input_init, - }; - --- -1.8.3.1 - diff --git a/0185-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch b/0125-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch similarity index 87% rename from 0185-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch rename to 0125-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch index 5845ccf225144e714fd76450a213afb93ab3dab2..a32c1465095b9fdbf423cca194bd87d2b17a8800 100644 --- a/0185-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch +++ b/0125-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch @@ -1,8 +1,11 @@ -From cdefb84f0b4e7773ebf97259b6f89445f39a44d8 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 26 Nov 2019 09:51:41 +0100 -Subject: [PATCH 185/220] grub.d: Fix boot_indeterminate getting set on - boot_success=0 boot +Subject: [PATCH] grub.d: Fix boot_indeterminate getting set on boot_success=0 + boot +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit The "grub.d: Split out boot success reset from menu auto hide script" not only moved the code to clear boot_success and boot_indeterminate @@ -42,12 +45,15 @@ boot_indeterminate to 2 when it was 1 before. Fixes: "grub.d: Split out boot success reset from menu auto hide script" Signed-off-by: Hans de Goede +[jpokorny: 01_menu_auto_hide.in: fix a then/than typo] +Signed-off-by: Jan Pokorný +Signed-off-by: Robbie Harwood --- util/grub.d/10_reset_boot_success.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/grub.d/10_reset_boot_success.in b/util/grub.d/10_reset_boot_success.in -index 6c88d93..737e1ae 100644 +index 6c88d933dde..e73f4137b36 100644 --- a/util/grub.d/10_reset_boot_success.in +++ b/util/grub.d/10_reset_boot_success.in @@ -6,18 +6,18 @@ @@ -67,12 +73,9 @@ index 6c88d93..737e1ae 100644 set boot_indeterminate=0 -else - increment boot_indeterminate -+# Avoid boot_indeterminate causing the menu to be hidden more then once ++# Avoid boot_indeterminate causing the menu to be hidden more than once +elif [ "\${boot_indeterminate}" = "1" ]; then + set boot_indeterminate=2 fi # Reset boot_success for current boot set boot_success=0 --- -1.8.3.1 - diff --git a/0190-Add-start-symbol-for-RISC-V.patch b/0126-Add-start-symbol-for-RISC-V.patch similarity index 81% rename from 0190-Add-start-symbol-for-RISC-V.patch rename to 0126-Add-start-symbol-for-RISC-V.patch index b5538a1c511f6764d95262ca02a0cf8c4c1081b1..677efae016068e1094f52d0c1befc213b846e677 100644 --- a/0190-Add-start-symbol-for-RISC-V.patch +++ b/0126-Add-start-symbol-for-RISC-V.patch @@ -1,7 +1,7 @@ -From 02d1800799c3ada95d10af90af4d4ed3a479f2e3 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: David Abdurachmanov Date: Sat, 9 Nov 2019 19:51:57 +0000 -Subject: [PATCH 190/220] Add start symbol for RISC-V +Subject: [PATCH] Add start symbol for RISC-V All other architectures have start symbol. @@ -15,7 +15,7 @@ Signed-off-by: David Abdurachmanov 1 file changed, 1 insertion(+) diff --git a/grub-core/kern/riscv/efi/startup.S b/grub-core/kern/riscv/efi/startup.S -index f2a7b2b..7817731 100644 +index f2a7b2b1ede..781773136e8 100644 --- a/grub-core/kern/riscv/efi/startup.S +++ b/grub-core/kern/riscv/efi/startup.S @@ -29,6 +29,7 @@ @@ -26,6 +26,3 @@ index f2a7b2b..7817731 100644 FUNCTION(_start) /* * EFI_SYSTEM_TABLE and EFI_HANDLE are passed in a1/a0. --- -1.8.3.1 - diff --git a/0126-Make-grub_getkeystatus-helper-funtion-available-ever.patch b/0126-Make-grub_getkeystatus-helper-funtion-available-ever.patch deleted file mode 100644 index c49a7878c79c6268526f4bc8a3a89e9b62334695..0000000000000000000000000000000000000000 --- a/0126-Make-grub_getkeystatus-helper-funtion-available-ever.patch +++ /dev/null @@ -1,91 +0,0 @@ -From 493de1bf8d04c9129efd66e7134eef12f436aba4 Mon Sep 17 00:00:00 2001 -From: Hans de Goede -Date: Wed, 6 Jun 2018 16:47:11 +0200 -Subject: [PATCH 126/220] Make grub_getkeystatus helper funtion available - everywhere - -Move the grub_getkeystatus helper function from -grub-core/commands/keystatus.c to grub-core/kern/term.c -and export it so that it can be used outside of the -keystatus command code too. - -Signed-off-by: Hans de Goede ---- - grub-core/commands/keystatus.c | 18 ------------------ - grub-core/kern/term.c | 18 ++++++++++++++++++ - include/grub/term.h | 1 + - 3 files changed, 19 insertions(+), 18 deletions(-) - -diff --git a/grub-core/commands/keystatus.c b/grub-core/commands/keystatus.c -index 460cf4e..ff3f587 100644 ---- a/grub-core/commands/keystatus.c -+++ b/grub-core/commands/keystatus.c -@@ -35,24 +35,6 @@ static const struct grub_arg_option options[] = - {0, 0, 0, 0, 0, 0} - }; - --static int --grub_getkeystatus (void) --{ -- int status = 0; -- grub_term_input_t term; -- -- if (grub_term_poll_usb) -- grub_term_poll_usb (0); -- -- FOR_ACTIVE_TERM_INPUTS(term) -- { -- if (term->getkeystatus) -- status |= term->getkeystatus (term); -- } -- -- return status; --} -- - static grub_err_t - grub_cmd_keystatus (grub_extcmd_context_t ctxt, - int argc __attribute__ ((unused)), -diff --git a/grub-core/kern/term.c b/grub-core/kern/term.c -index 07720ee..93bd337 100644 ---- a/grub-core/kern/term.c -+++ b/grub-core/kern/term.c -@@ -120,6 +120,24 @@ grub_getkey (void) - } - } - -+int -+grub_getkeystatus (void) -+{ -+ int status = 0; -+ grub_term_input_t term; -+ -+ if (grub_term_poll_usb) -+ grub_term_poll_usb (0); -+ -+ FOR_ACTIVE_TERM_INPUTS(term) -+ { -+ if (term->getkeystatus) -+ status |= term->getkeystatus (term); -+ } -+ -+ return status; -+} -+ - void - grub_refresh (void) - { -diff --git a/include/grub/term.h b/include/grub/term.h -index 8117e2a..c215133 100644 ---- a/include/grub/term.h -+++ b/include/grub/term.h -@@ -327,6 +327,7 @@ grub_term_unregister_output (grub_term_output_t term) - void grub_putcode (grub_uint32_t code, struct grub_term_output *term); - int EXPORT_FUNC(grub_getkey) (void); - int EXPORT_FUNC(grub_getkey_noblock) (void); -+int EXPORT_FUNC(grub_getkeystatus) (void); - void grub_cls (void); - void EXPORT_FUNC(grub_refresh) (void); - void grub_puts_terminal (const char *str, struct grub_term_output *term); --- -1.8.3.1 - diff --git a/0127-Accept-ESC-F8-and-holding-SHIFT-as-user-interrupt-ke.patch b/0127-Accept-ESC-F8-and-holding-SHIFT-as-user-interrupt-ke.patch deleted file mode 100644 index d7516f914c8e4d9e291d144ed801f6a927095206..0000000000000000000000000000000000000000 --- a/0127-Accept-ESC-F8-and-holding-SHIFT-as-user-interrupt-ke.patch +++ /dev/null @@ -1,98 +0,0 @@ -From a4df3e0fa8fa0e188889883195e5b7830def4cd7 Mon Sep 17 00:00:00 2001 -From: Hans de Goede -Date: Mon, 26 Mar 2018 16:15:53 +0200 -Subject: [PATCH 127/220] Accept ESC, F8 and holding SHIFT as user interrupt - keys - -On some devices the ESC key is the hotkey to enter the BIOS/EFI setup -screen, making it really hard to time pressing it right. Besides that -ESC is also pretty hard to discover for a user who does not know it -will unhide the menu. - -This commit makes F8, which used to be the hotkey to show the Windows -boot menu during boot for a long long time, also interrupt sleeps / -stop the menu countdown. - -This solves the ESC gets into the BIOS setup and also somewhat solves -the discoverability issue, but leaves the timing issue unresolved. - -This commit fixes the timing issue by also adding support for keeping -SHIFT pressed during boot to stop the menu countdown. This matches -what Ubuntu is doing, which should also help with discoverability. - -Signed-off-by: Hans de Goede ---- - grub-core/commands/sleep.c | 2 +- - grub-core/kern/term.c | 16 ++++++++++++++++ - grub-core/normal/menu.c | 2 +- - include/grub/term.h | 1 + - 4 files changed, 19 insertions(+), 2 deletions(-) - -diff --git a/grub-core/commands/sleep.c b/grub-core/commands/sleep.c -index e77e790..a1370b7 100644 ---- a/grub-core/commands/sleep.c -+++ b/grub-core/commands/sleep.c -@@ -55,7 +55,7 @@ grub_interruptible_millisleep (grub_uint32_t ms) - start = grub_get_time_ms (); - - while (grub_get_time_ms () - start < ms) -- if (grub_getkey_noblock () == GRUB_TERM_ESC) -+ if (grub_key_is_interrupt (grub_getkey_noblock ())) - return 1; - - return 0; -diff --git a/grub-core/kern/term.c b/grub-core/kern/term.c -index 93bd337..6cae4c2 100644 ---- a/grub-core/kern/term.c -+++ b/grub-core/kern/term.c -@@ -138,6 +138,22 @@ grub_getkeystatus (void) - return status; - } - -+int -+grub_key_is_interrupt (int key) -+{ -+ /* ESC sometimes is the BIOS setup hotkey and may be hard to discover, also -+ check F8, which was the key to get the Windows bootmenu for a long time. */ -+ if (key == GRUB_TERM_ESC || key == GRUB_TERM_KEY_F8) -+ return 1; -+ -+ /* Pressing keys at the right time during boot is hard to time, also allow -+ interrupting sleeps / the menu countdown by keeping shift pressed. */ -+ if (grub_getkeystatus() & (GRUB_TERM_STATUS_LSHIFT|GRUB_TERM_STATUS_RSHIFT)) -+ return 1; -+ -+ return 0; -+} -+ - void - grub_refresh (void) - { -diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c -index 783bde5..046a1fb 100644 ---- a/grub-core/normal/menu.c -+++ b/grub-core/normal/menu.c -@@ -655,7 +655,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) - if (entry >= 0) - break; - } -- if (key == GRUB_TERM_ESC) -+ if (grub_key_is_interrupt (key)) - { - timeout = -1; - break; -diff --git a/include/grub/term.h b/include/grub/term.h -index c215133..2b079c2 100644 ---- a/include/grub/term.h -+++ b/include/grub/term.h -@@ -328,6 +328,7 @@ void grub_putcode (grub_uint32_t code, struct grub_term_output *term); - int EXPORT_FUNC(grub_getkey) (void); - int EXPORT_FUNC(grub_getkey_noblock) (void); - int EXPORT_FUNC(grub_getkeystatus) (void); -+int EXPORT_FUNC(grub_key_is_interrupt) (int key); - void grub_cls (void); - void EXPORT_FUNC(grub_refresh) (void); - void grub_puts_terminal (const char *str, struct grub_term_output *term); --- -1.8.3.1 - diff --git a/0127-bootstrap.conf-Force-autogen.sh-to-use-python3.patch b/0127-bootstrap.conf-Force-autogen.sh-to-use-python3.patch new file mode 100644 index 0000000000000000000000000000000000000000..5c3b968bb21c6cf7ba2308f16d73a6d2f01c985b --- /dev/null +++ b/0127-bootstrap.conf-Force-autogen.sh-to-use-python3.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Wed, 15 Jan 2020 12:47:46 +0100 +Subject: [PATCH] bootstrap.conf: Force autogen.sh to use python3 + +The python-unversioned-command package is not installed in the buildroot, +but the bootstrap script expects the python command to be present if one +is not defined. So building the package leads to the following error: + +./autogen.sh: line 20: python: command not found + +This is harmless since gnulib is included as a source anyways, because the +builders can't download. But still the issue should be fixed by forcing to +use python3 that's the default in Fedora now. + +Signed-off-by: Javier Martinez Canillas +--- + bootstrap.conf | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/bootstrap.conf b/bootstrap.conf +index 452f4d79b0d..03f10930230 100644 +--- a/bootstrap.conf ++++ b/bootstrap.conf +@@ -93,7 +93,7 @@ bootstrap_post_import_hook () { + patch -d po -p3 \ + < "po/gettext-patches/$patchname.patch" + done +- FROM_BOOTSTRAP=1 ./autogen.sh ++ PYTHON=python3 FROM_BOOTSTRAP=1 ./autogen.sh + set +e # bootstrap expects this + } + diff --git a/0194-efi-http-Export-fw-http-_path-variables-to-make-them.patch b/0128-efi-http-Export-fw-http-_path-variables-to-make-them.patch similarity index 84% rename from 0194-efi-http-Export-fw-http-_path-variables-to-make-them.patch rename to 0128-efi-http-Export-fw-http-_path-variables-to-make-them.patch index 0fd459730438247063af5657d51ac3b1d89c3f7b..74183bc3fe99881989ab652053efb35367d91184 100644 --- a/0194-efi-http-Export-fw-http-_path-variables-to-make-them.patch +++ b/0128-efi-http-Export-fw-http-_path-variables-to-make-them.patch @@ -1,8 +1,7 @@ -From 14623de497794581948d8df3e69d22833588da43 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Thu, 5 Mar 2020 16:21:47 +0100 -Subject: [PATCH 194/220] efi/http: Export {fw,http}_path variables to make - them global +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 @@ -26,10 +25,10 @@ Signed-off-by: Javier Martinez Canillas 2 files changed, 2 insertions(+) diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c -index dcf4872..9bf6a8b 100644 +index 1c540fc8c26..b573be6650d 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c -@@ -142,6 +142,7 @@ grub_set_prefix_and_root (void) +@@ -143,6 +143,7 @@ grub_set_prefix_and_root (void) if (fw_path) { grub_env_set ("fw_path", fw_path); @@ -38,7 +37,7 @@ index dcf4872..9bf6a8b 100644 grub_free (fw_path); } diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c -index de351b2..755b7a6 100644 +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) @@ -49,6 +48,3 @@ index de351b2..755b7a6 100644 } } --- -1.8.3.1 - diff --git a/0195-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch b/0129-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch similarity index 95% rename from 0195-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch rename to 0129-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch index 995d9c7c6f663488d25b610388a1b087d54618d3..c3945498a8b421325377b9d40b22a8899cef3552 100644 --- a/0195-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch +++ b/0129-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch @@ -1,8 +1,7 @@ -From 0b3d15aa1bae1afbc7bd0b50a12e56d4f9b1248d Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Thu, 5 Mar 2020 16:21:58 +0100 -Subject: [PATCH 195/220] efi/http: Enclose literal IPv6 addresses in square - brackets +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 @@ -44,7 +43,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c -index 755b7a6..fc8cb25 100644 +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, @@ -113,6 +112,3 @@ index 755b7a6..fc8cb25 100644 if (status != GRUB_EFI_SUCCESS) { efi_call_1 (b->close_event, request_token.event); --- -1.8.3.1 - diff --git a/0130-Output-a-menu-entry-for-firmware-setup-on-UEFI-FastB.patch b/0130-Output-a-menu-entry-for-firmware-setup-on-UEFI-FastB.patch deleted file mode 100644 index 2b3fb8190e7f4c5550a1aab3230180e6cb43d27e..0000000000000000000000000000000000000000 --- a/0130-Output-a-menu-entry-for-firmware-setup-on-UEFI-FastB.patch +++ /dev/null @@ -1,97 +0,0 @@ -From ebd3c8a460e55ac9507f1c690d49b6919cf908ad Mon Sep 17 00:00:00 2001 -From: Steve Langasek -Date: Mon, 13 Jan 2014 12:13:12 +0000 -Subject: [PATCH 130/220] Output a menu entry for firmware setup on UEFI - FastBoot systems - -If fastboot is enabled in the BIOS then often it is not possible to -enter the firmware setup menu, add a menu entry for this. - -hdegoede: Cherry picked the Ubuntu patch from: -https://git.launchpad.net/~ubuntu-core-dev/grub/+git/ubuntu/tree/debian/patches/uefi_firmware_setup.patch -Into the Fedora / RH grub version - -According to: -https://git.launchpad.net/~ubuntu-core-dev/grub/+git/ubuntu/tree/debian/copyright -The patch is licensed under GPL-3+ - -[hdegoede: fix use with /sys/firmware/efi/efivars] -Signed-off-by: Hans de Goede ---- - Makefile.util.def | 6 ++++++ - util/grub.d/30_uefi-firmware.in | 46 +++++++++++++++++++++++++++++++++++++++++ - 2 files changed, 52 insertions(+) - create mode 100644 util/grub.d/30_uefi-firmware.in - -diff --git a/Makefile.util.def b/Makefile.util.def -index 026b458..89a9da1 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -546,6 +546,12 @@ script = { - }; - - script = { -+ name = '30_uefi-firmware'; -+ common = util/grub.d/30_uefi-firmware.in; -+ installdir = grubconf; -+}; -+ -+script = { - name = '40_custom'; - common = util/grub.d/40_custom.in; - installdir = grubconf; -diff --git a/util/grub.d/30_uefi-firmware.in b/util/grub.d/30_uefi-firmware.in -new file mode 100644 -index 0000000..93ececf ---- /dev/null -+++ b/util/grub.d/30_uefi-firmware.in -@@ -0,0 +1,46 @@ -+#! /bin/sh -+set -e -+ -+# grub-mkconfig helper script. -+# Copyright (C) 2012 Free Software Foundation, Inc. -+# -+# GRUB is free software: you can redistribute it and/or modify -+# it under the terms of the GNU General Public License as published by -+# the Free Software Foundation, either version 3 of the License, or -+# (at your option) any later version. -+# -+# GRUB is distributed in the hope that it will be useful, -+# but WITHOUT ANY WARRANTY; without even the implied warranty of -+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+# GNU General Public License for more details. -+# -+# You should have received a copy of the GNU General Public License -+# along with GRUB. If not, see . -+ -+prefix="@prefix@" -+exec_prefix="@exec_prefix@" -+datarootdir="@datarootdir@" -+ -+export TEXTDOMAIN=@PACKAGE@ -+export TEXTDOMAINDIR="@localedir@" -+ -+. "@datadir@/@PACKAGE@/grub-mkconfig_lib" -+ -+efi_vars_dir=/sys/firmware/efi/efivars -+EFI_GLOBAL_VARIABLE=8be4df61-93ca-11d2-aa0d-00e098032b8c -+OsIndications="$efi_vars_dir/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE" -+ -+if [ -e "$OsIndications" ] && \ -+ [ "$(( $(printf 0x%x \'"$(cat $OsIndications | cut -b5)") & 1 ))" = 1 ]; then -+ LABEL="System setup" -+ -+ gettext_printf "Adding boot menu entry for EFI firmware configuration\n" >&2 -+ -+ onstr="$(gettext_printf "(on %s)" "${DEVICE}")" -+ -+ cat << EOF -+menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' { -+ fwsetup -+} -+EOF -+fi --- -1.8.3.1 - diff --git a/0196-efi-net-Allow-to-specify-a-port-number-in-addresses.patch b/0130-efi-net-Allow-to-specify-a-port-number-in-addresses.patch similarity index 89% rename from 0196-efi-net-Allow-to-specify-a-port-number-in-addresses.patch rename to 0130-efi-net-Allow-to-specify-a-port-number-in-addresses.patch index 79750fcb295a0e14013f5856124722a923e8fbe1..209aed80f66762662a2229f2da9bd087ed15c691 100644 --- a/0196-efi-net-Allow-to-specify-a-port-number-in-addresses.patch +++ b/0130-efi-net-Allow-to-specify-a-port-number-in-addresses.patch @@ -1,7 +1,7 @@ -From f1933ae113b13658743a43e1bbbcca76d88e45e3 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Mon, 9 Mar 2020 15:29:45 +0100 -Subject: [PATCH 196/220] efi/net: Allow to specify a port number in addresses +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 @@ -25,7 +25,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c -index 6603cd8..8457393 100644 +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, @@ -46,6 +46,3 @@ index 6603cd8..8457393 100644 { ip6->prefix_length = 128; ip6->is_anycast = 0; --- -1.8.3.1 - diff --git a/0197-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch b/0131-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch similarity index 87% rename from 0197-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch rename to 0131-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch index cb8da9f3d7577d0214a151b619d6b000dfbd9fde..f92dee4405006f948c00a232a334764d86986b7c 100644 --- a/0197-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch +++ b/0131-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch @@ -1,7 +1,7 @@ -From 9c470c8bc1921a38d15c568f25aada9e2bdb3c71 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Mon, 9 Mar 2020 15:30:05 +0100 -Subject: [PATCH 197/220] efi/ip4_config: Improve check to detect literal IPv6 +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 @@ -21,7 +21,7 @@ Signed-off-by: Javier Martinez Canillas 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 b711a5d..313c818 100644 +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 @@ -46,6 +46,3 @@ index b711a5d..313c818 100644 for (i = 0; i < 4; i++) { unsigned long t; --- -1.8.3.1 - diff --git a/0198-efi-net-Print-a-debug-message-if-parsing-the-address.patch b/0132-efi-net-Print-a-debug-message-if-parsing-the-address.patch similarity index 92% rename from 0198-efi-net-Print-a-debug-message-if-parsing-the-address.patch rename to 0132-efi-net-Print-a-debug-message-if-parsing-the-address.patch index b38c6a75edbd649ae32edb057847e734bac882ce..33d8f886f35036de92470024908af1e11ba260ce 100644 --- a/0198-efi-net-Print-a-debug-message-if-parsing-the-address.patch +++ b/0132-efi-net-Print-a-debug-message-if-parsing-the-address.patch @@ -1,8 +1,7 @@ -From 51b1f81e7744031f7b3ad96a8264e493be5b069c Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Tue, 10 Mar 2020 11:23:49 +0100 -Subject: [PATCH 198/220] efi/net: Print a debug message if parsing the address - fails +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() @@ -23,7 +22,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c -index 8457393..a3f0535 100644 +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, @@ -67,6 +66,3 @@ index 8457393..a3f0535 100644 { grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("disk `%s' no route found"), name); --- -1.8.3.1 - diff --git a/0133-kern-term-Also-accept-F8-as-a-user-interrupt-key.patch b/0133-kern-term-Also-accept-F8-as-a-user-interrupt-key.patch new file mode 100644 index 0000000000000000000000000000000000000000..3dd525af8191a4c737c546212335b58353b98c3b --- /dev/null +++ b/0133-kern-term-Also-accept-F8-as-a-user-interrupt-key.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Wed, 22 Apr 2020 12:41:52 +0200 +Subject: [PATCH] kern/term: Also accept F8 as a user interrupt key + +Make F8, which used to be the hotkey to show the Windows boot menu during +boot for a long long time, also interrupt sleeps / stop the menu countdown. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/kern/term.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/grub-core/kern/term.c b/grub-core/kern/term.c +index 14d59649832..4d61f4e9790 100644 +--- a/grub-core/kern/term.c ++++ b/grub-core/kern/term.c +@@ -144,9 +144,10 @@ grub_key_is_interrupt (int key) + /* + * ESC sometimes is the BIOS setup hotkey and may be hard to discover, also + * check F4, which was chosen because is not used as a hotkey to enter the +- * BIOS setup by any vendor. ++ * BIOS setup by any vendor. Also, F8 which was the key to get the Windows ++ * bootmenu for a long time. + */ +- if (key == GRUB_TERM_ESC || key == GRUB_TERM_KEY_F4) ++ if (key == GRUB_TERM_ESC || key == GRUB_TERM_KEY_F4 || key == GRUB_TERM_KEY_F8) + return 1; + + /* diff --git a/0205-efi-Set-image-base-address-before-jumping-to-the-PE-.patch b/0134-efi-Set-image-base-address-before-jumping-to-the-PE-.patch similarity index 76% rename from 0205-efi-Set-image-base-address-before-jumping-to-the-PE-.patch rename to 0134-efi-Set-image-base-address-before-jumping-to-the-PE-.patch index a2987a420f1b2b43b53a6930cdf0ee6d44fe9f0d..336bcf18b2f140ec4e1cbb0d8b1cb226d7e955b5 100644 --- a/0205-efi-Set-image-base-address-before-jumping-to-the-PE-.patch +++ b/0134-efi-Set-image-base-address-before-jumping-to-the-PE-.patch @@ -1,8 +1,8 @@ -From c565dc1a029d823a601716a30d06f9d6626d4a93 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Thu, 23 Apr 2020 15:06:46 +0200 -Subject: [PATCH 205/220] efi: Set image base address before jumping to the - PE/COFF entry point +Subject: [PATCH] efi: Set image base address before jumping to the PE/COFF + entry point Upstream GRUB uses the EFI LoadImage() and StartImage() to boot the Linux kernel. But our custom EFI loader that supports Secure Boot instead uses @@ -21,15 +21,15 @@ and print the following warning message: EFI stub: ERROR: FIRMWARE BUG: efi_loaded_image_t::image_base has bogus value -Resolves: rhbz#1825411 +Resolves: rhbz#1814690 Signed-off-by: Javier Martinez Canillas --- - grub-core/loader/efi/linux.c | 12 ++++++++++++ - 1 file changed, 12 insertions(+) + grub-core/loader/efi/linux.c | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c -index b56ea0b..e09f824 100644 +index 0622dfa48d4..e8b9ecb17f6 100644 --- a/grub-core/loader/efi/linux.c +++ b/grub-core/loader/efi/linux.c @@ -72,6 +72,7 @@ grub_err_t @@ -40,7 +40,7 @@ index b56ea0b..e09f824 100644 handover_func hf; int offset = 0; -@@ -79,6 +80,17 @@ grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset, +@@ -79,6 +80,19 @@ grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset, offset = 512; #endif @@ -55,9 +55,8 @@ index b56ea0b..e09f824 100644 + else + grub_dprintf ("linux", "Loaded Image base address could not be set\n"); + - grub_dprintf ("linux", "kernel_addr: %p handover_offset: %p params: %p\n", - kernel_addr, (void *)(grub_efi_uintn_t)handover_offset, kernel_params); ++ grub_dprintf ("linux", "kernel_addr: %p handover_offset: %p params: %p\n", ++ kernel_addr, (void *)(grub_efi_uintn_t)handover_offset, kernel_params); hf = (handover_func)((char *)kernel_addr + handover_offset + offset); --- -1.8.3.1 - + hf (grub_efi_image_handle, grub_efi_system_table, kernel_params); + diff --git a/0211-tpm-Don-t-propagate-TPM-measurement-errors-to-the-ve.patch b/0135-tpm-Don-t-propagate-TPM-measurement-errors-to-the-ve.patch similarity index 82% rename from 0211-tpm-Don-t-propagate-TPM-measurement-errors-to-the-ve.patch rename to 0135-tpm-Don-t-propagate-TPM-measurement-errors-to-the-ve.patch index 34d34c829f88fa598f11fd21760bb8b8006a98fb..747773d1d60d8d4e222b8685974e3801020480d2 100644 --- a/0211-tpm-Don-t-propagate-TPM-measurement-errors-to-the-ve.patch +++ b/0135-tpm-Don-t-propagate-TPM-measurement-errors-to-the-ve.patch @@ -1,8 +1,8 @@ -From cf02c5792d50eb41f390dd82f8849d75ae7f2208 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Sat, 16 May 2020 11:33:18 +0200 -Subject: [PATCH 211/220] tpm: Don't propagate TPM measurement errors to the - verifiers layer +Subject: [PATCH] tpm: Don't propagate TPM measurement errors to the verifiers + layer Currently if the EFI firmware fails to do a TPM measurement for a file, the error will be propagated to the verifiers framework and so opening @@ -18,10 +18,10 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/grub-core/commands/tpm.c b/grub-core/commands/tpm.c -index 1441c49..dbaeae4 100644 +index 2052c36eaba..e287d042e6b 100644 --- a/grub-core/commands/tpm.c +++ b/grub-core/commands/tpm.c -@@ -49,7 +49,8 @@ grub_tpm_verify_init (grub_file_t io, +@@ -42,7 +42,8 @@ grub_tpm_verify_init (grub_file_t io, static grub_err_t grub_tpm_verify_write (void *context, void *buf, grub_size_t size) { @@ -31,7 +31,7 @@ index 1441c49..dbaeae4 100644 } static grub_err_t -@@ -57,7 +58,6 @@ grub_tpm_verify_string (char *str, enum grub_verify_string_type type) +@@ -50,7 +51,6 @@ grub_tpm_verify_string (char *str, enum grub_verify_string_type type) { const char *prefix = NULL; char *description; @@ -39,7 +39,7 @@ index 1441c49..dbaeae4 100644 switch (type) { -@@ -73,15 +73,15 @@ grub_tpm_verify_string (char *str, enum grub_verify_string_type type) +@@ -66,15 +66,15 @@ grub_tpm_verify_string (char *str, enum grub_verify_string_type type) } description = grub_malloc (grub_strlen (str) + grub_strlen (prefix) + 1); if (!description) @@ -60,6 +60,3 @@ index 1441c49..dbaeae4 100644 } struct grub_file_verifier grub_tpm_verifier = { --- -1.8.3.1 - diff --git a/0214-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch b/0136-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch similarity index 88% rename from 0214-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch rename to 0136-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch index a445031a924efac924c5b46051e9801e4637164f..825d0f7c80a55f777445fcc6ab864ffe16a7d630 100644 --- a/0214-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch +++ b/0136-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch @@ -1,7 +1,7 @@ -From c9ea6acded92ff5a4dfb336965da35e3b3407934 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Tue, 26 May 2020 16:59:28 +0200 -Subject: [PATCH 214/220] x86-efi: Reduce maximum bounce buffer size to 16 MiB +Subject: [PATCH] x86-efi: Reduce maximum bounce buffer size to 16 MiB The EFI linux loader allocates a bounce buffer to copy the initrd since in some machines doing DMA on addresses above 4GB is not possible during EFI. @@ -26,7 +26,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 50b7798..e5b2736 100644 +index 6bc18d5aef5..15d40d6e35b 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -144,7 +144,7 @@ grub_linuxefi_unload (void) @@ -38,6 +38,3 @@ index 50b7798..e5b2736 100644 static grub_ssize_t read(grub_file_t file, grub_uint8_t *bufp, grub_size_t len) --- -1.8.3.1 - diff --git a/0215-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch b/0137-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch similarity index 87% rename from 0215-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch rename to 0137-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch index a1afac786a374a50e15bfc845a2eba4a47908bbe..97d2e06ff840078efe4e932692586dfe88389811 100644 --- a/0215-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch +++ b/0137-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch @@ -1,8 +1,8 @@ -From 38e8b235d4fdb4ff0d615d83cb03e716c7fde08b Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Tue, 2 Jun 2020 13:25:01 +0200 -Subject: [PATCH 215/220] http: Prepend prefix when the HTTP path is relative - as done in efi/http +Subject: [PATCH] http: Prepend prefix when the HTTP path is relative as done + in efi/http There are two different HTTP drivers that can be used when requesting an HTTP resource: the efi/http that uses the EFI_HTTP_PROTOCOL and the http @@ -20,7 +20,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/grub-core/net/http.c b/grub-core/net/http.c -index b52b558..7f878b5 100644 +index b52b558d631..7f878b56157 100644 --- a/grub-core/net/http.c +++ b/grub-core/net/http.c @@ -501,13 +501,20 @@ http_open (struct grub_file *file, const char *filename) @@ -45,6 +45,3 @@ index b52b558..7f878b5 100644 if (!data->filename) { grub_free (data); --- -1.8.3.1 - diff --git a/0138-Fix-a-missing-return-in-efi-export-env-and-efi-load-.patch b/0138-Fix-a-missing-return-in-efi-export-env-and-efi-load-.patch new file mode 100644 index 0000000000000000000000000000000000000000..1657d7a8792fd27a03f1036bcab62a49eb74e53f --- /dev/null +++ b/0138-Fix-a-missing-return-in-efi-export-env-and-efi-load-.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 16 Jan 2019 13:21:46 -0500 +Subject: [PATCH] Fix a missing return in efi-export-env and efi-load-env + commands + +Somewhere along the way this got mis-merged to include a return without +a value. Fix it up. + +Signed-off-by: Peter Jones +--- + grub-core/commands/efi/env.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/grub-core/commands/efi/env.c b/grub-core/commands/efi/env.c +index cbd13e03e81..977edb6b065 100644 +--- a/grub-core/commands/efi/env.c ++++ b/grub-core/commands/efi/env.c +@@ -149,6 +149,8 @@ grub_efi_load_env(grub_command_t cmd __attribute__ ((unused)), + + grub_envblk_iterate (envblk, NULL, set_var); + grub_free (envblk_s.buf); ++ ++ return GRUB_ERR_NONE; + } + + static grub_command_t export_cmd, loadenv_cmd; diff --git a/0139-efi-dhcp-fix-some-allocation-error-checking.patch b/0139-efi-dhcp-fix-some-allocation-error-checking.patch new file mode 100644 index 0000000000000000000000000000000000000000..7549733862f45b4dc0ce2634558a54b5dcc5ac54 --- /dev/null +++ b/0139-efi-dhcp-fix-some-allocation-error-checking.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 19 Jul 2020 17:11:06 -0400 +Subject: [PATCH] efi+dhcp: fix some allocation error checking. + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/dhcp.c | 9 ++++++--- + 1 file changed, 6 insertions(+), 3 deletions(-) + +diff --git a/grub-core/net/efi/dhcp.c b/grub-core/net/efi/dhcp.c +index dbef63d8c08..e5c79b748b0 100644 +--- a/grub-core/net/efi/dhcp.c ++++ b/grub-core/net/efi/dhcp.c +@@ -80,7 +80,7 @@ grub_efi_dhcp4_parse_dns (grub_efi_dhcp4_protocol_t *dhcp4, grub_efi_dhcp4_packe + if (status != GRUB_EFI_BUFFER_TOO_SMALL) + return NULL; + +- option_list = grub_malloc (option_count * sizeof(*option_list)); ++ option_list = grub_calloc (option_count, sizeof(*option_list)); + if (!option_list) + return NULL; + +@@ -360,8 +360,11 @@ grub_cmd_efi_bootp6 (struct grub_command *cmd __attribute__ ((unused)), + + if (status == GRUB_EFI_BUFFER_TOO_SMALL && count) + { +- options = grub_malloc (count * sizeof(*options)); +- status = efi_call_4 (dev->dhcp6->parse, dev->dhcp6, mode.ia->reply_packet, &count, options); ++ options = grub_calloc (count, sizeof(*options)); ++ if (options) ++ status = efi_call_4 (dev->dhcp6->parse, dev->dhcp6, mode.ia->reply_packet, &count, options); ++ else ++ status = GRUB_EFI_OUT_OF_RESOURCES; + } + + if (status != GRUB_EFI_SUCCESS) diff --git a/0140-efi-http-fix-some-allocation-error-checking.patch b/0140-efi-http-fix-some-allocation-error-checking.patch new file mode 100644 index 0000000000000000000000000000000000000000..4dffab9e398d8b625f91d9af9cd6b0d7ceb0f682 --- /dev/null +++ b/0140-efi-http-fix-some-allocation-error-checking.patch @@ -0,0 +1,39 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 19 Jul 2020 17:14:15 -0400 +Subject: [PATCH] efi+http: fix some allocation error checking. + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/http.c | 11 +++++++---- + 1 file changed, 7 insertions(+), 4 deletions(-) + +diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c +index fc8cb25ae0a..26647a50fa4 100644 +--- a/grub-core/net/efi/http.c ++++ b/grub-core/net/efi/http.c +@@ -412,8 +412,8 @@ grub_efihttp_open (struct grub_efi_net_device *dev, + int type) + { + grub_err_t err; +- grub_off_t size; +- char *buf; ++ grub_off_t size = 0; ++ char *buf = NULL; + char *file_name = NULL; + const char *http_path; + +@@ -441,8 +441,11 @@ grub_efihttp_open (struct grub_efi_net_device *dev, + return err; + } + +- buf = grub_malloc (size); +- efihttp_read (dev, buf, size); ++ if (size) ++ { ++ buf = grub_malloc (size); ++ efihttp_read (dev, buf, size); ++ } + + file->size = size; + file->data = buf; diff --git a/0141-efi-ip-46-_config.c-fix-some-potential-allocation-ov.patch b/0141-efi-ip-46-_config.c-fix-some-potential-allocation-ov.patch new file mode 100644 index 0000000000000000000000000000000000000000..30c21a586bf41dc48fb44c45458e855c9b7e4d66 --- /dev/null +++ b/0141-efi-ip-46-_config.c-fix-some-potential-allocation-ov.patch @@ -0,0 +1,127 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 19 Jul 2020 17:27:00 -0400 +Subject: [PATCH] efi/ip[46]_config.c: fix some potential allocation overflows + +In theory all of this data comes from the firmware stack and it should +be safe, but it's better to be paranoid. + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/ip4_config.c | 25 ++++++++++++++++++------- + grub-core/net/efi/ip6_config.c | 13 ++++++++++--- + 2 files changed, 28 insertions(+), 10 deletions(-) + +diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c +index 313c818b184..9725e928f7e 100644 +--- a/grub-core/net/efi/ip4_config.c ++++ b/grub-core/net/efi/ip4_config.c +@@ -4,15 +4,20 @@ + #include + #include + #include ++#include + + char * + grub_efi_hw_address_to_string (grub_efi_uint32_t hw_address_size, grub_efi_mac_address_t hw_address) + { + char *hw_addr, *p; +- int sz, s; +- int i; ++ grub_size_t sz, s, i; + +- sz = (int)hw_address_size * (sizeof ("XX:") - 1) + 1; ++ if (grub_mul (hw_address_size, sizeof ("XX:") - 1, &sz) || ++ grub_add (sz, 1, &sz)) ++ { ++ grub_errno = GRUB_ERR_OUT_OF_RANGE; ++ return NULL; ++ } + + hw_addr = grub_malloc (sz); + if (!hw_addr) +@@ -20,7 +25,7 @@ grub_efi_hw_address_to_string (grub_efi_uint32_t hw_address_size, grub_efi_mac_a + + p = hw_addr; + s = sz; +- for (i = 0; i < (int)hw_address_size; i++) ++ for (i = 0; i < hw_address_size; i++) + { + grub_snprintf (p, sz, "%02x:", hw_address[i]); + p += sizeof ("XX:") - 1; +@@ -238,14 +243,20 @@ grub_efi_ip4_interface_route_table (struct grub_efi_net_device *dev) + { + grub_efi_ip4_config2_interface_info_t *interface_info; + char **ret; +- int i, id; ++ int id; ++ grub_size_t i, nmemb; + + interface_info = efi_ip4_config_interface_info (dev->ip4_config); + if (!interface_info) + return NULL; + +- ret = grub_malloc (sizeof (*ret) * (interface_info->route_table_size + 1)); ++ if (grub_add (interface_info->route_table_size, 1, &nmemb)) ++ { ++ grub_errno = GRUB_ERR_OUT_OF_RANGE; ++ return NULL; ++ } + ++ ret = grub_calloc (nmemb, sizeof (*ret)); + if (!ret) + { + grub_free (interface_info); +@@ -253,7 +264,7 @@ grub_efi_ip4_interface_route_table (struct grub_efi_net_device *dev) + } + + id = 0; +- for (i = 0; i < (int)interface_info->route_table_size; i++) ++ for (i = 0; i < interface_info->route_table_size; i++) + { + char *subnet, *gateway, *mask; + grub_uint32_t u32_subnet, u32_gateway; +diff --git a/grub-core/net/efi/ip6_config.c b/grub-core/net/efi/ip6_config.c +index 017c4d05bc7..a46f6f9b685 100644 +--- a/grub-core/net/efi/ip6_config.c ++++ b/grub-core/net/efi/ip6_config.c +@@ -3,6 +3,7 @@ + #include + #include + #include ++#include + + char * + grub_efi_ip6_address_to_string (grub_efi_pxe_ipv6_address_t *address) +@@ -228,14 +229,20 @@ grub_efi_ip6_interface_route_table (struct grub_efi_net_device *dev) + { + grub_efi_ip6_config_interface_info_t *interface_info; + char **ret; +- int i, id; ++ int id; ++ grub_size_t i, nmemb; + + interface_info = efi_ip6_config_interface_info (dev->ip6_config); + if (!interface_info) + return NULL; + +- ret = grub_malloc (sizeof (*ret) * (interface_info->route_count + 1)); ++ if (grub_add (interface_info->route_count, 1, &nmemb)) ++ { ++ grub_errno = GRUB_ERR_OUT_OF_RANGE; ++ return NULL; ++ } + ++ ret = grub_calloc (nmemb, sizeof (*ret)); + if (!ret) + { + grub_free (interface_info); +@@ -243,7 +250,7 @@ grub_efi_ip6_interface_route_table (struct grub_efi_net_device *dev) + } + + id = 0; +- for (i = 0; i < (int)interface_info->route_count ; i++) ++ for (i = 0; i < interface_info->route_count ; i++) + { + char *gateway, *destination; + grub_uint64_t u64_gateway[2]; diff --git a/0141-strip-R-.note.gnu.property-at-more-places.patch b/0141-strip-R-.note.gnu.property-at-more-places.patch deleted file mode 100644 index aa8663e43ead73ada4868da4d2485281d67dfc36..0000000000000000000000000000000000000000 --- a/0141-strip-R-.note.gnu.property-at-more-places.patch +++ /dev/null @@ -1,85 +0,0 @@ -From bb28d337980306efaaac35cf5515cdfbaecc28e3 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 3 Aug 2018 15:07:23 -0400 -Subject: [PATCH 141/220] strip "-R .note.gnu.property" at more places. - -For whatever reason, sometimes I see: - - lzma_decompress.image: file format elf32-i386 - lzma_decompress.image - architecture: i386, flags 0x00000012: - EXEC_P, HAS_SYMS - start address 0x00008200 - - Program Header: - LOAD off 0x000000c0 vaddr 0x00008200 paddr 0x00008200 align 2**5 - filesz 0x00000b10 memsz 0x00000b10 flags rwx - LOAD off 0x00000bd0 vaddr 0x080480b4 paddr 0x080480b4 align 2**2 - filesz 0x0000001c memsz 0x0000001c flags r-- - NOTE off 0x00000bd0 vaddr 0x080480b4 paddr 0x080480b4 align 2**2 - filesz 0x0000001c memsz 0x0000001c flags r-- - STACK off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**4 - filesz 0x00000000 memsz 0x00000000 flags rw- - - Sections: - Idx Name Size VMA LMA File off Algn - 0 .note.gnu.property 0000001c 080480b4 080480b4 00000bd0 2**2 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 1 .text 00000b10 00008200 00008200 000000c0 2**5 - CONTENTS, ALLOC, LOAD, CODE - SYMBOL TABLE: - 080480b4 l d .note.gnu.property 00000000 .note.gnu.property - 00008200 l d .text 00000000 .text - 00000000 l df *ABS* 00000000 startup_raw.S - ... - -Which just looks wrong no matter what to my eyes (seriously it's at -128M? Why?), and when we fail to strip it, we get: - -trillian:~/tmp/f29$ hexdump -C usr/lib/grub/i386-pc/lzma_decompress.img | tail -6 -00000b00 ff 45 e8 5a 83 c2 02 89 d1 e9 df fe ff ff 66 90 |.E.Z..........f.| -00000b10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| -* -0803feb0 00 00 00 00 04 00 00 00 0c 00 00 00 05 00 00 00 |................| -0803fec0 47 4e 55 00 02 00 00 c0 04 00 00 00 03 00 00 00 |GNU.............| -0803fed0 - -Which is very very much not what we want. - -Cut it out. - -Signed-off-by: Peter Jones ---- - Makefile.am | 2 +- - gentpl.py | 2 +- - 2 files changed, 2 insertions(+), 2 deletions(-) - -diff --git a/Makefile.am b/Makefile.am -index bf9c1ba..0d4dd7c 100644 ---- a/Makefile.am -+++ b/Makefile.am -@@ -209,7 +209,7 @@ pc-chainloader.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S $(srcdir)/grub- - $(TARGET_CC) -o $@ $< -static -DTARGET_CHAINLOADER=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x7c00 -m32 - - pc-chainloader.bin: pc-chainloader.elf -- $(TARGET_OBJCOPY) -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version $< $@; -+ $(TARGET_OBJCOPY) -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .note.gnu.property $< $@; - - ntldr.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S - $(TARGET_CC) -o $@ $< -DTARGET_NTLDR=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -static -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0 -m32 -diff --git a/gentpl.py b/gentpl.py -index 95fe1a2..32cf745 100644 ---- a/gentpl.py -+++ b/gentpl.py -@@ -779,7 +779,7 @@ def image(defn, platform): - if test x$(TARGET_APPLE_LINKER) = x1; then \ - $(MACHO2IMG) $< $@; \ - else \ -- $(TARGET_OBJCOPY) $(""" + cname(defn) + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .MIPS.abiflags -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .ARM.exidx $< $@; \ -+ $(TARGET_OBJCOPY) $(""" + cname(defn) + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .MIPS.abiflags -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .ARM.exidx -R .note.gnu.property $< $@; \ - fi - """) - --- -1.8.3.1 - diff --git a/0142-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch b/0142-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch new file mode 100644 index 0000000000000000000000000000000000000000..95f7e208dd83a16fb96519dd05ab09846ce9cc68 --- /dev/null +++ b/0142-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch @@ -0,0 +1,49 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Colin Watson +Date: Fri, 24 Jul 2020 17:18:09 +0100 +Subject: [PATCH] efilinux: Fix integer overflows in grub_cmd_initrd + +These could be triggered by an extremely large number of arguments to +the initrd command on 32-bit architectures, or a crafted filesystem with +very large files on any architecture. + +Signed-off-by: Colin Watson +--- + grub-core/loader/i386/efi/linux.c | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 15d40d6e35b..f992ceeef20 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -28,6 +28,8 @@ + #include + #include + #include ++#include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -206,7 +208,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- files = grub_zalloc (argc * sizeof (files[0])); ++ files = grub_calloc (argc, sizeof (files[0])); + if (!files) + goto fail; + +@@ -216,7 +218,11 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + if (! files[i]) + goto fail; + nfiles++; +- size += ALIGN_UP (grub_file_size (files[i]), 4); ++ if (grub_add (size, ALIGN_UP (grub_file_size (files[i]), 4), &size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ goto fail; ++ } + } + + initrd_mem = kernel_alloc(size, N_("can't allocate initrd")); diff --git a/0143-Make-linux_arm_kernel_header.hdr_offset-be-at-the-ri.patch b/0143-Make-linux_arm_kernel_header.hdr_offset-be-at-the-ri.patch deleted file mode 100644 index 73183f66e18b5199ef69da7af337220bd3a01ab3..0000000000000000000000000000000000000000 --- a/0143-Make-linux_arm_kernel_header.hdr_offset-be-at-the-ri.patch +++ /dev/null @@ -1,75 +0,0 @@ -From 1fc3dfd0a51daf61a4605217a89d35232d11959b Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 16 Aug 2018 11:08:11 -0400 -Subject: [PATCH 143/220] Make linux_arm_kernel_header.hdr_offset be at the - right place - -The kernel in front of me (slightly edited to make objdump work) looks like: - -00000000 4d 5a 10 13 4d 5a 10 13 4d 5a 10 13 4d 5a 10 13 |MZ..MZ..MZ..MZ..| -00000010 4d 5a 10 13 4d 5a 10 13 4d 5a 10 13 00 00 a0 e1 |MZ..MZ..MZ......| -00000020 f6 03 00 ea 18 28 6f 01 00 00 00 00 00 32 74 00 |.....(o......2t.| -00000030 01 02 03 04 45 45 45 45 74 a2 00 00 40 00 00 00 |....EEEEt...@...| -00000040 50 45 00 00 4c 01 04 00 00 00 00 00 00 00 00 00 |PE..L...........| -00000050 00 00 00 00 90 00 06 03 0b 01 02 14 00 20 74 00 |............. t.| -00000060 00 14 00 00 00 00 00 00 b4 19 00 00 00 10 00 00 |................| -00000070 00 30 74 00 00 00 00 00 00 10 00 00 00 02 00 00 |.0t.............| -00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| -00000090 00 44 74 00 00 10 00 00 00 00 00 00 0a 00 00 00 |.Dt.............| -000000a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| -000000b0 00 00 00 00 06 00 00 00 00 00 00 00 00 00 00 00 |................| -000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| -* - -(I don't know why the MZ header is there 7 times, but the offsets work out, so -it's merely a surprising distraction.) - -If linux_arm_kernel_header.reserved2 is 16 bytes, that means hdr_offset is -here: - -00000030 01 02 03 04 45 45 45 45 74 a2 00 00 40 00 00 00 |....EEEEt...@...| -00000040 50 45 00 00 4c 01 04 00 00 00 00 00 00 00 00 00 |PE..L...........| - ^^^^^^^^^^^ - -But it's supposed to be 4 bytes before that. - -This patch makes the reserved field be 3*32 instead of 4*32, and that means we -can find the PE header correcrtly at 0x40 by reading the value at 0x3c. - -Signed-off-by: Peter Jones ---- - grub-core/loader/efi/linux.c | 3 +++ - include/grub/arm/linux.h | 2 +- - 2 files changed, 4 insertions(+), 1 deletion(-) - -diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c -index 0622dfa..b56ea0b 100644 ---- a/grub-core/loader/efi/linux.c -+++ b/grub-core/loader/efi/linux.c -@@ -79,7 +79,10 @@ grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset, - offset = 512; - #endif - -+ grub_dprintf ("linux", "kernel_addr: %p handover_offset: %p params: %p\n", -+ kernel_addr, (void *)(grub_efi_uintn_t)handover_offset, kernel_params); - hf = (handover_func)((char *)kernel_addr + handover_offset + offset); -+ grub_dprintf ("linux", "handover_func() = %p\n", hf); - hf (grub_efi_image_handle, grub_efi_system_table, kernel_params); - - return GRUB_ERR_BUG; -diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h -index 775297d..b582f67 100644 ---- a/include/grub/arm/linux.h -+++ b/include/grub/arm/linux.h -@@ -31,7 +31,7 @@ struct linux_arm_kernel_header { - grub_uint32_t magic; - grub_uint32_t start; /* _start */ - grub_uint32_t end; /* _edata */ -- grub_uint32_t reserved2[4]; -+ grub_uint32_t reserved2[3]; - grub_uint32_t hdr_offset; - }; - --- -1.8.3.1 - diff --git a/0248-linuxefi-fail-kernel-validation-without-shim-protoco.patch b/0143-linuxefi-fail-kernel-validation-without-shim-protoco.patch similarity index 50% rename from 0248-linuxefi-fail-kernel-validation-without-shim-protoco.patch rename to 0143-linuxefi-fail-kernel-validation-without-shim-protoco.patch index 66fbfd94ac4e70d94964a36d4e166e48c3c831a1..20fc7869fd905eaee3638b632577d1589056b6ca 100644 --- a/0248-linuxefi-fail-kernel-validation-without-shim-protoco.patch +++ b/0143-linuxefi-fail-kernel-validation-without-shim-protoco.patch @@ -1,7 +1,7 @@ -From b01dc9aaedb5a5e91e2ca10748fce65406d657c0 Mon Sep 17 00:00:00 2001 -From: Fedora Ninjas -Date: Mon, 10 Aug 2020 14:54:34 +0800 -Subject: [PATCH 7/7] linuxefi: fail kernel validation without shim protocol. +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Dimitri John Ledkov +Date: Wed, 22 Jul 2020 11:31:43 +0100 +Subject: [PATCH] linuxefi: fail kernel validation without shim protocol. If certificates that signed grub are installed into db, grub can be booted directly. It will then boot any kernel without signature @@ -15,24 +15,32 @@ CVE-2020-15705 Reported-by: Mathieu Trudel-Lapierre Signed-off-by: Dimitri John Ledkov -Signed-off-by: Baogen Shang --- - grub-core/loader/arm64/linux.c | 12 ++++++++---- - grub-core/loader/efi/linux.c | 1 + - grub-core/loader/i386/efi/linux.c | 13 ++++++++----- - 3 files changed, 17 insertions(+), 9 deletions(-) + grub-core/loader/arm64/linux.c | 13 +++++++++---- + grub-core/loader/efi/chainloader.c | 1 + + grub-core/loader/efi/linux.c | 1 + + grub-core/loader/i386/efi/linux.c | 17 +++++++++++------ + 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c -index 8791b35..a18c487 100644 +index 70a0075ec5e..47f8cf0d84b 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c -@@ -383,11 +383,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -34,6 +34,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -363,11 +364,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); - rc = grub_linuxefi_secure_validate (kernel_addr, kernel_size); - if (rc < 0) -+ if (grub_efi_secure_boot ()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) { - grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]); - goto fail; @@ -46,8 +54,20 @@ index 8791b35..a18c487 100644 } pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset); +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index ac8dfd40c61..d41e8ea14a8 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -1084,6 +1084,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + + return 0; + } ++ // -1 fall-through to fail + + fail: + if (dev) diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c -index e09f824..927d89a 100644 +index e8b9ecb17f6..9260731c107 100644 --- a/grub-core/loader/efi/linux.c +++ b/grub-core/loader/efi/linux.c @@ -33,6 +33,7 @@ struct grub_efi_shim_lock @@ -59,16 +79,33 @@ index e09f824..927d89a 100644 grub_linuxefi_secure_validate (void *data, grub_uint32_t size) { diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index e5b2736..e613115 100644 +index f992ceeef20..3cf0f9b330b 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c -@@ -301,12 +301,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -30,6 +30,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -101,7 +102,7 @@ kernel_alloc(grub_efi_uintn_t size, const char * const errmsg) + + pages = BYTES_TO_PAGES(size); + grub_dprintf ("linux", "Trying to allocate %lu pages from %p\n", +- pages, (void *)max); ++ (unsigned long)pages, (void *)(unsigned long)max); + + prev_max = max; + addr = grub_efi_allocate_pages_real (max, pages, +@@ -307,12 +308,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } - rc = grub_linuxefi_secure_validate (kernel, filelen); - if (rc < 0) -+ if (grub_efi_secure_boot ()) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) { - grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), - argv[0]); @@ -83,6 +120,11 @@ index e5b2736..e613115 100644 } lh = (struct linux_i386_kernel_header *)kernel; --- -1.8.3.1 - +@@ -386,6 +390,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201); + grub_dprintf ("linux", "copying %lu bytes from %p to %p\n", ++ (unsigned long) + MIN((grub_size_t)0x202+setup_header_end_offset, + sizeof (*params)) - 0x1f1, + (grub_uint8_t *)kernel + 0x1f1, diff --git a/0144-Fix-const-char-pointers-in-grub-core-net-bootp.c.patch b/0144-Fix-const-char-pointers-in-grub-core-net-bootp.c.patch new file mode 100644 index 0000000000000000000000000000000000000000..9b0db5f9e1aa935a4367b7f5a8b16d3a862f2d53 --- /dev/null +++ b/0144-Fix-const-char-pointers-in-grub-core-net-bootp.c.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 20 Jul 2020 12:24:02 -0400 +Subject: [PATCH] Fix const char ** pointers in grub-core/net/bootp.c + +This will need to get folded back in the right place on the next rebase, +but it's before "Make grub_strtol() "end" pointers have safer const +qualifiers" currently, so for now I'm leaving it here instead of merging +it back with the original patch. + +Signed-off-by: Peter Jones +--- + grub-core/net/bootp.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index 8fb8918ae7e..7baf3540c81 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -329,7 +329,7 @@ grub_net_configure_by_dhcp_ack (const char *name, + struct grub_net_network_level_interface *inter; + int mask = -1; + char server_ip[sizeof ("xxx.xxx.xxx.xxx")]; +- const grub_uint8_t *opt; ++ const char *opt; + grub_uint8_t opt_len, overload = 0; + const char *boot_file = 0, *server_name = 0; + grub_size_t boot_file_len, server_name_len; +@@ -505,7 +505,7 @@ grub_net_configure_by_dhcp_ack (const char *name, + if (opt && opt_len) + { + grub_env_set_net_property (name, "vendor_class_identifier", (const char *) opt, opt_len); +- if (opt && grub_strcmp (opt, "HTTPClient") == 0) ++ if (opt && grub_strcmp ((char *)opt, "HTTPClient") == 0) + { + char *proto, *ip, *pa; + diff --git a/0145-Fix-const-char-pointers-in-grub-core-net-efi-ip4_con.patch b/0145-Fix-const-char-pointers-in-grub-core-net-efi-ip4_con.patch new file mode 100644 index 0000000000000000000000000000000000000000..6c16e9efd8123dfef1edd25fae1ca237559f1251 --- /dev/null +++ b/0145-Fix-const-char-pointers-in-grub-core-net-efi-ip4_con.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 20 Jul 2020 12:24:02 -0400 +Subject: [PATCH] Fix const char ** pointers in grub-core/net/efi/ip4_config.c + +This will need to get folded back in the right place on the next rebase, +but it's before "Make grub_strtol() "end" pointers have safer const +qualifiers" currently, so for now I'm leaving it here instead of merging +it back with the original patch. + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/ip4_config.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c +index 9725e928f7e..cb880fc3e8f 100644 +--- a/grub-core/net/efi/ip4_config.c ++++ b/grub-core/net/efi/ip4_config.c +@@ -61,7 +61,8 @@ 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, ncolon = 0; ++ grub_size_t i; ++ int ncolon = 0; + const char *ptr = val; + + /* Check that is not an IPv6 address */ +@@ -78,7 +79,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/0146-EFI-more-debug-output-on-GOP-and-UGA-probing.patch b/0146-EFI-more-debug-output-on-GOP-and-UGA-probing.patch deleted file mode 100644 index 85de92f2705341162b98f0e9230802227aebca25..0000000000000000000000000000000000000000 --- a/0146-EFI-more-debug-output-on-GOP-and-UGA-probing.patch +++ /dev/null @@ -1,69 +0,0 @@ -From 18dd72a5313ff33acaa0dd5e933ea7933439cedc Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 10 Sep 2018 13:01:24 -0400 -Subject: [PATCH 146/220] EFI: more debug output on GOP and UGA probing. - -Signed-off-by: Peter Jones ---- - grub-core/video/efi_gop.c | 8 +++++++- - grub-core/video/efi_uga.c | 4 ++-- - 2 files changed, 9 insertions(+), 3 deletions(-) - -diff --git a/grub-core/video/efi_gop.c b/grub-core/video/efi_gop.c -index c9e40e8..be446f8 100644 ---- a/grub-core/video/efi_gop.c -+++ b/grub-core/video/efi_gop.c -@@ -71,7 +71,10 @@ check_protocol (void) - handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, - &graphics_output_guid, NULL, &num_handles); - if (!handles || num_handles == 0) -- return 0; -+ { -+ grub_dprintf ("video", "GOP: no handles\n"); -+ return 0; -+ } - - for (i = 0; i < num_handles; i++) - { -@@ -81,6 +84,7 @@ check_protocol (void) - grub_video_gop_iterate (check_protocol_hook, &have_usable_mode); - if (have_usable_mode) - { -+ grub_dprintf ("video", "GOP: found usable mode\n"); - grub_free (handles); - return 1; - } -@@ -89,6 +93,8 @@ check_protocol (void) - gop = 0; - gop_handle = 0; - -+ grub_dprintf ("video", "GOP: no usable mode\n"); -+ - return 0; - } - -diff --git a/grub-core/video/efi_uga.c b/grub-core/video/efi_uga.c -index 97a607c..e74d6c2 100644 ---- a/grub-core/video/efi_uga.c -+++ b/grub-core/video/efi_uga.c -@@ -110,7 +110,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) - { - int i; - -- grub_dprintf ("fb", "Display controller: %d:%d.%d\nDevice id: %x\n", -+ grub_dprintf ("video", "Display controller: %d:%d.%d\nDevice id: %x\n", - grub_pci_get_bus (dev), grub_pci_get_device (dev), - grub_pci_get_function (dev), pciid); - addr += 8; -@@ -140,7 +140,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) - base64 <<= 32; - base64 |= (old_bar1 & GRUB_PCI_ADDR_MEM_MASK); - -- grub_dprintf ("fb", "%s(%d): 0x%" PRIxGRUB_UINT64_T "\n", -+ grub_dprintf ("video", "%s(%d): 0x%" PRIxGRUB_UINT64_T "\n", - ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) ? - "VMEM" : "MMIO"), type == GRUB_PCI_ADDR_MEM_TYPE_64 ? i - 1 : i, - base64); --- -1.8.3.1 - diff --git a/0146-Fix-const-char-pointers-in-grub-core-net-efi-ip6_con.patch b/0146-Fix-const-char-pointers-in-grub-core-net-efi-ip6_con.patch new file mode 100644 index 0000000000000000000000000000000000000000..7c29683eea176b76c6d2dcecd15e829e52442596 --- /dev/null +++ b/0146-Fix-const-char-pointers-in-grub-core-net-efi-ip6_con.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 20 Jul 2020 12:24:02 -0400 +Subject: [PATCH] Fix const char ** pointers in grub-core/net/efi/ip6_config.c + +This will need to get folded back in the right place on the next rebase, +but it's before "Make grub_strtol() "end" pointers have safer const +qualifiers" currently, so for now I'm leaving it here instead of merging +it back with the original patch. + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/ip6_config.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/net/efi/ip6_config.c b/grub-core/net/efi/ip6_config.c +index a46f6f9b685..1c5415d7185 100644 +--- a/grub-core/net/efi/ip6_config.c ++++ b/grub-core/net/efi/ip6_config.c +@@ -85,7 +85,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/0147-Fix-const-char-pointers-in-grub-core-net-efi-net.c.patch b/0147-Fix-const-char-pointers-in-grub-core-net-efi-net.c.patch new file mode 100644 index 0000000000000000000000000000000000000000..0fe90c8b0a0d4ec3b397db037236cf8bab467ad2 --- /dev/null +++ b/0147-Fix-const-char-pointers-in-grub-core-net-efi-net.c.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 20 Jul 2020 12:24:02 -0400 +Subject: [PATCH] Fix const char ** pointers in grub-core/net/efi/net.c + +This will need to get folded back in the right place on the next rebase, +but it's before "Make grub_strtol() "end" pointers have safer const +qualifiers" currently, so for now I'm leaving it here instead of merging +it back with the original patch. + +Signed-off-by: Peter Jones +--- + 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 a3f0535d43c..78e5442fc52 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/0148-Fix-const-char-pointers-in-grub-core-net-efi-pxe.c.patch b/0148-Fix-const-char-pointers-in-grub-core-net-efi-pxe.c.patch new file mode 100644 index 0000000000000000000000000000000000000000..59f29e4f651ca6a4a55f3a4f5919e2e663bcdbf5 --- /dev/null +++ b/0148-Fix-const-char-pointers-in-grub-core-net-efi-pxe.c.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 20 Jul 2020 12:24:02 -0400 +Subject: [PATCH] Fix const char ** pointers in grub-core/net/efi/pxe.c + +This will need to get folded back in the right place on the next rebase, +but it's before "Make grub_strtol() "end" pointers have safer const +qualifiers" currently, so for now I'm leaving it here instead of merging +it back with the original patch. + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/pxe.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +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/0149-Add-systemd-integration-scripts-to-make-systemctl-re.patch b/0149-Add-systemd-integration-scripts-to-make-systemctl-re.patch new file mode 100644 index 0000000000000000000000000000000000000000..8e2481e71d46bc3b8d74ea79054c818e9a6790a9 --- /dev/null +++ b/0149-Add-systemd-integration-scripts-to-make-systemctl-re.patch @@ -0,0 +1,190 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Wed, 22 Jul 2020 14:03:42 +0200 +Subject: [PATCH] Add systemd integration scripts to make "systemctl reboot + --boot-loader-menu=xxx" work with grub + +This commit adds a number of scripts / config files to make +"systemctl reboot --boot-loader-menu=xxx" work with grub: + +1. /lib/systemd/system/systemd-logind.service.d/10-grub.conf +This sets SYSTEMD_REBOOT_TO_BOOT_LOADER_MENU in the env. for logind, +indicating that the boot-loader which is used supports this feature, see: +https://github.com/systemd/systemd/blob/master/docs/ENVIRONMENT.md + +2. /lib/systemd/system/grub-systemd-integration.service + /lib/systemd/system/reboot.target.wants/grub-systemd-integration.service -> + ../grub-systemd-integration.service + /usr/libexec/grub/grub-systemd-integration.sh + +The symlink in the .wants dir causes the added service file to be started +by systemd just before rebooting the system. +If /run/systemd/reboot-to-boot-loader-menu exist then the service will run +the grub-systemd-integration.sh script. +This script sets the new menu_show_once_timeout grubenv variable to the +requested timeout in seconds. + +3. /etc/grub.d/14_menu_show_once + +This new grub-mkconfig snippet adds the necessary code to the generated +grub.conf to honor the new menu_show_once_timeout variable, and to +automatically clear it after consuming it. + +Note the service and libexec script use grub-systemd-integration as name +because in the future they may be used to add further integration with +systemctl reboot --foo options, e.g. support for --boot-loader-entry=NAME. + +A few notes about upstreaming this patch from the rhboot grub2 fork: +1. I have deliberately put the grub.conf bits for this in a new / separate + grub-mkconfig snippet generator for easy upstreaming +2. Even though the commit message mentions the .wants symlink for the .service + I have been unable to come up with a clean way to do this at "make install" + time, this should be fixed before upstreaming. + +Downstream notes: +1. Since make install does not add the .wants symlink, this needs to be done + in grub2.spec %install +2. This is keeping support for the "old" Fedora specific menu_show_once env + variable, which has a hardcoded timeout of 60 sec in 12_menu_auto_hide in + place for now. This can be dropped (eventually) in a follow-up patch once + GNOME has been converted to use the systemd dbus API equivalent of + "systemctl reboot --boot-loader-menu=xxx". + +Signed-off-by: Hans de Goede +--- + Makefile.util.def | 27 ++++++++++++++++++++++++ + conf/Makefile.common | 6 ++++++ + util/grub.d/14_menu_show_once.in | 13 ++++++++++++ + util/systemd/10-grub-logind-service.conf.in | 2 ++ + util/systemd/grub-systemd-integration.service.in | 8 +++++++ + util/systemd/systemd-integration.sh.in | 6 ++++++ + 6 files changed, 62 insertions(+) + create mode 100755 util/grub.d/14_menu_show_once.in + create mode 100644 util/systemd/10-grub-logind-service.conf.in + create mode 100644 util/systemd/grub-systemd-integration.service.in + create mode 100644 util/systemd/systemd-integration.sh.in + +diff --git a/Makefile.util.def b/Makefile.util.def +index 2e6ad979c3e..9927c2cfd6a 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -470,6 +470,12 @@ script = { + installdir = grubconf; + }; + ++script = { ++ name = '14_menu_show_once'; ++ common = util/grub.d/14_menu_show_once.in; ++ installdir = grubconf; ++}; ++ + script = { + name = '01_users'; + common = util/grub.d/01_users.in; +@@ -569,6 +575,27 @@ script = { + installdir = grubconf; + }; + ++script = { ++ name = 'grub-systemd-integration.service'; ++ common = util/systemd/grub-systemd-integration.service.in; ++ installdir = systemdunit; ++ condition = COND_HOST_LINUX; ++}; ++ ++script = { ++ name = 'systemd-integration.sh'; ++ common = util/systemd/systemd-integration.sh.in; ++ installdir = grublibexec; ++ condition = COND_HOST_LINUX; ++}; ++ ++script = { ++ name = '10-grub-logind-service.conf'; ++ common = util/systemd/10-grub-logind-service.conf.in; ++ installdir = systemd_logind_service_d; ++ condition = COND_HOST_LINUX; ++}; ++ + program = { + mansection = 1; + name = grub-mkrescue; +diff --git a/conf/Makefile.common b/conf/Makefile.common +index 0647c53b916..9fe5863b2d9 100644 +--- a/conf/Makefile.common ++++ b/conf/Makefile.common +@@ -63,8 +63,11 @@ CCASFLAGS_LIBRARY = $(UTILS_CCASFLAGS) + # Other variables + + grubconfdir = $(sysconfdir)/grub.d ++grublibexecdir = $(libexecdir)/$(grubdirname) + platformdir = $(pkglibdir)/$(target_cpu)-$(platform) + starfielddir = $(pkgdatadir)/themes/starfield ++systemdunitdir = ${prefix}/lib/systemd/system ++systemd_logind_service_ddir = $(systemdunitdir)/systemd-logind.service.d + + CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Werror=trampolines -fno-trampolines + CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib +@@ -121,6 +124,9 @@ noinst_LIBRARIES = + dist_noinst_DATA = + platform_SCRIPTS = + platform_PROGRAMS = ++grublibexec_SCRIPTS = ++systemdunit_SCRIPTS = ++systemd_logind_service_d_SCRIPTS = + + TESTS = + EXTRA_DIST = +diff --git a/util/grub.d/14_menu_show_once.in b/util/grub.d/14_menu_show_once.in +new file mode 100755 +index 00000000000..1cd7f36142b +--- /dev/null ++++ b/util/grub.d/14_menu_show_once.in +@@ -0,0 +1,13 @@ ++#! /bin/sh ++# Force the menu to be shown once, with a timeout of ${menu_show_once_timeout} ++# if requested by ${menu_show_once_timeout} being set in the env. ++cat << EOF ++if [ x\$feature_timeout_style = xy ]; then ++ if [ "\${menu_show_once_timeout}" ]; then ++ set timeout_style=menu ++ set timeout="\${menu_show_once_timeout}" ++ unset menu_show_once_timeout ++ save_env menu_show_once_timeout ++ fi ++fi ++EOF +diff --git a/util/systemd/10-grub-logind-service.conf.in b/util/systemd/10-grub-logind-service.conf.in +new file mode 100644 +index 00000000000..f2d4ac00732 +--- /dev/null ++++ b/util/systemd/10-grub-logind-service.conf.in +@@ -0,0 +1,2 @@ ++[Service] ++Environment=SYSTEMD_REBOOT_TO_BOOT_LOADER_MENU=true +diff --git a/util/systemd/grub-systemd-integration.service.in b/util/systemd/grub-systemd-integration.service.in +new file mode 100644 +index 00000000000..c81fb594ce1 +--- /dev/null ++++ b/util/systemd/grub-systemd-integration.service.in +@@ -0,0 +1,8 @@ ++[Unit] ++Description=Grub2 systemctl reboot --boot-loader-menu=... support ++Before=umount.target systemd-reboot.service ++DefaultDependencies=no ++ConditionPathExists=/run/systemd/reboot-to-boot-loader-menu ++ ++[Service] ++ExecStart=@libexecdir@/@grubdirname@/systemd-integration.sh +diff --git a/util/systemd/systemd-integration.sh.in b/util/systemd/systemd-integration.sh.in +new file mode 100644 +index 00000000000..dc1218597bc +--- /dev/null ++++ b/util/systemd/systemd-integration.sh.in +@@ -0,0 +1,6 @@ ++#!/bin/sh ++ ++TIMEOUT_USEC=$(cat /run/systemd/reboot-to-boot-loader-menu) ++TIMEOUT=$(((TIMEOUT_USEC + 500000) / 1000000)) ++ ++@grub_editenv@ - set menu_show_once_timeout=$TIMEOUT diff --git a/0150-systemd-integration.sh-Also-set-old-menu_show_once-g.patch b/0150-systemd-integration.sh-Also-set-old-menu_show_once-g.patch new file mode 100644 index 0000000000000000000000000000000000000000..9021de505793c9dad90df26f5264c2979268c13b --- /dev/null +++ b/0150-systemd-integration.sh-Also-set-old-menu_show_once-g.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Thu, 23 Jul 2020 09:27:36 +0200 +Subject: [PATCH] systemd-integration.sh: Also set old menu_show_once grubenv + var + +Downstream RH / Fedora patch for compatibility with old, not (yet) +regenerated grub.cfg files which miss the menu_show_once_timeout check. +This older grubenv variable leads to a fixed timeout of 60 seconds. + +Note that the new menu_show_once_timeout will overrule these 60 seconds +if both are set and the grub.cfg does have the menu_show_once_timeout +check. + +Signed-off-by: Hans de Goede +--- + util/systemd/systemd-integration.sh.in | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/util/systemd/systemd-integration.sh.in b/util/systemd/systemd-integration.sh.in +index dc1218597bc..a4c071c5b0c 100644 +--- a/util/systemd/systemd-integration.sh.in ++++ b/util/systemd/systemd-integration.sh.in +@@ -4,3 +4,8 @@ TIMEOUT_USEC=$(cat /run/systemd/reboot-to-boot-loader-menu) + TIMEOUT=$(((TIMEOUT_USEC + 500000) / 1000000)) + + @grub_editenv@ - set menu_show_once_timeout=$TIMEOUT ++ ++# Downstream RH / Fedora patch for compatibility with old, not (yet) ++# regenerated grub.cfg files which miss the menu_show_once_timeout check ++# this older grubenv variable leads to a fixed timeout of 60 seconds ++@grub_editenv@ - set menu_show_once=1 diff --git a/0151-at_keyboard-use-set-1-when-keyboard-is-in-Translate-.patch b/0151-at_keyboard-use-set-1-when-keyboard-is-in-Translate-.patch new file mode 100644 index 0000000000000000000000000000000000000000..c3388409860f73d9656d4ec7eabd6d51db6379ff --- /dev/null +++ b/0151-at_keyboard-use-set-1-when-keyboard-is-in-Translate-.patch @@ -0,0 +1,121 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Renaud=20M=C3=A9trich?= +Date: Thu, 3 Dec 2020 09:13:24 +0100 +Subject: [PATCH] at_keyboard: use set 1 when keyboard is in Translate mode +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +When keyboard controller acts in Translate mode (0x40 mask), then use +set 1 since translation is done. +Otherwise use the mode queried from the controller (usually set 2). + +Added "atkeyb" debugging messages in at_keyboard module as well. + +Resolves: rhbz#1897587 + +Tested on: +- Asus N53SN (set 1 used) +- Dell Precision (set 1 used) +- HP Elitebook (set 2 used) +- HP G5430 (set 1 used, keyboard in XT mode!) +- Lenovo P71 & Lenovo T460s (set 2 used) +- QEMU/KVM (set 1 used) + +Signed-off-by: Renaud Métrich +--- + grub-core/term/at_keyboard.c | 29 ++++++++++++++++++++++++----- + include/grub/at_keyboard.h | 4 ++++ + 2 files changed, 28 insertions(+), 5 deletions(-) + +diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c +index 597111077bd..26014382608 100644 +--- a/grub-core/term/at_keyboard.c ++++ b/grub-core/term/at_keyboard.c +@@ -135,20 +135,28 @@ query_mode (void) + int e; + + e = write_mode (0); +- if (!e) ++ if (!e) { ++ grub_dprintf("atkeyb", "query_mode: write_mode(0) failed\n"); + return 0; ++ } + + do { + keyboard_controller_wait_until_ready (); + ret = grub_inb (KEYBOARD_REG_DATA); + } while (ret == GRUB_AT_ACK); + /* QEMU translates the set even in no-translate mode. */ +- if (ret == 0x43 || ret == 1) ++ if (ret == 0x43 || ret == 1) { ++ grub_dprintf("atkeyb", "query_mode: returning 1 (ret=0x%x)\n", ret); + return 1; +- if (ret == 0x41 || ret == 2) ++ } ++ if (ret == 0x41 || ret == 2) { ++ grub_dprintf("atkeyb", "query_mode: returning 2 (ret=0x%x)\n", ret); + return 2; +- if (ret == 0x3f || ret == 3) ++ } ++ if (ret == 0x3f || ret == 3) { ++ grub_dprintf("atkeyb", "query_mode: returning 3 (ret=0x%x)\n", ret); + return 3; ++ } + return 0; + } + +@@ -165,7 +173,13 @@ set_scancodes (void) + } + + #if !USE_SCANCODE_SET +- ps2_state.current_set = 1; ++ if ((grub_keyboard_controller_orig & KEYBOARD_AT_TRANSLATE) == KEYBOARD_AT_TRANSLATE) { ++ grub_dprintf ("atkeyb", "queried set is %d but keyboard in Translate mode, so actually in set 1\n", grub_keyboard_orig_set); ++ ps2_state.current_set = 1; ++ } else { ++ grub_dprintf ("atkeyb", "using queried set %d\n", grub_keyboard_orig_set); ++ ps2_state.current_set = grub_keyboard_orig_set; ++ } + return; + #else + +@@ -266,6 +280,7 @@ grub_keyboard_controller_init (void) + grub_keyboard_orig_set = 2; + #else + grub_keyboard_controller_orig = grub_keyboard_controller_read (); ++ grub_dprintf ("atkeyb", "grub_keyboard_controller_orig = 0x%x\n", grub_keyboard_controller_orig); + grub_keyboard_orig_set = query_mode (); + #endif + set_scancodes (); +@@ -275,11 +290,15 @@ grub_keyboard_controller_init (void) + static grub_err_t + grub_keyboard_controller_fini (struct grub_term_input *term __attribute__ ((unused))) + { ++/* In !USE_SCANCODE_SET mode, we didn't change anything, so nothing to restore */ ++#if USE_SCANCODE_SET + if (ps2_state.current_set == 0) + return GRUB_ERR_NONE; ++ grub_dprintf ("atkeyb", "restoring set %d, controller 0x%x\n", grub_keyboard_orig_set, grub_keyboard_controller_orig); + if (grub_keyboard_orig_set) + write_mode (grub_keyboard_orig_set); + grub_keyboard_controller_write (grub_keyboard_controller_orig); ++#endif + return GRUB_ERR_NONE; + } + +diff --git a/include/grub/at_keyboard.h b/include/grub/at_keyboard.h +index bcb4d9ba78f..9414dc1b996 100644 +--- a/include/grub/at_keyboard.h ++++ b/include/grub/at_keyboard.h +@@ -19,6 +19,10 @@ + #ifndef GRUB_AT_KEYBOARD_HEADER + #define GRUB_AT_KEYBOARD_HEADER 1 + ++/* ++ * Refer to https://wiki.osdev.org/%228042%22_PS/2_Controller for details. ++ */ ++ + /* Used for sending commands to the controller. */ + #define KEYBOARD_COMMAND_ISREADY(x) !((x) & 0x02) + #define KEYBOARD_COMMAND_READ 0x20 diff --git a/0152-grub-install-disable-support-for-EFI-platforms.patch b/0152-grub-install-disable-support-for-EFI-platforms.patch new file mode 100644 index 0000000000000000000000000000000000000000..41003e2548dac8d0a1adccd069388e3e2c1f61c3 --- /dev/null +++ b/0152-grub-install-disable-support-for-EFI-platforms.patch @@ -0,0 +1,120 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jan Hlavac +Date: Fri, 20 Nov 2020 23:51:47 +0100 +Subject: [PATCH] grub-install: disable support for EFI platforms + +For each platform, GRUB is shipped as a kernel image and a set of +modules. These files are then used by the grub-install utility to +install GRUB on a specific device. However, in order to support UEFI +Secure Boot, the resulting EFI binary must be signed by a recognized +private key. For this reason, for EFI platforms, most distributions also +ship prebuilt EFI binaries signed by a distribution-specific private +key. In this case, however, the grub-install utility should not be used +because it would overwrite the signed EFI binary. + +The current fix is suboptimal because it preserves all EFI-related code. +A better solution could be to modularize the code and provide a +build-time option. + +Resolves: rhbz#1737444 + +Signed-off-by: Jan Hlavac +--- + util/grub-install.c | 37 ++++++++++++++++--------------------- + docs/grub.texi | 7 +++++++ + util/grub-install.8 | 4 +++- + 3 files changed, 26 insertions(+), 22 deletions(-) + +diff --git a/util/grub-install.c b/util/grub-install.c +index a2bec7446cb..5babc7af551 100644 +--- a/util/grub-install.c ++++ b/util/grub-install.c +@@ -899,6 +899,22 @@ main (int argc, char *argv[]) + + platform = grub_install_get_target (grub_install_source_directory); + ++ switch (platform) ++ { ++ case GRUB_INSTALL_PLATFORM_ARM_EFI: ++ case GRUB_INSTALL_PLATFORM_ARM64_EFI: ++ case GRUB_INSTALL_PLATFORM_I386_EFI: ++ case GRUB_INSTALL_PLATFORM_IA64_EFI: ++ case GRUB_INSTALL_PLATFORM_X86_64_EFI: ++ is_efi = 1; ++ grub_util_error (_("this utility cannot be used for EFI platforms" ++ " because it does not support UEFI Secure Boot")); ++ break; ++ default: ++ is_efi = 0; ++ break; ++ } ++ + { + char *platname = grub_install_get_platform_name (platform); + fprintf (stderr, _("Installing for %s platform.\n"), platname); +@@ -1011,28 +1027,7 @@ main (int argc, char *argv[]) + grub_hostfs_init (); + grub_host_init (); + +- switch (platform) +- { +- case GRUB_INSTALL_PLATFORM_I386_EFI: +- case GRUB_INSTALL_PLATFORM_X86_64_EFI: +- case GRUB_INSTALL_PLATFORM_ARM_EFI: +- case GRUB_INSTALL_PLATFORM_ARM64_EFI: +- case GRUB_INSTALL_PLATFORM_RISCV32_EFI: +- case GRUB_INSTALL_PLATFORM_RISCV64_EFI: +- case GRUB_INSTALL_PLATFORM_IA64_EFI: +- is_efi = 1; +- break; +- default: +- is_efi = 0; +- break; +- +- /* pacify warning. */ +- case GRUB_INSTALL_PLATFORM_MAX: +- break; +- } +- + /* Find the EFI System Partition. */ +- + if (is_efi) + { + grub_fs_t fs; +diff --git a/docs/grub.texi b/docs/grub.texi +index 04ed6ac1f07..4870faaa00a 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -6509,6 +6509,13 @@ grub2-install @var{install_device} + The device name @var{install_device} is an OS device name or a GRUB + device name. + ++In order to support UEFI Secure Boot, the resulting GRUB EFI binary must ++be signed by a recognized private key. For this reason, for EFI ++platforms, most distributions also ship prebuilt GRUB EFI binaries ++signed by a distribution-specific private key. In this case, however, ++@command{grub2-install} should not be used because it would overwrite ++the signed EFI binary. ++ + @command{grub2-install} accepts the following options: + + @table @option +diff --git a/util/grub-install.8 b/util/grub-install.8 +index 1db89e94b3b..811d441b16c 100644 +--- a/util/grub-install.8 ++++ b/util/grub-install.8 +@@ -1,4 +1,4 @@ +-.TH GRUB-INSTALL 1 "Wed Feb 26 2014" ++.TH GRUB-INSTALL 1 "Fri Nov 20 2020" + .SH NAME + \fBgrub-install\fR \(em Install GRUB on a device. + +@@ -31,6 +31,8 @@ + .SH DESCRIPTION + \fBgrub-install\fR installs GRUB onto a device. This includes copying GRUB images into the target directory (generally \fI/boot/grub\fR), and on some platforms may also include installing GRUB onto a boot sector. + ++In order to support UEFI Secure Boot, the resulting GRUB EFI binary must be signed by a recognized private key. For this reason, for EFI platforms, most distributions also ship prebuilt GRUB EFI binaries signed by a distribution-specific private key. In this case, however, the \fBgrub-install\fR utility should not be used because it would overwrite the signed EFI binary. ++ + .SH OPTIONS + .TP + \fB--modules\fR=\fIMODULES\fR\! diff --git a/0153-New-with-debug-timestamps-configure-flag-to-prepend-.patch b/0153-New-with-debug-timestamps-configure-flag-to-prepend-.patch new file mode 100644 index 0000000000000000000000000000000000000000..d216284c1218f2bf5243ae1d2bac12302ca9fc60 --- /dev/null +++ b/0153-New-with-debug-timestamps-configure-flag-to-prepend-.patch @@ -0,0 +1,112 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Renaud=20M=C3=A9trich?= +Date: Sat, 23 Nov 2019 14:57:41 +0100 +Subject: [PATCH] New --with-debug-timestamps configure flag to prepend debug + traces with absolute and relative timestamp +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Signed-off-by: Renaud Métrich +--- + configure.ac | 18 ++++++++++++++++++ + grub-core/kern/misc.c | 20 ++++++++++++++++++++ + config.h.in | 1 + + 3 files changed, 39 insertions(+) + +diff --git a/configure.ac b/configure.ac +index c6bd965f1f9..3c808a72230 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1613,6 +1613,17 @@ else + fi + AC_SUBST([BOOT_TIME_STATS]) + ++AC_ARG_WITH([debug-timestamps], ++ AS_HELP_STRING([--with-debug-timestamps], ++ [prepend debug traces with absolute and relative timestamps])) ++ ++if test x$with_debug_timestamps = xyes; then ++ DEBUG_WITH_TIMESTAMPS=1 ++else ++ DEBUG_WITH_TIMESTAMPS=0 ++fi ++AC_SUBST([DEBUG_WITH_TIMESTAMPS]) ++ + AC_ARG_ENABLE([grub-emu-sdl], + [AS_HELP_STRING([--enable-grub-emu-sdl], + [build and install the `grub-emu' debugging utility with SDL support (default=guessed)])]) +@@ -2194,6 +2205,7 @@ AM_CONDITIONAL([COND_APPLE_LINKER], [test x$TARGET_APPLE_LINKER = x1]) + AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes]) + AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1]) + AM_CONDITIONAL([COND_ENABLE_BOOT_TIME_STATS], [test x$BOOT_TIME_STATS = x1]) ++AM_CONDITIONAL([COND_DEBUG_WITH_TIMESTAMPS], [test x$DEBUG_WITH_TIMESTAMPS = x1]) + + AM_CONDITIONAL([COND_HAVE_CXX], [test x$HAVE_CXX = xyes]) + +@@ -2289,6 +2301,12 @@ else + echo With boot time statistics: No + fi + ++if [ x"$with_debug_timestamps" = xyes ]; then ++echo Debug traces with timestamps: Yes ++else ++echo Debug traces with timestamps: No ++fi ++ + if [ x"$efiemu_excuse" = x ]; then + echo efiemu runtime: Yes + else +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 578bf51a5fc..9f54b6b7d2d 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -25,6 +25,9 @@ + #include + #include + #include ++#if DEBUG_WITH_TIMESTAMPS ++#include ++#endif + + union printf_arg + { +@@ -192,9 +195,26 @@ grub_real_dprintf (const char *file, const int line, const char *condition, + const char *fmt, ...) + { + va_list args; ++#if DEBUG_WITH_TIMESTAMPS ++ static long unsigned int last_time = 0; ++ static int last_had_cr = 1; ++#endif + + if (grub_debug_enabled (condition)) + { ++#if DEBUG_WITH_TIMESTAMPS ++ /* Don't print timestamp if last printed message isn't terminated yet */ ++ if (last_had_cr) { ++ long unsigned int tmabs = (long unsigned int) grub_get_time_ms(); ++ long unsigned int tmrel = tmabs - last_time; ++ last_time = tmabs; ++ grub_printf ("%3lu.%03lus +%2lu.%03lus ", tmabs / 1000, tmabs % 1000, tmrel / 1000, tmrel % 1000); ++ } ++ if (fmt[grub_strlen(fmt)-1] == '\n') ++ last_had_cr = 1; ++ else ++ last_had_cr = 0; ++#endif + grub_printf ("%s:%d: ", file, line); + va_start (args, fmt); + grub_vprintf (fmt, args); +diff --git a/config.h.in b/config.h.in +index c7e316f0f1f..c80e3e0aba3 100644 +--- a/config.h.in ++++ b/config.h.in +@@ -12,6 +12,7 @@ + /* Define to 1 to enable disk cache statistics. */ + #define DISK_CACHE_STATS @DISK_CACHE_STATS@ + #define BOOT_TIME_STATS @BOOT_TIME_STATS@ ++#define DEBUG_WITH_TIMESTAMPS @DEBUG_WITH_TIMESTAMPS@ + + /* We don't need those. */ + #define MINILZO_CFG_SKIP_LZO_PTR 1 diff --git a/0154-Added-debug-statements-to-grub_disk_open-and-grub_di.patch b/0154-Added-debug-statements-to-grub_disk_open-and-grub_di.patch new file mode 100644 index 0000000000000000000000000000000000000000..cbb1a38e3ab76bad82372262ee46967cf5888a39 --- /dev/null +++ b/0154-Added-debug-statements-to-grub_disk_open-and-grub_di.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Renaud=20M=C3=A9trich?= +Date: Sat, 23 Nov 2019 15:22:16 +0100 +Subject: [PATCH] Added debug statements to grub_disk_open() and + grub_disk_close() on success +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Signed-off-by: Renaud Métrich +--- + grub-core/kern/disk.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c +index e1b0e073e09..05a28ab1429 100644 +--- a/grub-core/kern/disk.c ++++ b/grub-core/kern/disk.c +@@ -285,6 +285,8 @@ grub_disk_open (const char *name) + return 0; + } + ++ grub_dprintf ("disk", "Opening `%s' succeeded.\n", name); ++ + return disk; + } + +@@ -292,7 +294,7 @@ void + grub_disk_close (grub_disk_t disk) + { + grub_partition_t part; +- grub_dprintf ("disk", "Closing `%s'.\n", disk->name); ++ grub_dprintf ("disk", "Closing `%s'...\n", disk->name); + + if (disk->dev && disk->dev->disk_close) + (disk->dev->disk_close) (disk); +@@ -306,8 +308,10 @@ grub_disk_close (grub_disk_t disk) + grub_free (disk->partition); + disk->partition = part; + } ++ grub_dprintf ("disk", "Closing `%s' succeeded.\n", disk->name); + grub_free ((void *) disk->name); + grub_free (disk); ++ + } + + /* Small read (less than cache size and not pass across cache unit boundaries). diff --git a/0099-Add-grub_debug_enabled.patch b/0155-Introduce-function-grub_debug_is_enabled-void-return.patch similarity index 32% rename from 0099-Add-grub_debug_enabled.patch rename to 0155-Introduce-function-grub_debug_is_enabled-void-return.patch index 1cd52b20c59f4f96fbf1e736a958cd2e90761494..4e4718b7898a951a26d8ea939e0b681ab41c3795 100644 --- a/0099-Add-grub_debug_enabled.patch +++ b/0155-Introduce-function-grub_debug_is_enabled-void-return.patch @@ -1,63 +1,51 @@ -From 211d314fd314f2cced175de112ddc418ab763d23 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 30 Nov 2017 15:11:39 -0500 -Subject: [PATCH 099/220] Add grub_debug_enabled() +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Renaud=20M=C3=A9trich?= +Date: Mon, 25 Nov 2019 09:29:53 +0100 +Subject: [PATCH] Introduce function grub_debug_is_enabled(void) returning 1 if + 'debug' is in the environment and not empty +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +Signed-off-by: Renaud Métrich --- - grub-core/kern/misc.c | 21 ++++++++++++++++----- + grub-core/kern/misc.c | 13 +++++++++++++ include/grub/misc.h | 1 + - 2 files changed, 17 insertions(+), 5 deletions(-) + 2 files changed, 14 insertions(+) diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 636f97e..e758ab3 100644 +index 9f54b6b7d2d..a186ad3dd41 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c -@@ -159,17 +159,28 @@ int grub_err_printf (const char *fmt, ...) +@@ -163,6 +163,19 @@ int grub_err_printf (const char *fmt, ...) __attribute__ ((alias("grub_printf"))); #endif ++/* Return 1 if 'debug' is set and not empty */ +int -+grub_debug_enabled (const char * condition) ++grub_debug_is_enabled (void) +{ + const char *debug; + + debug = grub_env_get ("debug"); -+ if (!debug) ++ if (!debug || debug[0] == '\0') + return 0; + -+ if (grub_strword (debug, "all") || grub_strword (debug, condition)) -+ return 1; -+ -+ return 0; ++ return 1; +} + - void - grub_real_dprintf (const char *file, const int line, const char *condition, - const char *fmt, ...) + int + grub_debug_enabled (const char * condition) { - va_list args; -- const char *debug = grub_env_get ("debug"); -- -- if (! debug) -- return; - -- if (grub_strword (debug, "all") || grub_strword (debug, condition)) -+ if (grub_debug_enabled (condition)) - { - grub_printf ("%s:%d: ", file, line); - va_start (args, fmt); diff --git a/include/grub/misc.h b/include/grub/misc.h -index b433922..4a4f485 100644 +index 3adc4036e3b..6c4aa85ac50 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h -@@ -367,6 +367,7 @@ grub_puts (const char *s) +@@ -340,6 +340,7 @@ grub_puts (const char *s) } int EXPORT_FUNC(grub_puts_) (const char *s); -+int EXPORT_FUNC(grub_debug_enabled) (const char *condition); ++int EXPORT_FUNC(grub_debug_is_enabled) (void); + int EXPORT_FUNC(grub_debug_enabled) (const char *condition); void EXPORT_FUNC(grub_real_dprintf) (const char *file, const int line, - const char *condition, --- -1.8.3.1 - diff --git a/0030-Don-t-print-GNU-GRUB-header.patch b/0156-Don-t-clear-screen-when-debugging-is-enabled.patch similarity index 31% rename from 0030-Don-t-print-GNU-GRUB-header.patch rename to 0156-Don-t-clear-screen-when-debugging-is-enabled.patch index aff2b0207e133c79ecaf6c0ea3be2733baebf942..d17b080c5e02f587175459f019f0eace26eee521 100644 --- a/0030-Don-t-print-GNU-GRUB-header.patch +++ b/0156-Don-t-clear-screen-when-debugging-is-enabled.patch @@ -1,45 +1,31 @@ -From 9af19d1f8184aad31b3094768a64722316d4f0da Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Wed, 15 May 2013 13:53:48 -0400 -Subject: [PATCH 030/220] Don't print GNU GRUB header +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Renaud=20M=C3=A9trich?= +Date: Sat, 23 Nov 2019 16:23:54 +0100 +Subject: [PATCH] Don't clear screen when debugging is enabled +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit -No one cares. +Signed-off-by: Renaud Métrich +[rharwood@redhat.com: rebase fuzz] +Signed-off-by: Robbie Harwood --- - grub-core/normal/main.c | 8 +++++--- - 1 file changed, 5 insertions(+), 3 deletions(-) + grub-core/normal/main.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index a326b19..09d0dfe 100644 +index 1970e4816a8..4ebdbd228d4 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c -@@ -208,15 +208,16 @@ read_config_file (const char *config) - /* Initialize the screen. */ - void - grub_normal_init_page (struct grub_term_output *term, -- int y) -+ int y __attribute__((__unused__))) - { -+ grub_term_cls (term); -+ -+#if 0 - grub_ssize_t msg_len; - int posx; +@@ -215,8 +215,9 @@ grub_normal_init_page (struct grub_term_output *term, char *msg_formatted; grub_uint32_t *unicode_msg; grub_uint32_t *last_position; - - grub_term_cls (term); ++ ++ if (! grub_debug_is_enabled ()) ++ grub_term_cls (term); msg_formatted = grub_xasprintf (_("GNU GRUB version %s"), PACKAGE_VERSION); if (!msg_formatted) -@@ -241,6 +242,7 @@ grub_normal_init_page (struct grub_term_output *term, - grub_putcode ('\n', term); - grub_putcode ('\n', term); - grub_free (unicode_msg); -+#endif - } - - static void --- -1.8.3.1 - diff --git a/0157-grub_file_-instrumentation-new-file-debug-tag.patch b/0157-grub_file_-instrumentation-new-file-debug-tag.patch new file mode 100644 index 0000000000000000000000000000000000000000..0cc6b8c98eafa150f85697d0172c22e8b713b6ff --- /dev/null +++ b/0157-grub_file_-instrumentation-new-file-debug-tag.patch @@ -0,0 +1,71 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Renaud=20M=C3=A9trich?= +Date: Fri, 29 Nov 2019 11:02:00 +0100 +Subject: [PATCH] grub_file_* instrumentation (new 'file' debug tag) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Signed-off-by: Renaud Métrich +--- + grub-core/kern/file.c | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) + +diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c +index 58454458c47..e19aea3e514 100644 +--- a/grub-core/kern/file.c ++++ b/grub-core/kern/file.c +@@ -66,6 +66,8 @@ grub_file_open (const char *name, enum grub_file_type type) + const char *file_name; + grub_file_filter_id_t filter; + ++ grub_dprintf ("file", "Opening `%s' ...\n", name); ++ + device_name = grub_file_get_device_name (name); + if (grub_errno) + goto fail; +@@ -128,6 +130,8 @@ grub_file_open (const char *name, enum grub_file_type type) + if (!file) + grub_file_close (last_file); + ++ grub_dprintf ("file", "Opening `%s' succeeded.\n", name); ++ + return file; + + fail: +@@ -138,6 +142,8 @@ grub_file_open (const char *name, enum grub_file_type type) + + grub_free (file); + ++ grub_dprintf ("file", "Opening `%s' failed.\n", name); ++ + return 0; + } + +@@ -169,6 +175,7 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len) + + if (len == 0) + return 0; ++ + read_hook = file->read_hook; + read_hook_data = file->read_hook_data; + if (!file->read_hook) +@@ -189,11 +196,18 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len) + grub_err_t + grub_file_close (grub_file_t file) + { ++ grub_dprintf ("file", "Closing `%s' ...\n", file->name); + if (file->fs->fs_close) + (file->fs->fs_close) (file); + + if (file->device) + grub_device_close (file->device); ++ ++ if (grub_errno == GRUB_ERR_NONE) ++ grub_dprintf ("file", "Closing `%s' succeeded.\n", file->name); ++ else ++ grub_dprintf ("file", "Closing `%s' failed with %d.\n", file->name, grub_errno); ++ + grub_free (file->name); + grub_free (file); + return grub_errno; diff --git a/0158-ieee1275-Avoiding-many-unecessary-open-close.patch b/0158-ieee1275-Avoiding-many-unecessary-open-close.patch new file mode 100644 index 0000000000000000000000000000000000000000..6a0ad75b7c3e581a0144d9db8de9c5ceec3ea7f6 --- /dev/null +++ b/0158-ieee1275-Avoiding-many-unecessary-open-close.patch @@ -0,0 +1,136 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Diego Domingos +Date: Mon, 14 Dec 2020 17:42:45 +0100 +Subject: [PATCH] ieee1275: Avoiding many unecessary open/close + +Signed-off-by: Diego Domingos +--- + grub-core/disk/ieee1275/ofdisk.c | 64 ++++++++++++++++++++++------------------ + 1 file changed, 35 insertions(+), 29 deletions(-) + +diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c +index 03674cb477e..ea7f78ac7d8 100644 +--- a/grub-core/disk/ieee1275/ofdisk.c ++++ b/grub-core/disk/ieee1275/ofdisk.c +@@ -44,7 +44,7 @@ struct ofdisk_hash_ent + }; + + static grub_err_t +-grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size, ++grub_ofdisk_get_block_size (grub_uint32_t *block_size, + struct ofdisk_hash_ent *op); + + #define OFDISK_HASH_SZ 8 +@@ -461,6 +461,7 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) + grub_ssize_t actual; + grub_uint32_t block_size = 0; + grub_err_t err; ++ struct ofdisk_hash_ent *op; + + if (grub_strncmp (name, "ieee1275/", sizeof ("ieee1275/") - 1) != 0) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, +@@ -471,6 +472,35 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) + + grub_dprintf ("disk", "Opening `%s'.\n", devpath); + ++ op = ofdisk_hash_find (devpath); ++ if (!op) ++ op = ofdisk_hash_add (devpath, NULL); ++ if (!op) ++ { ++ grub_free (devpath); ++ return grub_errno; ++ } ++ ++ /* Check if the call to open is the same to the last disk already opened */ ++ if (last_devpath && !grub_strcmp(op->open_path,last_devpath)) ++ { ++ goto finish; ++ } ++ ++ /* If not, we need to close the previous disk and open the new one */ ++ else { ++ if (last_ihandle){ ++ grub_ieee1275_close (last_ihandle); ++ } ++ last_ihandle = 0; ++ last_devpath = NULL; ++ ++ grub_ieee1275_open (op->open_path, &last_ihandle); ++ if (! last_ihandle) ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); ++ last_devpath = op->open_path; ++ } ++ + if (grub_ieee1275_finddevice (devpath, &dev)) + { + grub_free (devpath); +@@ -491,25 +521,18 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a block device"); + } + ++ ++ finish: + /* XXX: There is no property to read the number of blocks. There + should be a property `#blocks', but it is not there. Perhaps it + is possible to use seek for this. */ + disk->total_sectors = GRUB_DISK_SIZE_UNKNOWN; + + { +- struct ofdisk_hash_ent *op; +- op = ofdisk_hash_find (devpath); +- if (!op) +- op = ofdisk_hash_add (devpath, NULL); +- if (!op) +- { +- grub_free (devpath); +- return grub_errno; +- } + disk->id = (unsigned long) op; + disk->data = op->open_path; + +- err = grub_ofdisk_get_block_size (devpath, &block_size, op); ++ err = grub_ofdisk_get_block_size (&block_size, op); + if (err) + { + grub_free (devpath); +@@ -532,13 +555,6 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) + static void + grub_ofdisk_close (grub_disk_t disk) + { +- if (disk->data == last_devpath) +- { +- if (last_ihandle) +- grub_ieee1275_close (last_ihandle); +- last_ihandle = 0; +- last_devpath = NULL; +- } + disk->data = 0; + } + +@@ -685,7 +701,7 @@ grub_ofdisk_init (void) + } + + static grub_err_t +-grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size, ++grub_ofdisk_get_block_size (grub_uint32_t *block_size, + struct ofdisk_hash_ent *op) + { + struct size_args_ieee1275 +@@ -698,16 +714,6 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size, + grub_ieee1275_cell_t size2; + } args_ieee1275; + +- if (last_ihandle) +- grub_ieee1275_close (last_ihandle); +- +- last_ihandle = 0; +- last_devpath = NULL; +- +- grub_ieee1275_open (device, &last_ihandle); +- if (! last_ihandle) +- return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); +- + *block_size = 0; + + if (op->block_size_fails >= 2) diff --git a/0159-ieee1275-powerpc-implements-fibre-channel-discovery-.patch b/0159-ieee1275-powerpc-implements-fibre-channel-discovery-.patch new file mode 100644 index 0000000000000000000000000000000000000000..9fa02bb1748cd09b8bc33e536d1736bca49b5c96 --- /dev/null +++ b/0159-ieee1275-powerpc-implements-fibre-channel-discovery-.patch @@ -0,0 +1,90 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Diego Domingos +Date: Mon, 14 Dec 2020 17:45:28 +0100 +Subject: [PATCH] ieee1275/powerpc: implements fibre channel discovery for + ofpathname + +grub-ofpathname doesn't work with fibre channel because there is no +function currently implemented for it. +This patch enables it by prividing a function that looks for the port +name, building the entire path for OF devices. + +Signed-off-by: Diego Domingos +--- + grub-core/osdep/linux/ofpath.c | 49 ++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 49 insertions(+) + +diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c +index a6153d35954..0f5d54e9f2d 100644 +--- a/grub-core/osdep/linux/ofpath.c ++++ b/grub-core/osdep/linux/ofpath.c +@@ -350,6 +350,38 @@ of_path_of_ide(const char *sys_devname __attribute__((unused)), const char *devi + return ret; + } + ++ ++static void ++of_fc_port_name(const char *path, const char *subpath, char *port_name) ++{ ++ char *bname, *basepath, *p; ++ int fd; ++ ++ bname = xmalloc(sizeof(char)*150); ++ basepath = xmalloc(strlen(path)); ++ ++ /* Generate the path to get port name information from the drive */ ++ strncpy(basepath,path,subpath-path); ++ basepath[subpath-path-1] = '\0'; ++ p = get_basename(basepath); ++ snprintf(bname,sizeof(char)*150,"%s/fc_transport/%s/port_name",basepath,p); ++ ++ /* Read the information from the port name */ ++ fd = open (bname, O_RDONLY); ++ if (fd < 0) ++ grub_util_error (_("cannot open `%s': %s"), bname, strerror (errno)); ++ ++ if (read(fd,port_name,sizeof(char)*19) < 0) ++ grub_util_error (_("cannot read `%s': %s"), bname, strerror (errno)); ++ ++ sscanf(port_name,"0x%s",port_name); ++ ++ close(fd); ++ ++ free(bname); ++ free(basepath); ++} ++ + #ifdef __sparc__ + static char * + of_path_of_nvme(const char *sys_devname __attribute__((unused)), +@@ -577,6 +609,16 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev + digit_string = trailing_digits (device); + if (strncmp (of_path, "/vdevice/", sizeof ("/vdevice/") - 1) == 0) + { ++ if(strstr(of_path,"vfc-client")) ++ { ++ char * port_name = xmalloc(sizeof(char)*17); ++ of_fc_port_name(sysfs_path, p, port_name); ++ ++ snprintf(disk,sizeof(disk),"/%s@%s", disk_name, port_name); ++ free(port_name); ++ } ++ else ++ { + unsigned long id = 0x8000 | (tgt << 8) | (bus << 5) | lun; + if (*digit_string == '\0') + { +@@ -590,6 +632,13 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev + snprintf(disk, sizeof (disk), + "/%s@%04lx000000000000:%c", disk_name, id, 'a' + (part - 1)); + } ++ } ++ } else if (strstr(of_path,"fibre-channel")||(strstr(of_path,"vfc-client"))){ ++ char * port_name = xmalloc(sizeof(char)*17); ++ of_fc_port_name(sysfs_path, p, port_name); ++ ++ snprintf(disk,sizeof(disk),"/%s@%s", disk_name, port_name); ++ free(port_name); + } + else + { 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 deleted file mode 100644 index 234bf07c198f98ba8b944ebe4e97a52cb288295f..0000000000000000000000000000000000000000 --- a/0160-Make-grub_strtol-end-pointers-have-safer-const-quali.patch +++ /dev/null @@ -1,990 +0,0 @@ -From 9b30aea6e6282803165d852d2dc0e1d35836114f Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 19 Oct 2018 13:41:48 -0400 -Subject: [PATCH 160/220] 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 +- - include/grub/misc.h | 24 +++++++++++++++++++++--- - util/grub-fstest.c | 2 +- - 38 files changed, 96 insertions(+), 75 deletions(-) - -diff --git a/grub-core/commands/date.c b/grub-core/commands/date.c -index 8e1f41f..5cb4faf 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 c839b70..9f6b56a 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 c818131..a980e46 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 15b9adf..46c4346 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 9c5e510..fa76f5a 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 da636e6..ab845d2 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 f99ad4a..f72628f 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 f00b184..7c5c72f 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 d5bc97d..e966af0 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 4e929e0..62d3fb3 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 4be8107..016a4d8 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 1a3eb6b..3f264be 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 7b265c7..0cbd0dd 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 c5c3d4b..dd42bc6 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 354dd7b..7578bfb 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 d6829bb..eae8308 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 2b85f49..88d3936 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 5c3899f..e21dd44 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 e499147..2c401b8 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 fd7744a..ccc1850 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 ef56150..05719ab 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 4afa992..de9fda0 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 5b9b92d..50cca30 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 376c726..201e659 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 fe3e1d4..0bf0e13 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 6329ec0..27afcaa 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 6a31cba..b569cb2 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 c9c5969..b52b558 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 27a0a1d..aa56393 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 046a1fb..37d753d 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 2be654c..3b2c9de 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 a697bcb..a8afc0c 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 ba38b5e..c6d2c36 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 db80b3b..f9271b0 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 29df35e..537a5c0 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 7da615f..5488ab2 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/include/grub/misc.h b/include/grub/misc.h -index 960097f..998e47e 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/util/grub-fstest.c b/util/grub-fstest.c -index 88f9c5d..39bad1f 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) - { --- -1.8.3.1 - diff --git a/0160-ieee1275-powerpc-enables-device-mapper-discovery.patch b/0160-ieee1275-powerpc-enables-device-mapper-discovery.patch new file mode 100644 index 0000000000000000000000000000000000000000..6f1c21b383fd252e4854dc3887291f85548cb242 --- /dev/null +++ b/0160-ieee1275-powerpc-enables-device-mapper-discovery.patch @@ -0,0 +1,106 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Diego Domingos +Date: Mon, 14 Dec 2020 17:47:16 +0100 +Subject: [PATCH] ieee1275/powerpc: enables device mapper discovery + +this patch enables the device mapper discovery on ofpath.c. Currently, +when we are dealing with a device like /dev/dm-* the ofpath returns null +since there is no function implemented to handle this case. + +This patch implements a function that will look into /sys/block/dm-* +devices and search recursively inside slaves directory to find the root +disk. + +Signed-off-by: Diego Domingos +--- + grub-core/osdep/linux/ofpath.c | 64 +++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 63 insertions(+), 1 deletion(-) + +diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c +index 0f5d54e9f2d..cc849d9c94c 100644 +--- a/grub-core/osdep/linux/ofpath.c ++++ b/grub-core/osdep/linux/ofpath.c +@@ -37,6 +37,7 @@ + #include + #include + #include ++#include + + #ifdef __sparc__ + typedef enum +@@ -755,13 +756,74 @@ strip_trailing_digits (const char *p) + return new; + } + ++static char * ++get_slave_from_dm(const char * device){ ++ char *curr_device, *tmp; ++ char *directory; ++ char *ret = NULL; ++ ++ directory = grub_strdup (device); ++ tmp = get_basename(directory); ++ curr_device = grub_strdup (tmp); ++ *tmp = '\0'; ++ ++ /* Recursively check for slaves devices so we can find the root device */ ++ while ((curr_device[0] == 'd') && (curr_device[1] == 'm') && (curr_device[2] == '-')){ ++ DIR *dp; ++ struct dirent *ep; ++ char* device_path; ++ ++ device_path = grub_xasprintf ("/sys/block/%s/slaves", curr_device); ++ dp = opendir(device_path); ++ free(device_path); ++ ++ if (dp != NULL) ++ { ++ ep = readdir (dp); ++ while (ep != NULL){ ++ ++ /* avoid some system directories */ ++ if (!strcmp(ep->d_name,".")) ++ goto next_dir; ++ if (!strcmp(ep->d_name,"..")) ++ goto next_dir; ++ ++ free (curr_device); ++ free (ret); ++ curr_device = grub_strdup (ep->d_name); ++ ret = grub_xasprintf ("%s%s", directory, curr_device); ++ break; ++ ++ next_dir: ++ ep = readdir (dp); ++ continue; ++ } ++ closedir (dp); ++ } ++ else ++ grub_util_warn (_("cannot open directory `%s'"), device_path); ++ } ++ ++ free (directory); ++ free (curr_device); ++ ++ return ret; ++} ++ + char * + grub_util_devname_to_ofpath (const char *sys_devname) + { +- char *name_buf, *device, *devnode, *devicenode, *ofpath; ++ char *name_buf, *device, *devnode, *devicenode, *ofpath, *realname; + + name_buf = xrealpath (sys_devname); + ++ realname = get_slave_from_dm (name_buf); ++ if (realname) ++ { ++ free (name_buf); ++ name_buf = realname; ++ } ++ + device = get_basename (name_buf); + devnode = strip_trailing_digits (name_buf); + devicenode = strip_trailing_digits (device); diff --git a/0161-Add-at_keyboard_fallback_set-var-to-force-the-set-ma.patch b/0161-Add-at_keyboard_fallback_set-var-to-force-the-set-ma.patch new file mode 100644 index 0000000000000000000000000000000000000000..01e7e678065830fce114171c60706ea62bc4d9ba --- /dev/null +++ b/0161-Add-at_keyboard_fallback_set-var-to-force-the-set-ma.patch @@ -0,0 +1,245 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Renaud=20M=C3=A9trich?= +Date: Fri, 18 Dec 2020 15:39:26 +0100 +Subject: [PATCH] Add 'at_keyboard_fallback_set' var to force the set manually +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This seems required with HP DL380p Gen 8 systems. +Indeed, with this system, we can see the following sequence: + +1. controller is queried to get current configuration (returns 0x30 which is quite standard) +2. controller is queried to get the current keyboard set in used, using code 0xf0 (first part) +3. controller answers with 0xfa which means "ACK" (== ok) +4. then we send "0" to tell "we want to know which set your are supporting" +5. controller answers with 0xfa ("ACK") +6. controller should then give us 1, 2, 3 or 0x43, 0x41, 0x3f, but here it gives us 0xfe which means "NACK" + +Since there seems no way to determine the current set, and in fact the +controller expects set2 to be used, we need to rely on an environment +variable. +Everything has been tested on this system: using 0xFE (resend command), +making sure we wait for ACK in the 2 steps "write_mode", etc. + +Below is litterature I used to come up with "there is no other +solution": +- https://wiki.osdev.org/%228042%22_PS/2_Controller +- http://www-ug.eecg.toronto.edu/msl/nios_devices/datasheets/PS2%20Keyboard%20Protocol.htm +- http://www.s100computers.com/My%20System%20Pages/MSDOS%20Board/PC%20Keyboard.pdf + +Signed-off-by: Renaud Métrich +Signed-off-by: Robbie Harwood +--- + grub-core/term/at_keyboard.c | 121 ++++++++++++++++++++++++++++++++++--------- + 1 file changed, 96 insertions(+), 25 deletions(-) + +diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c +index 26014382608..dac0f946fe6 100644 +--- a/grub-core/term/at_keyboard.c ++++ b/grub-core/term/at_keyboard.c +@@ -31,6 +31,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); + static grub_uint8_t grub_keyboard_controller_orig; + static grub_uint8_t grub_keyboard_orig_set; + struct grub_ps2_state ps2_state; ++static int fallback_set; + + static int ping_sent; + +@@ -76,6 +77,8 @@ at_command (grub_uint8_t data) + break; + return 0; + } ++ if (i == GRUB_AT_TRIES) ++ grub_dprintf ("atkeyb", "at_command() timed out! (stopped after %d tries)\n", i); + return (i != GRUB_AT_TRIES); + } + +@@ -105,6 +108,21 @@ grub_keyboard_controller_read (void) + + #endif + ++static int ++resend_last_result (void) ++{ ++ grub_uint8_t ret; ++ keyboard_controller_wait_until_ready (); ++ grub_dprintf ("atkeyb", "resend_last_result: sending 0xfe\n"); ++ grub_outb (0xfe, KEYBOARD_REG_DATA); ++ ret = wait_ack (); ++ grub_dprintf ("atkeyb", "resend_last_result: wait_ack() returned 0x%x\n", ret); ++ keyboard_controller_wait_until_ready (); ++ ret = grub_inb (KEYBOARD_REG_DATA); ++ grub_dprintf ("atkeyb", "resend_last_result: read 0x%x from controller\n", ret); ++ return ret; ++} ++ + static int + write_mode (int mode) + { +@@ -113,11 +131,14 @@ write_mode (int mode) + { + grub_uint8_t ack; + keyboard_controller_wait_until_ready (); ++ grub_dprintf ("atkeyb", "write_mode: sending 0xf0\n"); + grub_outb (0xf0, KEYBOARD_REG_DATA); + keyboard_controller_wait_until_ready (); ++ grub_dprintf ("atkeyb", "write_mode: sending mode %d\n", mode); + grub_outb (mode, KEYBOARD_REG_DATA); + keyboard_controller_wait_until_ready (); + ack = wait_ack (); ++ grub_dprintf ("atkeyb", "write_mode: wait_ack() returned 0x%x\n", ack); + if (ack == GRUB_AT_NACK) + continue; + if (ack == GRUB_AT_ACK) +@@ -125,6 +146,9 @@ write_mode (int mode) + return 0; + } + ++ if (i == GRUB_AT_TRIES) ++ grub_dprintf ("atkeyb", "write_mode() timed out! (stopped after %d tries)\n", i); ++ + return (i != GRUB_AT_TRIES); + } + +@@ -132,31 +156,66 @@ static int + query_mode (void) + { + grub_uint8_t ret; ++ grub_uint64_t endtime; ++ unsigned i; + int e; ++ char *envvar; + +- e = write_mode (0); +- if (!e) { +- grub_dprintf("atkeyb", "query_mode: write_mode(0) failed\n"); +- return 0; +- } ++ for (i = 0; i < GRUB_AT_TRIES; i++) { ++ grub_dprintf ("atkeyb", "query_mode: sending command to controller\n"); ++ e = write_mode (0); ++ if (!e) { ++ grub_dprintf ("atkeyb", "query_mode: write_mode(0) failed\n"); ++ return 0; ++ } + +- do { +- keyboard_controller_wait_until_ready (); +- ret = grub_inb (KEYBOARD_REG_DATA); +- } while (ret == GRUB_AT_ACK); +- /* QEMU translates the set even in no-translate mode. */ +- if (ret == 0x43 || ret == 1) { +- grub_dprintf("atkeyb", "query_mode: returning 1 (ret=0x%x)\n", ret); +- return 1; +- } +- if (ret == 0x41 || ret == 2) { +- grub_dprintf("atkeyb", "query_mode: returning 2 (ret=0x%x)\n", ret); +- return 2; ++ endtime = grub_get_time_ms () + 20; ++ do { ++ keyboard_controller_wait_until_ready (); ++ ret = grub_inb (KEYBOARD_REG_DATA); ++ grub_dprintf ("atkeyb", "query_mode/loop: read 0x%x from controller\n", ret); ++ } while ((ret == GRUB_AT_ACK || ret == GRUB_AT_NACK) && grub_get_time_ms () < endtime); ++ if (ret == 0xfe) { ++ grub_dprintf ("atkeyb", "query_mode: asking controller to resend last result\n"); ++ ret = resend_last_result(); ++ grub_dprintf ("atkeyb", "query_mode: read 0x%x from controller\n", ret); ++ } ++ /* QEMU translates the set even in no-translate mode. */ ++ if (ret == 0x43 || ret == 1) { ++ grub_dprintf ("atkeyb", "query_mode: controller returned 0x%x, returning 1\n", ret); ++ return 1; ++ } ++ if (ret == 0x41 || ret == 2) { ++ grub_dprintf ("atkeyb", "query_mode: controller returned 0x%x, returning 2\n", ret); ++ return 2; ++ } ++ if (ret == 0x3f || ret == 3) { ++ grub_dprintf ("atkeyb", "query_mode: controller returned 0x%x, returning 3\n", ret); ++ return 3; ++ } ++ grub_dprintf ("atkeyb", "query_mode: controller returned unexpected value 0x%x, retrying\n", ret); + } +- if (ret == 0x3f || ret == 3) { +- grub_dprintf("atkeyb", "query_mode: returning 3 (ret=0x%x)\n", ret); +- return 3; ++ ++ /* ++ * Falling here means we tried querying and the controller returned something ++ * we don't understand, try to use 'at_keyboard_fallback_set' if it exists, ++ * otherwise return 0. ++ */ ++ envvar = grub_env_get ("at_keyboard_fallback_set"); ++ if (envvar) { ++ fallback_set = grub_strtoul (envvar, 0, 10); ++ if ((grub_errno) || (fallback_set < 1) || (fallback_set > 3)) { ++ grub_dprintf ("atkeyb", "WARNING: ignoring unexpected value '%s' for '%s' variable\n", ++ envvar, "at_keyboard_fallback_set"); ++ fallback_set = 0; ++ } else { ++ grub_dprintf ("atkeyb", "query_mode: '%s' specified in environment, returning %d\n", ++ "at_keyboard_fallback_set", fallback_set); ++ } ++ return fallback_set; + } ++ grub_dprintf ("atkeyb", "WARNING: no '%s' specified in environment, returning 0\n", ++ "at_keyboard_fallback_set"); + return 0; + } + +@@ -165,14 +224,25 @@ set_scancodes (void) + { + /* You must have visited computer museum. Keyboard without scancode set + knowledge. Assume XT. */ +- if (!grub_keyboard_orig_set) +- { +- grub_dprintf ("atkeyb", "No sets support assumed\n"); +- ps2_state.current_set = 1; ++ if (!grub_keyboard_orig_set) { ++ if (fallback_set) { ++ grub_dprintf ("atkeyb", "No sets support assumed but set forced to %d\n", fallback_set); ++ ps2_state.current_set = fallback_set; + return; + } ++ grub_dprintf ("atkeyb", "No sets support assumed, forcing to set 1\n"); ++ ps2_state.current_set = 1; ++ return; ++ } + + #if !USE_SCANCODE_SET ++ if (fallback_set) { ++ grub_dprintf ("atkeyb", "queried set is %d but set forced to %d\n", ++ grub_keyboard_orig_set, fallback_set); ++ ps2_state.current_set = fallback_set; ++ return; ++ } ++ + if ((grub_keyboard_controller_orig & KEYBOARD_AT_TRANSLATE) == KEYBOARD_AT_TRANSLATE) { + grub_dprintf ("atkeyb", "queried set is %d but keyboard in Translate mode, so actually in set 1\n", grub_keyboard_orig_set); + ps2_state.current_set = 1; +@@ -261,6 +331,7 @@ grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused))) + static void + grub_keyboard_controller_init (void) + { ++ grub_dprintf ("atkeyb", "initializing the controller\n"); + ps2_state.at_keyboard_status = 0; + /* Drain input buffer. */ + while (1) +@@ -282,6 +353,7 @@ grub_keyboard_controller_init (void) + grub_keyboard_controller_orig = grub_keyboard_controller_read (); + grub_dprintf ("atkeyb", "grub_keyboard_controller_orig = 0x%x\n", grub_keyboard_controller_orig); + grub_keyboard_orig_set = query_mode (); ++ grub_dprintf ("atkeyb", "grub_keyboard_orig_set = %d\n", grub_keyboard_orig_set); + #endif + set_scancodes (); + keyboard_controller_led (ps2_state.led_status); +@@ -329,7 +401,6 @@ grub_at_restore_hw (void) + return GRUB_ERR_NONE; + } + +- + static struct grub_term_input grub_at_keyboard_term = + { + .name = "at_keyboard", diff --git a/0162-Add-suport-for-signing-grub-with-an-appended-signatu.patch b/0162-Add-suport-for-signing-grub-with-an-appended-signatu.patch new file mode 100644 index 0000000000000000000000000000000000000000..caab8d58080c155afbe7998d11c9078e2a5cca0e --- /dev/null +++ b/0162-Add-suport-for-signing-grub-with-an-appended-signatu.patch @@ -0,0 +1,316 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Rashmica Gupta +Date: Thu, 11 Jun 2020 11:26:23 +1000 +Subject: [PATCH] Add suport for signing grub with an appended signature + +Add infrastructure to allow firmware to verify the integrity of grub +by use of a Linux-kernel-module-style appended signature. We initially +target powerpc-ieee1275, but the code should be extensible to other +platforms. + +Usually these signatures are appended to a file without modifying the +ELF file itself. (This is what the 'sign-file' tool does, for example.) +The verifier loads the signed file from the file system and looks at the +end of the file for the appended signature. However, on powerpc-ieee1275 +platforms, the bootloader is often stored directly in the PReP partition +as raw bytes without a file-system. This makes determining the location +of an appended signature more difficult. + +To address this, we add a new ELF note. + +The name field of shall be the string "Appended-Signature", zero-padded +to 4 byte alignment. The type field shall be 0x41536967 (the ASCII values +for the string "ASig"). It must be the final section in the ELF binary. + +The description shall contain the appended signature structure as defined +by the Linux kernel. The description will also be padded to be a multiple +of 4 bytes. The padding shall be added before the appended signature +structure (not at the end) so that the final bytes of a signed ELF file +are the appended signature magic. + +A subsequent patch documents how to create a grub core.img validly signed +under this scheme. + +Signed-off-by: Daniel Axtens +Signed-off-by: Rashmica Gupta + +--- + +You can experiment with this code with a patched version of SLOF +that verifies these signatures. You can find one at: + https://github.com/daxtens/SLOF + +I will be proposing this for inclusion in a future Power Architecture +Platform Reference (PAPR). +--- + util/grub-install-common.c | 18 ++++++++++++++++-- + util/grub-mkimage.c | 15 +++++++++++++-- + util/grub-mkimagexx.c | 39 ++++++++++++++++++++++++++++++++++++++- + util/mkimage.c | 13 +++++++------ + include/grub/util/install.h | 8 ++++++-- + include/grub/util/mkimage.h | 4 ++-- + 6 files changed, 82 insertions(+), 15 deletions(-) + +diff --git a/util/grub-install-common.c b/util/grub-install-common.c +index 4e212e690c5..aab2a941f85 100644 +--- a/util/grub-install-common.c ++++ b/util/grub-install-common.c +@@ -461,10 +461,12 @@ static size_t npubkeys; + static char *sbat; + static int disable_shim_lock; + static grub_compression_t compression; ++static size_t appsig_size; + + int + grub_install_parse (int key, char *arg) + { ++ const char *end; + switch (key) + { + case 'C': +@@ -562,6 +564,12 @@ grub_install_parse (int key, char *arg) + grub_util_error (_("Unrecognized compression `%s'"), arg); + case GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE: + return 1; ++ case GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE: ++ grub_errno = 0; ++ appsig_size = grub_strtol(arg, &end, 10); ++ if (grub_errno) ++ return 0; ++ return 1; + default: + return 0; + } +@@ -665,7 +673,13 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, + dir, prefix, + outname, dtb ? : "", sbat ? : "", mkimage_target, + compnames[compression], note ? "--note" : "", +- disable_shim_lock ? "--disable-shim-lock" : "", s); ++ disable_shim_lock ? "--disable-shim-lock" : "", ++ "--format '%s' --compression '%s' " ++ "--appended-signature-size %zu %s %s\n", ++ dir, prefix, ++ outname, dtb ? : "", mkimage_target, ++ compnames[compression], appsig_size, ++ note ? "--note" : "", s); + free (s); + + tgt = grub_install_get_image_target (mkimage_target); +@@ -675,7 +689,7 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, + grub_install_generate_image (dir, prefix, fp, outname, + modules.entries, memdisk_path, + pubkeys, npubkeys, config_path, tgt, +- note, compression, dtb, sbat, ++ note, appsig_size, compression, dtb, sbat, + disable_shim_lock); + while (dc--) + grub_install_pop_module (); +diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c +index c0d55993702..8a53310548b 100644 +--- a/util/grub-mkimage.c ++++ b/util/grub-mkimage.c +@@ -84,6 +84,7 @@ static struct argp_option options[] = { + {"sbat", 's', N_("FILE"), 0, N_("SBAT metadata"), 0}, + {"disable-shim-lock", GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK, 0, 0, N_("disable shim_lock verifier"), 0}, + {"verbose", 'v', 0, 0, N_("print verbose messages."), 0}, ++ {"appended-signature-size", 'S', N_("SIZE"), 0, N_("Add a note segment reserving SIZE bytes for an appended signature"), 0}, + { 0, 0, 0, 0, 0, 0 } + }; + +@@ -128,6 +129,7 @@ struct arguments + char *sbat; + int note; + int disable_shim_lock; ++ size_t appsig_size; + const struct grub_install_image_target_desc *image_target; + grub_compression_t comp; + }; +@@ -138,6 +140,7 @@ argp_parser (int key, char *arg, struct argp_state *state) + /* Get the input argument from argp_parse, which we + know is a pointer to our arguments structure. */ + struct arguments *arguments = state->input; ++ const char* end; + + switch (key) + { +@@ -170,6 +173,13 @@ argp_parser (int key, char *arg, struct argp_state *state) + arguments->note = 1; + break; + ++ case 'S': ++ grub_errno = 0; ++ arguments->appsig_size = grub_strtol(arg, &end, 10); ++ if (grub_errno) ++ return 0; ++ break; ++ + case 'm': + if (arguments->memdisk) + free (arguments->memdisk); +@@ -324,8 +334,9 @@ main (int argc, char *argv[]) + arguments.memdisk, arguments.pubkeys, + arguments.npubkeys, arguments.config, + arguments.image_target, arguments.note, +- arguments.comp, arguments.dtb, +- arguments.sbat, arguments.disable_shim_lock); ++ arguments.appsig_size, arguments.comp, ++ arguments.dtb, arguments.sbat, ++ arguments.disable_shim_lock); + + if (grub_util_file_sync (fp) < 0) + grub_util_error (_("cannot sync `%s': %s"), arguments.output ? : "stdout", +diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c +index d78fa3e5330..393119486d3 100644 +--- a/util/grub-mkimagexx.c ++++ b/util/grub-mkimagexx.c +@@ -84,6 +84,15 @@ struct grub_ieee1275_note + struct grub_ieee1275_note_desc descriptor; + }; + ++#define GRUB_APPENDED_SIGNATURE_NOTE_NAME "Appended-Signature" ++#define GRUB_APPENDED_SIGNATURE_NOTE_TYPE 0x41536967 /* "ASig" */ ++ ++struct grub_appended_signature_note ++{ ++ Elf32_Nhdr header; ++ char name[ALIGN_UP(sizeof (GRUB_APPENDED_SIGNATURE_NOTE_NAME), 4)]; ++}; ++ + #define GRUB_XEN_NOTE_NAME "Xen" + + struct fixup_block_list +@@ -207,7 +216,7 @@ grub_arm_reloc_jump24 (grub_uint32_t *target, Elf32_Addr sym_addr) + + void + SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc *image_target, +- int note, char **core_img, size_t *core_size, ++ int note, size_t appsig_size, char **core_img, size_t *core_size, + Elf_Addr target_addr, + struct grub_mkimage_layout *layout) + { +@@ -221,6 +230,12 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc + int shnum = 4; + int string_size = sizeof (".text") + sizeof ("mods") + 1; + ++ if (appsig_size) ++ { ++ phnum++; ++ footer_size += ALIGN_UP(sizeof (struct grub_appended_signature_note) + appsig_size, 4); ++ } ++ + if (image_target->id != IMAGE_LOONGSON_ELF) + phnum += 2; + +@@ -484,6 +499,28 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc + phdr->p_offset = grub_host_to_target32 (header_size + program_size); + } + ++ if (appsig_size) { ++ int note_size = ALIGN_UP(sizeof (struct grub_appended_signature_note) + appsig_size, 4); ++ struct grub_appended_signature_note *note_ptr = (struct grub_appended_signature_note *) ++ (elf_img + program_size + header_size + (note ? sizeof (struct grub_ieee1275_note) : 0)); ++ ++ note_ptr->header.n_namesz = grub_host_to_target32 (sizeof (GRUB_APPENDED_SIGNATURE_NOTE_NAME)); ++ /* needs to sit at the end, so we round this up and sign some zero padding */ ++ note_ptr->header.n_descsz = grub_host_to_target32 (ALIGN_UP(appsig_size, 4)); ++ note_ptr->header.n_type = grub_host_to_target32 (GRUB_APPENDED_SIGNATURE_NOTE_TYPE); ++ strcpy (note_ptr->name, GRUB_APPENDED_SIGNATURE_NOTE_NAME); ++ ++ phdr++; ++ phdr->p_type = grub_host_to_target32 (PT_NOTE); ++ phdr->p_flags = grub_host_to_target32 (PF_R); ++ phdr->p_align = grub_host_to_target32 (image_target->voidp_sizeof); ++ phdr->p_vaddr = 0; ++ phdr->p_paddr = 0; ++ phdr->p_filesz = grub_host_to_target32 (note_size); ++ phdr->p_memsz = 0; ++ phdr->p_offset = grub_host_to_target32 (header_size + program_size + (note ? sizeof (struct grub_ieee1275_note) : 0)); ++ } ++ + { + char *str_start = (elf_img + sizeof (*ehdr) + phnum * sizeof (*phdr) + + shnum * sizeof (*shdr)); +diff --git a/util/mkimage.c b/util/mkimage.c +index a26cf76f72f..bab12276010 100644 +--- a/util/mkimage.c ++++ b/util/mkimage.c +@@ -869,8 +869,9 @@ grub_install_generate_image (const char *dir, const char *prefix, + char *memdisk_path, char **pubkey_paths, + size_t npubkeys, char *config_path, + const struct grub_install_image_target_desc *image_target, +- int note, grub_compression_t comp, const char *dtb_path, +- const char *sbat_path, int disable_shim_lock) ++ int note, size_t appsig_size, grub_compression_t comp, ++ const char *dtb_path, const char *sbat_path, ++ int disable_shim_lock) + { + char *kernel_img, *core_img; + size_t total_module_size, core_size; +@@ -1773,11 +1774,11 @@ grub_install_generate_image (const char *dir, const char *prefix, + else + target_addr = image_target->link_addr; + if (image_target->voidp_sizeof == 4) +- grub_mkimage_generate_elf32 (image_target, note, &core_img, &core_size, +- target_addr, &layout); ++ grub_mkimage_generate_elf32 (image_target, note, appsig_size, &core_img, ++ &core_size, target_addr, &layout); + else +- grub_mkimage_generate_elf64 (image_target, note, &core_img, &core_size, +- target_addr, &layout); ++ grub_mkimage_generate_elf64 (image_target, note, appsig_size, &core_img, ++ &core_size, target_addr, &layout); + } + break; + } +diff --git a/include/grub/util/install.h b/include/grub/util/install.h +index 7df3191f47e..cf4531e02b6 100644 +--- a/include/grub/util/install.h ++++ b/include/grub/util/install.h +@@ -67,6 +67,9 @@ + N_("SBAT metadata"), 0 }, \ + { "disable-shim-lock", GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK, 0, 0, \ + N_("disable shim_lock verifier"), 0 }, \ ++ { "appended-signature-size", GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE,\ ++ "SIZE", 0, N_("Add a note segment reserving SIZE bytes for an appended signature"), \ ++ 1}, \ + { "verbose", 'v', 0, 0, \ + N_("print verbose messages."), 1 } + +@@ -128,7 +131,8 @@ enum grub_install_options { + GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS, + GRUB_INSTALL_OPTIONS_DTB, + GRUB_INSTALL_OPTIONS_SBAT, +- GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK ++ GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK, ++ GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE + }; + + extern char *grub_install_source_directory; +@@ -188,7 +192,7 @@ grub_install_generate_image (const char *dir, const char *prefix, + size_t npubkeys, + char *config_path, + const struct grub_install_image_target_desc *image_target, +- int note, ++ int note, size_t appsig_size, + grub_compression_t comp, const char *dtb_file, + const char *sbat_path, const int disable_shim_lock); + +diff --git a/include/grub/util/mkimage.h b/include/grub/util/mkimage.h +index 3819a67441c..6f1da89b9b6 100644 +--- a/include/grub/util/mkimage.h ++++ b/include/grub/util/mkimage.h +@@ -51,12 +51,12 @@ grub_mkimage_load_image64 (const char *kernel_path, + const struct grub_install_image_target_desc *image_target); + void + grub_mkimage_generate_elf32 (const struct grub_install_image_target_desc *image_target, +- int note, char **core_img, size_t *core_size, ++ int note, size_t appsig_size, char **core_img, size_t *core_size, + Elf32_Addr target_addr, + struct grub_mkimage_layout *layout); + void + grub_mkimage_generate_elf64 (const struct grub_install_image_target_desc *image_target, +- int note, char **core_img, size_t *core_size, ++ int note, size_t appsig_size, char **core_img, size_t *core_size, + Elf64_Addr target_addr, + struct grub_mkimage_layout *layout); + diff --git a/0163-docs-grub-Document-signing-grub-under-UEFI.patch b/0163-docs-grub-Document-signing-grub-under-UEFI.patch new file mode 100644 index 0000000000000000000000000000000000000000..9b9b19a718dfbb331b8af80c9c8bf0bd7100c3b7 --- /dev/null +++ b/0163-docs-grub-Document-signing-grub-under-UEFI.patch @@ -0,0 +1,61 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Sat, 15 Aug 2020 02:00:57 +1000 +Subject: [PATCH] docs/grub: Document signing grub under UEFI + +Before adding information about how grub is signed with an appended +signature scheme, it's worth adding some information about how it +can currently be signed for UEFI. + +Signed-off-by: Daniel Axtens +--- + docs/grub.texi | 22 +++++++++++++++++++++- + 1 file changed, 21 insertions(+), 1 deletion(-) + +diff --git a/docs/grub.texi b/docs/grub.texi +index 4870faaa00a..365d1d6931b 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -5817,6 +5817,7 @@ environment variables and commands are listed in the same order. + * Secure Boot Advanced Targeting:: Embedded information for generation number based revocation + * Measured Boot:: Measuring boot components + * Lockdown:: Lockdown when booting on a secure setup ++* Signing GRUB itself:: Ensuring the integrity of the GRUB core image + @end menu + + @node Authentication and authorisation +@@ -5895,7 +5896,7 @@ commands. + + GRUB's @file{core.img} can optionally provide enforcement that all files + subsequently read from disk are covered by a valid digital signature. +-This document does @strong{not} cover how to ensure that your ++This section does @strong{not} cover how to ensure that your + platform's firmware (e.g., Coreboot) validates @file{core.img}. + + If environment variable @code{check_signatures} +@@ -6067,6 +6068,25 @@ be restricted and some operations/commands cannot be executed. + The @samp{lockdown} variable is set to @samp{y} when the GRUB is locked down. + Otherwise it does not exit. + ++@node Signing GRUB itself ++@section Signing GRUB itself ++ ++To ensure a complete secure-boot chain, there must be a way for the code that ++loads GRUB to verify the integrity of the core image. ++ ++This is ultimately platform-specific and individual platforms can define their ++own mechanisms. However, there are general-purpose mechanisms that can be used ++with GRUB. ++ ++@section Signing GRUB for UEFI secure boot ++ ++On UEFI platforms, @file{core.img} is a PE binary. Therefore, it can be signed ++with a tool such as @command{pesign} or @command{sbsign}. Refer to the ++suggestions in @pxref{UEFI secure boot and shim} to ensure that the final ++image works under UEFI secure boot and can maintain the secure-boot chain. It ++will also be necessary to enrol the public key used into a relevant firmware ++key database. ++ + @node Platform limitations + @chapter Platform limitations + diff --git a/0164-docs-grub-Document-signing-grub-with-an-appended-sig.patch b/0164-docs-grub-Document-signing-grub-with-an-appended-sig.patch new file mode 100644 index 0000000000000000000000000000000000000000..4d85d93822a8d109216b1730482e0695498c3810 --- /dev/null +++ b/0164-docs-grub-Document-signing-grub-with-an-appended-sig.patch @@ -0,0 +1,67 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Sat, 15 Aug 2020 02:19:36 +1000 +Subject: [PATCH] docs/grub: Document signing grub with an appended signature + +Signing grub for firmware that verifies an appended signature is a +bit fiddly. I don't want people to have to figure it out from scratch +so document it here. + +Signed-off-by: Daniel Axtens +--- + docs/grub.texi | 42 ++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 42 insertions(+) + +diff --git a/docs/grub.texi b/docs/grub.texi +index 365d1d6931b..afbde7c1f7b 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -6087,6 +6087,48 @@ image works under UEFI secure boot and can maintain the secure-boot chain. It + will also be necessary to enrol the public key used into a relevant firmware + key database. + ++@section Signing GRUB with an appended signature ++ ++The @file{core.elf} itself can be signed with a Linux kernel module-style ++appended signature. ++ ++To support IEEE1275 platforms where the boot image is often loaded directly ++from a disk partition rather than from a file system, the @file{core.elf} ++can specify the size and location of the appended signature with an ELF ++note added by @command{grub-install}. ++ ++An image can be signed this way using the @command{sign-file} command from ++the Linux kernel: ++ ++@example ++@group ++# grub.key is your private key and certificate.der is your public key ++ ++# Determine the size of the appended signature. It depends on the signing ++# certificate and the hash algorithm ++touch empty ++sign-file SHA256 grub.key certificate.der empty empty.sig ++SIG_SIZE=`stat -c '%s' empty.sig` ++rm empty empty.sig ++ ++# Build a grub image with $SIG_SIZE reserved for the signature ++grub-install --appended-signature-size $SIG_SIZE --modules="..." ... ++ ++# Replace the reserved size with a signature: ++# cut off the last $SIG_SIZE bytes with truncate's minus modifier ++truncate -s -$SIG_SIZE /boot/grub/powerpc-ieee1275/core.elf core.elf.unsigned ++# sign the trimmed file with an appended signature, restoring the correct size ++sign-file SHA256 grub.key certificate.der core.elf.unsigned core.elf.signed ++ ++# Don't forget to install the signed image as required ++# (e.g. on powerpc-ieee1275, to the PReP partition) ++@end group ++@end example ++ ++As with UEFI secure boot, it is necessary to build in the required modules, ++or sign them separately. ++ ++ + @node Platform limitations + @chapter Platform limitations + diff --git a/0165-dl-provide-a-fake-grub_dl_set_persistent-for-the-emu.patch b/0165-dl-provide-a-fake-grub_dl_set_persistent-for-the-emu.patch new file mode 100644 index 0000000000000000000000000000000000000000..6e46db010f1c517e287009efbc1147102de1879b --- /dev/null +++ b/0165-dl-provide-a-fake-grub_dl_set_persistent-for-the-emu.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Thu, 30 Jul 2020 00:13:21 +1000 +Subject: [PATCH] dl: provide a fake grub_dl_set_persistent for the emu target + +Trying to start grub-emu with a module that calls grub_dl_set_persistent +will crash because grub-emu fakes modules and passes NULL to the module +init function. + +Provide an empty function for the emu case. + +Fixes: ee7808e2197c (dl: Add support for persistent modules) +Signed-off-by: Daniel Axtens +--- + include/grub/dl.h | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +diff --git a/include/grub/dl.h b/include/grub/dl.h +index 2f76e6b0437..20d870f2a47 100644 +--- a/include/grub/dl.h ++++ b/include/grub/dl.h +@@ -245,11 +245,22 @@ grub_dl_get (const char *name) + return 0; + } + ++#ifdef GRUB_MACHINE_EMU ++/* ++ * Under grub-emu, modules are faked and NULL is passed to GRUB_MOD_INIT. ++ * So we fake this out to avoid a NULL deref. ++ */ ++static inline void ++grub_dl_set_persistent (grub_dl_t mod __attribute__((unused))) ++{ ++} ++#else + static inline void + grub_dl_set_persistent (grub_dl_t mod) + { + mod->persistent = 1; + } ++#endif + + static inline int + grub_dl_is_persistent (grub_dl_t mod) diff --git a/0166-Fix-the-looking-up-grub.cfg-XXX-while-tftp-booting.patch b/0166-Fix-the-looking-up-grub.cfg-XXX-while-tftp-booting.patch deleted file mode 100644 index f36868e3ec3fdbaba3a914bea65a4ec7145bbd21..0000000000000000000000000000000000000000 --- a/0166-Fix-the-looking-up-grub.cfg-XXX-while-tftp-booting.patch +++ /dev/null @@ -1,45 +0,0 @@ -From d564918e5c24a056a75d43b59335d56bfa3478be Mon Sep 17 00:00:00 2001 -From: Masayoshi Mizuma -Date: Tue, 18 Dec 2018 21:27:45 -0500 -Subject: [PATCH 166/220] Fix the looking up grub.cfg-XXX while tftp booting. - -Currently, grub doesn't look up grub.cfg-UUID, grub.cfg-MAC and grub.cfg-IP -while the boot is from tftp. That is because the uuid size is got by -grub_snprintf(, 0, ,), but the grub_snprintf() always returns 0, -so grub judges there's no available uuid in the client and give up -the looking up grub.cfg-XXX. - -This issue can be fixed by changing grub_snprintf(, 0, ,) behaivior -to like as snprintf() from glibc, however, somewhere may expect -such argument as the error, so it's risky. - -Let's use sizeof() and grub_strlen() to calculate the uuid size -instead of grub_snprintf(). - -Resolves: rhbz#1658500 ---- - grub-core/net/net.c | 8 +++----- - 1 file changed, 3 insertions(+), 5 deletions(-) - -diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index aa56393..15073dd 100644 ---- a/grub-core/net/net.c -+++ b/grub-core/net/net.c -@@ -1942,11 +1942,9 @@ grub_net_search_configfile (char *config) - char *client_uuid_var; - grub_size_t client_uuid_var_size; - -- client_uuid_var_size = grub_snprintf (NULL, 0, -- "net_%s_clientuuid", inf->name); -- if (client_uuid_var_size <= 0) -- continue; -- client_uuid_var_size += 1; -+ client_uuid_var_size = sizeof ("net_") + grub_strlen (inf->name) + -+ sizeof ("_clientuuid") + 1; -+ - client_uuid_var = grub_malloc(client_uuid_var_size); - if (!client_uuid_var) - continue; --- -1.8.3.1 - diff --git a/0166-pgp-factor-out-rsa_pad.patch b/0166-pgp-factor-out-rsa_pad.patch new file mode 100644 index 0000000000000000000000000000000000000000..a8154e7496544e078887cdd3d1aee8c9ad274ddd --- /dev/null +++ b/0166-pgp-factor-out-rsa_pad.patch @@ -0,0 +1,191 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Thu, 1 Oct 2020 20:23:48 +1000 +Subject: [PATCH] pgp: factor out rsa_pad + +rsa_pad does the PKCS#1 v1.5 padding for the RSA signature scheme. +We want to use it in other RSA signature verification applications. + +I considered and rejected putting it in lib/crypto.c. That file doesn't +currently require any MPI functions, but rsa_pad does. That's not so +much of a problem for the grub kernel and modules, but crypto.c also +gets built into all the grub utilities. So - despite the utils not +using any asymmetric ciphers - we would need to built the entire MPI +infrastructure in to them. + +A better and simpler solution is just to spin rsa_pad out into its own +PKCS#1 v1.5 module. + +Signed-off-by: Daniel Axtens +--- + grub-core/Makefile.core.def | 8 ++++++ + grub-core/commands/pgp.c | 28 ++------------------- + grub-core/lib/pkcs1_v15.c | 59 +++++++++++++++++++++++++++++++++++++++++++++ + include/grub/pkcs1_v15.h | 27 +++++++++++++++++++++ + 4 files changed, 96 insertions(+), 26 deletions(-) + create mode 100644 grub-core/lib/pkcs1_v15.c + create mode 100644 include/grub/pkcs1_v15.h + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 81fc274148e..97347ae76f9 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -2510,6 +2510,14 @@ module = { + cppflags = '$(CPPFLAGS_GCRY)'; + }; + ++module = { ++ name = pkcs1_v15; ++ common = lib/pkcs1_v15.c; ++ ++ cflags = '$(CFLAGS_GCRY) -Wno-redundant-decls -Wno-sign-compare'; ++ cppflags = '$(CPPFLAGS_GCRY)'; ++}; ++ + module = { + name = all_video; + common = lib/fake_module.c; +diff --git a/grub-core/commands/pgp.c b/grub-core/commands/pgp.c +index 5daa1e9d00c..2408db4994f 100644 +--- a/grub-core/commands/pgp.c ++++ b/grub-core/commands/pgp.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -411,32 +412,7 @@ static int + rsa_pad (gcry_mpi_t *hmpi, grub_uint8_t *hval, + const gcry_md_spec_t *hash, struct grub_public_subkey *sk) + { +- grub_size_t tlen, emlen, fflen; +- grub_uint8_t *em, *emptr; +- unsigned nbits = gcry_mpi_get_nbits (sk->mpis[0]); +- int ret; +- tlen = hash->mdlen + hash->asnlen; +- emlen = (nbits + 7) / 8; +- if (emlen < tlen + 11) +- return 1; +- +- em = grub_malloc (emlen); +- if (!em) +- return 1; +- +- em[0] = 0x00; +- em[1] = 0x01; +- fflen = emlen - tlen - 3; +- for (emptr = em + 2; emptr < em + 2 + fflen; emptr++) +- *emptr = 0xff; +- *emptr++ = 0x00; +- grub_memcpy (emptr, hash->asnoid, hash->asnlen); +- emptr += hash->asnlen; +- grub_memcpy (emptr, hval, hash->mdlen); +- +- ret = gcry_mpi_scan (hmpi, GCRYMPI_FMT_USG, em, emlen, 0); +- grub_free (em); +- return ret; ++ return grub_crypto_rsa_pad(hmpi, hval, hash, sk->mpis[0]); + } + + struct grub_pubkey_context +diff --git a/grub-core/lib/pkcs1_v15.c b/grub-core/lib/pkcs1_v15.c +new file mode 100644 +index 00000000000..dbacd563d01 +--- /dev/null ++++ b/grub-core/lib/pkcs1_v15.c +@@ -0,0 +1,59 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2013 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++/* ++ * Given a hash value 'hval', of hash specification 'hash', perform ++ * the EMSA-PKCS1-v1_5 padding suitable for a key with modulus 'mod' ++ * (see RFC 8017 s 9.2) and place the result in 'hmpi'. ++ */ ++gcry_err_code_t ++grub_crypto_rsa_pad (gcry_mpi_t * hmpi, grub_uint8_t * hval, ++ const gcry_md_spec_t * hash, gcry_mpi_t mod) ++{ ++ grub_size_t tlen, emlen, fflen; ++ grub_uint8_t *em, *emptr; ++ unsigned nbits = gcry_mpi_get_nbits (mod); ++ int ret; ++ tlen = hash->mdlen + hash->asnlen; ++ emlen = (nbits + 7) / 8; ++ if (emlen < tlen + 11) ++ return GPG_ERR_TOO_SHORT; ++ ++ em = grub_malloc (emlen); ++ if (!em) ++ return 1; ++ ++ em[0] = 0x00; ++ em[1] = 0x01; ++ fflen = emlen - tlen - 3; ++ for (emptr = em + 2; emptr < em + 2 + fflen; emptr++) ++ *emptr = 0xff; ++ *emptr++ = 0x00; ++ grub_memcpy (emptr, hash->asnoid, hash->asnlen); ++ emptr += hash->asnlen; ++ grub_memcpy (emptr, hval, hash->mdlen); ++ ++ ret = gcry_mpi_scan (hmpi, GCRYMPI_FMT_USG, em, emlen, 0); ++ grub_free (em); ++ return ret; ++} +diff --git a/include/grub/pkcs1_v15.h b/include/grub/pkcs1_v15.h +new file mode 100644 +index 00000000000..5c338c84a15 +--- /dev/null ++++ b/include/grub/pkcs1_v15.h +@@ -0,0 +1,27 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2013 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++/* ++ * Given a hash value 'hval', of hash specification 'hash', perform ++ * the EMSA-PKCS1-v1_5 padding suitable for a key with modulus 'mod' ++ * (See RFC 8017 s 9.2) ++ */ ++gcry_err_code_t ++grub_crypto_rsa_pad (gcry_mpi_t * hmpi, grub_uint8_t * hval, ++ const gcry_md_spec_t * hash, gcry_mpi_t mod); ++ diff --git a/0167-Don-t-make-grub_strtoull-print-an-error-if-no-conver.patch b/0167-Don-t-make-grub_strtoull-print-an-error-if-no-conver.patch deleted file mode 100644 index 9ee412721a79d0b108b2ab877b5fd004d9765892..0000000000000000000000000000000000000000 --- a/0167-Don-t-make-grub_strtoull-print-an-error-if-no-conver.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 46b860c3c423cefdf427aa547e43927400d02f8c Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Mon, 11 Feb 2019 15:14:10 +0100 -Subject: [PATCH 167/220] Don't make grub_strtoull() print an error if no - conversion is performed - -Callers can check if grub_errno was set to GRUB_ERR_BAD_NUMBER, so there's -no need to print an error if a conversion couldn't be performed. This just -pollutes the output with noisy error messages. - -Resolves: rhbz#1674512 - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/kern/misc.c | 3 +-- - 1 file changed, 1 insertion(+), 2 deletions(-) - -diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 18a7dbf..87afb43 100644 ---- a/grub-core/kern/misc.c -+++ b/grub-core/kern/misc.c -@@ -475,8 +475,7 @@ grub_strtoull (const char * restrict str, const char ** const restrict end, - - if (! found) - { -- grub_error (GRUB_ERR_BAD_NUMBER, -- N_("unrecognized number")); -+ grub_errno = GRUB_ERR_BAD_NUMBER; - return 0; - } - --- -1.8.3.1 - diff --git a/0167-crypto-move-storage-for-grub_crypto_pk_-to-crypto.c.patch b/0167-crypto-move-storage-for-grub_crypto_pk_-to-crypto.c.patch new file mode 100644 index 0000000000000000000000000000000000000000..763cdc63f966e9045a2356c42e6bf5f1f8ff7fd4 --- /dev/null +++ b/0167-crypto-move-storage-for-grub_crypto_pk_-to-crypto.c.patch @@ -0,0 +1,71 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Fri, 2 Oct 2020 10:49:26 +1000 +Subject: [PATCH] crypto: move storage for grub_crypto_pk_* to crypto.c + +The way gcry_rsa and friends (the asymmetric ciphers) are loaded for the +pgp module is a bit quirky. + +include/grub/crypto.h contains: + extern struct gcry_pk_spec *grub_crypto_pk_rsa; + +commands/pgp.c contains the actual storage: + struct gcry_pk_spec *grub_crypto_pk_rsa; + +And the module itself saves to the storage in pgp.c: + GRUB_MOD_INIT(gcry_rsa) + { + grub_crypto_pk_rsa = &_gcry_pubkey_spec_rsa; + } + +This is annoying: gcry_rsa now has a dependency on pgp! + +We want to be able to bring in gcry_rsa without bringing in PGP, +so move the storage to crypto.c. + +Previously, gcry_rsa depended on pgp and mpi. Now it depends on +crypto and mpi. As pgp depends on crypto, this doesn't add any new +module dependencies using the PGP verfier. + +[FWIW, the story is different for the symmetric ciphers. cryptodisk +and friends (zfs encryption etc) use grub_crypto_lookup_cipher_by_name() +to get a cipher handle. That depends on grub_ciphers being populated +by people calling grub_cipher_register. import_gcry.py ensures that the +symmetric ciphers call it.] + +Signed-off-by: Daniel Axtens +--- + grub-core/commands/pgp.c | 4 ---- + grub-core/lib/crypto.c | 4 ++++ + 2 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/grub-core/commands/pgp.c b/grub-core/commands/pgp.c +index 2408db4994f..355a43844ac 100644 +--- a/grub-core/commands/pgp.c ++++ b/grub-core/commands/pgp.c +@@ -147,10 +147,6 @@ const char *hashes[] = { + [0x0b] = "sha224" + }; + +-struct gcry_pk_spec *grub_crypto_pk_dsa; +-struct gcry_pk_spec *grub_crypto_pk_ecdsa; +-struct gcry_pk_spec *grub_crypto_pk_rsa; +- + static int + dsa_pad (gcry_mpi_t *hmpi, grub_uint8_t *hval, + const gcry_md_spec_t *hash, struct grub_public_subkey *sk); +diff --git a/grub-core/lib/crypto.c b/grub-core/lib/crypto.c +index ca334d5a40e..c578128a59d 100644 +--- a/grub-core/lib/crypto.c ++++ b/grub-core/lib/crypto.c +@@ -121,6 +121,10 @@ grub_md_unregister (gcry_md_spec_t *cipher) + } + } + ++struct gcry_pk_spec *grub_crypto_pk_dsa; ++struct gcry_pk_spec *grub_crypto_pk_ecdsa; ++struct gcry_pk_spec *grub_crypto_pk_rsa; ++ + void + grub_crypto_hash (const gcry_md_spec_t *hash, void *out, const void *in, + grub_size_t inlen) diff --git a/0168-Fix-the-type-of-grub_efi_status_t.patch b/0168-Fix-the-type-of-grub_efi_status_t.patch deleted file mode 100644 index 2186ddfc6ee26822602fae06c5a8535ff309a1b9..0000000000000000000000000000000000000000 --- a/0168-Fix-the-type-of-grub_efi_status_t.patch +++ /dev/null @@ -1,82 +0,0 @@ -From a9484492c1672abbae572d2bfae5b1dd8c91d4d2 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 21 Mar 2019 13:06:06 -0400 -Subject: [PATCH 168/220] Fix the type of grub_efi_status_t - -Currently, in some builds with some checkers, we see: - -1. grub-core/disk/efi/efidisk.c:601: error[shiftTooManyBitsSigned]: Shifting signed 64-bit value by 63 bits is undefined behaviour - -This is because grub_efi_status_t is defined as grub_efi_intn_t, which is -signed, and shifting into the sign bit is not defined behavior. UEFI fixed -this in the spec in 2.3: - -2.3 | Change the defined type of EFI_STATUS from INTN to UINTN | May 7, 2009 - -And the current EDK2 code has: -MdePkg/Include/Base.h-// -MdePkg/Include/Base.h-// Status codes common to all execution phases -MdePkg/Include/Base.h-// -MdePkg/Include/Base.h:typedef UINTN RETURN_STATUS; -MdePkg/Include/Base.h- -MdePkg/Include/Base.h-/** -MdePkg/Include/Base.h- Produces a RETURN_STATUS code with the highest bit set. -MdePkg/Include/Base.h- -MdePkg/Include/Base.h- @param StatusCode The status code value to convert into a warning code. -MdePkg/Include/Base.h- StatusCode must be in the range 0x00000000..0x7FFFFFFF. -MdePkg/Include/Base.h- -MdePkg/Include/Base.h- @return The value specified by StatusCode with the highest bit set. -MdePkg/Include/Base.h- -MdePkg/Include/Base.h-**/ -MdePkg/Include/Base.h-#define ENCODE_ERROR(StatusCode) ((RETURN_STATUS)(MAX_BIT | (StatusCode))) -MdePkg/Include/Base.h- -MdePkg/Include/Base.h-/** -MdePkg/Include/Base.h- Produces a RETURN_STATUS code with the highest bit clear. -MdePkg/Include/Base.h- -MdePkg/Include/Base.h- @param StatusCode The status code value to convert into a warning code. -MdePkg/Include/Base.h- StatusCode must be in the range 0x00000000..0x7FFFFFFF. -MdePkg/Include/Base.h- -MdePkg/Include/Base.h- @return The value specified by StatusCode with the highest bit clear. -MdePkg/Include/Base.h- -MdePkg/Include/Base.h-**/ -MdePkg/Include/Base.h-#define ENCODE_WARNING(StatusCode) ((RETURN_STATUS)(StatusCode)) -MdePkg/Include/Base.h- -MdePkg/Include/Base.h-/** -MdePkg/Include/Base.h- Returns TRUE if a specified RETURN_STATUS code is an error code. -MdePkg/Include/Base.h- -MdePkg/Include/Base.h- This function returns TRUE if StatusCode has the high bit set. Otherwise, FALSE is returned. -MdePkg/Include/Base.h- -MdePkg/Include/Base.h- @param StatusCode The status code value to evaluate. -MdePkg/Include/Base.h- -MdePkg/Include/Base.h- @retval TRUE The high bit of StatusCode is set. -MdePkg/Include/Base.h- @retval FALSE The high bit of StatusCode is clear. -MdePkg/Include/Base.h- -MdePkg/Include/Base.h-**/ -MdePkg/Include/Base.h-#define RETURN_ERROR(StatusCode) (((INTN)(RETURN_STATUS)(StatusCode)) < 0) -... -Uefi/UefiBaseType.h:typedef RETURN_STATUS EFI_STATUS; - -This patch makes grub's implementation match the Edk2 declaration with regards -to the signedness of the type. - -Signed-off-by: Peter Jones ---- - include/grub/efi/api.h | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index 2ed9c26..dec7b06 100644 ---- a/include/grub/efi/api.h -+++ b/include/grub/efi/api.h -@@ -536,7 +536,7 @@ typedef grub_uint64_t grub_efi_uint64_t; - typedef grub_uint8_t grub_efi_char8_t; - typedef grub_uint16_t grub_efi_char16_t; - --typedef grub_efi_intn_t grub_efi_status_t; -+typedef grub_efi_uintn_t grub_efi_status_t; - /* Make grub_efi_status_t reasonably printable. */ - #if GRUB_CPU_SIZEOF_VOID_P == 8 - #define PRIxGRUB_EFI_STATUS "lx" --- -1.8.3.1 - diff --git a/0168-posix_wrap-tweaks-in-preparation-for-libtasn1.patch b/0168-posix_wrap-tweaks-in-preparation-for-libtasn1.patch new file mode 100644 index 0000000000000000000000000000000000000000..a09cab19833a92ac4b34a3464c5b6f0d41b4ab62 --- /dev/null +++ b/0168-posix_wrap-tweaks-in-preparation-for-libtasn1.patch @@ -0,0 +1,64 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Sat, 2 May 2020 00:27:57 +1000 +Subject: [PATCH] posix_wrap: tweaks in preparation for libtasn1 + + - Define SIZEOF_UNSIGNED_LONG_INT, it's the same as + SIZEOF_UNSIGNED_LONG. + + - Define WORD_BIT, the size in bits of an int. This is a defined + in the Single Unix Specification and in gnulib's limits.h. gnulib + assumes it's 32 bits on all our platforms, including 64 bit + platforms, so we also use that value. + + - Provide strto[u]l[l] preprocessor macros that resolve to + grub_strto[u]l[l]. To avoid gcrypt redefining strtoul, we + also define HAVE_STRTOUL here. + +Signed-off-by: Daniel Axtens +--- + grub-core/lib/posix_wrap/limits.h | 1 + + grub-core/lib/posix_wrap/stdlib.h | 8 ++++++++ + grub-core/lib/posix_wrap/sys/types.h | 1 + + 3 files changed, 10 insertions(+) + +diff --git a/grub-core/lib/posix_wrap/limits.h b/grub-core/lib/posix_wrap/limits.h +index 7217138ffd6..591dbf3289d 100644 +--- a/grub-core/lib/posix_wrap/limits.h ++++ b/grub-core/lib/posix_wrap/limits.h +@@ -37,5 +37,6 @@ + #define LONG_MAX GRUB_LONG_MAX + + #define CHAR_BIT 8 ++#define WORD_BIT 32 + + #endif +diff --git a/grub-core/lib/posix_wrap/stdlib.h b/grub-core/lib/posix_wrap/stdlib.h +index 7a8d385e973..4634db09f29 100644 +--- a/grub-core/lib/posix_wrap/stdlib.h ++++ b/grub-core/lib/posix_wrap/stdlib.h +@@ -58,4 +58,12 @@ abs (int c) + return (c >= 0) ? c : -c; + } + ++#define strtol grub_strtol ++ ++/* for libgcrypt */ ++#define HAVE_STRTOUL ++#define strtoul grub_strtoul ++ ++#define strtoull grub_strtoull ++ + #endif +diff --git a/grub-core/lib/posix_wrap/sys/types.h b/grub-core/lib/posix_wrap/sys/types.h +index 854eb0122ef..f63412c8da0 100644 +--- a/grub-core/lib/posix_wrap/sys/types.h ++++ b/grub-core/lib/posix_wrap/sys/types.h +@@ -51,6 +51,7 @@ typedef grub_uint8_t byte; + typedef grub_addr_t uintptr_t; + + #define SIZEOF_UNSIGNED_LONG GRUB_CPU_SIZEOF_LONG ++#define SIZEOF_UNSIGNED_LONG_INT GRUB_CPU_SIZEOF_LONG + #define SIZEOF_UNSIGNED_INT 4 + #define SIZEOF_UNSIGNED_LONG_LONG 8 + #define SIZEOF_UNSIGNED_SHORT 2 diff --git a/0169-libtasn1-import-libtasn1-4.16.0.patch b/0169-libtasn1-import-libtasn1-4.16.0.patch new file mode 100644 index 0000000000000000000000000000000000000000..89552c884536b70ec7b130ee81660c985908119c --- /dev/null +++ b/0169-libtasn1-import-libtasn1-4.16.0.patch @@ -0,0 +1,8934 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Wed, 10 Jun 2020 16:31:22 +1000 +Subject: [PATCH] libtasn1: import libtasn1-4.16.0 + +Import a very trimmed-down set of libtasn1 files: + +pushd /tmp +wget https://ftp.gnu.org/gnu/libtasn1/libtasn1-4.16.0.tar.gz +popd +pushd grub-core/lib +mkdir libtasn1 +cp /tmp/libtasn1-4.16.0/{README.md,LICENSE} libtasn1/ +mkdir libtasn1/lib +cp /tmp/libtasn1-4.16.0/lib/{coding.c,decoding.c,element.c,element.h,errors.c,gstr.c,gstr.h,int.h,parser_aux.c,parser_aux.h,structure.c,structure.h} libtasn1/lib +cp /tmp/libtasn1-4.16.0/lib/includes/libtasn1.h ../../include/grub/ +git add libtasn1/ ../../include/grub/libtasn1.h +popd + +Signed-off-by: Daniel Axtens +--- + grub-core/lib/libtasn1/lib/coding.c | 1415 ++++++++++++++++++ + grub-core/lib/libtasn1/lib/decoding.c | 2478 +++++++++++++++++++++++++++++++ + grub-core/lib/libtasn1/lib/element.c | 1111 ++++++++++++++ + grub-core/lib/libtasn1/lib/errors.c | 100 ++ + grub-core/lib/libtasn1/lib/gstr.c | 74 + + grub-core/lib/libtasn1/lib/parser_aux.c | 1173 +++++++++++++++ + grub-core/lib/libtasn1/lib/structure.c | 1220 +++++++++++++++ + grub-core/lib/libtasn1/lib/element.h | 40 + + grub-core/lib/libtasn1/lib/gstr.h | 47 + + grub-core/lib/libtasn1/lib/int.h | 221 +++ + grub-core/lib/libtasn1/lib/parser_aux.h | 172 +++ + grub-core/lib/libtasn1/lib/structure.h | 45 + + include/grub/libtasn1.h | 588 ++++++++ + grub-core/lib/libtasn1/LICENSE | 16 + + grub-core/lib/libtasn1/README.md | 91 ++ + 15 files changed, 8791 insertions(+) + create mode 100644 grub-core/lib/libtasn1/lib/coding.c + create mode 100644 grub-core/lib/libtasn1/lib/decoding.c + create mode 100644 grub-core/lib/libtasn1/lib/element.c + create mode 100644 grub-core/lib/libtasn1/lib/errors.c + create mode 100644 grub-core/lib/libtasn1/lib/gstr.c + create mode 100644 grub-core/lib/libtasn1/lib/parser_aux.c + create mode 100644 grub-core/lib/libtasn1/lib/structure.c + create mode 100644 grub-core/lib/libtasn1/lib/element.h + create mode 100644 grub-core/lib/libtasn1/lib/gstr.h + create mode 100644 grub-core/lib/libtasn1/lib/int.h + create mode 100644 grub-core/lib/libtasn1/lib/parser_aux.h + create mode 100644 grub-core/lib/libtasn1/lib/structure.h + create mode 100644 include/grub/libtasn1.h + create mode 100644 grub-core/lib/libtasn1/LICENSE + create mode 100644 grub-core/lib/libtasn1/README.md + +diff --git a/grub-core/lib/libtasn1/lib/coding.c b/grub-core/lib/libtasn1/lib/coding.c +new file mode 100644 +index 00000000000..245ea64cf0a +--- /dev/null ++++ b/grub-core/lib/libtasn1/lib/coding.c +@@ -0,0 +1,1415 @@ ++/* ++ * Copyright (C) 2002-2014 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * The LIBTASN1 library is free software; you can redistribute it ++ * and/or modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ++ * 02110-1301, USA ++ */ ++ ++ ++/*****************************************************/ ++/* File: coding.c */ ++/* Description: Functions to create a DER coding of */ ++/* an ASN1 type. */ ++/*****************************************************/ ++ ++#include ++#include "parser_aux.h" ++#include ++#include "element.h" ++#include "minmax.h" ++#include ++ ++#define MAX_TAG_LEN 16 ++ ++/******************************************************/ ++/* Function : _asn1_error_description_value_not_found */ ++/* Description: creates the ErrorDescription string */ ++/* for the ASN1_VALUE_NOT_FOUND error. */ ++/* Parameters: */ ++/* node: node of the tree where the value is NULL. */ ++/* ErrorDescription: string returned. */ ++/* Return: */ ++/******************************************************/ ++static void ++_asn1_error_description_value_not_found (asn1_node node, ++ char *ErrorDescription) ++{ ++ ++ if (ErrorDescription == NULL) ++ return; ++ ++ Estrcpy (ErrorDescription, ":: value of element '"); ++ _asn1_hierarchical_name (node, ErrorDescription + strlen (ErrorDescription), ++ ASN1_MAX_ERROR_DESCRIPTION_SIZE - 40); ++ Estrcat (ErrorDescription, "' not found"); ++ ++} ++ ++/** ++ * asn1_length_der: ++ * @len: value to convert. ++ * @der: buffer to hold the returned encoding (may be %NULL). ++ * @der_len: number of meaningful bytes of ANS (der[0]..der[der_len-1]). ++ * ++ * Creates the DER encoding of the provided length value. ++ * The @der buffer must have enough room for the output. The maximum ++ * length this function will encode is %ASN1_MAX_LENGTH_SIZE. ++ * ++ * To know the size of the DER encoding use a %NULL value for @der. ++ **/ ++void ++asn1_length_der (unsigned long int len, unsigned char *der, int *der_len) ++{ ++ int k; ++ unsigned char temp[ASN1_MAX_LENGTH_SIZE]; ++#if SIZEOF_UNSIGNED_LONG_INT > 8 ++ len &= 0xFFFFFFFFFFFFFFFF; ++#endif ++ ++ if (len < 128) ++ { ++ /* short form */ ++ if (der != NULL) ++ der[0] = (unsigned char) len; ++ *der_len = 1; ++ } ++ else ++ { ++ /* Long form */ ++ k = 0; ++ while (len) ++ { ++ temp[k++] = len & 0xFF; ++ len = len >> 8; ++ } ++ *der_len = k + 1; ++ if (der != NULL) ++ { ++ der[0] = ((unsigned char) k & 0x7F) + 128; ++ while (k--) ++ der[*der_len - 1 - k] = temp[k]; ++ } ++ } ++} ++ ++/******************************************************/ ++/* Function : _asn1_tag_der */ ++/* Description: creates the DER coding for the CLASS */ ++/* and TAG parameters. */ ++/* It is limited by the ASN1_MAX_TAG_SIZE variable */ ++/* Parameters: */ ++/* class: value to convert. */ ++/* tag_value: value to convert. */ ++/* ans: string returned. */ ++/* ans_len: number of meaningful bytes of ANS */ ++/* (ans[0]..ans[ans_len-1]). */ ++/* Return: */ ++/******************************************************/ ++static void ++_asn1_tag_der (unsigned char class, unsigned int tag_value, ++ unsigned char ans[ASN1_MAX_TAG_SIZE], int *ans_len) ++{ ++ int k; ++ unsigned char temp[ASN1_MAX_TAG_SIZE]; ++ ++ if (tag_value < 31) ++ { ++ /* short form */ ++ ans[0] = (class & 0xE0) + ((unsigned char) (tag_value & 0x1F)); ++ *ans_len = 1; ++ } ++ else ++ { ++ /* Long form */ ++ ans[0] = (class & 0xE0) + 31; ++ k = 0; ++ while (tag_value != 0) ++ { ++ temp[k++] = tag_value & 0x7F; ++ tag_value >>= 7; ++ ++ if (k > ASN1_MAX_TAG_SIZE - 1) ++ break; /* will not encode larger tags */ ++ } ++ *ans_len = k + 1; ++ while (k--) ++ ans[*ans_len - 1 - k] = temp[k] + 128; ++ ans[*ans_len - 1] -= 128; ++ } ++} ++ ++/** ++ * asn1_octet_der: ++ * @str: the input data. ++ * @str_len: STR length (str[0]..str[*str_len-1]). ++ * @der: encoded string returned. ++ * @der_len: number of meaningful bytes of DER (der[0]..der[der_len-1]). ++ * ++ * Creates a length-value DER encoding for the input data. ++ * The DER encoding of the input data will be placed in the @der variable. ++ * ++ * Note that the OCTET STRING tag is not included in the output. ++ * ++ * This function does not return any value because it is expected ++ * that @der_len will contain enough bytes to store the string ++ * plus the DER encoding. The DER encoding size can be obtained using ++ * asn1_length_der(). ++ **/ ++void ++asn1_octet_der (const unsigned char *str, int str_len, ++ unsigned char *der, int *der_len) ++{ ++ int len_len; ++ ++ if (der == NULL || str_len < 0) ++ return; ++ ++ asn1_length_der (str_len, der, &len_len); ++ memcpy (der + len_len, str, str_len); ++ *der_len = str_len + len_len; ++} ++ ++ ++/** ++ * asn1_encode_simple_der: ++ * @etype: The type of the string to be encoded (ASN1_ETYPE_) ++ * @str: the string data. ++ * @str_len: the string length ++ * @tl: the encoded tag and length ++ * @tl_len: the bytes of the @tl field ++ * ++ * Creates the DER encoding for various simple ASN.1 types like strings etc. ++ * It stores the tag and length in @tl, which should have space for at least ++ * %ASN1_MAX_TL_SIZE bytes. Initially @tl_len should contain the size of @tl. ++ * ++ * The complete DER encoding should consist of the value in @tl appended ++ * with the provided @str. ++ * ++ * Returns: %ASN1_SUCCESS if successful or an error value. ++ **/ ++int ++asn1_encode_simple_der (unsigned int etype, const unsigned char *str, ++ unsigned int str_len, unsigned char *tl, ++ unsigned int *tl_len) ++{ ++ int tag_len, len_len; ++ unsigned tlen; ++ unsigned char der_tag[ASN1_MAX_TAG_SIZE]; ++ unsigned char der_length[ASN1_MAX_LENGTH_SIZE]; ++ unsigned char *p; ++ ++ if (str == NULL) ++ return ASN1_VALUE_NOT_VALID; ++ ++ if (ETYPE_OK (etype) == 0) ++ return ASN1_VALUE_NOT_VALID; ++ ++ /* doesn't handle constructed classes */ ++ if (ETYPE_CLASS (etype) != ASN1_CLASS_UNIVERSAL) ++ return ASN1_VALUE_NOT_VALID; ++ ++ _asn1_tag_der (ETYPE_CLASS (etype), ETYPE_TAG (etype), der_tag, &tag_len); ++ ++ asn1_length_der (str_len, der_length, &len_len); ++ ++ if (tag_len <= 0 || len_len <= 0) ++ return ASN1_VALUE_NOT_VALID; ++ ++ tlen = tag_len + len_len; ++ ++ if (*tl_len < tlen) ++ return ASN1_MEM_ERROR; ++ ++ p = tl; ++ memcpy (p, der_tag, tag_len); ++ p += tag_len; ++ memcpy (p, der_length, len_len); ++ ++ *tl_len = tlen; ++ ++ return ASN1_SUCCESS; ++} ++ ++/******************************************************/ ++/* Function : _asn1_time_der */ ++/* Description: creates the DER coding for a TIME */ ++/* type (length included). */ ++/* Parameters: */ ++/* str: TIME null-terminated string. */ ++/* der: string returned. */ ++/* der_len: number of meaningful bytes of DER */ ++/* (der[0]..der[ans_len-1]). Initially it */ ++/* if must store the lenght of DER. */ ++/* Return: */ ++/* ASN1_MEM_ERROR when DER isn't big enough */ ++/* ASN1_SUCCESS otherwise */ ++/******************************************************/ ++static int ++_asn1_time_der (unsigned char *str, int str_len, unsigned char *der, ++ int *der_len) ++{ ++ int len_len; ++ int max_len; ++ ++ if (der == NULL) ++ return ASN1_VALUE_NOT_VALID; ++ ++ max_len = *der_len; ++ ++ asn1_length_der (str_len, (max_len > 0) ? der : NULL, &len_len); ++ ++ if ((len_len + str_len) <= max_len) ++ memcpy (der + len_len, str, str_len); ++ *der_len = len_len + str_len; ++ ++ if ((*der_len) > max_len) ++ return ASN1_MEM_ERROR; ++ ++ return ASN1_SUCCESS; ++} ++ ++ ++/* ++void ++_asn1_get_utctime_der(unsigned char *der,int *der_len,unsigned char *str) ++{ ++ int len_len,str_len; ++ char temp[20]; ++ ++ if(str==NULL) return; ++ str_len=asn1_get_length_der(der,*der_len,&len_len); ++ if (str_len<0) return; ++ memcpy(temp,der+len_len,str_len); ++ *der_len=str_len+len_len; ++ switch(str_len) ++ { ++ case 11: ++ temp[10]=0; ++ strcat(temp,"00+0000"); ++ break; ++ case 13: ++ temp[12]=0; ++ strcat(temp,"+0000"); ++ break; ++ case 15: ++ temp[15]=0; ++ memmove(temp+12,temp+10,6); ++ temp[10]=temp[11]='0'; ++ break; ++ case 17: ++ temp[17]=0; ++ break; ++ default: ++ return; ++ } ++ strcpy(str,temp); ++} ++*/ ++ ++static ++void encode_val(uint64_t val, unsigned char *der, int max_len, int *der_len) ++{ ++ int first, k; ++ unsigned char bit7; ++ ++ first = 0; ++ for (k = sizeof(val); k >= 0; k--) ++ { ++ bit7 = (val >> (k * 7)) & 0x7F; ++ if (bit7 || first || !k) ++ { ++ if (k) ++ bit7 |= 0x80; ++ if (max_len > (*der_len)) ++ der[*der_len] = bit7; ++ (*der_len)++; ++ first = 1; ++ } ++ } ++} ++ ++/******************************************************/ ++/* Function : _asn1_object_id_der */ ++/* Description: creates the DER coding for an */ ++/* OBJECT IDENTIFIER type (length included). */ ++/* Parameters: */ ++/* str: OBJECT IDENTIFIER null-terminated string. */ ++/* der: string returned. */ ++/* der_len: number of meaningful bytes of DER */ ++/* (der[0]..der[ans_len-1]). Initially it */ ++/* must store the length of DER. */ ++/* Return: */ ++/* ASN1_MEM_ERROR when DER isn't big enough */ ++/* ASN1_SUCCESS if succesful */ ++/* or an error value. */ ++/******************************************************/ ++static int ++_asn1_object_id_der (const char *str, unsigned char *der, int *der_len) ++{ ++ int len_len, counter, max_len; ++ char *temp, *n_end, *n_start; ++ uint64_t val, val1 = 0; ++ int str_len = _asn1_strlen (str); ++ ++ max_len = *der_len; ++ *der_len = 0; ++ ++ if (der == NULL && max_len > 0) ++ return ASN1_VALUE_NOT_VALID; ++ ++ temp = malloc (str_len + 2); ++ if (temp == NULL) ++ return ASN1_MEM_ALLOC_ERROR; ++ ++ memcpy (temp, str, str_len); ++ temp[str_len] = '.'; ++ temp[str_len + 1] = 0; ++ ++ counter = 0; ++ n_start = temp; ++ while ((n_end = strchr (n_start, '.'))) ++ { ++ *n_end = 0; ++ val = _asn1_strtou64 (n_start, NULL, 10); ++ counter++; ++ ++ if (counter == 1) ++ { ++ val1 = val; ++ } ++ else if (counter == 2) ++ { ++ uint64_t val0; ++ ++ if (val1 > 2) ++ { ++ free(temp); ++ return ASN1_VALUE_NOT_VALID; ++ } ++ else if ((val1 == 0 || val1 == 1) && val > 39) ++ { ++ free(temp); ++ return ASN1_VALUE_NOT_VALID; ++ } ++ ++ val0 = 40 * val1 + val; ++ encode_val(val0, der, max_len, der_len); ++ } ++ else ++ { ++ encode_val(val, der, max_len, der_len); ++ } ++ n_start = n_end + 1; ++ } ++ ++ asn1_length_der (*der_len, NULL, &len_len); ++ if (max_len >= (*der_len + len_len)) ++ { ++ memmove (der + len_len, der, *der_len); ++ asn1_length_der (*der_len, der, &len_len); ++ } ++ *der_len += len_len; ++ ++ free (temp); ++ ++ if (max_len < (*der_len)) ++ return ASN1_MEM_ERROR; ++ ++ return ASN1_SUCCESS; ++} ++ ++/** ++ * asn1_object_id_der: ++ * @str: An object identifier in numeric, dot format. ++ * @der: buffer to hold the returned encoding (may be %NULL). ++ * @der_len: initially the size of @der; will hold the final size. ++ * @flags: must be zero ++ * ++ * Creates the DER encoding of the provided object identifier. ++ * ++ * Returns: %ASN1_SUCCESS if DER encoding was OK, %ASN1_VALUE_NOT_VALID ++ * if @str is not a valid OID, %ASN1_MEM_ERROR if the @der ++ * vector isn't big enough and in this case @der_len will contain the ++ * length needed. ++ **/ ++int asn1_object_id_der(const char *str, unsigned char *der, int *der_len, unsigned flags) ++{ ++ unsigned char tag_der[MAX_TAG_LEN]; ++ int tag_len = 0, r; ++ int max_len = *der_len; ++ ++ *der_len = 0; ++ ++ _asn1_tag_der (ETYPE_CLASS (ASN1_ETYPE_OBJECT_ID), ETYPE_TAG (ASN1_ETYPE_OBJECT_ID), ++ tag_der, &tag_len); ++ ++ if (max_len > tag_len) ++ { ++ memcpy(der, tag_der, tag_len); ++ } ++ max_len -= tag_len; ++ der += tag_len; ++ ++ r = _asn1_object_id_der (str, der, &max_len); ++ if (r == ASN1_MEM_ERROR || r == ASN1_SUCCESS) ++ { ++ *der_len = max_len + tag_len; ++ } ++ ++ return r; ++} ++ ++static const unsigned char bit_mask[] = ++ { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80 }; ++ ++/** ++ * asn1_bit_der: ++ * @str: BIT string. ++ * @bit_len: number of meaningful bits in STR. ++ * @der: string returned. ++ * @der_len: number of meaningful bytes of DER ++ * (der[0]..der[ans_len-1]). ++ * ++ * Creates a length-value DER encoding for the input data ++ * as it would have been for a BIT STRING. ++ * The DER encoded data will be copied in @der. ++ * ++ * Note that the BIT STRING tag is not included in the output. ++ * ++ * This function does not return any value because it is expected ++ * that @der_len will contain enough bytes to store the string ++ * plus the DER encoding. The DER encoding size can be obtained using ++ * asn1_length_der(). ++ **/ ++void ++asn1_bit_der (const unsigned char *str, int bit_len, ++ unsigned char *der, int *der_len) ++{ ++ int len_len, len_byte, len_pad; ++ ++ if (der == NULL) ++ return; ++ ++ len_byte = bit_len >> 3; ++ len_pad = 8 - (bit_len & 7); ++ if (len_pad == 8) ++ len_pad = 0; ++ else ++ len_byte++; ++ asn1_length_der (len_byte + 1, der, &len_len); ++ der[len_len] = len_pad; ++ ++ if (str) ++ memcpy (der + len_len + 1, str, len_byte); ++ der[len_len + len_byte] &= bit_mask[len_pad]; ++ *der_len = len_byte + len_len + 1; ++} ++ ++ ++/******************************************************/ ++/* Function : _asn1_complete_explicit_tag */ ++/* Description: add the length coding to the EXPLICIT */ ++/* tags. */ ++/* Parameters: */ ++/* node: pointer to the tree element. */ ++/* der: string with the DER coding of the whole tree*/ ++/* counter: number of meaningful bytes of DER */ ++/* (der[0]..der[*counter-1]). */ ++/* max_len: size of der vector */ ++/* Return: */ ++/* ASN1_MEM_ERROR if der vector isn't big enough, */ ++/* otherwise ASN1_SUCCESS. */ ++/******************************************************/ ++static int ++_asn1_complete_explicit_tag (asn1_node node, unsigned char *der, ++ int *counter, int *max_len) ++{ ++ asn1_node p; ++ int is_tag_implicit, len2, len3; ++ unsigned char temp[SIZEOF_UNSIGNED_INT]; ++ ++ if (der == NULL && *max_len > 0) ++ return ASN1_VALUE_NOT_VALID; ++ ++ is_tag_implicit = 0; ++ ++ if (node->type & CONST_TAG) ++ { ++ p = node->down; ++ if (p == NULL) ++ return ASN1_DER_ERROR; ++ /* When there are nested tags we must complete them reverse to ++ the order they were created. This is because completing a tag ++ modifies all data within it, including the incomplete tags ++ which store buffer positions -- simon@josefsson.org 2002-09-06 ++ */ ++ while (p->right) ++ p = p->right; ++ while (p && p != node->down->left) ++ { ++ if (type_field (p->type) == ASN1_ETYPE_TAG) ++ { ++ if (p->type & CONST_EXPLICIT) ++ { ++ len2 = strtol (p->name, NULL, 10); ++ _asn1_set_name (p, NULL); ++ ++ asn1_length_der (*counter - len2, temp, &len3); ++ if (len3 <= (*max_len)) ++ { ++ memmove (der + len2 + len3, der + len2, ++ *counter - len2); ++ memcpy (der + len2, temp, len3); ++ } ++ *max_len -= len3; ++ *counter += len3; ++ is_tag_implicit = 0; ++ } ++ else ++ { /* CONST_IMPLICIT */ ++ if (!is_tag_implicit) ++ { ++ is_tag_implicit = 1; ++ } ++ } ++ } ++ p = p->left; ++ } ++ } ++ ++ if (*max_len < 0) ++ return ASN1_MEM_ERROR; ++ ++ return ASN1_SUCCESS; ++} ++ ++const tag_and_class_st _asn1_tags[] = { ++ [ASN1_ETYPE_GENERALSTRING] = ++ {ASN1_TAG_GENERALSTRING, ASN1_CLASS_UNIVERSAL, "type:GENERALSTRING"}, ++ [ASN1_ETYPE_NUMERIC_STRING] = ++ {ASN1_TAG_NUMERIC_STRING, ASN1_CLASS_UNIVERSAL, "type:NUMERIC_STR"}, ++ [ASN1_ETYPE_IA5_STRING] = ++ {ASN1_TAG_IA5_STRING, ASN1_CLASS_UNIVERSAL, "type:IA5_STR"}, ++ [ASN1_ETYPE_TELETEX_STRING] = ++ {ASN1_TAG_TELETEX_STRING, ASN1_CLASS_UNIVERSAL, "type:TELETEX_STR"}, ++ [ASN1_ETYPE_PRINTABLE_STRING] = ++ {ASN1_TAG_PRINTABLE_STRING, ASN1_CLASS_UNIVERSAL, "type:PRINTABLE_STR"}, ++ [ASN1_ETYPE_UNIVERSAL_STRING] = ++ {ASN1_TAG_UNIVERSAL_STRING, ASN1_CLASS_UNIVERSAL, "type:UNIVERSAL_STR"}, ++ [ASN1_ETYPE_BMP_STRING] = ++ {ASN1_TAG_BMP_STRING, ASN1_CLASS_UNIVERSAL, "type:BMP_STR"}, ++ [ASN1_ETYPE_UTF8_STRING] = ++ {ASN1_TAG_UTF8_STRING, ASN1_CLASS_UNIVERSAL, "type:UTF8_STR"}, ++ [ASN1_ETYPE_VISIBLE_STRING] = ++ {ASN1_TAG_VISIBLE_STRING, ASN1_CLASS_UNIVERSAL, "type:VISIBLE_STR"}, ++ [ASN1_ETYPE_OCTET_STRING] = ++ {ASN1_TAG_OCTET_STRING, ASN1_CLASS_UNIVERSAL, "type:OCT_STR"}, ++ [ASN1_ETYPE_BIT_STRING] = ++ {ASN1_TAG_BIT_STRING, ASN1_CLASS_UNIVERSAL, "type:BIT_STR"}, ++ [ASN1_ETYPE_OBJECT_ID] = ++ {ASN1_TAG_OBJECT_ID, ASN1_CLASS_UNIVERSAL, "type:OBJ_ID"}, ++ [ASN1_ETYPE_NULL] = {ASN1_TAG_NULL, ASN1_CLASS_UNIVERSAL, "type:NULL"}, ++ [ASN1_ETYPE_BOOLEAN] = ++ {ASN1_TAG_BOOLEAN, ASN1_CLASS_UNIVERSAL, "type:BOOLEAN"}, ++ [ASN1_ETYPE_INTEGER] = ++ {ASN1_TAG_INTEGER, ASN1_CLASS_UNIVERSAL, "type:INTEGER"}, ++ [ASN1_ETYPE_ENUMERATED] = ++ {ASN1_TAG_ENUMERATED, ASN1_CLASS_UNIVERSAL, "type:ENUMERATED"}, ++ [ASN1_ETYPE_SEQUENCE] = ++ {ASN1_TAG_SEQUENCE, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, ++ "type:SEQUENCE"}, ++ [ASN1_ETYPE_SEQUENCE_OF] = ++ {ASN1_TAG_SEQUENCE, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, ++ "type:SEQ_OF"}, ++ [ASN1_ETYPE_SET] = ++ {ASN1_TAG_SET, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, "type:SET"}, ++ [ASN1_ETYPE_SET_OF] = ++ {ASN1_TAG_SET, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, ++ "type:SET_OF"}, ++ [ASN1_ETYPE_GENERALIZED_TIME] = ++ {ASN1_TAG_GENERALIZEDTime, ASN1_CLASS_UNIVERSAL, "type:GENERALIZED_TIME"}, ++ [ASN1_ETYPE_UTC_TIME] = ++ {ASN1_TAG_UTCTime, ASN1_CLASS_UNIVERSAL, "type:UTC_TIME"}, ++}; ++ ++unsigned int _asn1_tags_size = sizeof (_asn1_tags) / sizeof (_asn1_tags[0]); ++ ++/******************************************************/ ++/* Function : _asn1_insert_tag_der */ ++/* Description: creates the DER coding of tags of one */ ++/* NODE. */ ++/* Parameters: */ ++/* node: pointer to the tree element. */ ++/* der: string returned */ ++/* counter: number of meaningful bytes of DER */ ++/* (counter[0]..der[*counter-1]). */ ++/* max_len: size of der vector */ ++/* Return: */ ++/* ASN1_GENERIC_ERROR if the type is unknown, */ ++/* ASN1_MEM_ERROR if der vector isn't big enough, */ ++/* otherwise ASN1_SUCCESS. */ ++/******************************************************/ ++static int ++_asn1_insert_tag_der (asn1_node node, unsigned char *der, int *counter, ++ int *max_len) ++{ ++ asn1_node p; ++ int tag_len, is_tag_implicit; ++ unsigned char class, class_implicit = 0, temp[MAX(SIZEOF_UNSIGNED_INT * 3 + 1, LTOSTR_MAX_SIZE)]; ++ unsigned long tag_implicit = 0; ++ unsigned char tag_der[MAX_TAG_LEN]; ++ ++ is_tag_implicit = 0; ++ ++ if (node->type & CONST_TAG) ++ { ++ p = node->down; ++ while (p) ++ { ++ if (type_field (p->type) == ASN1_ETYPE_TAG) ++ { ++ if (p->type & CONST_APPLICATION) ++ class = ASN1_CLASS_APPLICATION; ++ else if (p->type & CONST_UNIVERSAL) ++ class = ASN1_CLASS_UNIVERSAL; ++ else if (p->type & CONST_PRIVATE) ++ class = ASN1_CLASS_PRIVATE; ++ else ++ class = ASN1_CLASS_CONTEXT_SPECIFIC; ++ ++ if (p->type & CONST_EXPLICIT) ++ { ++ if (is_tag_implicit) ++ _asn1_tag_der (class_implicit, tag_implicit, tag_der, ++ &tag_len); ++ else ++ _asn1_tag_der (class | ASN1_CLASS_STRUCTURED, ++ _asn1_strtoul (p->value, NULL, 10), ++ tag_der, &tag_len); ++ ++ *max_len -= tag_len; ++ if (der && *max_len >= 0) ++ memcpy (der + *counter, tag_der, tag_len); ++ *counter += tag_len; ++ ++ _asn1_ltostr (*counter, (char *) temp); ++ _asn1_set_name (p, (const char *) temp); ++ ++ is_tag_implicit = 0; ++ } ++ else ++ { /* CONST_IMPLICIT */ ++ if (!is_tag_implicit) ++ { ++ if ((type_field (node->type) == ASN1_ETYPE_SEQUENCE) || ++ (type_field (node->type) == ASN1_ETYPE_SEQUENCE_OF) ++ || (type_field (node->type) == ASN1_ETYPE_SET) ++ || (type_field (node->type) == ASN1_ETYPE_SET_OF)) ++ class |= ASN1_CLASS_STRUCTURED; ++ class_implicit = class; ++ tag_implicit = _asn1_strtoul (p->value, NULL, 10); ++ is_tag_implicit = 1; ++ } ++ } ++ } ++ p = p->right; ++ } ++ } ++ ++ if (is_tag_implicit) ++ { ++ _asn1_tag_der (class_implicit, tag_implicit, tag_der, &tag_len); ++ } ++ else ++ { ++ unsigned type = type_field (node->type); ++ switch (type) ++ { ++ CASE_HANDLED_ETYPES: ++ _asn1_tag_der (_asn1_tags[type].class, _asn1_tags[type].tag, ++ tag_der, &tag_len); ++ break; ++ case ASN1_ETYPE_TAG: ++ case ASN1_ETYPE_CHOICE: ++ case ASN1_ETYPE_ANY: ++ tag_len = 0; ++ break; ++ default: ++ return ASN1_GENERIC_ERROR; ++ } ++ } ++ ++ *max_len -= tag_len; ++ if (der && *max_len >= 0) ++ memcpy (der + *counter, tag_der, tag_len); ++ *counter += tag_len; ++ ++ if (*max_len < 0) ++ return ASN1_MEM_ERROR; ++ ++ return ASN1_SUCCESS; ++} ++ ++/******************************************************/ ++/* Function : _asn1_ordering_set */ ++/* Description: puts the elements of a SET type in */ ++/* the correct order according to DER rules. */ ++/* Parameters: */ ++/* der: string with the DER coding. */ ++/* node: pointer to the SET element. */ ++/* Return: */ ++/* ASN1_SUCCESS if successful */ ++/* or an error value. */ ++/******************************************************/ ++static int ++_asn1_ordering_set (unsigned char *der, int der_len, asn1_node node) ++{ ++ struct vet ++ { ++ int end; ++ unsigned long value; ++ struct vet *next, *prev; ++ }; ++ ++ int counter, len, len2; ++ struct vet *first, *last, *p_vet, *p2_vet; ++ asn1_node p; ++ unsigned char class, *temp; ++ unsigned long tag, t; ++ int err; ++ ++ counter = 0; ++ ++ if (type_field (node->type) != ASN1_ETYPE_SET) ++ return ASN1_VALUE_NOT_VALID; ++ ++ p = node->down; ++ while (p && ((type_field (p->type) == ASN1_ETYPE_TAG) || ++ (type_field (p->type) == ASN1_ETYPE_SIZE))) ++ p = p->right; ++ ++ if ((p == NULL) || (p->right == NULL)) ++ return ASN1_SUCCESS; ++ ++ first = last = NULL; ++ while (p) ++ { ++ p_vet = malloc (sizeof (struct vet)); ++ if (p_vet == NULL) ++ { ++ err = ASN1_MEM_ALLOC_ERROR; ++ goto error; ++ } ++ ++ p_vet->next = NULL; ++ p_vet->prev = last; ++ if (first == NULL) ++ first = p_vet; ++ else ++ last->next = p_vet; ++ last = p_vet; ++ ++ /* tag value calculation */ ++ err = asn1_get_tag_der (der + counter, der_len - counter, &class, &len2, ++ &tag); ++ if (err != ASN1_SUCCESS) ++ goto error; ++ ++ t = ((unsigned int)class) << 24; ++ p_vet->value = t | tag; ++ counter += len2; ++ ++ /* extraction and length */ ++ len2 = asn1_get_length_der (der + counter, der_len - counter, &len); ++ if (len2 < 0) ++ { ++ err = ASN1_DER_ERROR; ++ goto error; ++ } ++ counter += len + len2; ++ ++ p_vet->end = counter; ++ p = p->right; ++ } ++ ++ p_vet = first; ++ ++ while (p_vet) ++ { ++ p2_vet = p_vet->next; ++ counter = 0; ++ while (p2_vet) ++ { ++ if (p_vet->value > p2_vet->value) ++ { ++ /* change position */ ++ temp = malloc (p_vet->end - counter); ++ if (temp == NULL) ++ { ++ err = ASN1_MEM_ALLOC_ERROR; ++ goto error; ++ } ++ ++ memcpy (temp, der + counter, p_vet->end - counter); ++ memcpy (der + counter, der + p_vet->end, ++ p2_vet->end - p_vet->end); ++ memcpy (der + counter + p2_vet->end - p_vet->end, temp, ++ p_vet->end - counter); ++ free (temp); ++ ++ tag = p_vet->value; ++ p_vet->value = p2_vet->value; ++ p2_vet->value = tag; ++ ++ p_vet->end = counter + (p2_vet->end - p_vet->end); ++ } ++ counter = p_vet->end; ++ ++ p2_vet = p2_vet->next; ++ p_vet = p_vet->next; ++ } ++ ++ if (p_vet != first) ++ p_vet->prev->next = NULL; ++ else ++ first = NULL; ++ free (p_vet); ++ p_vet = first; ++ } ++ return ASN1_SUCCESS; ++ ++error: ++ while (first != NULL) ++ { ++ p_vet = first; ++ first = first->next; ++ free(p_vet); ++ } ++ return err; ++} ++ ++struct vet ++{ ++ unsigned char *ptr; ++ int size; ++}; ++ ++static int setof_compar(const void *_e1, const void *_e2) ++{ ++ unsigned length; ++ const struct vet *e1 = _e1, *e2 = _e2; ++ int rval; ++ ++ /* The encodings of the component values of a set-of value shall ++ * appear in ascending order, the encodings being compared ++ * as octet strings with the shorter components being ++ * padded at their trailing end with 0-octets. ++ * The padding octets are for comparison purposes and ++ * do not appear in the encodings. ++ */ ++ length = MIN(e1->size, e2->size); ++ ++ rval = memcmp(e1->ptr, e2->ptr, length); ++ if (rval == 0 && e1->size != e2->size) ++ { ++ if (e1->size > e2->size) ++ rval = 1; ++ else if (e2->size > e1->size) ++ rval = -1; ++ } ++ ++ return rval; ++} ++ ++/******************************************************/ ++/* Function : _asn1_ordering_set_of */ ++/* Description: puts the elements of a SET OF type in */ ++/* the correct order according to DER rules. */ ++/* Parameters: */ ++/* der: string with the DER coding. */ ++/* node: pointer to the SET OF element. */ ++/* Return: */ ++/* ASN1_SUCCESS if successful */ ++/* or an error value. */ ++/******************************************************/ ++static int ++_asn1_ordering_set_of (unsigned char *der, int der_len, asn1_node node) ++{ ++ int counter, len, len2; ++ struct vet *list = NULL, *tlist; ++ unsigned list_size = 0; ++ struct vet *p_vet; ++ asn1_node p; ++ unsigned char class; ++ unsigned i; ++ unsigned char *out = NULL; ++ int err; ++ ++ if (der == NULL) ++ return ASN1_VALUE_NOT_VALID; ++ ++ counter = 0; ++ ++ if (type_field (node->type) != ASN1_ETYPE_SET_OF) ++ return ASN1_VALUE_NOT_VALID; ++ ++ p = node->down; ++ while (p && ((type_field (p->type) == ASN1_ETYPE_TAG) || ++ (type_field (p->type) == ASN1_ETYPE_SIZE))) ++ p = p->right; ++ if (p == NULL) ++ return ASN1_VALUE_NOT_VALID; ++ p = p->right; ++ ++ if ((p == NULL) || (p->right == NULL)) ++ return ASN1_SUCCESS; ++ ++ while (p) ++ { ++ list_size++; ++ tlist = realloc (list, list_size*sizeof(struct vet)); ++ if (tlist == NULL) ++ { ++ err = ASN1_MEM_ALLOC_ERROR; ++ goto error; ++ } ++ list = tlist; ++ p_vet = &list[list_size-1]; ++ ++ p_vet->ptr = der+counter; ++ p_vet->size = 0; ++ ++ /* extraction of tag and length */ ++ if (der_len - counter > 0) ++ { ++ err = asn1_get_tag_der (der + counter, der_len - counter, &class, ++ &len, NULL); ++ if (err != ASN1_SUCCESS) ++ goto error; ++ counter += len; ++ p_vet->size += len; ++ ++ len2 = asn1_get_length_der (der + counter, der_len - counter, &len); ++ if (len2 < 0) ++ { ++ err = ASN1_DER_ERROR; ++ goto error; ++ } ++ counter += len + len2; ++ p_vet->size += len + len2; ++ ++ } ++ else ++ { ++ err = ASN1_DER_ERROR; ++ goto error; ++ } ++ p = p->right; ++ } ++ ++ if (counter > der_len) ++ { ++ err = ASN1_DER_ERROR; ++ goto error; ++ } ++ ++ qsort(list, list_size, sizeof(struct vet), setof_compar); ++ ++ out = malloc(der_len); ++ if (out == NULL) ++ { ++ err = ASN1_MEM_ERROR; ++ goto error; ++ } ++ ++ /* the sum of p_vet->size == der_len */ ++ counter = 0; ++ for (i = 0; i < list_size; i++) ++ { ++ p_vet = &list[i]; ++ memcpy(out+counter, p_vet->ptr, p_vet->size); ++ counter += p_vet->size; ++ } ++ memcpy(der, out, der_len); ++ free(out); ++ ++ err = ASN1_SUCCESS; ++ ++error: ++ free(list); ++ return err; ++} ++ ++/** ++ * asn1_der_coding: ++ * @element: pointer to an ASN1 element ++ * @name: the name of the structure you want to encode (it must be ++ * inside *POINTER). ++ * @ider: vector that will contain the DER encoding. DER must be a ++ * pointer to memory cells already allocated. ++ * @len: number of bytes of *@ider: @ider[0]..@ider[len-1], Initialy ++ * holds the sizeof of der vector. ++ * @ErrorDescription: return the error description or an empty ++ * string if success. ++ * ++ * Creates the DER encoding for the NAME structure (inside *POINTER ++ * structure). ++ * ++ * Returns: %ASN1_SUCCESS if DER encoding OK, %ASN1_ELEMENT_NOT_FOUND ++ * if @name is not a valid element, %ASN1_VALUE_NOT_FOUND if there ++ * is an element without a value, %ASN1_MEM_ERROR if the @ider ++ * vector isn't big enough and in this case @len will contain the ++ * length needed. ++ **/ ++int ++asn1_der_coding (asn1_node_const element, const char *name, void *ider, int *len, ++ char *ErrorDescription) ++{ ++ asn1_node node, p, p2; ++ unsigned char temp[MAX(LTOSTR_MAX_SIZE, SIZEOF_UNSIGNED_LONG_INT * 3 + 1)]; ++ int counter, counter_old, len2, len3, move, max_len, max_len_old; ++ int err; ++ unsigned char *der = ider; ++ ++ if (ErrorDescription) ++ ErrorDescription[0] = 0; ++ ++ node = asn1_find_node (element, name); ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ /* Node is now a locally allocated variable. ++ * That is because in some point we modify the ++ * structure, and I don't know why! --nmav ++ */ ++ node = _asn1_copy_structure3 (node); ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ max_len = *len; ++ ++ if (der == NULL && max_len > 0) ++ return ASN1_VALUE_NOT_VALID; ++ ++ counter = 0; ++ move = DOWN; ++ p = node; ++ ++ while (1) ++ { ++ ++ counter_old = counter; ++ max_len_old = max_len; ++ if (move != UP) ++ { ++ p->start = counter; ++ err = _asn1_insert_tag_der (p, der, &counter, &max_len); ++ if (err != ASN1_SUCCESS && err != ASN1_MEM_ERROR) ++ goto error; ++ } ++ switch (type_field (p->type)) ++ { ++ case ASN1_ETYPE_NULL: ++ max_len--; ++ if (der != NULL && max_len >= 0) ++ der[counter] = 0; ++ counter++; ++ move = RIGHT; ++ break; ++ case ASN1_ETYPE_BOOLEAN: ++ if ((p->type & CONST_DEFAULT) && (p->value == NULL)) ++ { ++ counter = counter_old; ++ max_len = max_len_old; ++ } ++ else ++ { ++ if (p->value == NULL) ++ { ++ _asn1_error_description_value_not_found (p, ++ ErrorDescription); ++ err = ASN1_VALUE_NOT_FOUND; ++ goto error; ++ } ++ max_len -= 2; ++ if (der != NULL && max_len >= 0) ++ { ++ der[counter++] = 1; ++ if (p->value[0] == 'F') ++ der[counter++] = 0; ++ else ++ der[counter++] = 0xFF; ++ } ++ else ++ counter += 2; ++ } ++ move = RIGHT; ++ break; ++ case ASN1_ETYPE_INTEGER: ++ case ASN1_ETYPE_ENUMERATED: ++ if ((p->type & CONST_DEFAULT) && (p->value == NULL)) ++ { ++ counter = counter_old; ++ max_len = max_len_old; ++ } ++ else ++ { ++ if (p->value == NULL) ++ { ++ _asn1_error_description_value_not_found (p, ++ ErrorDescription); ++ err = ASN1_VALUE_NOT_FOUND; ++ goto error; ++ } ++ len2 = asn1_get_length_der (p->value, p->value_len, &len3); ++ if (len2 < 0) ++ { ++ err = ASN1_DER_ERROR; ++ goto error; ++ } ++ max_len -= len2 + len3; ++ if (der != NULL && max_len >= 0) ++ memcpy (der + counter, p->value, len3 + len2); ++ counter += len3 + len2; ++ } ++ move = RIGHT; ++ break; ++ case ASN1_ETYPE_OBJECT_ID: ++ if ((p->type & CONST_DEFAULT) && (p->value == NULL)) ++ { ++ counter = counter_old; ++ max_len = max_len_old; ++ } ++ else ++ { ++ if (p->value == NULL) ++ { ++ _asn1_error_description_value_not_found (p, ++ ErrorDescription); ++ err = ASN1_VALUE_NOT_FOUND; ++ goto error; ++ } ++ len2 = max_len; ++ err = _asn1_object_id_der ((char*)p->value, der + counter, &len2); ++ if (err != ASN1_SUCCESS && err != ASN1_MEM_ERROR) ++ goto error; ++ ++ max_len -= len2; ++ counter += len2; ++ } ++ move = RIGHT; ++ break; ++ case ASN1_ETYPE_GENERALIZED_TIME: ++ case ASN1_ETYPE_UTC_TIME: ++ if (p->value == NULL) ++ { ++ _asn1_error_description_value_not_found (p, ErrorDescription); ++ err = ASN1_VALUE_NOT_FOUND; ++ goto error; ++ } ++ len2 = max_len; ++ err = _asn1_time_der (p->value, p->value_len, der + counter, &len2); ++ if (err != ASN1_SUCCESS && err != ASN1_MEM_ERROR) ++ goto error; ++ ++ max_len -= len2; ++ counter += len2; ++ move = RIGHT; ++ break; ++ case ASN1_ETYPE_OCTET_STRING: ++ case ASN1_ETYPE_GENERALSTRING: ++ case ASN1_ETYPE_NUMERIC_STRING: ++ case ASN1_ETYPE_IA5_STRING: ++ case ASN1_ETYPE_TELETEX_STRING: ++ case ASN1_ETYPE_PRINTABLE_STRING: ++ case ASN1_ETYPE_UNIVERSAL_STRING: ++ case ASN1_ETYPE_BMP_STRING: ++ case ASN1_ETYPE_UTF8_STRING: ++ case ASN1_ETYPE_VISIBLE_STRING: ++ case ASN1_ETYPE_BIT_STRING: ++ if (p->value == NULL) ++ { ++ _asn1_error_description_value_not_found (p, ErrorDescription); ++ err = ASN1_VALUE_NOT_FOUND; ++ goto error; ++ } ++ len2 = asn1_get_length_der (p->value, p->value_len, &len3); ++ if (len2 < 0) ++ { ++ err = ASN1_DER_ERROR; ++ goto error; ++ } ++ max_len -= len2 + len3; ++ if (der != NULL && max_len >= 0) ++ memcpy (der + counter, p->value, len3 + len2); ++ counter += len3 + len2; ++ move = RIGHT; ++ break; ++ case ASN1_ETYPE_SEQUENCE: ++ case ASN1_ETYPE_SET: ++ if (move != UP) ++ { ++ p->tmp_ival = counter; ++ if (p->down == NULL) ++ { ++ move = UP; ++ continue; ++ } ++ else ++ { ++ p2 = p->down; ++ while (p2 && (type_field (p2->type) == ASN1_ETYPE_TAG)) ++ p2 = p2->right; ++ if (p2) ++ { ++ p = p2; ++ move = RIGHT; ++ continue; ++ } ++ move = UP; ++ continue; ++ } ++ } ++ else ++ { /* move==UP */ ++ len2 = p->tmp_ival; ++ p->tmp_ival = 0; ++ if ((type_field (p->type) == ASN1_ETYPE_SET) && (max_len >= 0)) ++ { ++ err = _asn1_ordering_set (der + len2, counter - len2, p); ++ if (err != ASN1_SUCCESS) ++ goto error; ++ } ++ asn1_length_der (counter - len2, temp, &len3); ++ max_len -= len3; ++ if (der != NULL && max_len >= 0) ++ { ++ memmove (der + len2 + len3, der + len2, counter - len2); ++ memcpy (der + len2, temp, len3); ++ } ++ counter += len3; ++ move = RIGHT; ++ } ++ break; ++ case ASN1_ETYPE_SEQUENCE_OF: ++ case ASN1_ETYPE_SET_OF: ++ if (move != UP) ++ { ++ p->tmp_ival = counter; ++ p = p->down; ++ while ((type_field (p->type) == ASN1_ETYPE_TAG) ++ || (type_field (p->type) == ASN1_ETYPE_SIZE)) ++ p = p->right; ++ if (p->right) ++ { ++ p = p->right; ++ move = RIGHT; ++ continue; ++ } ++ else ++ p = _asn1_find_up (p); ++ move = UP; ++ } ++ if (move == UP) ++ { ++ len2 = p->tmp_ival; ++ p->tmp_ival = 0; ++ if ((type_field (p->type) == ASN1_ETYPE_SET_OF) ++ && (counter - len2 > 0) && (max_len >= 0)) ++ { ++ err = _asn1_ordering_set_of (der + len2, counter - len2, p); ++ if (err != ASN1_SUCCESS) ++ goto error; ++ } ++ asn1_length_der (counter - len2, temp, &len3); ++ max_len -= len3; ++ if (der != NULL && max_len >= 0) ++ { ++ memmove (der + len2 + len3, der + len2, counter - len2); ++ memcpy (der + len2, temp, len3); ++ } ++ counter += len3; ++ move = RIGHT; ++ } ++ break; ++ case ASN1_ETYPE_ANY: ++ if (p->value == NULL) ++ { ++ _asn1_error_description_value_not_found (p, ErrorDescription); ++ err = ASN1_VALUE_NOT_FOUND; ++ goto error; ++ } ++ len2 = asn1_get_length_der (p->value, p->value_len, &len3); ++ if (len2 < 0) ++ { ++ err = ASN1_DER_ERROR; ++ goto error; ++ } ++ max_len -= len2; ++ if (der != NULL && max_len >= 0) ++ memcpy (der + counter, p->value + len3, len2); ++ counter += len2; ++ move = RIGHT; ++ break; ++ default: ++ move = (move == UP) ? RIGHT : DOWN; ++ break; ++ } ++ ++ if ((move != DOWN) && (counter != counter_old)) ++ { ++ p->end = counter - 1; ++ err = _asn1_complete_explicit_tag (p, der, &counter, &max_len); ++ if (err != ASN1_SUCCESS && err != ASN1_MEM_ERROR) ++ goto error; ++ } ++ ++ if (p == node && move != DOWN) ++ break; ++ ++ if (move == DOWN) ++ { ++ if (p->down) ++ p = p->down; ++ else ++ move = RIGHT; ++ } ++ if (move == RIGHT) ++ { ++ if (p->right) ++ p = p->right; ++ else ++ move = UP; ++ } ++ if (move == UP) ++ p = _asn1_find_up (p); ++ } ++ ++ *len = counter; ++ ++ if (max_len < 0) ++ { ++ err = ASN1_MEM_ERROR; ++ goto error; ++ } ++ ++ err = ASN1_SUCCESS; ++ ++error: ++ asn1_delete_structure (&node); ++ return err; ++} +diff --git a/grub-core/lib/libtasn1/lib/decoding.c b/grub-core/lib/libtasn1/lib/decoding.c +new file mode 100644 +index 00000000000..ff04eb778cb +--- /dev/null ++++ b/grub-core/lib/libtasn1/lib/decoding.c +@@ -0,0 +1,2478 @@ ++/* ++ * Copyright (C) 2002-2016 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * The LIBTASN1 library is free software; you can redistribute it ++ * and/or modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ++ * 02110-1301, USA ++ */ ++ ++ ++/*****************************************************/ ++/* File: decoding.c */ ++/* Description: Functions to manage DER decoding */ ++/*****************************************************/ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#ifdef DEBUG ++# define warn() fprintf(stderr, "%s: %d\n", __func__, __LINE__) ++#else ++# define warn() ++#endif ++ ++#define IS_ERR(len, flags) (len < -1 || ((flags & ASN1_DECODE_FLAG_STRICT_DER) && len < 0)) ++ ++#define HAVE_TWO(x) (x>=2?1:0) ++ ++/* Decoding flags (dflags) used in several decoding functions. ++ * DECODE_FLAG_HAVE_TAG: The provided buffer includes a tag ++ * DECODE_FLAG_CONSTRUCTED: The provided buffer is of indefinite encoding (useful ++ * when no tags are present). ++ * DECODE_FLAG_LEVEL1: Internal flag to indicate a level of recursion for BER strings. ++ * DECODE_FLAG_LEVEL2: Internal flag to indicate two levels of recursion for BER strings. ++ * DECODE_FLAG_LEVEL3: Internal flag to indicate three levels of recursion for BER strings. ++ * This is the maximum levels of recursion possible to prevent stack ++ * exhaustion. ++ */ ++ ++#define DECODE_FLAG_HAVE_TAG 1 ++#define DECODE_FLAG_CONSTRUCTED (1<<1) ++#define DECODE_FLAG_LEVEL1 (1<<2) ++#define DECODE_FLAG_LEVEL2 (1<<3) ++#define DECODE_FLAG_LEVEL3 (1<<4) ++ ++#define DECR_LEN(l, s) do { \ ++ l -= s; \ ++ if (l < 0) { \ ++ warn(); \ ++ result = ASN1_DER_ERROR; \ ++ goto cleanup; \ ++ } \ ++ } while (0) ++ ++static int ++_asn1_get_indefinite_length_string (const unsigned char *der, int der_len, int *len); ++ ++static int ++_asn1_decode_simple_ber (unsigned int etype, const unsigned char *der, ++ unsigned int _der_len, unsigned char **str, ++ unsigned int *str_len, unsigned int *ber_len, ++ unsigned dflags); ++ ++static int ++_asn1_decode_simple_der (unsigned int etype, const unsigned char *der, ++ unsigned int _der_len, const unsigned char **str, ++ unsigned int *str_len, unsigned dflags); ++ ++static void ++_asn1_error_description_tag_error (asn1_node node, char *ErrorDescription) ++{ ++ ++ Estrcpy (ErrorDescription, ":: tag error near element '"); ++ _asn1_hierarchical_name (node, ErrorDescription + strlen (ErrorDescription), ++ ASN1_MAX_ERROR_DESCRIPTION_SIZE - 40); ++ Estrcat (ErrorDescription, "'"); ++ ++} ++ ++/** ++ * asn1_get_length_der: ++ * @der: DER data to decode. ++ * @der_len: Length of DER data to decode. ++ * @len: Output variable containing the length of the DER length field. ++ * ++ * Extract a length field from DER data. ++ * ++ * Returns: Return the decoded length value, or -1 on indefinite ++ * length, or -2 when the value was too big to fit in a int, or -4 ++ * when the decoded length value plus @len would exceed @der_len. ++ **/ ++long ++asn1_get_length_der (const unsigned char *der, int der_len, int *len) ++{ ++ unsigned int ans; ++ int k, punt, sum; ++ ++ *len = 0; ++ if (der_len <= 0) ++ return 0; ++ ++ if (!(der[0] & 128)) ++ { ++ /* short form */ ++ *len = 1; ++ ans = der[0]; ++ } ++ else ++ { ++ /* Long form */ ++ k = der[0] & 0x7F; ++ punt = 1; ++ if (k) ++ { /* definite length method */ ++ ans = 0; ++ while (punt <= k && punt < der_len) ++ { ++ if (INT_MULTIPLY_OVERFLOW (ans, 256)) ++ return -2; ++ ans *= 256; ++ ++ if (INT_ADD_OVERFLOW (ans, ((unsigned) der[punt]))) ++ return -2; ++ ans += der[punt]; ++ punt++; ++ } ++ } ++ else ++ { /* indefinite length method */ ++ *len = punt; ++ return -1; ++ } ++ ++ *len = punt; ++ } ++ ++ sum = ans; ++ if (ans >= INT_MAX || INT_ADD_OVERFLOW (sum, (*len))) ++ return -2; ++ sum += *len; ++ ++ if (sum > der_len) ++ return -4; ++ ++ return ans; ++} ++ ++/** ++ * asn1_get_tag_der: ++ * @der: DER data to decode. ++ * @der_len: Length of DER data to decode. ++ * @cls: Output variable containing decoded class. ++ * @len: Output variable containing the length of the DER TAG data. ++ * @tag: Output variable containing the decoded tag (may be %NULL). ++ * ++ * Decode the class and TAG from DER code. ++ * ++ * Returns: Returns %ASN1_SUCCESS on success, or an error. ++ **/ ++int ++asn1_get_tag_der (const unsigned char *der, int der_len, ++ unsigned char *cls, int *len, unsigned long *tag) ++{ ++ unsigned int ris; ++ int punt; ++ ++ if (der == NULL || der_len < 2 || len == NULL) ++ return ASN1_DER_ERROR; ++ ++ *cls = der[0] & 0xE0; ++ if ((der[0] & 0x1F) != 0x1F) ++ { ++ /* short form */ ++ *len = 1; ++ ris = der[0] & 0x1F; ++ } ++ else ++ { ++ /* Long form */ ++ punt = 1; ++ ris = 0; ++ while (punt < der_len && der[punt] & 128) ++ { ++ ++ if (INT_MULTIPLY_OVERFLOW (ris, 128)) ++ return ASN1_DER_ERROR; ++ ris *= 128; ++ ++ if (INT_ADD_OVERFLOW (ris, ((unsigned) (der[punt] & 0x7F)))) ++ return ASN1_DER_ERROR; ++ ris += (der[punt] & 0x7F); ++ punt++; ++ } ++ ++ if (punt >= der_len) ++ return ASN1_DER_ERROR; ++ ++ if (INT_MULTIPLY_OVERFLOW (ris, 128)) ++ return ASN1_DER_ERROR; ++ ris *= 128; ++ ++ if (INT_ADD_OVERFLOW (ris, ((unsigned) (der[punt] & 0x7F)))) ++ return ASN1_DER_ERROR; ++ ris += (der[punt] & 0x7F); ++ punt++; ++ ++ *len = punt; ++ } ++ ++ if (tag) ++ *tag = ris; ++ return ASN1_SUCCESS; ++} ++ ++/** ++ * asn1_get_length_ber: ++ * @ber: BER data to decode. ++ * @ber_len: Length of BER data to decode. ++ * @len: Output variable containing the length of the BER length field. ++ * ++ * Extract a length field from BER data. The difference to ++ * asn1_get_length_der() is that this function will return a length ++ * even if the value has indefinite encoding. ++ * ++ * Returns: Return the decoded length value, or negative value when ++ * the value was too big. ++ * ++ * Since: 2.0 ++ **/ ++long ++asn1_get_length_ber (const unsigned char *ber, int ber_len, int *len) ++{ ++ int ret; ++ long err; ++ ++ ret = asn1_get_length_der (ber, ber_len, len); ++ ++ if (ret == -1 && ber_len > 1) ++ { /* indefinite length method */ ++ err = _asn1_get_indefinite_length_string (ber + 1, ber_len-1, &ret); ++ if (err != ASN1_SUCCESS) ++ return -3; ++ } ++ ++ return ret; ++} ++ ++/** ++ * asn1_get_octet_der: ++ * @der: DER data to decode containing the OCTET SEQUENCE. ++ * @der_len: The length of the @der data to decode. ++ * @ret_len: Output variable containing the encoded length of the DER data. ++ * @str: Pre-allocated output buffer to put decoded OCTET SEQUENCE in. ++ * @str_size: Length of pre-allocated output buffer. ++ * @str_len: Output variable containing the length of the contents of the OCTET SEQUENCE. ++ * ++ * Extract an OCTET SEQUENCE from DER data. Note that this function ++ * expects the DER data past the tag field, i.e., the length and ++ * content octets. ++ * ++ * Returns: Returns %ASN1_SUCCESS on success, or an error. ++ **/ ++int ++asn1_get_octet_der (const unsigned char *der, int der_len, ++ int *ret_len, unsigned char *str, int str_size, ++ int *str_len) ++{ ++ int len_len = 0; ++ ++ if (der_len <= 0) ++ return ASN1_GENERIC_ERROR; ++ ++ *str_len = asn1_get_length_der (der, der_len, &len_len); ++ ++ if (*str_len < 0) ++ return ASN1_DER_ERROR; ++ ++ *ret_len = *str_len + len_len; ++ if (str_size >= *str_len) ++ { ++ if (*str_len > 0 && str != NULL) ++ memcpy (str, der + len_len, *str_len); ++ } ++ else ++ { ++ return ASN1_MEM_ERROR; ++ } ++ ++ return ASN1_SUCCESS; ++} ++ ++ ++/*- ++ * _asn1_get_time_der: ++ * @type: %ASN1_ETYPE_GENERALIZED_TIME or %ASN1_ETYPE_UTC_TIME ++ * @der: DER data to decode containing the time ++ * @der_len: Length of DER data to decode. ++ * @ret_len: Output variable containing the length of the DER data. ++ * @str: Pre-allocated output buffer to put the textual time in. ++ * @str_size: Length of pre-allocated output buffer. ++ * @flags: Zero or %ASN1_DECODE_FLAG_STRICT_DER ++ * ++ * Performs basic checks in the DER encoded time object and returns its textual form. ++ * The textual form will be in the YYYYMMDD000000Z format for GeneralizedTime ++ * and YYMMDD000000Z for UTCTime. ++ * ++ * Returns: %ASN1_SUCCESS on success, or an error. ++ -*/ ++static int ++_asn1_get_time_der (unsigned type, const unsigned char *der, int der_len, int *ret_len, ++ char *str, int str_size, unsigned flags) ++{ ++ int len_len, str_len; ++ unsigned i; ++ unsigned sign_count = 0; ++ unsigned dot_count = 0; ++ const unsigned char *p; ++ ++ if (der_len <= 0 || str == NULL) ++ return ASN1_DER_ERROR; ++ ++ str_len = asn1_get_length_der (der, der_len, &len_len); ++ if (str_len <= 0 || str_size < str_len) ++ return ASN1_DER_ERROR; ++ ++ /* perform some sanity checks on the data */ ++ if (str_len < 8) ++ { ++ warn(); ++ return ASN1_TIME_ENCODING_ERROR; ++ } ++ ++ if ((flags & ASN1_DECODE_FLAG_STRICT_DER) && !(flags & ASN1_DECODE_FLAG_ALLOW_INCORRECT_TIME)) ++ { ++ p = &der[len_len]; ++ for (i=0;i<(unsigned)(str_len-1);i++) ++ { ++ if (c_isdigit(p[i]) == 0) ++ { ++ if (type == ASN1_ETYPE_GENERALIZED_TIME) ++ { ++ /* tolerate lax encodings */ ++ if (p[i] == '.' && dot_count == 0) ++ { ++ dot_count++; ++ continue; ++ } ++ ++ /* This is not really valid DER, but there are ++ * structures using that */ ++ if (!(flags & ASN1_DECODE_FLAG_STRICT_DER) && ++ (p[i] == '+' || p[i] == '-') && sign_count == 0) ++ { ++ sign_count++; ++ continue; ++ } ++ } ++ ++ warn(); ++ return ASN1_TIME_ENCODING_ERROR; ++ } ++ } ++ ++ if (sign_count == 0 && p[str_len-1] != 'Z') ++ { ++ warn(); ++ return ASN1_TIME_ENCODING_ERROR; ++ } ++ } ++ memcpy (str, der + len_len, str_len); ++ str[str_len] = 0; ++ *ret_len = str_len + len_len; ++ ++ return ASN1_SUCCESS; ++} ++ ++/** ++ * asn1_get_object_id_der: ++ * @der: DER data to decode containing the OBJECT IDENTIFIER ++ * @der_len: Length of DER data to decode. ++ * @ret_len: Output variable containing the length of the DER data. ++ * @str: Pre-allocated output buffer to put the textual object id in. ++ * @str_size: Length of pre-allocated output buffer. ++ * ++ * Converts a DER encoded object identifier to its textual form. This ++ * function expects the DER object identifier without the tag. ++ * ++ * Returns: %ASN1_SUCCESS on success, or an error. ++ **/ ++int ++asn1_get_object_id_der (const unsigned char *der, int der_len, int *ret_len, ++ char *str, int str_size) ++{ ++ int len_len, len, k; ++ int leading, parsed; ++ char temp[LTOSTR_MAX_SIZE]; ++ uint64_t val, val1, val0; ++ ++ *ret_len = 0; ++ if (str && str_size > 0) ++ str[0] = 0; /* no oid */ ++ ++ if (str == NULL || der_len <= 0) ++ return ASN1_GENERIC_ERROR; ++ ++ len = asn1_get_length_der (der, der_len, &len_len); ++ ++ if (len <= 0 || len + len_len > der_len) ++ return ASN1_DER_ERROR; ++ ++ /* leading octet can never be 0x80 */ ++ if (der[len_len] == 0x80) ++ return ASN1_DER_ERROR; ++ ++ val0 = 0; ++ ++ for (k = 0; k < len; k++) ++ { ++ if (INT_LEFT_SHIFT_OVERFLOW (val0, 7)) ++ return ASN1_DER_ERROR; ++ ++ val0 <<= 7; ++ val0 |= der[len_len + k] & 0x7F; ++ if (!(der[len_len + k] & 0x80)) ++ break; ++ } ++ parsed = ++k; ++ ++ /* val0 = (X*40) + Y, X={0,1,2}, Y<=39 when X={0,1} */ ++ /* X = val, Y = val1 */ ++ ++ /* check if X == 0 */ ++ val = 0; ++ val1 = val0; ++ if (val1 > 39) ++ { ++ val = 1; ++ val1 = val0 - 40; ++ if (val1 > 39) ++ { ++ val = 2; ++ val1 = val0 - 80; ++ } ++ } ++ ++ _asn1_str_cpy (str, str_size, _asn1_ltostr (val, temp)); ++ _asn1_str_cat (str, str_size, "."); ++ _asn1_str_cat (str, str_size, _asn1_ltostr (val1, temp)); ++ ++ val = 0; ++ leading = 1; ++ for (k = parsed; k < len; k++) ++ { ++ /* X.690 mandates that the leading byte must never be 0x80 ++ */ ++ if (leading != 0 && der[len_len + k] == 0x80) ++ return ASN1_DER_ERROR; ++ leading = 0; ++ ++ /* check for wrap around */ ++ if (INT_LEFT_SHIFT_OVERFLOW (val, 7)) ++ return ASN1_DER_ERROR; ++ ++ val = val << 7; ++ val |= der[len_len + k] & 0x7F; ++ ++ if (!(der[len_len + k] & 0x80)) ++ { ++ _asn1_str_cat (str, str_size, "."); ++ _asn1_str_cat (str, str_size, _asn1_ltostr (val, temp)); ++ val = 0; ++ leading = 1; ++ } ++ } ++ ++ if (INT_ADD_OVERFLOW (len, len_len)) ++ return ASN1_DER_ERROR; ++ ++ *ret_len = len + len_len; ++ ++ return ASN1_SUCCESS; ++} ++ ++/** ++ * asn1_get_bit_der: ++ * @der: DER data to decode containing the BIT SEQUENCE. ++ * @der_len: Length of DER data to decode. ++ * @ret_len: Output variable containing the length of the DER data. ++ * @str: Pre-allocated output buffer to put decoded BIT SEQUENCE in. ++ * @str_size: Length of pre-allocated output buffer. ++ * @bit_len: Output variable containing the size of the BIT SEQUENCE. ++ * ++ * Extract a BIT SEQUENCE from DER data. ++ * ++ * Returns: %ASN1_SUCCESS on success, or an error. ++ **/ ++int ++asn1_get_bit_der (const unsigned char *der, int der_len, ++ int *ret_len, unsigned char *str, int str_size, ++ int *bit_len) ++{ ++ int len_len = 0, len_byte; ++ ++ if (der_len <= 0) ++ return ASN1_GENERIC_ERROR; ++ ++ len_byte = asn1_get_length_der (der, der_len, &len_len) - 1; ++ if (len_byte < 0) ++ return ASN1_DER_ERROR; ++ ++ *ret_len = len_byte + len_len + 1; ++ *bit_len = len_byte * 8 - der[len_len]; ++ ++ if (*bit_len < 0) ++ return ASN1_DER_ERROR; ++ ++ if (str_size >= len_byte) ++ { ++ if (len_byte > 0 && str) ++ memcpy (str, der + len_len + 1, len_byte); ++ } ++ else ++ { ++ return ASN1_MEM_ERROR; ++ } ++ ++ return ASN1_SUCCESS; ++} ++ ++/* tag_len: the total tag length (explicit+inner) ++ * inner_tag_len: the inner_tag length ++ */ ++static int ++_asn1_extract_tag_der (asn1_node node, const unsigned char *der, int der_len, ++ int *tag_len, int *inner_tag_len, unsigned flags) ++{ ++ asn1_node p; ++ int counter, len2, len3, is_tag_implicit; ++ int result; ++ unsigned long tag, tag_implicit = 0; ++ unsigned char class, class2, class_implicit = 0; ++ ++ if (der_len <= 0) ++ return ASN1_GENERIC_ERROR; ++ ++ counter = is_tag_implicit = 0; ++ ++ if (node->type & CONST_TAG) ++ { ++ p = node->down; ++ while (p) ++ { ++ if (type_field (p->type) == ASN1_ETYPE_TAG) ++ { ++ if (p->type & CONST_APPLICATION) ++ class2 = ASN1_CLASS_APPLICATION; ++ else if (p->type & CONST_UNIVERSAL) ++ class2 = ASN1_CLASS_UNIVERSAL; ++ else if (p->type & CONST_PRIVATE) ++ class2 = ASN1_CLASS_PRIVATE; ++ else ++ class2 = ASN1_CLASS_CONTEXT_SPECIFIC; ++ ++ if (p->type & CONST_EXPLICIT) ++ { ++ if (asn1_get_tag_der ++ (der + counter, der_len, &class, &len2, ++ &tag) != ASN1_SUCCESS) ++ return ASN1_DER_ERROR; ++ ++ DECR_LEN(der_len, len2); ++ counter += len2; ++ ++ if (flags & ASN1_DECODE_FLAG_STRICT_DER) ++ len3 = ++ asn1_get_length_der (der + counter, der_len, ++ &len2); ++ else ++ len3 = ++ asn1_get_length_ber (der + counter, der_len, ++ &len2); ++ if (len3 < 0) ++ return ASN1_DER_ERROR; ++ ++ DECR_LEN(der_len, len2); ++ counter += len2; ++ ++ if (!is_tag_implicit) ++ { ++ if ((class != (class2 | ASN1_CLASS_STRUCTURED)) || ++ (tag != strtoul ((char *) p->value, NULL, 10))) ++ return ASN1_TAG_ERROR; ++ } ++ else ++ { /* ASN1_TAG_IMPLICIT */ ++ if ((class != class_implicit) || (tag != tag_implicit)) ++ return ASN1_TAG_ERROR; ++ } ++ is_tag_implicit = 0; ++ } ++ else ++ { /* ASN1_TAG_IMPLICIT */ ++ if (!is_tag_implicit) ++ { ++ if ((type_field (node->type) == ASN1_ETYPE_SEQUENCE) || ++ (type_field (node->type) == ASN1_ETYPE_SEQUENCE_OF) ++ || (type_field (node->type) == ASN1_ETYPE_SET) ++ || (type_field (node->type) == ASN1_ETYPE_SET_OF)) ++ class2 |= ASN1_CLASS_STRUCTURED; ++ class_implicit = class2; ++ tag_implicit = strtoul ((char *) p->value, NULL, 10); ++ is_tag_implicit = 1; ++ } ++ } ++ } ++ p = p->right; ++ } ++ } ++ ++ if (is_tag_implicit) ++ { ++ if (asn1_get_tag_der ++ (der + counter, der_len, &class, &len2, ++ &tag) != ASN1_SUCCESS) ++ return ASN1_DER_ERROR; ++ ++ DECR_LEN(der_len, len2); ++ ++ if ((class != class_implicit) || (tag != tag_implicit)) ++ { ++ if (type_field (node->type) == ASN1_ETYPE_OCTET_STRING) ++ { ++ class_implicit |= ASN1_CLASS_STRUCTURED; ++ if ((class != class_implicit) || (tag != tag_implicit)) ++ return ASN1_TAG_ERROR; ++ } ++ else ++ return ASN1_TAG_ERROR; ++ } ++ } ++ else ++ { ++ unsigned type = type_field (node->type); ++ if (type == ASN1_ETYPE_TAG) ++ { ++ *tag_len = 0; ++ if (inner_tag_len) ++ *inner_tag_len = 0; ++ return ASN1_SUCCESS; ++ } ++ ++ if (asn1_get_tag_der ++ (der + counter, der_len, &class, &len2, ++ &tag) != ASN1_SUCCESS) ++ return ASN1_DER_ERROR; ++ ++ DECR_LEN(der_len, len2); ++ ++ switch (type) ++ { ++ case ASN1_ETYPE_NULL: ++ case ASN1_ETYPE_BOOLEAN: ++ case ASN1_ETYPE_INTEGER: ++ case ASN1_ETYPE_ENUMERATED: ++ case ASN1_ETYPE_OBJECT_ID: ++ case ASN1_ETYPE_GENERALSTRING: ++ case ASN1_ETYPE_NUMERIC_STRING: ++ case ASN1_ETYPE_IA5_STRING: ++ case ASN1_ETYPE_TELETEX_STRING: ++ case ASN1_ETYPE_PRINTABLE_STRING: ++ case ASN1_ETYPE_UNIVERSAL_STRING: ++ case ASN1_ETYPE_BMP_STRING: ++ case ASN1_ETYPE_UTF8_STRING: ++ case ASN1_ETYPE_VISIBLE_STRING: ++ case ASN1_ETYPE_BIT_STRING: ++ case ASN1_ETYPE_SEQUENCE: ++ case ASN1_ETYPE_SEQUENCE_OF: ++ case ASN1_ETYPE_SET: ++ case ASN1_ETYPE_SET_OF: ++ case ASN1_ETYPE_GENERALIZED_TIME: ++ case ASN1_ETYPE_UTC_TIME: ++ if ((class != _asn1_tags[type].class) ++ || (tag != _asn1_tags[type].tag)) ++ return ASN1_DER_ERROR; ++ break; ++ ++ case ASN1_ETYPE_OCTET_STRING: ++ /* OCTET STRING is handled differently to allow ++ * BER encodings (structured class). */ ++ if (((class != ASN1_CLASS_UNIVERSAL) ++ && (class != (ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED))) ++ || (tag != ASN1_TAG_OCTET_STRING)) ++ return ASN1_DER_ERROR; ++ break; ++ case ASN1_ETYPE_ANY: ++ counter -= len2; ++ break; ++ case ASN1_ETYPE_CHOICE: ++ counter -= len2; ++ break; ++ default: ++ return ASN1_DER_ERROR; ++ break; ++ } ++ } ++ ++ counter += len2; ++ *tag_len = counter; ++ if (inner_tag_len) ++ *inner_tag_len = len2; ++ return ASN1_SUCCESS; ++ ++cleanup: ++ return result; ++} ++ ++static int ++extract_tag_der_recursive(asn1_node node, const unsigned char *der, int der_len, ++ int *ret_len, int *inner_len, unsigned flags) ++{ ++asn1_node p; ++int ris = ASN1_DER_ERROR; ++ ++ if (type_field (node->type) == ASN1_ETYPE_CHOICE) ++ { ++ p = node->down; ++ while (p) ++ { ++ ris = _asn1_extract_tag_der (p, der, der_len, ret_len, inner_len, flags); ++ if (ris == ASN1_SUCCESS) ++ break; ++ p = p->right; ++ } ++ ++ *ret_len = 0; ++ return ris; ++ } ++ else ++ return _asn1_extract_tag_der (node, der, der_len, ret_len, inner_len, flags); ++} ++ ++static int ++_asn1_delete_not_used (asn1_node node) ++{ ++ asn1_node p, p2; ++ ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ p = node; ++ while (p) ++ { ++ if (p->type & CONST_NOT_USED) ++ { ++ p2 = NULL; ++ if (p != node) ++ { ++ p2 = _asn1_find_left (p); ++ if (!p2) ++ p2 = _asn1_find_up (p); ++ } ++ asn1_delete_structure (&p); ++ p = p2; ++ } ++ ++ if (!p) ++ break; /* reach node */ ++ ++ if (p->down) ++ { ++ p = p->down; ++ } ++ else ++ { ++ if (p == node) ++ p = NULL; ++ else if (p->right) ++ p = p->right; ++ else ++ { ++ while (1) ++ { ++ p = _asn1_find_up (p); ++ if (p == node) ++ { ++ p = NULL; ++ break; ++ } ++ if (p->right) ++ { ++ p = p->right; ++ break; ++ } ++ } ++ } ++ } ++ } ++ return ASN1_SUCCESS; ++} ++ ++static int ++_asn1_get_indefinite_length_string (const unsigned char *der, ++ int der_len, int *len) ++{ ++ int len2, len3, counter, indefinite; ++ int result; ++ unsigned long tag; ++ unsigned char class; ++ ++ counter = indefinite = 0; ++ ++ while (1) ++ { ++ if (HAVE_TWO(der_len) && (der[counter] == 0) && (der[counter + 1] == 0)) ++ { ++ counter += 2; ++ DECR_LEN(der_len, 2); ++ ++ indefinite--; ++ if (indefinite <= 0) ++ break; ++ else ++ continue; ++ } ++ ++ if (asn1_get_tag_der ++ (der + counter, der_len, &class, &len2, ++ &tag) != ASN1_SUCCESS) ++ return ASN1_DER_ERROR; ++ ++ DECR_LEN(der_len, len2); ++ counter += len2; ++ ++ len2 = asn1_get_length_der (der + counter, der_len, &len3); ++ if (len2 < -1) ++ return ASN1_DER_ERROR; ++ ++ if (len2 == -1) ++ { ++ indefinite++; ++ counter += 1; ++ DECR_LEN(der_len, 1); ++ } ++ else ++ { ++ counter += len2 + len3; ++ DECR_LEN(der_len, len2+len3); ++ } ++ } ++ ++ *len = counter; ++ return ASN1_SUCCESS; ++ ++cleanup: ++ return result; ++} ++ ++static void delete_unneeded_choice_fields(asn1_node p) ++{ ++ asn1_node p2; ++ ++ while (p->right) ++ { ++ p2 = p->right; ++ asn1_delete_structure (&p2); ++ } ++} ++ ++ ++/** ++ * asn1_der_decoding2 ++ * @element: pointer to an ASN1 structure. ++ * @ider: vector that contains the DER encoding. ++ * @max_ider_len: pointer to an integer giving the information about the ++ * maximal number of bytes occupied by *@ider. The real size of the DER ++ * encoding is returned through this pointer. ++ * @flags: flags controlling the behaviour of the function. ++ * @errorDescription: null-terminated string contains details when an ++ * error occurred. ++ * ++ * Fill the structure *@element with values of a DER encoding string. The ++ * structure must just be created with function asn1_create_element(). ++ * ++ * If %ASN1_DECODE_FLAG_ALLOW_PADDING flag is set then the function will ignore ++ * padding after the decoded DER data. Upon a successful return the value of ++ * *@max_ider_len will be set to the number of bytes decoded. ++ * ++ * If %ASN1_DECODE_FLAG_STRICT_DER flag is set then the function will ++ * not decode any BER-encoded elements. ++ * ++ * Returns: %ASN1_SUCCESS if DER encoding OK, %ASN1_ELEMENT_NOT_FOUND ++ * if @ELEMENT is %NULL, and %ASN1_TAG_ERROR or ++ * %ASN1_DER_ERROR if the der encoding doesn't match the structure ++ * name (*@ELEMENT deleted). ++ **/ ++int ++asn1_der_decoding2 (asn1_node *element, const void *ider, int *max_ider_len, ++ unsigned int flags, char *errorDescription) ++{ ++ asn1_node node, p, p2, p3; ++ char temp[128]; ++ int counter, len2, len3, len4, move, ris, tlen; ++ struct node_tail_cache_st tcache = {NULL, NULL}; ++ unsigned char class; ++ unsigned long tag; ++ int tag_len; ++ int indefinite, result, total_len = *max_ider_len, ider_len = *max_ider_len; ++ int inner_tag_len; ++ unsigned char *ptmp; ++ const unsigned char *ptag; ++ const unsigned char *der = ider; ++ ++ node = *element; ++ ++ if (errorDescription != NULL) ++ errorDescription[0] = 0; ++ ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ if (node->type & CONST_OPTION) ++ { ++ result = ASN1_GENERIC_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ ++ counter = 0; ++ move = DOWN; ++ p = node; ++ while (1) ++ { ++ tag_len = 0; ++ inner_tag_len = 0; ++ ris = ASN1_SUCCESS; ++ if (move != UP) ++ { ++ if (p->type & CONST_SET) ++ { ++ p2 = _asn1_find_up (p); ++ len2 = p2->tmp_ival; ++ if (len2 == -1) ++ { ++ if (HAVE_TWO(ider_len) && !der[counter] && !der[counter + 1]) ++ { ++ p = p2; ++ move = UP; ++ counter += 2; ++ DECR_LEN(ider_len, 2); ++ continue; ++ } ++ } ++ else if (counter == len2) ++ { ++ p = p2; ++ move = UP; ++ continue; ++ } ++ else if (counter > len2) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ p2 = p2->down; ++ while (p2) ++ { ++ if ((p2->type & CONST_SET) && (p2->type & CONST_NOT_USED)) ++ { ++ ris = ++ extract_tag_der_recursive (p2, der + counter, ++ ider_len, &len2, NULL, flags); ++ if (ris == ASN1_SUCCESS) ++ { ++ p2->type &= ~CONST_NOT_USED; ++ p = p2; ++ break; ++ } ++ } ++ p2 = p2->right; ++ } ++ if (p2 == NULL) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ } ++ ++ /* the position in the DER structure this starts */ ++ p->start = counter; ++ p->end = total_len - 1; ++ ++ if ((p->type & CONST_OPTION) || (p->type & CONST_DEFAULT)) ++ { ++ p2 = _asn1_find_up (p); ++ len2 = p2->tmp_ival; ++ if (counter == len2) ++ { ++ if (p->right) ++ { ++ p2 = p->right; ++ move = RIGHT; ++ } ++ else ++ move = UP; ++ ++ if (p->type & CONST_OPTION) ++ asn1_delete_structure (&p); ++ ++ p = p2; ++ continue; ++ } ++ } ++ ++ if (type_field (p->type) == ASN1_ETYPE_CHOICE) ++ { ++ while (p->down) ++ { ++ ris = ++ extract_tag_der_recursive (p->down, der + counter, ++ ider_len, &len2, NULL, flags); ++ ++ if (ris == ASN1_SUCCESS) ++ { ++ delete_unneeded_choice_fields(p->down); ++ break; ++ } ++ else if (ris == ASN1_ERROR_TYPE_ANY) ++ { ++ result = ASN1_ERROR_TYPE_ANY; ++ warn(); ++ goto cleanup; ++ } ++ else ++ { ++ p2 = p->down; ++ asn1_delete_structure (&p2); ++ } ++ } ++ ++ if (p->down == NULL) ++ { ++ if (!(p->type & CONST_OPTION)) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ } ++ else if (type_field (p->type) != ASN1_ETYPE_CHOICE) ++ p = p->down; ++ ++ p->start = counter; ++ } ++ ++ if ((p->type & CONST_OPTION) || (p->type & CONST_DEFAULT)) ++ { ++ p2 = _asn1_find_up (p); ++ len2 = p2->tmp_ival; ++ ++ if ((len2 != -1) && (counter > len2)) ++ ris = ASN1_TAG_ERROR; ++ } ++ ++ if (ris == ASN1_SUCCESS) ++ ris = ++ extract_tag_der_recursive (p, der + counter, ider_len, ++ &tag_len, &inner_tag_len, flags); ++ ++ if (ris != ASN1_SUCCESS) ++ { ++ if (p->type & CONST_OPTION) ++ { ++ p->type |= CONST_NOT_USED; ++ move = RIGHT; ++ } ++ else if (p->type & CONST_DEFAULT) ++ { ++ _asn1_set_value (p, NULL, 0); ++ move = RIGHT; ++ } ++ else ++ { ++ if (errorDescription != NULL) ++ _asn1_error_description_tag_error (p, errorDescription); ++ ++ result = ASN1_TAG_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ } ++ else ++ { ++ DECR_LEN(ider_len, tag_len); ++ counter += tag_len; ++ } ++ } ++ ++ if (ris == ASN1_SUCCESS) ++ { ++ switch (type_field (p->type)) ++ { ++ case ASN1_ETYPE_NULL: ++ DECR_LEN(ider_len, 1); ++ if (der[counter]) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ counter++; ++ move = RIGHT; ++ break; ++ case ASN1_ETYPE_BOOLEAN: ++ DECR_LEN(ider_len, 2); ++ ++ if (der[counter++] != 1) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ if (der[counter++] == 0) ++ _asn1_set_value (p, "F", 1); ++ else ++ _asn1_set_value (p, "T", 1); ++ move = RIGHT; ++ break; ++ case ASN1_ETYPE_INTEGER: ++ case ASN1_ETYPE_ENUMERATED: ++ len2 = ++ asn1_get_length_der (der + counter, ider_len, &len3); ++ if (len2 < 0) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ ++ DECR_LEN(ider_len, len3+len2); ++ ++ _asn1_set_value (p, der + counter, len3 + len2); ++ counter += len3 + len2; ++ move = RIGHT; ++ break; ++ case ASN1_ETYPE_OBJECT_ID: ++ result = ++ asn1_get_object_id_der (der + counter, ider_len, &len2, ++ temp, sizeof (temp)); ++ if (result != ASN1_SUCCESS) ++ { ++ warn(); ++ goto cleanup; ++ } ++ ++ DECR_LEN(ider_len, len2); ++ ++ tlen = strlen (temp); ++ if (tlen > 0) ++ _asn1_set_value (p, temp, tlen + 1); ++ ++ counter += len2; ++ move = RIGHT; ++ break; ++ case ASN1_ETYPE_GENERALIZED_TIME: ++ case ASN1_ETYPE_UTC_TIME: ++ result = ++ _asn1_get_time_der (type_field (p->type), der + counter, ider_len, &len2, temp, ++ sizeof (temp) - 1, flags); ++ if (result != ASN1_SUCCESS) ++ { ++ warn(); ++ goto cleanup; ++ } ++ ++ DECR_LEN(ider_len, len2); ++ ++ tlen = strlen (temp); ++ if (tlen > 0) ++ _asn1_set_value (p, temp, tlen); ++ ++ counter += len2; ++ move = RIGHT; ++ break; ++ case ASN1_ETYPE_OCTET_STRING: ++ if (counter < inner_tag_len) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ ++ ptag = der + counter - inner_tag_len; ++ if ((flags & ASN1_DECODE_FLAG_STRICT_DER) || !(ptag[0] & ASN1_CLASS_STRUCTURED)) ++ { ++ if (ptag[0] & ASN1_CLASS_STRUCTURED) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ ++ len2 = ++ asn1_get_length_der (der + counter, ider_len, &len3); ++ if (len2 < 0) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ ++ DECR_LEN(ider_len, len3+len2); ++ ++ _asn1_set_value (p, der + counter, len3 + len2); ++ counter += len3 + len2; ++ } ++ else ++ { ++ unsigned dflags = 0, vlen, ber_len; ++ ++ if (ptag[0] & ASN1_CLASS_STRUCTURED) ++ dflags |= DECODE_FLAG_CONSTRUCTED; ++ ++ result = _asn1_decode_simple_ber(type_field (p->type), der+counter, ider_len, &ptmp, &vlen, &ber_len, dflags); ++ if (result != ASN1_SUCCESS) ++ { ++ warn(); ++ goto cleanup; ++ } ++ ++ DECR_LEN(ider_len, ber_len); ++ ++ _asn1_set_value_lv (p, ptmp, vlen); ++ ++ counter += ber_len; ++ free(ptmp); ++ } ++ move = RIGHT; ++ break; ++ case ASN1_ETYPE_GENERALSTRING: ++ case ASN1_ETYPE_NUMERIC_STRING: ++ case ASN1_ETYPE_IA5_STRING: ++ case ASN1_ETYPE_TELETEX_STRING: ++ case ASN1_ETYPE_PRINTABLE_STRING: ++ case ASN1_ETYPE_UNIVERSAL_STRING: ++ case ASN1_ETYPE_BMP_STRING: ++ case ASN1_ETYPE_UTF8_STRING: ++ case ASN1_ETYPE_VISIBLE_STRING: ++ case ASN1_ETYPE_BIT_STRING: ++ len2 = ++ asn1_get_length_der (der + counter, ider_len, &len3); ++ if (len2 < 0) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ ++ DECR_LEN(ider_len, len3+len2); ++ ++ _asn1_set_value (p, der + counter, len3 + len2); ++ counter += len3 + len2; ++ move = RIGHT; ++ break; ++ case ASN1_ETYPE_SEQUENCE: ++ case ASN1_ETYPE_SET: ++ if (move == UP) ++ { ++ len2 = p->tmp_ival; ++ p->tmp_ival = 0; ++ if (len2 == -1) ++ { /* indefinite length method */ ++ DECR_LEN(ider_len, 2); ++ if ((der[counter]) || der[counter + 1]) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ counter += 2; ++ } ++ else ++ { /* definite length method */ ++ if (len2 != counter) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ } ++ move = RIGHT; ++ } ++ else ++ { /* move==DOWN || move==RIGHT */ ++ len3 = ++ asn1_get_length_der (der + counter, ider_len, &len2); ++ if (IS_ERR(len3, flags)) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ ++ DECR_LEN(ider_len, len2); ++ counter += len2; ++ ++ if (len3 > 0) ++ { ++ p->tmp_ival = counter + len3; ++ move = DOWN; ++ } ++ else if (len3 == 0) ++ { ++ p2 = p->down; ++ while (p2) ++ { ++ if (type_field (p2->type) != ASN1_ETYPE_TAG) ++ { ++ p3 = p2->right; ++ asn1_delete_structure (&p2); ++ p2 = p3; ++ } ++ else ++ p2 = p2->right; ++ } ++ move = RIGHT; ++ } ++ else ++ { /* indefinite length method */ ++ p->tmp_ival = -1; ++ move = DOWN; ++ } ++ } ++ break; ++ case ASN1_ETYPE_SEQUENCE_OF: ++ case ASN1_ETYPE_SET_OF: ++ if (move == UP) ++ { ++ len2 = p->tmp_ival; ++ if (len2 == -1) ++ { /* indefinite length method */ ++ if (!HAVE_TWO(ider_len) || ((der[counter]) || der[counter + 1])) ++ { ++ result = _asn1_append_sequence_set (p, &tcache); ++ if (result != 0) ++ { ++ warn(); ++ goto cleanup; ++ } ++ p = tcache.tail; ++ move = RIGHT; ++ continue; ++ } ++ ++ p->tmp_ival = 0; ++ tcache.tail = NULL; /* finished decoding this structure */ ++ tcache.head = NULL; ++ DECR_LEN(ider_len, 2); ++ counter += 2; ++ } ++ else ++ { /* definite length method */ ++ if (len2 > counter) ++ { ++ result = _asn1_append_sequence_set (p, &tcache); ++ if (result != 0) ++ { ++ warn(); ++ goto cleanup; ++ } ++ p = tcache.tail; ++ move = RIGHT; ++ continue; ++ } ++ ++ p->tmp_ival = 0; ++ tcache.tail = NULL; /* finished decoding this structure */ ++ tcache.head = NULL; ++ ++ if (len2 != counter) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ } ++ } ++ else ++ { /* move==DOWN || move==RIGHT */ ++ len3 = ++ asn1_get_length_der (der + counter, ider_len, &len2); ++ if (IS_ERR(len3, flags)) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ ++ DECR_LEN(ider_len, len2); ++ counter += len2; ++ if (len3) ++ { ++ if (len3 > 0) ++ { /* definite length method */ ++ p->tmp_ival = counter + len3; ++ } ++ else ++ { /* indefinite length method */ ++ p->tmp_ival = -1; ++ } ++ ++ p2 = p->down; ++ if (p2 == NULL) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ ++ while ((type_field (p2->type) == ASN1_ETYPE_TAG) ++ || (type_field (p2->type) == ASN1_ETYPE_SIZE)) ++ p2 = p2->right; ++ if (p2->right == NULL) ++ { ++ result = _asn1_append_sequence_set (p, &tcache); ++ if (result != 0) ++ { ++ warn(); ++ goto cleanup; ++ } ++ } ++ p = p2; ++ } ++ } ++ move = RIGHT; ++ break; ++ case ASN1_ETYPE_ANY: ++ /* Check indefinite lenth method in an EXPLICIT TAG */ ++ ++ if (!(flags & ASN1_DECODE_FLAG_STRICT_DER) && (p->type & CONST_TAG) && ++ tag_len == 2 && (der[counter - 1] == 0x80)) ++ indefinite = 1; ++ else ++ indefinite = 0; ++ ++ if (asn1_get_tag_der ++ (der + counter, ider_len, &class, &len2, ++ &tag) != ASN1_SUCCESS) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ ++ DECR_LEN(ider_len, len2); ++ ++ len4 = ++ asn1_get_length_der (der + counter + len2, ++ ider_len, &len3); ++ if (IS_ERR(len4, flags)) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ if (len4 != -1) /* definite */ ++ { ++ len2 += len4; ++ ++ DECR_LEN(ider_len, len4+len3); ++ _asn1_set_value_lv (p, der + counter, len2 + len3); ++ counter += len2 + len3; ++ } ++ else /* == -1 */ ++ { /* indefinite length */ ++ ider_len += len2; /* undo DECR_LEN */ ++ ++ if (counter == 0) ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ ++ result = ++ _asn1_get_indefinite_length_string (der + counter, ider_len, &len2); ++ if (result != ASN1_SUCCESS) ++ { ++ warn(); ++ goto cleanup; ++ } ++ ++ DECR_LEN(ider_len, len2); ++ _asn1_set_value_lv (p, der + counter, len2); ++ counter += len2; ++ ++ } ++ ++ /* Check if a couple of 0x00 are present due to an EXPLICIT TAG with ++ an indefinite length method. */ ++ if (indefinite) ++ { ++ DECR_LEN(ider_len, 2); ++ if (!der[counter] && !der[counter + 1]) ++ { ++ counter += 2; ++ } ++ else ++ { ++ result = ASN1_DER_ERROR; ++ warn(); ++ goto cleanup; ++ } ++ } ++ ++ move = RIGHT; ++ break; ++ default: ++ move = (move == UP) ? RIGHT : DOWN; ++ break; ++ } ++ } ++ ++ if (p) ++ { ++ p->end = counter - 1; ++ } ++ ++ if (p == node && move != DOWN) ++ break; ++ ++ if (move == DOWN) ++ { ++ if (p->down) ++ p = p->down; ++ else ++ move = RIGHT; ++ } ++ if ((move == RIGHT) && !(p->type & CONST_SET)) ++ { ++ if (p->right) ++ p = p->right; ++ else ++ move = UP; ++ } ++ if (move == UP) ++ p = _asn1_find_up (p); ++ } ++ ++ _asn1_delete_not_used (*element); ++ ++ if ((ider_len < 0) || ++ (!(flags & ASN1_DECODE_FLAG_ALLOW_PADDING) && (ider_len != 0))) ++ { ++ warn(); ++ result = ASN1_DER_ERROR; ++ goto cleanup; ++ } ++ ++ *max_ider_len = total_len - ider_len; ++ ++ return ASN1_SUCCESS; ++ ++cleanup: ++ asn1_delete_structure (element); ++ return result; ++} ++ ++ ++/** ++ * asn1_der_decoding: ++ * @element: pointer to an ASN1 structure. ++ * @ider: vector that contains the DER encoding. ++ * @ider_len: number of bytes of *@ider: @ider[0]..@ider[len-1]. ++ * @errorDescription: null-terminated string contains details when an ++ * error occurred. ++ * ++ * Fill the structure *@element with values of a DER encoding ++ * string. The structure must just be created with function ++ * asn1_create_element(). ++ * ++ * Note that the *@element variable is provided as a pointer for ++ * historical reasons. ++ * ++ * Returns: %ASN1_SUCCESS if DER encoding OK, %ASN1_ELEMENT_NOT_FOUND ++ * if @ELEMENT is %NULL, and %ASN1_TAG_ERROR or ++ * %ASN1_DER_ERROR if the der encoding doesn't match the structure ++ * name (*@ELEMENT deleted). ++ **/ ++int ++asn1_der_decoding (asn1_node * element, const void *ider, int ider_len, ++ char *errorDescription) ++{ ++ return asn1_der_decoding2 (element, ider, &ider_len, 0, errorDescription); ++} ++ ++/** ++ * asn1_der_decoding_element: ++ * @structure: pointer to an ASN1 structure ++ * @elementName: name of the element to fill ++ * @ider: vector that contains the DER encoding of the whole structure. ++ * @len: number of bytes of *der: der[0]..der[len-1] ++ * @errorDescription: null-terminated string contains details when an ++ * error occurred. ++ * ++ * Fill the element named @ELEMENTNAME with values of a DER encoding ++ * string. The structure must just be created with function ++ * asn1_create_element(). The DER vector must contain the encoding ++ * string of the whole @STRUCTURE. If an error occurs during the ++ * decoding procedure, the *@STRUCTURE is deleted and set equal to ++ * %NULL. ++ * ++ * This function is deprecated and may just be an alias to asn1_der_decoding ++ * in future versions. Use asn1_der_decoding() instead. ++ * ++ * Returns: %ASN1_SUCCESS if DER encoding OK, %ASN1_ELEMENT_NOT_FOUND ++ * if ELEMENT is %NULL or @elementName == NULL, and ++ * %ASN1_TAG_ERROR or %ASN1_DER_ERROR if the der encoding doesn't ++ * match the structure @structure (*ELEMENT deleted). ++ **/ ++int ++asn1_der_decoding_element (asn1_node * structure, const char *elementName, ++ const void *ider, int len, char *errorDescription) ++{ ++ return asn1_der_decoding(structure, ider, len, errorDescription); ++} ++ ++/** ++ * asn1_der_decoding_startEnd: ++ * @element: pointer to an ASN1 element ++ * @ider: vector that contains the DER encoding. ++ * @ider_len: number of bytes of *@ider: @ider[0]..@ider[len-1] ++ * @name_element: an element of NAME structure. ++ * @start: the position of the first byte of NAME_ELEMENT decoding ++ * (@ider[*start]) ++ * @end: the position of the last byte of NAME_ELEMENT decoding ++ * (@ider[*end]) ++ * ++ * Find the start and end point of an element in a DER encoding ++ * string. I mean that if you have a der encoding and you have already ++ * used the function asn1_der_decoding() to fill a structure, it may ++ * happen that you want to find the piece of string concerning an ++ * element of the structure. ++ * ++ * One example is the sequence "tbsCertificate" inside an X509 ++ * certificate. ++ * ++ * Note that since libtasn1 3.7 the @ider and @ider_len parameters ++ * can be omitted, if the element is already decoded using asn1_der_decoding(). ++ * ++ * Returns: %ASN1_SUCCESS if DER encoding OK, %ASN1_ELEMENT_NOT_FOUND ++ * if ELEMENT is %asn1_node EMPTY or @name_element is not a valid ++ * element, %ASN1_TAG_ERROR or %ASN1_DER_ERROR if the der encoding ++ * doesn't match the structure ELEMENT. ++ **/ ++int ++asn1_der_decoding_startEnd (asn1_node element, const void *ider, int ider_len, ++ const char *name_element, int *start, int *end) ++{ ++ asn1_node node, node_to_find; ++ int result = ASN1_DER_ERROR; ++ ++ node = element; ++ ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ node_to_find = asn1_find_node (node, name_element); ++ ++ if (node_to_find == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ *start = node_to_find->start; ++ *end = node_to_find->end; ++ ++ if (*start == 0 && *end == 0) ++ { ++ if (ider == NULL || ider_len == 0) ++ return ASN1_GENERIC_ERROR; ++ ++ /* it seems asn1_der_decoding() wasn't called before. Do it now */ ++ result = asn1_der_decoding (&node, ider, ider_len, NULL); ++ if (result != ASN1_SUCCESS) ++ { ++ warn(); ++ return result; ++ } ++ ++ node_to_find = asn1_find_node (node, name_element); ++ if (node_to_find == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ *start = node_to_find->start; ++ *end = node_to_find->end; ++ } ++ ++ if (*end < *start) ++ return ASN1_GENERIC_ERROR; ++ ++ return ASN1_SUCCESS; ++} ++ ++/** ++ * asn1_expand_any_defined_by: ++ * @definitions: ASN1 definitions ++ * @element: pointer to an ASN1 structure ++ * ++ * Expands every "ANY DEFINED BY" element of a structure created from ++ * a DER decoding process (asn1_der_decoding function). The element ++ * ANY must be defined by an OBJECT IDENTIFIER. The type used to ++ * expand the element ANY is the first one following the definition of ++ * the actual value of the OBJECT IDENTIFIER. ++ * ++ * Returns: %ASN1_SUCCESS if Substitution OK, %ASN1_ERROR_TYPE_ANY if ++ * some "ANY DEFINED BY" element couldn't be expanded due to a ++ * problem in OBJECT_ID -> TYPE association, or other error codes ++ * depending on DER decoding. ++ **/ ++int ++asn1_expand_any_defined_by (asn1_node_const definitions, asn1_node * element) ++{ ++ char name[2 * ASN1_MAX_NAME_SIZE + 2], ++ value[ASN1_MAX_NAME_SIZE]; ++ int retCode = ASN1_SUCCESS, result; ++ int len, len2, len3; ++ asn1_node_const p2; ++ asn1_node p, p3, aux = NULL; ++ char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; ++ const char *definitionsName; ++ ++ if ((definitions == NULL) || (*element == NULL)) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ definitionsName = definitions->name; ++ ++ p = *element; ++ while (p) ++ { ++ ++ switch (type_field (p->type)) ++ { ++ case ASN1_ETYPE_ANY: ++ if ((p->type & CONST_DEFINED_BY) && (p->value)) ++ { ++ /* search the "DEF_BY" element */ ++ p2 = p->down; ++ while ((p2) && (type_field (p2->type) != ASN1_ETYPE_CONSTANT)) ++ p2 = p2->right; ++ ++ if (!p2) ++ { ++ retCode = ASN1_ERROR_TYPE_ANY; ++ break; ++ } ++ ++ p3 = _asn1_find_up (p); ++ ++ if (!p3) ++ { ++ retCode = ASN1_ERROR_TYPE_ANY; ++ break; ++ } ++ ++ p3 = p3->down; ++ while (p3) ++ { ++ if (!(strcmp (p3->name, p2->name))) ++ break; ++ p3 = p3->right; ++ } ++ ++ if ((!p3) || (type_field (p3->type) != ASN1_ETYPE_OBJECT_ID) || ++ (p3->value == NULL)) ++ { ++ ++ p3 = _asn1_find_up (p); ++ p3 = _asn1_find_up (p3); ++ ++ if (!p3) ++ { ++ retCode = ASN1_ERROR_TYPE_ANY; ++ break; ++ } ++ ++ p3 = p3->down; ++ ++ while (p3) ++ { ++ if (!(strcmp (p3->name, p2->name))) ++ break; ++ p3 = p3->right; ++ } ++ ++ if ((!p3) || (type_field (p3->type) != ASN1_ETYPE_OBJECT_ID) ++ || (p3->value == NULL)) ++ { ++ retCode = ASN1_ERROR_TYPE_ANY; ++ break; ++ } ++ } ++ ++ /* search the OBJECT_ID into definitions */ ++ p2 = definitions->down; ++ while (p2) ++ { ++ if ((type_field (p2->type) == ASN1_ETYPE_OBJECT_ID) && ++ (p2->type & CONST_ASSIGN)) ++ { ++ snprintf(name, sizeof(name), "%s.%s", definitionsName, p2->name); ++ ++ len = ASN1_MAX_NAME_SIZE; ++ result = ++ asn1_read_value (definitions, name, value, &len); ++ ++ if ((result == ASN1_SUCCESS) ++ && (!_asn1_strcmp (p3->value, value))) ++ { ++ p2 = p2->right; /* pointer to the structure to ++ use for expansion */ ++ while ((p2) && (p2->type & CONST_ASSIGN)) ++ p2 = p2->right; ++ ++ if (p2) ++ { ++ snprintf(name, sizeof(name), "%s.%s", definitionsName, p2->name); ++ ++ result = ++ asn1_create_element (definitions, name, &aux); ++ if (result == ASN1_SUCCESS) ++ { ++ _asn1_cpy_name (aux, p); ++ len2 = ++ asn1_get_length_der (p->value, ++ p->value_len, &len3); ++ if (len2 < 0) ++ return ASN1_DER_ERROR; ++ ++ result = ++ asn1_der_decoding (&aux, p->value + len3, ++ len2, ++ errorDescription); ++ if (result == ASN1_SUCCESS) ++ { ++ ++ _asn1_set_right (aux, p->right); ++ _asn1_set_right (p, aux); ++ ++ result = asn1_delete_structure (&p); ++ if (result == ASN1_SUCCESS) ++ { ++ p = aux; ++ aux = NULL; ++ break; ++ } ++ else ++ { /* error with asn1_delete_structure */ ++ asn1_delete_structure (&aux); ++ retCode = result; ++ break; ++ } ++ } ++ else ++ { /* error with asn1_der_decoding */ ++ retCode = result; ++ break; ++ } ++ } ++ else ++ { /* error with asn1_create_element */ ++ retCode = result; ++ break; ++ } ++ } ++ else ++ { /* error with the pointer to the structure to exapand */ ++ retCode = ASN1_ERROR_TYPE_ANY; ++ break; ++ } ++ } ++ } ++ p2 = p2->right; ++ } /* end while */ ++ ++ if (!p2) ++ { ++ retCode = ASN1_ERROR_TYPE_ANY; ++ break; ++ } ++ ++ } ++ break; ++ default: ++ break; ++ } ++ ++ ++ if (p->down) ++ { ++ p = p->down; ++ } ++ else if (p == *element) ++ { ++ p = NULL; ++ break; ++ } ++ else if (p->right) ++ p = p->right; ++ else ++ { ++ while (1) ++ { ++ p = _asn1_find_up (p); ++ if (p == *element) ++ { ++ p = NULL; ++ break; ++ } ++ if (p->right) ++ { ++ p = p->right; ++ break; ++ } ++ } ++ } ++ } ++ ++ return retCode; ++} ++ ++/** ++ * asn1_expand_octet_string: ++ * @definitions: ASN1 definitions ++ * @element: pointer to an ASN1 structure ++ * @octetName: name of the OCTECT STRING field to expand. ++ * @objectName: name of the OBJECT IDENTIFIER field to use to define ++ * the type for expansion. ++ * ++ * Expands an "OCTET STRING" element of a structure created from a DER ++ * decoding process (the asn1_der_decoding() function). The type used ++ * for expansion is the first one following the definition of the ++ * actual value of the OBJECT IDENTIFIER indicated by OBJECTNAME. ++ * ++ * Returns: %ASN1_SUCCESS if substitution OK, %ASN1_ELEMENT_NOT_FOUND ++ * if @objectName or @octetName are not correct, ++ * %ASN1_VALUE_NOT_VALID if it wasn't possible to find the type to ++ * use for expansion, or other errors depending on DER decoding. ++ **/ ++int ++asn1_expand_octet_string (asn1_node_const definitions, asn1_node * element, ++ const char *octetName, const char *objectName) ++{ ++ char name[2 * ASN1_MAX_NAME_SIZE + 1], value[ASN1_MAX_NAME_SIZE]; ++ int retCode = ASN1_SUCCESS, result; ++ int len, len2, len3; ++ asn1_node_const p2; ++ asn1_node aux = NULL; ++ asn1_node octetNode = NULL, objectNode = NULL; ++ char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; ++ ++ if ((definitions == NULL) || (*element == NULL)) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ octetNode = asn1_find_node (*element, octetName); ++ if (octetNode == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ if (type_field (octetNode->type) != ASN1_ETYPE_OCTET_STRING) ++ return ASN1_ELEMENT_NOT_FOUND; ++ if (octetNode->value == NULL) ++ return ASN1_VALUE_NOT_FOUND; ++ ++ objectNode = asn1_find_node (*element, objectName); ++ if (objectNode == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ if (type_field (objectNode->type) != ASN1_ETYPE_OBJECT_ID) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ if (objectNode->value == NULL) ++ return ASN1_VALUE_NOT_FOUND; ++ ++ ++ /* search the OBJECT_ID into definitions */ ++ p2 = definitions->down; ++ while (p2) ++ { ++ if ((type_field (p2->type) == ASN1_ETYPE_OBJECT_ID) && ++ (p2->type & CONST_ASSIGN)) ++ { ++ strcpy (name, definitions->name); ++ strcat (name, "."); ++ strcat (name, p2->name); ++ ++ len = sizeof (value); ++ result = asn1_read_value (definitions, name, value, &len); ++ ++ if ((result == ASN1_SUCCESS) ++ && (!_asn1_strcmp (objectNode->value, value))) ++ { ++ ++ p2 = p2->right; /* pointer to the structure to ++ use for expansion */ ++ while ((p2) && (p2->type & CONST_ASSIGN)) ++ p2 = p2->right; ++ ++ if (p2) ++ { ++ strcpy (name, definitions->name); ++ strcat (name, "."); ++ strcat (name, p2->name); ++ ++ result = asn1_create_element (definitions, name, &aux); ++ if (result == ASN1_SUCCESS) ++ { ++ _asn1_cpy_name (aux, octetNode); ++ len2 = ++ asn1_get_length_der (octetNode->value, ++ octetNode->value_len, &len3); ++ if (len2 < 0) ++ return ASN1_DER_ERROR; ++ ++ result = ++ asn1_der_decoding (&aux, octetNode->value + len3, ++ len2, errorDescription); ++ if (result == ASN1_SUCCESS) ++ { ++ ++ _asn1_set_right (aux, octetNode->right); ++ _asn1_set_right (octetNode, aux); ++ ++ result = asn1_delete_structure (&octetNode); ++ if (result == ASN1_SUCCESS) ++ { ++ aux = NULL; ++ break; ++ } ++ else ++ { /* error with asn1_delete_structure */ ++ asn1_delete_structure (&aux); ++ retCode = result; ++ break; ++ } ++ } ++ else ++ { /* error with asn1_der_decoding */ ++ retCode = result; ++ break; ++ } ++ } ++ else ++ { /* error with asn1_create_element */ ++ retCode = result; ++ break; ++ } ++ } ++ else ++ { /* error with the pointer to the structure to exapand */ ++ retCode = ASN1_VALUE_NOT_VALID; ++ break; ++ } ++ } ++ } ++ ++ p2 = p2->right; ++ ++ } ++ ++ if (!p2) ++ retCode = ASN1_VALUE_NOT_VALID; ++ ++ return retCode; ++} ++ ++/*- ++ * _asn1_decode_simple_der: ++ * @etype: The type of the string to be encoded (ASN1_ETYPE_) ++ * @der: the encoded string ++ * @_der_len: the bytes of the encoded string ++ * @str: a pointer to the data ++ * @str_len: the length of the data ++ * @dflags: DECODE_FLAG_* ++ * ++ * Decodes a simple DER encoded type (e.g. a string, which is not constructed). ++ * The output is a pointer inside the @der. ++ * ++ * Returns: %ASN1_SUCCESS if successful or an error value. ++ -*/ ++static int ++_asn1_decode_simple_der (unsigned int etype, const unsigned char *der, ++ unsigned int _der_len, const unsigned char **str, ++ unsigned int *str_len, unsigned dflags) ++{ ++ int tag_len, len_len; ++ const unsigned char *p; ++ int der_len = _der_len; ++ unsigned char class; ++ unsigned long tag; ++ long ret; ++ ++ if (der == NULL || der_len == 0) ++ return ASN1_VALUE_NOT_VALID; ++ ++ if (ETYPE_OK (etype) == 0 || ETYPE_IS_STRING(etype) == 0) ++ return ASN1_VALUE_NOT_VALID; ++ ++ /* doesn't handle constructed classes */ ++ class = ETYPE_CLASS(etype); ++ if (class != ASN1_CLASS_UNIVERSAL) ++ return ASN1_VALUE_NOT_VALID; ++ ++ p = der; ++ ++ if (dflags & DECODE_FLAG_HAVE_TAG) ++ { ++ ret = asn1_get_tag_der (p, der_len, &class, &tag_len, &tag); ++ if (ret != ASN1_SUCCESS) ++ return ret; ++ ++ if (class != ETYPE_CLASS (etype) || tag != ETYPE_TAG (etype)) ++ { ++ warn(); ++ return ASN1_DER_ERROR; ++ } ++ ++ p += tag_len; ++ der_len -= tag_len; ++ if (der_len <= 0) ++ return ASN1_DER_ERROR; ++ } ++ ++ ret = asn1_get_length_der (p, der_len, &len_len); ++ if (ret < 0) ++ return ASN1_DER_ERROR; ++ ++ p += len_len; ++ der_len -= len_len; ++ if (der_len <= 0) ++ return ASN1_DER_ERROR; ++ ++ *str_len = ret; ++ *str = p; ++ ++ return ASN1_SUCCESS; ++} ++ ++/** ++ * asn1_decode_simple_der: ++ * @etype: The type of the string to be encoded (ASN1_ETYPE_) ++ * @der: the encoded string ++ * @_der_len: the bytes of the encoded string ++ * @str: a pointer to the data ++ * @str_len: the length of the data ++ * ++ * Decodes a simple DER encoded type (e.g. a string, which is not constructed). ++ * The output is a pointer inside the @der. ++ * ++ * Returns: %ASN1_SUCCESS if successful or an error value. ++ **/ ++int ++asn1_decode_simple_der (unsigned int etype, const unsigned char *der, ++ unsigned int _der_len, const unsigned char **str, ++ unsigned int *str_len) ++{ ++ return _asn1_decode_simple_der(etype, der, _der_len, str, str_len, DECODE_FLAG_HAVE_TAG); ++} ++ ++static int append(uint8_t **dst, unsigned *dst_size, const unsigned char *src, unsigned src_size) ++{ ++ if (src_size == 0) ++ return ASN1_SUCCESS; ++ ++ *dst = _asn1_realloc(*dst, *dst_size+src_size); ++ if (*dst == NULL) ++ return ASN1_MEM_ALLOC_ERROR; ++ memcpy(*dst + *dst_size, src, src_size); ++ *dst_size += src_size; ++ return ASN1_SUCCESS; ++} ++ ++/*- ++ * _asn1_decode_simple_ber: ++ * @etype: The type of the string to be encoded (ASN1_ETYPE_) ++ * @der: the encoded string ++ * @_der_len: the bytes of the encoded string ++ * @str: a pointer to the data ++ * @str_len: the length of the data ++ * @ber_len: the total length occupied by BER (may be %NULL) ++ * @have_tag: whether a DER tag is included ++ * ++ * Decodes a BER encoded type. The output is an allocated value ++ * of the data. This decodes BER STRINGS only. Other types are ++ * decoded as DER. ++ * ++ * Returns: %ASN1_SUCCESS if successful or an error value. ++ -*/ ++static int ++_asn1_decode_simple_ber (unsigned int etype, const unsigned char *der, ++ unsigned int _der_len, unsigned char **str, ++ unsigned int *str_len, unsigned int *ber_len, ++ unsigned dflags) ++{ ++ int tag_len, len_len; ++ const unsigned char *p; ++ int der_len = _der_len; ++ uint8_t *total = NULL; ++ unsigned total_size = 0; ++ unsigned char class; ++ unsigned long tag; ++ unsigned char *out = NULL; ++ const unsigned char *cout = NULL; ++ unsigned out_len; ++ long result; ++ ++ if (ber_len) *ber_len = 0; ++ ++ if (der == NULL || der_len == 0) ++ { ++ warn(); ++ return ASN1_VALUE_NOT_VALID; ++ } ++ ++ if (ETYPE_OK (etype) == 0) ++ { ++ warn(); ++ return ASN1_VALUE_NOT_VALID; ++ } ++ ++ /* doesn't handle constructed + definite classes */ ++ class = ETYPE_CLASS (etype); ++ if (class != ASN1_CLASS_UNIVERSAL) ++ { ++ warn(); ++ return ASN1_VALUE_NOT_VALID; ++ } ++ ++ p = der; ++ ++ if (dflags & DECODE_FLAG_HAVE_TAG) ++ { ++ result = asn1_get_tag_der (p, der_len, &class, &tag_len, &tag); ++ if (result != ASN1_SUCCESS) ++ { ++ warn(); ++ return result; ++ } ++ ++ if (tag != ETYPE_TAG (etype)) ++ { ++ warn(); ++ return ASN1_DER_ERROR; ++ } ++ ++ p += tag_len; ++ ++ DECR_LEN(der_len, tag_len); ++ ++ if (ber_len) *ber_len += tag_len; ++ } ++ ++ /* indefinite constructed */ ++ if ((((dflags & DECODE_FLAG_CONSTRUCTED) || class == ASN1_CLASS_STRUCTURED) && ETYPE_IS_STRING(etype)) && ++ !(dflags & DECODE_FLAG_LEVEL3)) ++ { ++ if (der_len == 0) ++ { ++ warn(); ++ result = ASN1_DER_ERROR; ++ goto cleanup; ++ } ++ ++ if (der_len > 0 && p[0] == 0x80) /* indefinite */ ++ { ++ len_len = 1; ++ DECR_LEN(der_len, len_len); ++ p += len_len; ++ ++ if (ber_len) *ber_len += len_len; ++ ++ /* decode the available octet strings */ ++ do ++ { ++ unsigned tmp_len; ++ unsigned flags = DECODE_FLAG_HAVE_TAG; ++ ++ if (dflags & DECODE_FLAG_LEVEL1) ++ flags |= DECODE_FLAG_LEVEL2; ++ else if (dflags & DECODE_FLAG_LEVEL2) ++ flags |= DECODE_FLAG_LEVEL3; ++ else ++ flags |= DECODE_FLAG_LEVEL1; ++ ++ result = _asn1_decode_simple_ber(etype, p, der_len, &out, &out_len, &tmp_len, ++ flags); ++ if (result != ASN1_SUCCESS) ++ { ++ warn(); ++ goto cleanup; ++ } ++ ++ p += tmp_len; ++ DECR_LEN(der_len, tmp_len); ++ ++ if (ber_len) *ber_len += tmp_len; ++ ++ DECR_LEN(der_len, 2); /* we need the EOC */ ++ ++ result = append(&total, &total_size, out, out_len); ++ if (result != ASN1_SUCCESS) ++ { ++ warn(); ++ goto cleanup; ++ } ++ ++ free(out); ++ out = NULL; ++ ++ if (p[0] == 0 && p[1] == 0) /* EOC */ ++ { ++ if (ber_len) *ber_len += 2; ++ break; ++ } ++ ++ /* no EOC */ ++ der_len += 2; ++ ++ if (der_len == 2) ++ { ++ warn(); ++ result = ASN1_DER_ERROR; ++ goto cleanup; ++ } ++ } ++ while(1); ++ } ++ else /* constructed */ ++ { ++ long const_len; ++ ++ result = asn1_get_length_ber(p, der_len, &len_len); ++ if (result < 0) ++ { ++ warn(); ++ result = ASN1_DER_ERROR; ++ goto cleanup; ++ } ++ ++ DECR_LEN(der_len, len_len); ++ p += len_len; ++ ++ const_len = result; ++ ++ if (ber_len) *ber_len += len_len; ++ ++ /* decode the available octet strings */ ++ while(const_len > 0) ++ { ++ unsigned tmp_len; ++ unsigned flags = DECODE_FLAG_HAVE_TAG; ++ ++ if (dflags & DECODE_FLAG_LEVEL1) ++ flags |= DECODE_FLAG_LEVEL2; ++ else if (dflags & DECODE_FLAG_LEVEL2) ++ flags |= DECODE_FLAG_LEVEL3; ++ else ++ flags |= DECODE_FLAG_LEVEL1; ++ ++ result = _asn1_decode_simple_ber(etype, p, der_len, &out, &out_len, &tmp_len, ++ flags); ++ if (result != ASN1_SUCCESS) ++ { ++ warn(); ++ goto cleanup; ++ } ++ ++ p += tmp_len; ++ DECR_LEN(der_len, tmp_len); ++ DECR_LEN(const_len, tmp_len); ++ ++ if (ber_len) *ber_len += tmp_len; ++ ++ result = append(&total, &total_size, out, out_len); ++ if (result != ASN1_SUCCESS) ++ { ++ warn(); ++ goto cleanup; ++ } ++ ++ free(out); ++ out = NULL; ++ } ++ } ++ } ++ else if (class == ETYPE_CLASS(etype)) ++ { ++ if (ber_len) ++ { ++ result = asn1_get_length_der (p, der_len, &len_len); ++ if (result < 0) ++ { ++ warn(); ++ result = ASN1_DER_ERROR; ++ goto cleanup; ++ } ++ *ber_len += result + len_len; ++ } ++ ++ /* non-string values are decoded as DER */ ++ result = _asn1_decode_simple_der(etype, der, _der_len, &cout, &out_len, dflags); ++ if (result != ASN1_SUCCESS) ++ { ++ warn(); ++ goto cleanup; ++ } ++ ++ result = append(&total, &total_size, cout, out_len); ++ if (result != ASN1_SUCCESS) ++ { ++ warn(); ++ goto cleanup; ++ } ++ } ++ else ++ { ++ warn(); ++ result = ASN1_DER_ERROR; ++ goto cleanup; ++ } ++ ++ *str = total; ++ *str_len = total_size; ++ ++ return ASN1_SUCCESS; ++cleanup: ++ free(out); ++ free(total); ++ return result; ++} ++ ++/** ++ * asn1_decode_simple_ber: ++ * @etype: The type of the string to be encoded (ASN1_ETYPE_) ++ * @der: the encoded string ++ * @_der_len: the bytes of the encoded string ++ * @str: a pointer to the data ++ * @str_len: the length of the data ++ * @ber_len: the total length occupied by BER (may be %NULL) ++ * ++ * Decodes a BER encoded type. The output is an allocated value ++ * of the data. This decodes BER STRINGS only. Other types are ++ * decoded as DER. ++ * ++ * Returns: %ASN1_SUCCESS if successful or an error value. ++ **/ ++int ++asn1_decode_simple_ber (unsigned int etype, const unsigned char *der, ++ unsigned int _der_len, unsigned char **str, ++ unsigned int *str_len, unsigned int *ber_len) ++{ ++ return _asn1_decode_simple_ber(etype, der, _der_len, str, str_len, ber_len, DECODE_FLAG_HAVE_TAG); ++} +diff --git a/grub-core/lib/libtasn1/lib/element.c b/grub-core/lib/libtasn1/lib/element.c +new file mode 100644 +index 00000000000..997eb2725dc +--- /dev/null ++++ b/grub-core/lib/libtasn1/lib/element.c +@@ -0,0 +1,1111 @@ ++/* ++ * Copyright (C) 2000-2014 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * The LIBTASN1 library is free software; you can redistribute it ++ * and/or modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ++ * 02110-1301, USA ++ */ ++ ++/*****************************************************/ ++/* File: element.c */ ++/* Description: Functions with the read and write */ ++/* functions. */ ++/*****************************************************/ ++ ++ ++#include ++#include "parser_aux.h" ++#include ++#include "structure.h" ++#include "c-ctype.h" ++#include "element.h" ++ ++void ++_asn1_hierarchical_name (asn1_node_const node, char *name, int name_size) ++{ ++ asn1_node_const p; ++ char tmp_name[64]; ++ ++ p = node; ++ ++ name[0] = 0; ++ ++ while (p != NULL) ++ { ++ if (p->name[0] != 0) ++ { ++ _asn1_str_cpy (tmp_name, sizeof (tmp_name), name), ++ _asn1_str_cpy (name, name_size, p->name); ++ _asn1_str_cat (name, name_size, "."); ++ _asn1_str_cat (name, name_size, tmp_name); ++ } ++ p = _asn1_find_up (p); ++ } ++ ++ if (name[0] == 0) ++ _asn1_str_cpy (name, name_size, "ROOT"); ++} ++ ++ ++/******************************************************************/ ++/* Function : _asn1_convert_integer */ ++/* Description: converts an integer from a null terminated string */ ++/* to der decoding. The convertion from a null */ ++/* terminated string to an integer is made with */ ++/* the 'strtol' function. */ ++/* Parameters: */ ++/* value: null terminated string to convert. */ ++/* value_out: convertion result (memory must be already */ ++/* allocated). */ ++/* value_out_size: number of bytes of value_out. */ ++/* len: number of significant byte of value_out. */ ++/* Return: ASN1_MEM_ERROR or ASN1_SUCCESS */ ++/******************************************************************/ ++int ++_asn1_convert_integer (const unsigned char *value, unsigned char *value_out, ++ int value_out_size, int *len) ++{ ++ char negative; ++ unsigned char val[SIZEOF_UNSIGNED_LONG_INT]; ++ long valtmp; ++ int k, k2; ++ ++ valtmp = _asn1_strtol (value, NULL, 10); ++ ++ for (k = 0; k < SIZEOF_UNSIGNED_LONG_INT; k++) ++ { ++ val[SIZEOF_UNSIGNED_LONG_INT - k - 1] = (valtmp >> (8 * k)) & 0xFF; ++ } ++ ++ if (val[0] & 0x80) ++ negative = 1; ++ else ++ negative = 0; ++ ++ for (k = 0; k < SIZEOF_UNSIGNED_LONG_INT - 1; k++) ++ { ++ if (negative && (val[k] != 0xFF)) ++ break; ++ else if (!negative && val[k]) ++ break; ++ } ++ ++ if ((negative && !(val[k] & 0x80)) || (!negative && (val[k] & 0x80))) ++ k--; ++ ++ *len = SIZEOF_UNSIGNED_LONG_INT - k; ++ ++ if (SIZEOF_UNSIGNED_LONG_INT - k > value_out_size) ++ /* VALUE_OUT is too short to contain the value conversion */ ++ return ASN1_MEM_ERROR; ++ ++ if (value_out != NULL) ++ { ++ for (k2 = k; k2 < SIZEOF_UNSIGNED_LONG_INT; k2++) ++ value_out[k2 - k] = val[k2]; ++ } ++ ++#if 0 ++ printf ("_asn1_convert_integer: valueIn=%s, lenOut=%d", value, *len); ++ for (k = 0; k < SIZEOF_UNSIGNED_LONG_INT; k++) ++ printf (", vOut[%d]=%d", k, value_out[k]); ++ printf ("\n"); ++#endif ++ ++ return ASN1_SUCCESS; ++} ++ ++/* Appends a new element into the sequence (or set) defined by this ++ * node. The new element will have a name of '?number', where number ++ * is a monotonically increased serial number. ++ * ++ * The last element in the list may be provided in @pcache, to avoid ++ * traversing the list, an expensive operation in long lists. ++ * ++ * On success it returns in @pcache the added element (which is the ++ * tail in the list of added elements). ++ */ ++int ++_asn1_append_sequence_set (asn1_node node, struct node_tail_cache_st *pcache) ++{ ++ asn1_node p, p2; ++ char temp[LTOSTR_MAX_SIZE]; ++ long n; ++ ++ if (!node || !(node->down)) ++ return ASN1_GENERIC_ERROR; ++ ++ p = node->down; ++ while ((type_field (p->type) == ASN1_ETYPE_TAG) ++ || (type_field (p->type) == ASN1_ETYPE_SIZE)) ++ p = p->right; ++ ++ p2 = _asn1_copy_structure3 (p); ++ if (p2 == NULL) ++ return ASN1_GENERIC_ERROR; ++ ++ if (pcache == NULL || pcache->tail == NULL || pcache->head != node) ++ { ++ while (p->right) ++ { ++ p = p->right; ++ } ++ } ++ else ++ { ++ p = pcache->tail; ++ } ++ ++ _asn1_set_right (p, p2); ++ if (pcache) ++ { ++ pcache->head = node; ++ pcache->tail = p2; ++ } ++ ++ if (p->name[0] == 0) ++ _asn1_str_cpy (temp, sizeof (temp), "?1"); ++ else ++ { ++ n = strtol (p->name + 1, NULL, 0); ++ n++; ++ temp[0] = '?'; ++ _asn1_ltostr (n, temp + 1); ++ } ++ _asn1_set_name (p2, temp); ++ /* p2->type |= CONST_OPTION; */ ++ ++ return ASN1_SUCCESS; ++} ++ ++ ++/** ++ * asn1_write_value: ++ * @node_root: pointer to a structure ++ * @name: the name of the element inside the structure that you want to set. ++ * @ivalue: vector used to specify the value to set. If len is >0, ++ * VALUE must be a two's complement form integer. if len=0 *VALUE ++ * must be a null terminated string with an integer value. ++ * @len: number of bytes of *value to use to set the value: ++ * value[0]..value[len-1] or 0 if value is a null terminated string ++ * ++ * Set the value of one element inside a structure. ++ * ++ * If an element is OPTIONAL and you want to delete it, you must use ++ * the value=NULL and len=0. Using "pkix.asn": ++ * ++ * result=asn1_write_value(cert, "tbsCertificate.issuerUniqueID", ++ * NULL, 0); ++ * ++ * Description for each type: ++ * ++ * INTEGER: VALUE must contain a two's complement form integer. ++ * ++ * value[0]=0xFF , len=1 -> integer=-1. ++ * value[0]=0xFF value[1]=0xFF , len=2 -> integer=-1. ++ * value[0]=0x01 , len=1 -> integer= 1. ++ * value[0]=0x00 value[1]=0x01 , len=2 -> integer= 1. ++ * value="123" , len=0 -> integer= 123. ++ * ++ * ENUMERATED: As INTEGER (but only with not negative numbers). ++ * ++ * BOOLEAN: VALUE must be the null terminated string "TRUE" or ++ * "FALSE" and LEN != 0. ++ * ++ * value="TRUE" , len=1 -> boolean=TRUE. ++ * value="FALSE" , len=1 -> boolean=FALSE. ++ * ++ * OBJECT IDENTIFIER: VALUE must be a null terminated string with ++ * each number separated by a dot (e.g. "1.2.3.543.1"). LEN != 0. ++ * ++ * value="1 2 840 10040 4 3" , len=1 -> OID=dsa-with-sha. ++ * ++ * UTCTime: VALUE must be a null terminated string in one of these ++ * formats: "YYMMDDhhmmssZ", "YYMMDDhhmmssZ", ++ * "YYMMDDhhmmss+hh'mm'", "YYMMDDhhmmss-hh'mm'", ++ * "YYMMDDhhmm+hh'mm'", or "YYMMDDhhmm-hh'mm'". LEN != 0. ++ * ++ * value="9801011200Z" , len=1 -> time=Jannuary 1st, 1998 ++ * at 12h 00m Greenwich Mean Time ++ * ++ * GeneralizedTime: VALUE must be in one of this format: ++ * "YYYYMMDDhhmmss.sZ", "YYYYMMDDhhmmss.sZ", ++ * "YYYYMMDDhhmmss.s+hh'mm'", "YYYYMMDDhhmmss.s-hh'mm'", ++ * "YYYYMMDDhhmm+hh'mm'", or "YYYYMMDDhhmm-hh'mm'" where ss.s ++ * indicates the seconds with any precision like "10.1" or "01.02". ++ * LEN != 0 ++ * ++ * value="2001010112001.12-0700" , len=1 -> time=Jannuary ++ * 1st, 2001 at 12h 00m 01.12s Pacific Daylight Time ++ * ++ * OCTET STRING: VALUE contains the octet string and LEN is the ++ * number of octets. ++ * ++ * value="$\backslash$x01$\backslash$x02$\backslash$x03" , ++ * len=3 -> three bytes octet string ++ * ++ * GeneralString: VALUE contains the generalstring and LEN is the ++ * number of octets. ++ * ++ * value="$\backslash$x01$\backslash$x02$\backslash$x03" , ++ * len=3 -> three bytes generalstring ++ * ++ * BIT STRING: VALUE contains the bit string organized by bytes and ++ * LEN is the number of bits. ++ * ++ * value="$\backslash$xCF" , len=6 -> bit string="110011" (six ++ * bits) ++ * ++ * CHOICE: if NAME indicates a choice type, VALUE must specify one of ++ * the alternatives with a null terminated string. LEN != 0. Using ++ * "pkix.asn"\: ++ * ++ * result=asn1_write_value(cert, ++ * "certificate1.tbsCertificate.subject", "rdnSequence", ++ * 1); ++ * ++ * ANY: VALUE indicates the der encoding of a structure. LEN != 0. ++ * ++ * SEQUENCE OF: VALUE must be the null terminated string "NEW" and ++ * LEN != 0. With this instruction another element is appended in ++ * the sequence. The name of this element will be "?1" if it's the ++ * first one, "?2" for the second and so on. ++ * ++ * Using "pkix.asn"\: ++ * ++ * result=asn1_write_value(cert, ++ * "certificate1.tbsCertificate.subject.rdnSequence", "NEW", 1); ++ * ++ * SET OF: the same as SEQUENCE OF. Using "pkix.asn": ++ * ++ * result=asn1_write_value(cert, ++ * "tbsCertificate.subject.rdnSequence.?LAST", "NEW", 1); ++ * ++ * Returns: %ASN1_SUCCESS if the value was set, ++ * %ASN1_ELEMENT_NOT_FOUND if @name is not a valid element, and ++ * %ASN1_VALUE_NOT_VALID if @ivalue has a wrong format. ++ **/ ++int ++asn1_write_value (asn1_node node_root, const char *name, ++ const void *ivalue, int len) ++{ ++ asn1_node node, p, p2; ++ unsigned char *temp, *value_temp = NULL, *default_temp = NULL; ++ int len2, k, k2, negative; ++ size_t i; ++ const unsigned char *value = ivalue; ++ unsigned int type; ++ ++ node = asn1_find_node (node_root, name); ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ if ((node->type & CONST_OPTION) && (value == NULL) && (len == 0)) ++ { ++ asn1_delete_structure (&node); ++ return ASN1_SUCCESS; ++ } ++ ++ type = type_field (node->type); ++ ++ if ((type == ASN1_ETYPE_SEQUENCE_OF || type == ASN1_ETYPE_SET_OF) && (value == NULL) && (len == 0)) ++ { ++ p = node->down; ++ while ((type_field (p->type) == ASN1_ETYPE_TAG) ++ || (type_field (p->type) == ASN1_ETYPE_SIZE)) ++ p = p->right; ++ ++ while (p->right) ++ asn1_delete_structure (&p->right); ++ ++ return ASN1_SUCCESS; ++ } ++ ++ /* Don't allow element deletion for other types */ ++ if (value == NULL) ++ { ++ return ASN1_VALUE_NOT_VALID; ++ } ++ ++ switch (type) ++ { ++ case ASN1_ETYPE_BOOLEAN: ++ if (!_asn1_strcmp (value, "TRUE")) ++ { ++ if (node->type & CONST_DEFAULT) ++ { ++ p = node->down; ++ while (type_field (p->type) != ASN1_ETYPE_DEFAULT) ++ p = p->right; ++ if (p->type & CONST_TRUE) ++ _asn1_set_value (node, NULL, 0); ++ else ++ _asn1_set_value (node, "T", 1); ++ } ++ else ++ _asn1_set_value (node, "T", 1); ++ } ++ else if (!_asn1_strcmp (value, "FALSE")) ++ { ++ if (node->type & CONST_DEFAULT) ++ { ++ p = node->down; ++ while (type_field (p->type) != ASN1_ETYPE_DEFAULT) ++ p = p->right; ++ if (p->type & CONST_FALSE) ++ _asn1_set_value (node, NULL, 0); ++ else ++ _asn1_set_value (node, "F", 1); ++ } ++ else ++ _asn1_set_value (node, "F", 1); ++ } ++ else ++ return ASN1_VALUE_NOT_VALID; ++ break; ++ case ASN1_ETYPE_INTEGER: ++ case ASN1_ETYPE_ENUMERATED: ++ if (len == 0) ++ { ++ if ((c_isdigit (value[0])) || (value[0] == '-')) ++ { ++ value_temp = malloc (SIZEOF_UNSIGNED_LONG_INT); ++ if (value_temp == NULL) ++ return ASN1_MEM_ALLOC_ERROR; ++ ++ _asn1_convert_integer (value, value_temp, ++ SIZEOF_UNSIGNED_LONG_INT, &len); ++ } ++ else ++ { /* is an identifier like v1 */ ++ if (!(node->type & CONST_LIST)) ++ return ASN1_VALUE_NOT_VALID; ++ p = node->down; ++ while (p) ++ { ++ if (type_field (p->type) == ASN1_ETYPE_CONSTANT) ++ { ++ if (!_asn1_strcmp (p->name, value)) ++ { ++ value_temp = malloc (SIZEOF_UNSIGNED_LONG_INT); ++ if (value_temp == NULL) ++ return ASN1_MEM_ALLOC_ERROR; ++ ++ _asn1_convert_integer (p->value, ++ value_temp, ++ SIZEOF_UNSIGNED_LONG_INT, ++ &len); ++ break; ++ } ++ } ++ p = p->right; ++ } ++ if (p == NULL) ++ return ASN1_VALUE_NOT_VALID; ++ } ++ } ++ else ++ { /* len != 0 */ ++ value_temp = malloc (len); ++ if (value_temp == NULL) ++ return ASN1_MEM_ALLOC_ERROR; ++ memcpy (value_temp, value, len); ++ } ++ ++ if (value_temp[0] & 0x80) ++ negative = 1; ++ else ++ negative = 0; ++ ++ if (negative && (type_field (node->type) == ASN1_ETYPE_ENUMERATED)) ++ { ++ free (value_temp); ++ return ASN1_VALUE_NOT_VALID; ++ } ++ ++ for (k = 0; k < len - 1; k++) ++ if (negative && (value_temp[k] != 0xFF)) ++ break; ++ else if (!negative && value_temp[k]) ++ break; ++ ++ if ((negative && !(value_temp[k] & 0x80)) || ++ (!negative && (value_temp[k] & 0x80))) ++ k--; ++ ++ _asn1_set_value_lv (node, value_temp + k, len - k); ++ ++ if (node->type & CONST_DEFAULT) ++ { ++ p = node->down; ++ while (type_field (p->type) != ASN1_ETYPE_DEFAULT) ++ p = p->right; ++ if ((c_isdigit (p->value[0])) || (p->value[0] == '-')) ++ { ++ default_temp = malloc (SIZEOF_UNSIGNED_LONG_INT); ++ if (default_temp == NULL) ++ { ++ free (value_temp); ++ return ASN1_MEM_ALLOC_ERROR; ++ } ++ ++ _asn1_convert_integer (p->value, default_temp, ++ SIZEOF_UNSIGNED_LONG_INT, &len2); ++ } ++ else ++ { /* is an identifier like v1 */ ++ if (!(node->type & CONST_LIST)) ++ { ++ free (value_temp); ++ return ASN1_VALUE_NOT_VALID; ++ } ++ p2 = node->down; ++ while (p2) ++ { ++ if (type_field (p2->type) == ASN1_ETYPE_CONSTANT) ++ { ++ if (!_asn1_strcmp (p2->name, p->value)) ++ { ++ default_temp = malloc (SIZEOF_UNSIGNED_LONG_INT); ++ if (default_temp == NULL) ++ { ++ free (value_temp); ++ return ASN1_MEM_ALLOC_ERROR; ++ } ++ ++ _asn1_convert_integer (p2->value, ++ default_temp, ++ SIZEOF_UNSIGNED_LONG_INT, ++ &len2); ++ break; ++ } ++ } ++ p2 = p2->right; ++ } ++ if (p2 == NULL) ++ { ++ free (value_temp); ++ return ASN1_VALUE_NOT_VALID; ++ } ++ } ++ ++ ++ if ((len - k) == len2) ++ { ++ for (k2 = 0; k2 < len2; k2++) ++ if (value_temp[k + k2] != default_temp[k2]) ++ { ++ break; ++ } ++ if (k2 == len2) ++ _asn1_set_value (node, NULL, 0); ++ } ++ free (default_temp); ++ } ++ free (value_temp); ++ break; ++ case ASN1_ETYPE_OBJECT_ID: ++ for (i = 0; i < _asn1_strlen (value); i++) ++ if ((!c_isdigit (value[i])) && (value[i] != '.') && (value[i] != '+')) ++ return ASN1_VALUE_NOT_VALID; ++ if (node->type & CONST_DEFAULT) ++ { ++ p = node->down; ++ while (type_field (p->type) != ASN1_ETYPE_DEFAULT) ++ p = p->right; ++ if (!_asn1_strcmp (value, p->value)) ++ { ++ _asn1_set_value (node, NULL, 0); ++ break; ++ } ++ } ++ _asn1_set_value (node, value, _asn1_strlen (value) + 1); ++ break; ++ case ASN1_ETYPE_UTC_TIME: ++ { ++ len = _asn1_strlen (value); ++ if (len < 11) ++ return ASN1_VALUE_NOT_VALID; ++ for (k = 0; k < 10; k++) ++ if (!c_isdigit (value[k])) ++ return ASN1_VALUE_NOT_VALID; ++ switch (len) ++ { ++ case 11: ++ if (value[10] != 'Z') ++ return ASN1_VALUE_NOT_VALID; ++ break; ++ case 13: ++ if ((!c_isdigit (value[10])) || (!c_isdigit (value[11])) || ++ (value[12] != 'Z')) ++ return ASN1_VALUE_NOT_VALID; ++ break; ++ case 15: ++ if ((value[10] != '+') && (value[10] != '-')) ++ return ASN1_VALUE_NOT_VALID; ++ for (k = 11; k < 15; k++) ++ if (!c_isdigit (value[k])) ++ return ASN1_VALUE_NOT_VALID; ++ break; ++ case 17: ++ if ((!c_isdigit (value[10])) || (!c_isdigit (value[11]))) ++ return ASN1_VALUE_NOT_VALID; ++ if ((value[12] != '+') && (value[12] != '-')) ++ return ASN1_VALUE_NOT_VALID; ++ for (k = 13; k < 17; k++) ++ if (!c_isdigit (value[k])) ++ return ASN1_VALUE_NOT_VALID; ++ break; ++ default: ++ return ASN1_VALUE_NOT_FOUND; ++ } ++ _asn1_set_value (node, value, len); ++ } ++ break; ++ case ASN1_ETYPE_GENERALIZED_TIME: ++ len = _asn1_strlen (value); ++ _asn1_set_value (node, value, len); ++ break; ++ case ASN1_ETYPE_OCTET_STRING: ++ case ASN1_ETYPE_GENERALSTRING: ++ case ASN1_ETYPE_NUMERIC_STRING: ++ case ASN1_ETYPE_IA5_STRING: ++ case ASN1_ETYPE_TELETEX_STRING: ++ case ASN1_ETYPE_PRINTABLE_STRING: ++ case ASN1_ETYPE_UNIVERSAL_STRING: ++ case ASN1_ETYPE_BMP_STRING: ++ case ASN1_ETYPE_UTF8_STRING: ++ case ASN1_ETYPE_VISIBLE_STRING: ++ if (len == 0) ++ len = _asn1_strlen (value); ++ _asn1_set_value_lv (node, value, len); ++ break; ++ case ASN1_ETYPE_BIT_STRING: ++ if (len == 0) ++ len = _asn1_strlen (value); ++ asn1_length_der ((len >> 3) + 2, NULL, &len2); ++ temp = malloc ((len >> 3) + 2 + len2); ++ if (temp == NULL) ++ return ASN1_MEM_ALLOC_ERROR; ++ ++ asn1_bit_der (value, len, temp, &len2); ++ _asn1_set_value_m (node, temp, len2); ++ temp = NULL; ++ break; ++ case ASN1_ETYPE_CHOICE: ++ p = node->down; ++ while (p) ++ { ++ if (!_asn1_strcmp (p->name, value)) ++ { ++ p2 = node->down; ++ while (p2) ++ { ++ if (p2 != p) ++ { ++ asn1_delete_structure (&p2); ++ p2 = node->down; ++ } ++ else ++ p2 = p2->right; ++ } ++ break; ++ } ++ p = p->right; ++ } ++ if (!p) ++ return ASN1_ELEMENT_NOT_FOUND; ++ break; ++ case ASN1_ETYPE_ANY: ++ _asn1_set_value_lv (node, value, len); ++ break; ++ case ASN1_ETYPE_SEQUENCE_OF: ++ case ASN1_ETYPE_SET_OF: ++ if (_asn1_strcmp (value, "NEW")) ++ return ASN1_VALUE_NOT_VALID; ++ _asn1_append_sequence_set (node, NULL); ++ break; ++ default: ++ return ASN1_ELEMENT_NOT_FOUND; ++ break; ++ } ++ ++ return ASN1_SUCCESS; ++} ++ ++ ++#define PUT_VALUE( ptr, ptr_size, data, data_size) \ ++ *len = data_size; \ ++ if (ptr_size < data_size) { \ ++ return ASN1_MEM_ERROR; \ ++ } else { \ ++ if (ptr && data_size > 0) \ ++ memcpy (ptr, data, data_size); \ ++ } ++ ++#define PUT_STR_VALUE( ptr, ptr_size, data) \ ++ *len = _asn1_strlen (data) + 1; \ ++ if (ptr_size < *len) { \ ++ return ASN1_MEM_ERROR; \ ++ } else { \ ++ /* this strcpy is checked */ \ ++ if (ptr) { \ ++ _asn1_strcpy (ptr, data); \ ++ } \ ++ } ++ ++#define PUT_AS_STR_VALUE( ptr, ptr_size, data, data_size) \ ++ *len = data_size + 1; \ ++ if (ptr_size < *len) { \ ++ return ASN1_MEM_ERROR; \ ++ } else { \ ++ /* this strcpy is checked */ \ ++ if (ptr) { \ ++ if (data_size > 0) \ ++ memcpy (ptr, data, data_size); \ ++ ptr[data_size] = 0; \ ++ } \ ++ } ++ ++#define ADD_STR_VALUE( ptr, ptr_size, data) \ ++ *len += _asn1_strlen(data); \ ++ if (ptr_size < (int) *len) { \ ++ (*len)++; \ ++ return ASN1_MEM_ERROR; \ ++ } else { \ ++ /* this strcat is checked */ \ ++ if (ptr) _asn1_strcat (ptr, data); \ ++ } ++ ++/** ++ * asn1_read_value: ++ * @root: pointer to a structure. ++ * @name: the name of the element inside a structure that you want to read. ++ * @ivalue: vector that will contain the element's content, must be a ++ * pointer to memory cells already allocated (may be %NULL). ++ * @len: number of bytes of *value: value[0]..value[len-1]. Initialy ++ * holds the sizeof value. ++ * ++ * Returns the value of one element inside a structure. ++ * If an element is OPTIONAL and this returns ++ * %ASN1_ELEMENT_NOT_FOUND, it means that this element wasn't present ++ * in the der encoding that created the structure. The first element ++ * of a SEQUENCE_OF or SET_OF is named "?1". The second one "?2" and ++ * so on. If the @root provided is a node to specific sequence element, ++ * then the keyword "?CURRENT" is also acceptable and indicates the ++ * current sequence element of this node. ++ * ++ * Note that there can be valid values with length zero. In these case ++ * this function will succeed and @len will be zero. ++ * ++ * INTEGER: VALUE will contain a two's complement form integer. ++ * ++ * integer=-1 -> value[0]=0xFF , len=1. ++ * integer=1 -> value[0]=0x01 , len=1. ++ * ++ * ENUMERATED: As INTEGER (but only with not negative numbers). ++ * ++ * BOOLEAN: VALUE will be the null terminated string "TRUE" or ++ * "FALSE" and LEN=5 or LEN=6. ++ * ++ * OBJECT IDENTIFIER: VALUE will be a null terminated string with ++ * each number separated by a dot (i.e. "1.2.3.543.1"). ++ * ++ * LEN = strlen(VALUE)+1 ++ * ++ * UTCTime: VALUE will be a null terminated string in one of these ++ * formats: "YYMMDDhhmmss+hh'mm'" or "YYMMDDhhmmss-hh'mm'". ++ * LEN=strlen(VALUE)+1. ++ * ++ * GeneralizedTime: VALUE will be a null terminated string in the ++ * same format used to set the value. ++ * ++ * OCTET STRING: VALUE will contain the octet string and LEN will be ++ * the number of octets. ++ * ++ * GeneralString: VALUE will contain the generalstring and LEN will ++ * be the number of octets. ++ * ++ * BIT STRING: VALUE will contain the bit string organized by bytes ++ * and LEN will be the number of bits. ++ * ++ * CHOICE: If NAME indicates a choice type, VALUE will specify the ++ * alternative selected. ++ * ++ * ANY: If NAME indicates an any type, VALUE will indicate the DER ++ * encoding of the structure actually used. ++ * ++ * Returns: %ASN1_SUCCESS if value is returned, ++ * %ASN1_ELEMENT_NOT_FOUND if @name is not a valid element, ++ * %ASN1_VALUE_NOT_FOUND if there isn't any value for the element ++ * selected, and %ASN1_MEM_ERROR if The value vector isn't big enough ++ * to store the result, and in this case @len will contain the number of ++ * bytes needed. On the occasion that the stored data are of zero-length ++ * this function may return %ASN1_SUCCESS even if the provided @len is zero. ++ **/ ++int ++asn1_read_value (asn1_node_const root, const char *name, void *ivalue, int *len) ++{ ++ return asn1_read_value_type (root, name, ivalue, len, NULL); ++} ++ ++/** ++ * asn1_read_value_type: ++ * @root: pointer to a structure. ++ * @name: the name of the element inside a structure that you want to read. ++ * @ivalue: vector that will contain the element's content, must be a ++ * pointer to memory cells already allocated (may be %NULL). ++ * @len: number of bytes of *value: value[0]..value[len-1]. Initialy ++ * holds the sizeof value. ++ * @etype: The type of the value read (ASN1_ETYPE) ++ * ++ * Returns the type and value of one element inside a structure. ++ * If an element is OPTIONAL and this returns ++ * %ASN1_ELEMENT_NOT_FOUND, it means that this element wasn't present ++ * in the der encoding that created the structure. The first element ++ * of a SEQUENCE_OF or SET_OF is named "?1". The second one "?2" and ++ * so on. If the @root provided is a node to specific sequence element, ++ * then the keyword "?CURRENT" is also acceptable and indicates the ++ * current sequence element of this node. ++ * ++ * Note that there can be valid values with length zero. In these case ++ * this function will succeed and @len will be zero. ++ * ++ * ++ * INTEGER: VALUE will contain a two's complement form integer. ++ * ++ * integer=-1 -> value[0]=0xFF , len=1. ++ * integer=1 -> value[0]=0x01 , len=1. ++ * ++ * ENUMERATED: As INTEGER (but only with not negative numbers). ++ * ++ * BOOLEAN: VALUE will be the null terminated string "TRUE" or ++ * "FALSE" and LEN=5 or LEN=6. ++ * ++ * OBJECT IDENTIFIER: VALUE will be a null terminated string with ++ * each number separated by a dot (i.e. "1.2.3.543.1"). ++ * ++ * LEN = strlen(VALUE)+1 ++ * ++ * UTCTime: VALUE will be a null terminated string in one of these ++ * formats: "YYMMDDhhmmss+hh'mm'" or "YYMMDDhhmmss-hh'mm'". ++ * LEN=strlen(VALUE)+1. ++ * ++ * GeneralizedTime: VALUE will be a null terminated string in the ++ * same format used to set the value. ++ * ++ * OCTET STRING: VALUE will contain the octet string and LEN will be ++ * the number of octets. ++ * ++ * GeneralString: VALUE will contain the generalstring and LEN will ++ * be the number of octets. ++ * ++ * BIT STRING: VALUE will contain the bit string organized by bytes ++ * and LEN will be the number of bits. ++ * ++ * CHOICE: If NAME indicates a choice type, VALUE will specify the ++ * alternative selected. ++ * ++ * ANY: If NAME indicates an any type, VALUE will indicate the DER ++ * encoding of the structure actually used. ++ * ++ * Returns: %ASN1_SUCCESS if value is returned, ++ * %ASN1_ELEMENT_NOT_FOUND if @name is not a valid element, ++ * %ASN1_VALUE_NOT_FOUND if there isn't any value for the element ++ * selected, and %ASN1_MEM_ERROR if The value vector isn't big enough ++ * to store the result, and in this case @len will contain the number of ++ * bytes needed. On the occasion that the stored data are of zero-length ++ * this function may return %ASN1_SUCCESS even if the provided @len is zero. ++ **/ ++int ++asn1_read_value_type (asn1_node_const root, const char *name, void *ivalue, ++ int *len, unsigned int *etype) ++{ ++ asn1_node_const node, p, p2; ++ int len2, len3, result; ++ int value_size = *len; ++ unsigned char *value = ivalue; ++ unsigned type; ++ ++ node = asn1_find_node (root, name); ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ type = type_field (node->type); ++ ++ if ((type != ASN1_ETYPE_NULL) && ++ (type != ASN1_ETYPE_CHOICE) && ++ !(node->type & CONST_DEFAULT) && !(node->type & CONST_ASSIGN) && ++ (node->value == NULL)) ++ return ASN1_VALUE_NOT_FOUND; ++ ++ if (etype) ++ *etype = type; ++ switch (type) ++ { ++ case ASN1_ETYPE_NULL: ++ PUT_STR_VALUE (value, value_size, "NULL"); ++ break; ++ case ASN1_ETYPE_BOOLEAN: ++ if ((node->type & CONST_DEFAULT) && (node->value == NULL)) ++ { ++ p = node->down; ++ while (type_field (p->type) != ASN1_ETYPE_DEFAULT) ++ p = p->right; ++ if (p->type & CONST_TRUE) ++ { ++ PUT_STR_VALUE (value, value_size, "TRUE"); ++ } ++ else ++ { ++ PUT_STR_VALUE (value, value_size, "FALSE"); ++ } ++ } ++ else if (node->value[0] == 'T') ++ { ++ PUT_STR_VALUE (value, value_size, "TRUE"); ++ } ++ else ++ { ++ PUT_STR_VALUE (value, value_size, "FALSE"); ++ } ++ break; ++ case ASN1_ETYPE_INTEGER: ++ case ASN1_ETYPE_ENUMERATED: ++ if ((node->type & CONST_DEFAULT) && (node->value == NULL)) ++ { ++ p = node->down; ++ while (type_field (p->type) != ASN1_ETYPE_DEFAULT) ++ p = p->right; ++ if ((c_isdigit (p->value[0])) || (p->value[0] == '-') ++ || (p->value[0] == '+')) ++ { ++ result = _asn1_convert_integer ++ (p->value, value, value_size, len); ++ if (result != ASN1_SUCCESS) ++ return result; ++ } ++ else ++ { /* is an identifier like v1 */ ++ p2 = node->down; ++ while (p2) ++ { ++ if (type_field (p2->type) == ASN1_ETYPE_CONSTANT) ++ { ++ if (!_asn1_strcmp (p2->name, p->value)) ++ { ++ result = _asn1_convert_integer ++ (p2->value, value, value_size, ++ len); ++ if (result != ASN1_SUCCESS) ++ return result; ++ break; ++ } ++ } ++ p2 = p2->right; ++ } ++ } ++ } ++ else ++ { ++ len2 = -1; ++ result = asn1_get_octet_der ++ (node->value, node->value_len, &len2, value, value_size, ++ len); ++ if (result != ASN1_SUCCESS) ++ return result; ++ } ++ break; ++ case ASN1_ETYPE_OBJECT_ID: ++ if (node->type & CONST_ASSIGN) ++ { ++ *len = 0; ++ if (value) ++ value[0] = 0; ++ p = node->down; ++ while (p) ++ { ++ if (type_field (p->type) == ASN1_ETYPE_CONSTANT) ++ { ++ ADD_STR_VALUE (value, value_size, p->value); ++ if (p->right) ++ { ++ ADD_STR_VALUE (value, value_size, "."); ++ } ++ } ++ p = p->right; ++ } ++ (*len)++; ++ } ++ else if ((node->type & CONST_DEFAULT) && (node->value == NULL)) ++ { ++ p = node->down; ++ while (type_field (p->type) != ASN1_ETYPE_DEFAULT) ++ p = p->right; ++ PUT_STR_VALUE (value, value_size, p->value); ++ } ++ else ++ { ++ PUT_STR_VALUE (value, value_size, node->value); ++ } ++ break; ++ case ASN1_ETYPE_GENERALIZED_TIME: ++ case ASN1_ETYPE_UTC_TIME: ++ PUT_AS_STR_VALUE (value, value_size, node->value, node->value_len); ++ break; ++ case ASN1_ETYPE_OCTET_STRING: ++ case ASN1_ETYPE_GENERALSTRING: ++ case ASN1_ETYPE_NUMERIC_STRING: ++ case ASN1_ETYPE_IA5_STRING: ++ case ASN1_ETYPE_TELETEX_STRING: ++ case ASN1_ETYPE_PRINTABLE_STRING: ++ case ASN1_ETYPE_UNIVERSAL_STRING: ++ case ASN1_ETYPE_BMP_STRING: ++ case ASN1_ETYPE_UTF8_STRING: ++ case ASN1_ETYPE_VISIBLE_STRING: ++ len2 = -1; ++ result = asn1_get_octet_der ++ (node->value, node->value_len, &len2, value, value_size, ++ len); ++ if (result != ASN1_SUCCESS) ++ return result; ++ break; ++ case ASN1_ETYPE_BIT_STRING: ++ len2 = -1; ++ result = asn1_get_bit_der ++ (node->value, node->value_len, &len2, value, value_size, ++ len); ++ if (result != ASN1_SUCCESS) ++ return result; ++ break; ++ case ASN1_ETYPE_CHOICE: ++ PUT_STR_VALUE (value, value_size, node->down->name); ++ break; ++ case ASN1_ETYPE_ANY: ++ len3 = -1; ++ len2 = asn1_get_length_der (node->value, node->value_len, &len3); ++ if (len2 < 0) ++ return ASN1_DER_ERROR; ++ PUT_VALUE (value, value_size, node->value + len3, len2); ++ break; ++ default: ++ return ASN1_ELEMENT_NOT_FOUND; ++ break; ++ } ++ return ASN1_SUCCESS; ++} ++ ++ ++/** ++ * asn1_read_tag: ++ * @root: pointer to a structure ++ * @name: the name of the element inside a structure. ++ * @tagValue: variable that will contain the TAG value. ++ * @classValue: variable that will specify the TAG type. ++ * ++ * Returns the TAG and the CLASS of one element inside a structure. ++ * CLASS can have one of these constants: %ASN1_CLASS_APPLICATION, ++ * %ASN1_CLASS_UNIVERSAL, %ASN1_CLASS_PRIVATE or ++ * %ASN1_CLASS_CONTEXT_SPECIFIC. ++ * ++ * Returns: %ASN1_SUCCESS if successful, %ASN1_ELEMENT_NOT_FOUND if ++ * @name is not a valid element. ++ **/ ++int ++asn1_read_tag (asn1_node_const root, const char *name, int *tagValue, ++ int *classValue) ++{ ++ asn1_node node, p, pTag; ++ ++ node = asn1_find_node (root, name); ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ p = node->down; ++ ++ /* pTag will points to the IMPLICIT TAG */ ++ pTag = NULL; ++ if (node->type & CONST_TAG) ++ { ++ while (p) ++ { ++ if (type_field (p->type) == ASN1_ETYPE_TAG) ++ { ++ if ((p->type & CONST_IMPLICIT) && (pTag == NULL)) ++ pTag = p; ++ else if (p->type & CONST_EXPLICIT) ++ pTag = NULL; ++ } ++ p = p->right; ++ } ++ } ++ ++ if (pTag) ++ { ++ *tagValue = _asn1_strtoul (pTag->value, NULL, 10); ++ ++ if (pTag->type & CONST_APPLICATION) ++ *classValue = ASN1_CLASS_APPLICATION; ++ else if (pTag->type & CONST_UNIVERSAL) ++ *classValue = ASN1_CLASS_UNIVERSAL; ++ else if (pTag->type & CONST_PRIVATE) ++ *classValue = ASN1_CLASS_PRIVATE; ++ else ++ *classValue = ASN1_CLASS_CONTEXT_SPECIFIC; ++ } ++ else ++ { ++ unsigned type = type_field (node->type); ++ *classValue = ASN1_CLASS_UNIVERSAL; ++ ++ switch (type) ++ { ++ CASE_HANDLED_ETYPES: ++ *tagValue = _asn1_tags[type].tag; ++ break; ++ case ASN1_ETYPE_TAG: ++ case ASN1_ETYPE_CHOICE: ++ case ASN1_ETYPE_ANY: ++ *tagValue = -1; ++ break; ++ default: ++ break; ++ } ++ } ++ ++ return ASN1_SUCCESS; ++} ++ ++/** ++ * asn1_read_node_value: ++ * @node: pointer to a node. ++ * @data: a point to a asn1_data_node_st ++ * ++ * Returns the value a data node inside a asn1_node structure. ++ * The data returned should be handled as constant values. ++ * ++ * Returns: %ASN1_SUCCESS if the node exists. ++ **/ ++int ++asn1_read_node_value (asn1_node_const node, asn1_data_node_st * data) ++{ ++ data->name = node->name; ++ data->value = node->value; ++ data->value_len = node->value_len; ++ data->type = type_field (node->type); ++ ++ return ASN1_SUCCESS; ++} +diff --git a/grub-core/lib/libtasn1/lib/errors.c b/grub-core/lib/libtasn1/lib/errors.c +new file mode 100644 +index 00000000000..cee74daf795 +--- /dev/null ++++ b/grub-core/lib/libtasn1/lib/errors.c +@@ -0,0 +1,100 @@ ++/* ++ * Copyright (C) 2002-2014 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * The LIBTASN1 library is free software; you can redistribute it ++ * and/or modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ++ * 02110-1301, USA ++ */ ++ ++#include ++#ifdef STDC_HEADERS ++#include ++#endif ++ ++#define LIBTASN1_ERROR_ENTRY(name) { #name, name } ++ ++struct libtasn1_error_entry ++{ ++ const char *name; ++ int number; ++}; ++typedef struct libtasn1_error_entry libtasn1_error_entry; ++ ++static const libtasn1_error_entry error_algorithms[] = { ++ LIBTASN1_ERROR_ENTRY (ASN1_SUCCESS), ++ LIBTASN1_ERROR_ENTRY (ASN1_FILE_NOT_FOUND), ++ LIBTASN1_ERROR_ENTRY (ASN1_ELEMENT_NOT_FOUND), ++ LIBTASN1_ERROR_ENTRY (ASN1_IDENTIFIER_NOT_FOUND), ++ LIBTASN1_ERROR_ENTRY (ASN1_DER_ERROR), ++ LIBTASN1_ERROR_ENTRY (ASN1_VALUE_NOT_FOUND), ++ LIBTASN1_ERROR_ENTRY (ASN1_GENERIC_ERROR), ++ LIBTASN1_ERROR_ENTRY (ASN1_VALUE_NOT_VALID), ++ LIBTASN1_ERROR_ENTRY (ASN1_TAG_ERROR), ++ LIBTASN1_ERROR_ENTRY (ASN1_TAG_IMPLICIT), ++ LIBTASN1_ERROR_ENTRY (ASN1_ERROR_TYPE_ANY), ++ LIBTASN1_ERROR_ENTRY (ASN1_SYNTAX_ERROR), ++ LIBTASN1_ERROR_ENTRY (ASN1_MEM_ERROR), ++ LIBTASN1_ERROR_ENTRY (ASN1_MEM_ALLOC_ERROR), ++ LIBTASN1_ERROR_ENTRY (ASN1_DER_OVERFLOW), ++ LIBTASN1_ERROR_ENTRY (ASN1_NAME_TOO_LONG), ++ LIBTASN1_ERROR_ENTRY (ASN1_ARRAY_ERROR), ++ LIBTASN1_ERROR_ENTRY (ASN1_ELEMENT_NOT_EMPTY), ++ LIBTASN1_ERROR_ENTRY (ASN1_TIME_ENCODING_ERROR), ++ LIBTASN1_ERROR_ENTRY (ASN1_RECURSION), ++ {0, 0} ++}; ++ ++/** ++ * asn1_perror: ++ * @error: is an error returned by a libtasn1 function. ++ * ++ * Prints a string to stderr with a description of an error. This ++ * function is like perror(). The only difference is that it accepts ++ * an error returned by a libtasn1 function. ++ * ++ * Since: 1.6 ++ **/ ++void ++asn1_perror (int error) ++{ ++ const char *str = asn1_strerror (error); ++ fprintf (stderr, "LIBTASN1 ERROR: %s\n", str ? str : "(null)"); ++} ++ ++/** ++ * asn1_strerror: ++ * @error: is an error returned by a libtasn1 function. ++ * ++ * Returns a string with a description of an error. This function is ++ * similar to strerror. The only difference is that it accepts an ++ * error (number) returned by a libtasn1 function. ++ * ++ * Returns: Pointer to static zero-terminated string describing error ++ * code. ++ * ++ * Since: 1.6 ++ **/ ++const char * ++asn1_strerror (int error) ++{ ++ const libtasn1_error_entry *p; ++ ++ for (p = error_algorithms; p->name != NULL; p++) ++ if (p->number == error) ++ return p->name + sizeof ("ASN1_") - 1; ++ ++ return NULL; ++} +diff --git a/grub-core/lib/libtasn1/lib/gstr.c b/grub-core/lib/libtasn1/lib/gstr.c +new file mode 100644 +index 00000000000..e91a3a151c0 +--- /dev/null ++++ b/grub-core/lib/libtasn1/lib/gstr.c +@@ -0,0 +1,74 @@ ++/* ++ * Copyright (C) 2002-2014 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * The LIBTASN1 library is free software; you can redistribute it ++ * and/or modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ++ * 02110-1301, USA ++ */ ++ ++#include ++#include "gstr.h" ++ ++/* These function are like strcat, strcpy. They only ++ * do bounds checking (they shouldn't cause buffer overruns), ++ * and they always produce null terminated strings. ++ * ++ * They should be used only with null terminated strings. ++ */ ++void ++_asn1_str_cat (char *dest, size_t dest_tot_size, const char *src) ++{ ++ size_t str_size = strlen (src); ++ size_t dest_size = strlen (dest); ++ ++ if (dest_tot_size - dest_size > str_size) ++ { ++ strcat (dest, src); ++ } ++ else ++ { ++ if (dest_tot_size - dest_size > 0) ++ { ++ strncat (dest, src, (dest_tot_size - dest_size) - 1); ++ dest[dest_tot_size - 1] = 0; ++ } ++ } ++} ++ ++/* Returns the bytes copied (not including the null terminator) */ ++unsigned int ++_asn1_str_cpy (char *dest, size_t dest_tot_size, const char *src) ++{ ++ size_t str_size = strlen (src); ++ ++ if (dest_tot_size > str_size) ++ { ++ strcpy (dest, src); ++ return str_size; ++ } ++ else ++ { ++ if (dest_tot_size > 0) ++ { ++ str_size = dest_tot_size - 1; ++ memcpy (dest, src, str_size); ++ dest[str_size] = 0; ++ return str_size; ++ } ++ else ++ return 0; ++ } ++} +diff --git a/grub-core/lib/libtasn1/lib/parser_aux.c b/grub-core/lib/libtasn1/lib/parser_aux.c +new file mode 100644 +index 00000000000..d5dbbf8765d +--- /dev/null ++++ b/grub-core/lib/libtasn1/lib/parser_aux.c +@@ -0,0 +1,1173 @@ ++/* ++ * Copyright (C) 2000-2016 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * The LIBTASN1 library is free software; you can redistribute it ++ * and/or modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ++ * 02110-1301, USA ++ */ ++ ++#include // WORD_BIT ++ ++#include "int.h" ++#include "parser_aux.h" ++#include "gstr.h" ++#include "structure.h" ++#include "element.h" ++#include "c-ctype.h" ++ ++char _asn1_identifierMissing[ASN1_MAX_NAME_SIZE + 1]; /* identifier name not found */ ++ ++/* Return a hash of the N bytes of X using the method described by ++ Bruno Haible in https://www.haible.de/bruno/hashfunc.html. ++ Note that while many hash functions reduce their result via modulo ++ to a 0..table_size-1 range, this function does not do that. ++ ++ This implementation has been changed from size_t -> unsigned int. */ ++ ++#ifdef __clang__ ++__attribute__((no_sanitize("integer"))) ++#endif ++_GL_ATTRIBUTE_PURE ++static unsigned int ++_asn1_hash_name (const char *x) ++{ ++ const unsigned char *s = (unsigned char *) x; ++ unsigned h = 0; ++ ++ while (*s) ++ h = (*s++) + ((h << 9) | (h >> (WORD_BIT - 9))); ++ ++ return h; ++} ++ ++/******************************************************/ ++/* Function : _asn1_add_static_node */ ++/* Description: creates a new NODE_ASN element and */ ++/* puts it in the list pointed by e_list. */ ++/* Parameters: */ ++/* e_list: of type list_type; must be NULL initially */ ++/* type: type of the new element (see ASN1_ETYPE_ */ ++/* and CONST_ constants). */ ++/* Return: pointer to the new element. */ ++/******************************************************/ ++asn1_node ++_asn1_add_static_node (list_type **e_list, unsigned int type) ++{ ++ list_type *p; ++ asn1_node punt; ++ ++ punt = calloc (1, sizeof (struct asn1_node_st)); ++ if (punt == NULL) ++ return NULL; ++ ++ p = malloc (sizeof (list_type)); ++ if (p == NULL) ++ { ++ free (punt); ++ return NULL; ++ } ++ ++ p->node = punt; ++ p->next = *e_list; ++ *e_list = p; ++ ++ punt->type = type; ++ ++ return punt; ++} ++ ++static ++int _asn1_add_static_node2 (list_type **e_list, asn1_node node) ++{ ++ list_type *p; ++ ++ p = malloc (sizeof (list_type)); ++ if (p == NULL) ++ { ++ return -1; ++ } ++ ++ p->node = node; ++ p->next = *e_list; ++ *e_list = p; ++ ++ return 0; ++} ++ ++/** ++ * asn1_find_node: ++ * @pointer: NODE_ASN element pointer. ++ * @name: null terminated string with the element's name to find. ++ * ++ * Searches for an element called @name starting from @pointer. The ++ * name is composed by different identifiers separated by dots. When ++ * *@pointer has a name, the first identifier must be the name of ++ * *@pointer, otherwise it must be the name of one child of *@pointer. ++ * ++ * Returns: the search result, or %NULL if not found. ++ **/ ++asn1_node ++asn1_find_node (asn1_node_const pointer, const char *name) ++{ ++ asn1_node_const p; ++ char *n_end, n[ASN1_MAX_NAME_SIZE + 1]; ++ const char *n_start; ++ unsigned int nsize; ++ unsigned int nhash; ++ ++ if (pointer == NULL) ++ return NULL; ++ ++ if (name == NULL) ++ return NULL; ++ ++ p = pointer; ++ n_start = name; ++ ++ if (name[0] == '?' && name[1] == 'C' && p->name[0] == '?') ++ { /* ?CURRENT */ ++ n_start = strchr(n_start, '.'); ++ if (n_start) ++ n_start++; ++ } ++ else if (p->name[0] != 0) ++ { /* has *pointer got a name ? */ ++ n_end = strchr (n_start, '.'); /* search the first dot */ ++ if (n_end) ++ { ++ nsize = n_end - n_start; ++ if (nsize >= sizeof(n)) ++ return NULL; ++ ++ memcpy (n, n_start, nsize); ++ n[nsize] = 0; ++ n_start = n_end; ++ n_start++; ++ ++ nhash = _asn1_hash_name (n); ++ } ++ else ++ { ++ _asn1_str_cpy (n, sizeof (n), n_start); ++ nhash = _asn1_hash_name (n); ++ ++ n_start = NULL; ++ } ++ ++ while (p) ++ { ++ if (nhash == p->name_hash && (!strcmp (p->name, n))) ++ break; ++ else ++ p = p->right; ++ } /* while */ ++ ++ if (p == NULL) ++ return NULL; ++ } ++ else ++ { /* *pointer doesn't have a name */ ++ if (n_start[0] == 0) ++ return (asn1_node) p; ++ } ++ ++ while (n_start) ++ { /* Has the end of NAME been reached? */ ++ n_end = strchr (n_start, '.'); /* search the next dot */ ++ if (n_end) ++ { ++ nsize = n_end - n_start; ++ if (nsize >= sizeof(n)) ++ return NULL; ++ ++ memcpy (n, n_start, nsize); ++ n[nsize] = 0; ++ n_start = n_end; ++ n_start++; ++ ++ nhash = _asn1_hash_name (n); ++ } ++ else ++ { ++ _asn1_str_cpy (n, sizeof (n), n_start); ++ nhash = _asn1_hash_name (n); ++ n_start = NULL; ++ } ++ ++ if (p->down == NULL) ++ return NULL; ++ ++ p = p->down; ++ if (p == NULL) ++ return NULL; ++ ++ /* The identifier "?LAST" indicates the last element ++ in the right chain. */ ++ if (n[0] == '?' && n[1] == 'L') /* ?LAST */ ++ { ++ while (p->right) ++ p = p->right; ++ } ++ else ++ { /* no "?LAST" */ ++ while (p) ++ { ++ if (p->name_hash == nhash && !strcmp (p->name, n)) ++ break; ++ else ++ p = p->right; ++ } ++ } ++ if (p == NULL) ++ return NULL; ++ } /* while */ ++ ++ return (asn1_node) p; ++} ++ ++ ++/******************************************************************/ ++/* Function : _asn1_set_value */ ++/* Description: sets the field VALUE in a NODE_ASN element. The */ ++/* previous value (if exist) will be lost */ ++/* Parameters: */ ++/* node: element pointer. */ ++/* value: pointer to the value that you want to set. */ ++/* len: character number of value. */ ++/* Return: pointer to the NODE_ASN element. */ ++/******************************************************************/ ++asn1_node ++_asn1_set_value (asn1_node node, const void *value, unsigned int len) ++{ ++ if (node == NULL) ++ return node; ++ if (node->value) ++ { ++ if (node->value != node->small_value) ++ free (node->value); ++ node->value = NULL; ++ node->value_len = 0; ++ } ++ ++ if (!len) ++ return node; ++ ++ if (len < sizeof (node->small_value)) ++ { ++ node->value = node->small_value; ++ } ++ else ++ { ++ node->value = malloc (len); ++ if (node->value == NULL) ++ return NULL; ++ } ++ node->value_len = len; ++ ++ memcpy (node->value, value, len); ++ return node; ++} ++ ++/******************************************************************/ ++/* Function : _asn1_set_value_lv */ ++/* Description: sets the field VALUE in a NODE_ASN element. The */ ++/* previous value (if exist) will be lost. The value */ ++/* given is stored as an length-value format (LV */ ++/* Parameters: */ ++/* node: element pointer. */ ++/* value: pointer to the value that you want to set. */ ++/* len: character number of value. */ ++/* Return: pointer to the NODE_ASN element. */ ++/******************************************************************/ ++asn1_node ++_asn1_set_value_lv (asn1_node node, const void *value, unsigned int len) ++{ ++ int len2; ++ void *temp; ++ ++ if (node == NULL) ++ return node; ++ ++ asn1_length_der (len, NULL, &len2); ++ temp = malloc (len + len2); ++ if (temp == NULL) ++ return NULL; ++ ++ asn1_octet_der (value, len, temp, &len2); ++ return _asn1_set_value_m (node, temp, len2); ++} ++ ++/* the same as _asn1_set_value except that it sets an already malloc'ed ++ * value. ++ */ ++asn1_node ++_asn1_set_value_m (asn1_node node, void *value, unsigned int len) ++{ ++ if (node == NULL) ++ return node; ++ ++ if (node->value) ++ { ++ if (node->value != node->small_value) ++ free (node->value); ++ node->value = NULL; ++ node->value_len = 0; ++ } ++ ++ if (!len) ++ return node; ++ ++ node->value = value; ++ node->value_len = len; ++ ++ return node; ++} ++ ++/******************************************************************/ ++/* Function : _asn1_append_value */ ++/* Description: appends to the field VALUE in a NODE_ASN element. */ ++/* */ ++/* Parameters: */ ++/* node: element pointer. */ ++/* value: pointer to the value that you want to be appended. */ ++/* len: character number of value. */ ++/* Return: pointer to the NODE_ASN element. */ ++/******************************************************************/ ++asn1_node ++_asn1_append_value (asn1_node node, const void *value, unsigned int len) ++{ ++ if (node == NULL) ++ return node; ++ ++ if (node->value == NULL) ++ return _asn1_set_value (node, value, len); ++ ++ if (len == 0) ++ return node; ++ ++ if (node->value == node->small_value) ++ { ++ /* value is in node */ ++ int prev_len = node->value_len; ++ node->value_len += len; ++ node->value = malloc (node->value_len); ++ if (node->value == NULL) ++ { ++ node->value_len = 0; ++ return NULL; ++ } ++ ++ if (prev_len > 0) ++ memcpy (node->value, node->small_value, prev_len); ++ ++ memcpy (&node->value[prev_len], value, len); ++ ++ return node; ++ } ++ else /* if (node->value != NULL && node->value != node->small_value) */ ++ { ++ /* value is allocated */ ++ int prev_len = node->value_len; ++ node->value_len += len; ++ ++ node->value = _asn1_realloc (node->value, node->value_len); ++ if (node->value == NULL) ++ { ++ node->value_len = 0; ++ return NULL; ++ } ++ ++ memcpy (&node->value[prev_len], value, len); ++ ++ return node; ++ } ++} ++ ++/******************************************************************/ ++/* Function : _asn1_set_name */ ++/* Description: sets the field NAME in a NODE_ASN element. The */ ++/* previous value (if exist) will be lost */ ++/* Parameters: */ ++/* node: element pointer. */ ++/* name: a null terminated string with the name that you want */ ++/* to set. */ ++/* Return: pointer to the NODE_ASN element. */ ++/******************************************************************/ ++asn1_node ++_asn1_set_name (asn1_node node, const char *name) ++{ ++ if (node == NULL) ++ return node; ++ ++ _asn1_str_cpy (node->name, sizeof (node->name), name ? name : ""); ++ node->name_hash = _asn1_hash_name (node->name); ++ ++ return node; ++} ++ ++/******************************************************************/ ++/* Function : _asn1_cpy_name */ ++/* Description: copies the field NAME in a NODE_ASN element. */ ++/* Parameters: */ ++/* dst: a dest element pointer. */ ++/* src: a source element pointer. */ ++/* Return: pointer to the NODE_ASN element. */ ++/******************************************************************/ ++asn1_node ++_asn1_cpy_name (asn1_node dst, asn1_node_const src) ++{ ++ if (dst == NULL) ++ return dst; ++ ++ if (src == NULL) ++ { ++ dst->name[0] = 0; ++ dst->name_hash = _asn1_hash_name (dst->name); ++ return dst; ++ } ++ ++ _asn1_str_cpy (dst->name, sizeof (dst->name), src->name); ++ dst->name_hash = src->name_hash; ++ ++ return dst; ++} ++ ++/******************************************************************/ ++/* Function : _asn1_set_right */ ++/* Description: sets the field RIGHT in a NODE_ASN element. */ ++/* Parameters: */ ++/* node: element pointer. */ ++/* right: pointer to a NODE_ASN element that you want be pointed*/ ++/* by NODE. */ ++/* Return: pointer to *NODE. */ ++/******************************************************************/ ++asn1_node ++_asn1_set_right (asn1_node node, asn1_node right) ++{ ++ if (node == NULL) ++ return node; ++ node->right = right; ++ if (right) ++ right->left = node; ++ return node; ++} ++ ++ ++/******************************************************************/ ++/* Function : _asn1_get_last_right */ ++/* Description: return the last element along the right chain. */ ++/* Parameters: */ ++/* node: starting element pointer. */ ++/* Return: pointer to the last element along the right chain. */ ++/******************************************************************/ ++asn1_node ++_asn1_get_last_right (asn1_node_const node) ++{ ++ asn1_node_const p; ++ ++ if (node == NULL) ++ return NULL; ++ p = node; ++ while (p->right) ++ p = p->right; ++ return (asn1_node) p; ++} ++ ++/******************************************************************/ ++/* Function : _asn1_remove_node */ ++/* Description: gets free the memory allocated for an NODE_ASN */ ++/* element (not the elements pointed by it). */ ++/* Parameters: */ ++/* node: NODE_ASN element pointer. */ ++/* flags: ASN1_DELETE_FLAG_* */ ++/******************************************************************/ ++void ++_asn1_remove_node (asn1_node node, unsigned int flags) ++{ ++ if (node == NULL) ++ return; ++ ++ if (node->value != NULL) ++ { ++ if (flags & ASN1_DELETE_FLAG_ZEROIZE) ++ { ++ safe_memset(node->value, 0, node->value_len); ++ } ++ ++ if (node->value != node->small_value) ++ free (node->value); ++ } ++ free (node); ++} ++ ++/******************************************************************/ ++/* Function : _asn1_find_up */ ++/* Description: return the father of the NODE_ASN element. */ ++/* Parameters: */ ++/* node: NODE_ASN element pointer. */ ++/* Return: Null if not found. */ ++/******************************************************************/ ++asn1_node ++_asn1_find_up (asn1_node_const node) ++{ ++ asn1_node_const p; ++ ++ if (node == NULL) ++ return NULL; ++ ++ p = node; ++ ++ while ((p->left != NULL) && (p->left->right == p)) ++ p = p->left; ++ ++ return p->left; ++} ++ ++static ++unsigned _asn1_is_up (asn1_node_const up_cand, asn1_node_const down) ++{ ++ asn1_node_const d, u; ++ ++ if (up_cand == NULL || down == NULL) ++ return 0; ++ ++ d = down; ++ ++ while ((u = _asn1_find_up(d)) != NULL && u != d) ++ { ++ if (u == up_cand) ++ return 1; ++ d = u; ++ } ++ ++ return 0; ++} ++ ++/******************************************************************/ ++/* Function : _asn1_delete_node_from_list */ ++/* Description: deletes the list element given */ ++/******************************************************************/ ++void ++_asn1_delete_node_from_list (list_type *list, asn1_node node) ++{ ++ list_type *p = list; ++ ++ while (p) ++ { ++ if (p->node == node) ++ p->node = NULL; ++ p = p->next; ++ } ++} ++ ++/******************************************************************/ ++/* Function : _asn1_delete_list */ ++/* Description: deletes the list elements (not the elements */ ++/* pointed by them). */ ++/******************************************************************/ ++void ++_asn1_delete_list (list_type *e_list) ++{ ++ list_type *p; ++ ++ while (e_list) ++ { ++ p = e_list; ++ e_list = e_list->next; ++ free (p); ++ } ++} ++ ++/******************************************************************/ ++/* Function : _asn1_delete_list_and nodes */ ++/* Description: deletes the list elements and the elements */ ++/* pointed by them. */ ++/******************************************************************/ ++void ++_asn1_delete_list_and_nodes (list_type *e_list) ++{ ++ list_type *p; ++ ++ while (e_list) ++ { ++ p = e_list; ++ e_list = e_list->next; ++ _asn1_remove_node (p->node, 0); ++ free (p); ++ } ++} ++ ++ ++char * ++_asn1_ltostr (int64_t v, char str[LTOSTR_MAX_SIZE]) ++{ ++ uint64_t d, r; ++ char temp[LTOSTR_MAX_SIZE]; ++ int count, k, start; ++ uint64_t val; ++ ++ if (v < 0) ++ { ++ str[0] = '-'; ++ start = 1; ++ val = -((uint64_t)v); ++ } ++ else ++ { ++ val = v; ++ start = 0; ++ } ++ ++ count = 0; ++ do ++ { ++ d = val / 10; ++ r = val - d * 10; ++ temp[start + count] = '0' + (char) r; ++ count++; ++ val = d; ++ } ++ while (val && ((start+count) < LTOSTR_MAX_SIZE-1)); ++ ++ for (k = 0; k < count; k++) ++ str[k + start] = temp[start + count - k - 1]; ++ str[count + start] = 0; ++ return str; ++} ++ ++ ++/******************************************************************/ ++/* Function : _asn1_change_integer_value */ ++/* Description: converts into DER coding the value assign to an */ ++/* INTEGER constant. */ ++/* Parameters: */ ++/* node: root of an ASN1element. */ ++/* Return: */ ++/* ASN1_ELEMENT_NOT_FOUND if NODE is NULL, */ ++/* otherwise ASN1_SUCCESS */ ++/******************************************************************/ ++int ++_asn1_change_integer_value (asn1_node node) ++{ ++ asn1_node p; ++ unsigned char val[SIZEOF_UNSIGNED_LONG_INT]; ++ unsigned char val2[SIZEOF_UNSIGNED_LONG_INT + 1]; ++ int len; ++ ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ p = node; ++ while (p) ++ { ++ if ((type_field (p->type) == ASN1_ETYPE_INTEGER) ++ && (p->type & CONST_ASSIGN)) ++ { ++ if (p->value) ++ { ++ _asn1_convert_integer (p->value, val, sizeof (val), &len); ++ asn1_octet_der (val, len, val2, &len); ++ _asn1_set_value (p, val2, len); ++ } ++ } ++ ++ if (p->down) ++ { ++ p = p->down; ++ } ++ else ++ { ++ if (p == node) ++ p = NULL; ++ else if (p->right) ++ p = p->right; ++ else ++ { ++ while (1) ++ { ++ p = _asn1_find_up (p); ++ if (p == node) ++ { ++ p = NULL; ++ break; ++ } ++ if (p && p->right) ++ { ++ p = p->right; ++ break; ++ } ++ } ++ } ++ } ++ } ++ ++ return ASN1_SUCCESS; ++} ++ ++#define MAX_CONSTANTS 1024 ++/******************************************************************/ ++/* Function : _asn1_expand_object_id */ ++/* Description: expand the IDs of an OBJECT IDENTIFIER constant. */ ++/* Parameters: */ ++/* list: root of an object list */ ++/* node: root of an ASN1 element. */ ++/* Return: */ ++/* ASN1_ELEMENT_NOT_FOUND if NODE is NULL, */ ++/* otherwise ASN1_SUCCESS */ ++/******************************************************************/ ++int ++_asn1_expand_object_id (list_type **list, asn1_node node) ++{ ++ asn1_node p, p2, p3, p4, p5; ++ char name_root[ASN1_MAX_NAME_SIZE], name2[2 * ASN1_MAX_NAME_SIZE + 1]; ++ int move, tlen, tries; ++ unsigned max_constants; ++ ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ _asn1_str_cpy (name_root, sizeof (name_root), node->name); ++ ++ p = node; ++ move = DOWN; ++ tries = 0; ++ ++ while (!((p == node) && (move == UP))) ++ { ++ if (move != UP) ++ { ++ if ((type_field (p->type) == ASN1_ETYPE_OBJECT_ID) ++ && (p->type & CONST_ASSIGN)) ++ { ++ p2 = p->down; ++ if (p2 && (type_field (p2->type) == ASN1_ETYPE_CONSTANT)) ++ { ++ if (p2->value && !c_isdigit (p2->value[0])) ++ { ++ _asn1_str_cpy (name2, sizeof (name2), name_root); ++ _asn1_str_cat (name2, sizeof (name2), "."); ++ _asn1_str_cat (name2, sizeof (name2), (char *) p2->value); ++ p3 = asn1_find_node (node, name2); ++ if (!p3 || _asn1_is_up(p2, p3) || ++ (type_field (p3->type) != ASN1_ETYPE_OBJECT_ID) || ++ !(p3->type & CONST_ASSIGN)) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ _asn1_set_down (p, p2->right); ++ if (p2->down) ++ _asn1_delete_structure (*list, &p2->down, 0); ++ _asn1_delete_node_from_list(*list, p2); ++ _asn1_remove_node (p2, 0); ++ p2 = p; ++ p4 = p3->down; ++ max_constants = 0; ++ while (p4) ++ { ++ if (type_field (p4->type) == ASN1_ETYPE_CONSTANT) ++ { ++ max_constants++; ++ if (max_constants == MAX_CONSTANTS) ++ return ASN1_RECURSION; ++ ++ p5 = ++ _asn1_add_single_node (ASN1_ETYPE_CONSTANT); ++ _asn1_set_name (p5, p4->name); ++ if (p4->value) ++ { ++ tlen = _asn1_strlen (p4->value); ++ if (tlen > 0) ++ _asn1_set_value (p5, p4->value, tlen + 1); ++ } ++ _asn1_add_static_node2(list, p5); ++ ++ if (p2 == p) ++ { ++ _asn1_set_right (p5, p->down); ++ _asn1_set_down (p, p5); ++ } ++ else ++ { ++ _asn1_set_right (p5, p2->right); ++ _asn1_set_right (p2, p5); ++ } ++ p2 = p5; ++ } ++ p4 = p4->right; ++ } ++ move = DOWN; ++ ++ tries++; ++ if (tries >= EXPAND_OBJECT_ID_MAX_RECURSION) ++ return ASN1_RECURSION; ++ ++ continue; ++ } ++ } ++ } ++ move = DOWN; ++ } ++ else ++ move = RIGHT; ++ ++ tries = 0; ++ if (move == DOWN) ++ { ++ if (p->down) ++ p = p->down; ++ else ++ move = RIGHT; ++ } ++ ++ if (p == node) ++ { ++ move = UP; ++ continue; ++ } ++ ++ if (move == RIGHT) ++ { ++ if (p && p->right) ++ p = p->right; ++ else ++ move = UP; ++ } ++ if (move == UP) ++ p = _asn1_find_up (p); ++ } ++ ++ /*******************************/ ++ /* expand DEFAULT */ ++ /*******************************/ ++ p = node; ++ move = DOWN; ++ ++ while (!((p == node) && (move == UP))) ++ { ++ if (move != UP) ++ { ++ if ((type_field (p->type) == ASN1_ETYPE_OBJECT_ID) && ++ (p->type & CONST_DEFAULT)) ++ { ++ p2 = p->down; ++ if (p2 && (type_field (p2->type) == ASN1_ETYPE_DEFAULT)) ++ { ++ _asn1_str_cpy (name2, sizeof (name2), name_root); ++ _asn1_str_cat (name2, sizeof (name2), "."); ++ if (p2->value) ++ _asn1_str_cat (name2, sizeof (name2), (char *) p2->value); ++ p3 = asn1_find_node (node, name2); ++ if (!p3 || (type_field (p3->type) != ASN1_ETYPE_OBJECT_ID) ++ || !(p3->type & CONST_ASSIGN)) ++ return ASN1_ELEMENT_NOT_FOUND; ++ p4 = p3->down; ++ name2[0] = 0; ++ while (p4) ++ { ++ if (type_field (p4->type) == ASN1_ETYPE_CONSTANT) ++ { ++ if (p4->value == NULL) ++ return ASN1_VALUE_NOT_FOUND; ++ ++ if (name2[0]) ++ _asn1_str_cat (name2, sizeof (name2), "."); ++ _asn1_str_cat (name2, sizeof (name2), ++ (char *) p4->value); ++ } ++ p4 = p4->right; ++ } ++ tlen = strlen (name2); ++ if (tlen > 0) ++ _asn1_set_value (p2, name2, tlen + 1); ++ } ++ } ++ move = DOWN; ++ } ++ else ++ move = RIGHT; ++ ++ if (move == DOWN) ++ { ++ if (p->down) ++ p = p->down; ++ else ++ move = RIGHT; ++ } ++ ++ if (p == node) ++ { ++ move = UP; ++ continue; ++ } ++ ++ if (move == RIGHT) ++ { ++ if (p && p->right) ++ p = p->right; ++ else ++ move = UP; ++ } ++ if (move == UP) ++ p = _asn1_find_up (p); ++ } ++ ++ return ASN1_SUCCESS; ++} ++ ++ ++/******************************************************************/ ++/* Function : _asn1_type_set_config */ ++/* Description: sets the CONST_SET and CONST_NOT_USED properties */ ++/* in the fields of the SET elements. */ ++/* Parameters: */ ++/* node: root of an ASN1 element. */ ++/* Return: */ ++/* ASN1_ELEMENT_NOT_FOUND if NODE is NULL, */ ++/* otherwise ASN1_SUCCESS */ ++/******************************************************************/ ++int ++_asn1_type_set_config (asn1_node node) ++{ ++ asn1_node p, p2; ++ int move; ++ ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ p = node; ++ move = DOWN; ++ ++ while (!((p == node) && (move == UP))) ++ { ++ if (move != UP) ++ { ++ if (type_field (p->type) == ASN1_ETYPE_SET) ++ { ++ p2 = p->down; ++ while (p2) ++ { ++ if (type_field (p2->type) != ASN1_ETYPE_TAG) ++ p2->type |= CONST_SET | CONST_NOT_USED; ++ p2 = p2->right; ++ } ++ } ++ move = DOWN; ++ } ++ else ++ move = RIGHT; ++ ++ if (move == DOWN) ++ { ++ if (p->down) ++ p = p->down; ++ else ++ move = RIGHT; ++ } ++ ++ if (p == node) ++ { ++ move = UP; ++ continue; ++ } ++ ++ if (move == RIGHT) ++ { ++ if (p && p->right) ++ p = p->right; ++ else ++ move = UP; ++ } ++ if (move == UP) ++ p = _asn1_find_up (p); ++ } ++ ++ return ASN1_SUCCESS; ++} ++ ++ ++/******************************************************************/ ++/* Function : _asn1_check_identifier */ ++/* Description: checks the definitions of all the identifiers */ ++/* and the first element of an OBJECT_ID (e.g. {pkix 0 4}). */ ++/* The _asn1_identifierMissing global variable is filled if */ ++/* necessary. */ ++/* Parameters: */ ++/* node: root of an ASN1 element. */ ++/* Return: */ ++/* ASN1_ELEMENT_NOT_FOUND if NODE is NULL, */ ++/* ASN1_IDENTIFIER_NOT_FOUND if an identifier is not defined, */ ++/* otherwise ASN1_SUCCESS */ ++/******************************************************************/ ++int ++_asn1_check_identifier (asn1_node_const node) ++{ ++ asn1_node_const p, p2; ++ char name2[ASN1_MAX_NAME_SIZE * 2 + 2]; ++ ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ p = node; ++ while (p) ++ { ++ if (p->value && type_field (p->type) == ASN1_ETYPE_IDENTIFIER) ++ { ++ _asn1_str_cpy (name2, sizeof (name2), node->name); ++ _asn1_str_cat (name2, sizeof (name2), "."); ++ _asn1_str_cat (name2, sizeof (name2), (char *) p->value); ++ p2 = asn1_find_node (node, name2); ++ if (p2 == NULL) ++ { ++ if (p->value) ++ _asn1_str_cpy (_asn1_identifierMissing, sizeof(_asn1_identifierMissing), (char*)p->value); ++ else ++ _asn1_strcpy (_asn1_identifierMissing, "(null)"); ++ return ASN1_IDENTIFIER_NOT_FOUND; ++ } ++ } ++ else if ((type_field (p->type) == ASN1_ETYPE_OBJECT_ID) && ++ (p->type & CONST_DEFAULT)) ++ { ++ p2 = p->down; ++ if (p2 && (type_field (p2->type) == ASN1_ETYPE_DEFAULT)) ++ { ++ _asn1_str_cpy (name2, sizeof (name2), node->name); ++ if (p2->value) ++ { ++ _asn1_str_cat (name2, sizeof (name2), "."); ++ _asn1_str_cat (name2, sizeof (name2), (char *) p2->value); ++ _asn1_str_cpy (_asn1_identifierMissing, sizeof(_asn1_identifierMissing), (char*)p2->value); ++ } ++ else ++ _asn1_strcpy (_asn1_identifierMissing, "(null)"); ++ ++ p2 = asn1_find_node (node, name2); ++ if (!p2 || (type_field (p2->type) != ASN1_ETYPE_OBJECT_ID) || ++ !(p2->type & CONST_ASSIGN)) ++ return ASN1_IDENTIFIER_NOT_FOUND; ++ else ++ _asn1_identifierMissing[0] = 0; ++ } ++ } ++ else if ((type_field (p->type) == ASN1_ETYPE_OBJECT_ID) && ++ (p->type & CONST_ASSIGN)) ++ { ++ p2 = p->down; ++ if (p2 && (type_field (p2->type) == ASN1_ETYPE_CONSTANT)) ++ { ++ if (p2->value && !c_isdigit (p2->value[0])) ++ { ++ _asn1_str_cpy (name2, sizeof (name2), node->name); ++ _asn1_str_cat (name2, sizeof (name2), "."); ++ _asn1_str_cat (name2, sizeof (name2), (char *) p2->value); ++ _asn1_str_cpy (_asn1_identifierMissing, sizeof(_asn1_identifierMissing), (char*)p2->value); ++ ++ p2 = asn1_find_node (node, name2); ++ if (!p2 || (type_field (p2->type) != ASN1_ETYPE_OBJECT_ID) ++ || !(p2->type & CONST_ASSIGN)) ++ return ASN1_IDENTIFIER_NOT_FOUND; ++ else ++ _asn1_identifierMissing[0] = 0; ++ } ++ } ++ } ++ ++ if (p->down) ++ { ++ p = p->down; ++ } ++ else if (p->right) ++ p = p->right; ++ else ++ { ++ while (p) ++ { ++ p = _asn1_find_up (p); ++ if (p == node) ++ { ++ p = NULL; ++ break; ++ } ++ if (p && p->right) ++ { ++ p = p->right; ++ break; ++ } ++ } ++ } ++ } ++ ++ return ASN1_SUCCESS; ++} ++ ++ ++/******************************************************************/ ++/* Function : _asn1_set_default_tag */ ++/* Description: sets the default IMPLICIT or EXPLICIT property in */ ++/* the tagged elements that don't have this declaration. */ ++/* Parameters: */ ++/* node: pointer to a DEFINITIONS element. */ ++/* Return: */ ++/* ASN1_ELEMENT_NOT_FOUND if NODE is NULL or not a pointer to */ ++/* a DEFINITIONS element, */ ++/* otherwise ASN1_SUCCESS */ ++/******************************************************************/ ++int ++_asn1_set_default_tag (asn1_node node) ++{ ++ asn1_node p; ++ ++ if ((node == NULL) || (type_field (node->type) != ASN1_ETYPE_DEFINITIONS)) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ p = node; ++ while (p) ++ { ++ if ((type_field (p->type) == ASN1_ETYPE_TAG) && ++ !(p->type & CONST_EXPLICIT) && !(p->type & CONST_IMPLICIT)) ++ { ++ if (node->type & CONST_EXPLICIT) ++ p->type |= CONST_EXPLICIT; ++ else ++ p->type |= CONST_IMPLICIT; ++ } ++ ++ if (p->down) ++ { ++ p = p->down; ++ } ++ else if (p->right) ++ p = p->right; ++ else ++ { ++ while (1) ++ { ++ p = _asn1_find_up (p); ++ if (p == node) ++ { ++ p = NULL; ++ break; ++ } ++ if (p && p->right) ++ { ++ p = p->right; ++ break; ++ } ++ } ++ } ++ } ++ ++ return ASN1_SUCCESS; ++} +diff --git a/grub-core/lib/libtasn1/lib/structure.c b/grub-core/lib/libtasn1/lib/structure.c +new file mode 100644 +index 00000000000..8189c56a4c9 +--- /dev/null ++++ b/grub-core/lib/libtasn1/lib/structure.c +@@ -0,0 +1,1220 @@ ++/* ++ * Copyright (C) 2002-2014 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * The LIBTASN1 library is free software; you can redistribute it ++ * and/or modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ++ * 02110-1301, USA ++ */ ++ ++ ++/*****************************************************/ ++/* File: structure.c */ ++/* Description: Functions to create and delete an */ ++/* ASN1 tree. */ ++/*****************************************************/ ++ ++ ++#include ++#include ++#include "parser_aux.h" ++#include ++ ++ ++extern char _asn1_identifierMissing[]; ++ ++ ++/******************************************************/ ++/* Function : _asn1_add_single_node */ ++/* Description: creates a new NODE_ASN element. */ ++/* Parameters: */ ++/* type: type of the new element (see ASN1_ETYPE_ */ ++/* and CONST_ constants). */ ++/* Return: pointer to the new element. */ ++/******************************************************/ ++asn1_node ++_asn1_add_single_node (unsigned int type) ++{ ++ asn1_node punt; ++ ++ punt = calloc (1, sizeof (struct asn1_node_st)); ++ if (punt == NULL) ++ return NULL; ++ ++ punt->type = type; ++ ++ return punt; ++} ++ ++ ++/******************************************************************/ ++/* Function : _asn1_find_left */ ++/* Description: returns the NODE_ASN element with RIGHT field that*/ ++/* points the element NODE. */ ++/* Parameters: */ ++/* node: NODE_ASN element pointer. */ ++/* Return: NULL if not found. */ ++/******************************************************************/ ++asn1_node ++_asn1_find_left (asn1_node_const node) ++{ ++ if ((node == NULL) || (node->left == NULL) || (node->left->down == node)) ++ return NULL; ++ ++ return node->left; ++} ++ ++ ++int ++_asn1_create_static_structure (asn1_node_const pointer, char *output_file_name, ++ char *vector_name) ++{ ++ FILE *file; ++ asn1_node_const p; ++ unsigned long t; ++ ++ file = fopen (output_file_name, "w"); ++ ++ if (file == NULL) ++ return ASN1_FILE_NOT_FOUND; ++ ++ fprintf (file, "#if HAVE_CONFIG_H\n"); ++ fprintf (file, "# include \"config.h\"\n"); ++ fprintf (file, "#endif\n\n"); ++ ++ fprintf (file, "#include \n\n"); ++ ++ fprintf (file, "const asn1_static_node %s[] = {\n", vector_name); ++ ++ p = pointer; ++ ++ while (p) ++ { ++ fprintf (file, " { "); ++ ++ if (p->name[0] != 0) ++ fprintf (file, "\"%s\", ", p->name); ++ else ++ fprintf (file, "NULL, "); ++ ++ t = p->type; ++ if (p->down) ++ t |= CONST_DOWN; ++ if (p->right) ++ t |= CONST_RIGHT; ++ ++ fprintf (file, "%lu, ", t); ++ ++ if (p->value) ++ fprintf (file, "\"%s\"},\n", p->value); ++ else ++ fprintf (file, "NULL },\n"); ++ ++ if (p->down) ++ { ++ p = p->down; ++ } ++ else if (p->right) ++ { ++ p = p->right; ++ } ++ else ++ { ++ while (1) ++ { ++ p = _asn1_find_up (p); ++ if (p == pointer) ++ { ++ p = NULL; ++ break; ++ } ++ if (p->right) ++ { ++ p = p->right; ++ break; ++ } ++ } ++ } ++ } ++ ++ fprintf (file, " { NULL, 0, NULL }\n};\n"); ++ ++ fclose (file); ++ ++ return ASN1_SUCCESS; ++} ++ ++ ++/** ++ * asn1_array2tree: ++ * @array: specify the array that contains ASN.1 declarations ++ * @definitions: return the pointer to the structure created by ++ * *ARRAY ASN.1 declarations ++ * @errorDescription: return the error description. ++ * ++ * Creates the structures needed to manage the ASN.1 definitions. ++ * @array is a vector created by asn1_parser2array(). ++ * ++ * Returns: %ASN1_SUCCESS if structure was created correctly, ++ * %ASN1_ELEMENT_NOT_EMPTY if *@definitions not NULL, ++ * %ASN1_IDENTIFIER_NOT_FOUND if in the file there is an identifier ++ * that is not defined (see @errorDescription for more information), ++ * %ASN1_ARRAY_ERROR if the array pointed by @array is wrong. ++ **/ ++int ++asn1_array2tree (const asn1_static_node * array, asn1_node * definitions, ++ char *errorDescription) ++{ ++ asn1_node p, p_last = NULL; ++ unsigned long k; ++ int move; ++ int result; ++ unsigned int type; ++ list_type *e_list = NULL; ++ ++ if (errorDescription) ++ errorDescription[0] = 0; ++ ++ if (*definitions != NULL) ++ return ASN1_ELEMENT_NOT_EMPTY; ++ ++ move = UP; ++ ++ for (k = 0; array[k].value || array[k].type || array[k].name; k++) ++ { ++ type = convert_old_type (array[k].type); ++ ++ p = _asn1_add_static_node (&e_list, type & (~CONST_DOWN)); ++ if (array[k].name) ++ _asn1_set_name (p, array[k].name); ++ if (array[k].value) ++ _asn1_set_value (p, array[k].value, strlen (array[k].value) + 1); ++ ++ if (*definitions == NULL) ++ *definitions = p; ++ ++ if (move == DOWN) ++ { ++ if (p_last && p_last->down) ++ _asn1_delete_structure (e_list, &p_last->down, 0); ++ _asn1_set_down (p_last, p); ++ } ++ else if (move == RIGHT) ++ { ++ if (p_last && p_last->right) ++ _asn1_delete_structure (e_list, &p_last->right, 0); ++ _asn1_set_right (p_last, p); ++ } ++ ++ p_last = p; ++ ++ if (type & CONST_DOWN) ++ move = DOWN; ++ else if (type & CONST_RIGHT) ++ move = RIGHT; ++ else ++ { ++ while (p_last != *definitions) ++ { ++ p_last = _asn1_find_up (p_last); ++ ++ if (p_last == NULL) ++ break; ++ ++ if (p_last->type & CONST_RIGHT) ++ { ++ p_last->type &= ~CONST_RIGHT; ++ move = RIGHT; ++ break; ++ } ++ } /* while */ ++ } ++ } /* while */ ++ ++ if (p_last == *definitions) ++ { ++ result = _asn1_check_identifier (*definitions); ++ if (result == ASN1_SUCCESS) ++ { ++ _asn1_change_integer_value (*definitions); ++ result = _asn1_expand_object_id (&e_list, *definitions); ++ } ++ } ++ else ++ { ++ result = ASN1_ARRAY_ERROR; ++ } ++ ++ if (errorDescription != NULL) ++ { ++ if (result == ASN1_IDENTIFIER_NOT_FOUND) ++ { ++ Estrcpy (errorDescription, ":: identifier '"); ++ Estrcat (errorDescription, _asn1_identifierMissing); ++ Estrcat (errorDescription, "' not found"); ++ } ++ else ++ errorDescription[0] = 0; ++ } ++ ++ if (result != ASN1_SUCCESS) ++ { ++ _asn1_delete_list_and_nodes (e_list); ++ *definitions = NULL; ++ } ++ else ++ _asn1_delete_list (e_list); ++ ++ return result; ++} ++ ++/** ++ * asn1_delete_structure: ++ * @structure: pointer to the structure that you want to delete. ++ * ++ * Deletes the structure *@structure. At the end, *@structure is set ++ * to NULL. ++ * ++ * Returns: %ASN1_SUCCESS if successful, %ASN1_ELEMENT_NOT_FOUND if ++ * *@structure was NULL. ++ **/ ++int ++asn1_delete_structure (asn1_node * structure) ++{ ++ return _asn1_delete_structure (NULL, structure, 0); ++} ++ ++/** ++ * asn1_delete_structure2: ++ * @structure: pointer to the structure that you want to delete. ++ * @flags: additional flags (see %ASN1_DELETE_FLAG) ++ * ++ * Deletes the structure *@structure. At the end, *@structure is set ++ * to NULL. ++ * ++ * Returns: %ASN1_SUCCESS if successful, %ASN1_ELEMENT_NOT_FOUND if ++ * *@structure was NULL. ++ **/ ++int ++asn1_delete_structure2 (asn1_node * structure, unsigned int flags) ++{ ++ return _asn1_delete_structure (NULL, structure, flags); ++} ++ ++int ++_asn1_delete_structure (list_type *e_list, asn1_node * structure, unsigned int flags) ++{ ++ asn1_node p, p2, p3; ++ ++ if (*structure == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ p = *structure; ++ while (p) ++ { ++ if (p->down) ++ { ++ p = p->down; ++ } ++ else ++ { /* no down */ ++ p2 = p->right; ++ if (p != *structure) ++ { ++ p3 = _asn1_find_up (p); ++ _asn1_set_down (p3, p2); ++ if (e_list) ++ _asn1_delete_node_from_list (e_list, p); ++ _asn1_remove_node (p, flags); ++ p = p3; ++ } ++ else ++ { /* p==root */ ++ p3 = _asn1_find_left (p); ++ if (!p3) ++ { ++ p3 = _asn1_find_up (p); ++ if (p3) ++ _asn1_set_down (p3, p2); ++ else ++ { ++ if (p->right) ++ p->right->left = NULL; ++ } ++ } ++ else ++ _asn1_set_right (p3, p2); ++ if (e_list) ++ _asn1_delete_node_from_list (e_list, p); ++ _asn1_remove_node (p, flags); ++ p = NULL; ++ } ++ } ++ } ++ ++ *structure = NULL; ++ return ASN1_SUCCESS; ++} ++ ++ ++/** ++ * asn1_delete_element: ++ * @structure: pointer to the structure that contains the element you ++ * want to delete. ++ * @element_name: element's name you want to delete. ++ * ++ * Deletes the element named *@element_name inside *@structure. ++ * ++ * Returns: %ASN1_SUCCESS if successful, %ASN1_ELEMENT_NOT_FOUND if ++ * the @element_name was not found. ++ **/ ++int ++asn1_delete_element (asn1_node structure, const char *element_name) ++{ ++ asn1_node p2, p3, source_node; ++ ++ source_node = asn1_find_node (structure, element_name); ++ ++ if (source_node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ p2 = source_node->right; ++ p3 = _asn1_find_left (source_node); ++ if (!p3) ++ { ++ p3 = _asn1_find_up (source_node); ++ if (p3) ++ _asn1_set_down (p3, p2); ++ else if (source_node->right) ++ source_node->right->left = NULL; ++ } ++ else ++ _asn1_set_right (p3, p2); ++ ++ return asn1_delete_structure (&source_node); ++} ++ ++#ifndef __clang_analyzer__ ++asn1_node ++_asn1_copy_structure3 (asn1_node_const source_node) ++{ ++ asn1_node_const p_s; ++ asn1_node dest_node, p_d, p_d_prev; ++ int move; ++ ++ if (source_node == NULL) ++ return NULL; ++ ++ dest_node = _asn1_add_single_node (source_node->type); ++ ++ p_s = source_node; ++ p_d = dest_node; ++ ++ move = DOWN; ++ ++ do ++ { ++ if (move != UP) ++ { ++ if (p_s->name[0] != 0) ++ _asn1_cpy_name (p_d, p_s); ++ if (p_s->value) ++ _asn1_set_value (p_d, p_s->value, p_s->value_len); ++ if (p_s->down) ++ { ++ p_s = p_s->down; ++ p_d_prev = p_d; ++ p_d = _asn1_add_single_node (p_s->type); ++ _asn1_set_down (p_d_prev, p_d); ++ continue; ++ } ++ p_d->start = p_s->start; ++ p_d->end = p_s->end; ++ } ++ ++ if (p_s == source_node) ++ break; ++ ++ if (p_s->right) ++ { ++ move = RIGHT; ++ p_s = p_s->right; ++ p_d_prev = p_d; ++ p_d = _asn1_add_single_node (p_s->type); ++ _asn1_set_right (p_d_prev, p_d); ++ } ++ else ++ { ++ move = UP; ++ p_s = _asn1_find_up (p_s); ++ p_d = _asn1_find_up (p_d); ++ } ++ } ++ while (p_s != source_node); ++ return dest_node; ++} ++#else ++ ++/* Non-production code */ ++asn1_node ++_asn1_copy_structure3 (asn1_node_const source_node) ++{ ++ return NULL; ++} ++#endif /* __clang_analyzer__ */ ++ ++ ++static asn1_node ++_asn1_copy_structure2 (asn1_node_const root, const char *source_name) ++{ ++ asn1_node source_node; ++ ++ source_node = asn1_find_node (root, source_name); ++ ++ return _asn1_copy_structure3 (source_node); ++ ++} ++ ++ ++static int ++_asn1_type_choice_config (asn1_node node) ++{ ++ asn1_node p, p2, p3, p4; ++ int move, tlen; ++ ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ p = node; ++ move = DOWN; ++ ++ while (!((p == node) && (move == UP))) ++ { ++ if (move != UP) ++ { ++ if ((type_field (p->type) == ASN1_ETYPE_CHOICE) ++ && (p->type & CONST_TAG)) ++ { ++ p2 = p->down; ++ while (p2) ++ { ++ if (type_field (p2->type) != ASN1_ETYPE_TAG) ++ { ++ p2->type |= CONST_TAG; ++ p3 = _asn1_find_left (p2); ++ while (p3) ++ { ++ if (type_field (p3->type) == ASN1_ETYPE_TAG) ++ { ++ p4 = _asn1_add_single_node (p3->type); ++ tlen = _asn1_strlen (p3->value); ++ if (tlen > 0) ++ _asn1_set_value (p4, p3->value, tlen + 1); ++ _asn1_set_right (p4, p2->down); ++ _asn1_set_down (p2, p4); ++ } ++ p3 = _asn1_find_left (p3); ++ } ++ } ++ p2 = p2->right; ++ } ++ p->type &= ~(CONST_TAG); ++ p2 = p->down; ++ while (p2) ++ { ++ p3 = p2->right; ++ if (type_field (p2->type) == ASN1_ETYPE_TAG) ++ asn1_delete_structure (&p2); ++ p2 = p3; ++ } ++ } ++ move = DOWN; ++ } ++ else ++ move = RIGHT; ++ ++ if (move == DOWN) ++ { ++ if (p->down) ++ p = p->down; ++ else ++ move = RIGHT; ++ } ++ ++ if (p == node) ++ { ++ move = UP; ++ continue; ++ } ++ ++ if (move == RIGHT) ++ { ++ if (p->right) ++ p = p->right; ++ else ++ move = UP; ++ } ++ if (move == UP) ++ p = _asn1_find_up (p); ++ } ++ ++ return ASN1_SUCCESS; ++} ++ ++ ++static int ++_asn1_expand_identifier (asn1_node * node, asn1_node_const root) ++{ ++ asn1_node p, p2, p3; ++ char name2[ASN1_MAX_NAME_SIZE + 2]; ++ int move; ++ ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ p = *node; ++ move = DOWN; ++ ++ while (!((p == *node) && (move == UP))) ++ { ++ if (move != UP) ++ { ++ if (type_field (p->type) == ASN1_ETYPE_IDENTIFIER) ++ { ++ snprintf (name2, sizeof (name2), "%s.%s", root->name, p->value); ++ p2 = _asn1_copy_structure2 (root, name2); ++ if (p2 == NULL) ++ { ++ return ASN1_IDENTIFIER_NOT_FOUND; ++ } ++ _asn1_cpy_name (p2, p); ++ p2->right = p->right; ++ p2->left = p->left; ++ if (p->right) ++ p->right->left = p2; ++ p3 = p->down; ++ if (p3) ++ { ++ while (p3->right) ++ p3 = p3->right; ++ _asn1_set_right (p3, p2->down); ++ _asn1_set_down (p2, p->down); ++ } ++ ++ p3 = _asn1_find_left (p); ++ if (p3) ++ _asn1_set_right (p3, p2); ++ else ++ { ++ p3 = _asn1_find_up (p); ++ if (p3) ++ _asn1_set_down (p3, p2); ++ else ++ { ++ p2->left = NULL; ++ } ++ } ++ ++ if (p->type & CONST_SIZE) ++ p2->type |= CONST_SIZE; ++ if (p->type & CONST_TAG) ++ p2->type |= CONST_TAG; ++ if (p->type & CONST_OPTION) ++ p2->type |= CONST_OPTION; ++ if (p->type & CONST_DEFAULT) ++ p2->type |= CONST_DEFAULT; ++ if (p->type & CONST_SET) ++ p2->type |= CONST_SET; ++ if (p->type & CONST_NOT_USED) ++ p2->type |= CONST_NOT_USED; ++ ++ if (p == *node) ++ *node = p2; ++ _asn1_remove_node (p, 0); ++ p = p2; ++ move = DOWN; ++ continue; ++ } ++ move = DOWN; ++ } ++ else ++ move = RIGHT; ++ ++ if (move == DOWN) ++ { ++ if (p->down) ++ p = p->down; ++ else ++ move = RIGHT; ++ } ++ ++ if (p == *node) ++ { ++ move = UP; ++ continue; ++ } ++ ++ if (move == RIGHT) ++ { ++ if (p->right) ++ p = p->right; ++ else ++ move = UP; ++ } ++ if (move == UP) ++ p = _asn1_find_up (p); ++ } ++ ++ return ASN1_SUCCESS; ++} ++ ++ ++/** ++ * asn1_create_element: ++ * @definitions: pointer to the structure returned by "parser_asn1" function ++ * @source_name: the name of the type of the new structure (must be ++ * inside p_structure). ++ * @element: pointer to the structure created. ++ * ++ * Creates a structure of type @source_name. Example using ++ * "pkix.asn": ++ * ++ * rc = asn1_create_element(cert_def, "PKIX1.Certificate", certptr); ++ * ++ * Returns: %ASN1_SUCCESS if creation OK, %ASN1_ELEMENT_NOT_FOUND if ++ * @source_name is not known. ++ **/ ++int ++asn1_create_element (asn1_node_const definitions, const char *source_name, ++ asn1_node * element) ++{ ++ asn1_node dest_node; ++ int res; ++ ++ dest_node = _asn1_copy_structure2 (definitions, source_name); ++ ++ if (dest_node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ _asn1_set_name (dest_node, ""); ++ ++ res = _asn1_expand_identifier (&dest_node, definitions); ++ _asn1_type_choice_config (dest_node); ++ ++ *element = dest_node; ++ ++ return res; ++} ++ ++ ++/** ++ * asn1_print_structure: ++ * @out: pointer to the output file (e.g. stdout). ++ * @structure: pointer to the structure that you want to visit. ++ * @name: an element of the structure ++ * @mode: specify how much of the structure to print, can be ++ * %ASN1_PRINT_NAME, %ASN1_PRINT_NAME_TYPE, ++ * %ASN1_PRINT_NAME_TYPE_VALUE, or %ASN1_PRINT_ALL. ++ * ++ * Prints on the @out file descriptor the structure's tree starting ++ * from the @name element inside the structure @structure. ++ **/ ++void ++asn1_print_structure (FILE * out, asn1_node_const structure, const char *name, ++ int mode) ++{ ++ asn1_node_const p, root; ++ int k, indent = 0, len, len2, len3; ++ ++ if (out == NULL) ++ return; ++ ++ root = asn1_find_node (structure, name); ++ ++ if (root == NULL) ++ return; ++ ++ p = root; ++ while (p) ++ { ++ if (mode == ASN1_PRINT_ALL) ++ { ++ for (k = 0; k < indent; k++) ++ fprintf (out, " "); ++ fprintf (out, "name:"); ++ if (p->name[0] != 0) ++ fprintf (out, "%s ", p->name); ++ else ++ fprintf (out, "NULL "); ++ } ++ else ++ { ++ switch (type_field (p->type)) ++ { ++ case ASN1_ETYPE_CONSTANT: ++ case ASN1_ETYPE_TAG: ++ case ASN1_ETYPE_SIZE: ++ break; ++ default: ++ for (k = 0; k < indent; k++) ++ fprintf (out, " "); ++ fprintf (out, "name:"); ++ if (p->name[0] != 0) ++ fprintf (out, "%s ", p->name); ++ else ++ fprintf (out, "NULL "); ++ } ++ } ++ ++ if (mode != ASN1_PRINT_NAME) ++ { ++ unsigned type = type_field (p->type); ++ switch (type) ++ { ++ case ASN1_ETYPE_CONSTANT: ++ if (mode == ASN1_PRINT_ALL) ++ fprintf (out, "type:CONST"); ++ break; ++ case ASN1_ETYPE_TAG: ++ if (mode == ASN1_PRINT_ALL) ++ fprintf (out, "type:TAG"); ++ break; ++ case ASN1_ETYPE_SIZE: ++ if (mode == ASN1_PRINT_ALL) ++ fprintf (out, "type:SIZE"); ++ break; ++ case ASN1_ETYPE_DEFAULT: ++ fprintf (out, "type:DEFAULT"); ++ break; ++ case ASN1_ETYPE_IDENTIFIER: ++ fprintf (out, "type:IDENTIFIER"); ++ break; ++ case ASN1_ETYPE_ANY: ++ fprintf (out, "type:ANY"); ++ break; ++ case ASN1_ETYPE_CHOICE: ++ fprintf (out, "type:CHOICE"); ++ break; ++ case ASN1_ETYPE_DEFINITIONS: ++ fprintf (out, "type:DEFINITIONS"); ++ break; ++ CASE_HANDLED_ETYPES: ++ fprintf (out, "%s", _asn1_tags[type].desc); ++ break; ++ default: ++ break; ++ } ++ } ++ ++ if ((mode == ASN1_PRINT_NAME_TYPE_VALUE) || (mode == ASN1_PRINT_ALL)) ++ { ++ switch (type_field (p->type)) ++ { ++ case ASN1_ETYPE_CONSTANT: ++ if (mode == ASN1_PRINT_ALL) ++ if (p->value) ++ fprintf (out, " value:%s", p->value); ++ break; ++ case ASN1_ETYPE_TAG: ++ if (mode == ASN1_PRINT_ALL) ++ if (p->value) ++ fprintf (out, " value:%s", p->value); ++ break; ++ case ASN1_ETYPE_SIZE: ++ if (mode == ASN1_PRINT_ALL) ++ if (p->value) ++ fprintf (out, " value:%s", p->value); ++ break; ++ case ASN1_ETYPE_DEFAULT: ++ if (p->value) ++ fprintf (out, " value:%s", p->value); ++ else if (p->type & CONST_TRUE) ++ fprintf (out, " value:TRUE"); ++ else if (p->type & CONST_FALSE) ++ fprintf (out, " value:FALSE"); ++ break; ++ case ASN1_ETYPE_IDENTIFIER: ++ if (p->value) ++ fprintf (out, " value:%s", p->value); ++ break; ++ case ASN1_ETYPE_INTEGER: ++ if (p->value) ++ { ++ len2 = -1; ++ len = asn1_get_length_der (p->value, p->value_len, &len2); ++ fprintf (out, " value:0x"); ++ if (len > 0) ++ for (k = 0; k < len; k++) ++ fprintf (out, "%02x", (unsigned) (p->value)[k + len2]); ++ } ++ break; ++ case ASN1_ETYPE_ENUMERATED: ++ if (p->value) ++ { ++ len2 = -1; ++ len = asn1_get_length_der (p->value, p->value_len, &len2); ++ fprintf (out, " value:0x"); ++ if (len > 0) ++ for (k = 0; k < len; k++) ++ fprintf (out, "%02x", (unsigned) (p->value)[k + len2]); ++ } ++ break; ++ case ASN1_ETYPE_BOOLEAN: ++ if (p->value) ++ { ++ if (p->value[0] == 'T') ++ fprintf (out, " value:TRUE"); ++ else if (p->value[0] == 'F') ++ fprintf (out, " value:FALSE"); ++ } ++ break; ++ case ASN1_ETYPE_BIT_STRING: ++ if (p->value) ++ { ++ len2 = -1; ++ len = asn1_get_length_der (p->value, p->value_len, &len2); ++ if (len > 0) ++ { ++ fprintf (out, " value(%i):", ++ (len - 1) * 8 - (p->value[len2])); ++ for (k = 1; k < len; k++) ++ fprintf (out, "%02x", (unsigned) (p->value)[k + len2]); ++ } ++ } ++ break; ++ case ASN1_ETYPE_GENERALIZED_TIME: ++ case ASN1_ETYPE_UTC_TIME: ++ if (p->value) ++ { ++ fprintf (out, " value:"); ++ for (k = 0; k < p->value_len; k++) ++ fprintf (out, "%c", (p->value)[k]); ++ } ++ break; ++ case ASN1_ETYPE_GENERALSTRING: ++ case ASN1_ETYPE_NUMERIC_STRING: ++ case ASN1_ETYPE_IA5_STRING: ++ case ASN1_ETYPE_TELETEX_STRING: ++ case ASN1_ETYPE_PRINTABLE_STRING: ++ case ASN1_ETYPE_UNIVERSAL_STRING: ++ case ASN1_ETYPE_UTF8_STRING: ++ case ASN1_ETYPE_VISIBLE_STRING: ++ if (p->value) ++ { ++ len2 = -1; ++ len = asn1_get_length_der (p->value, p->value_len, &len2); ++ fprintf (out, " value:"); ++ if (len > 0) ++ for (k = 0; k < len; k++) ++ fprintf (out, "%c", (p->value)[k + len2]); ++ } ++ break; ++ case ASN1_ETYPE_BMP_STRING: ++ case ASN1_ETYPE_OCTET_STRING: ++ if (p->value) ++ { ++ len2 = -1; ++ len = asn1_get_length_der (p->value, p->value_len, &len2); ++ fprintf (out, " value:"); ++ if (len > 0) ++ for (k = 0; k < len; k++) ++ fprintf (out, "%02x", (unsigned) (p->value)[k + len2]); ++ } ++ break; ++ case ASN1_ETYPE_OBJECT_ID: ++ if (p->value) ++ fprintf (out, " value:%s", p->value); ++ break; ++ case ASN1_ETYPE_ANY: ++ if (p->value) ++ { ++ len3 = -1; ++ len2 = asn1_get_length_der (p->value, p->value_len, &len3); ++ fprintf (out, " value:"); ++ if (len2 > 0) ++ for (k = 0; k < len2; k++) ++ fprintf (out, "%02x", (unsigned) (p->value)[k + len3]); ++ } ++ break; ++ case ASN1_ETYPE_SET: ++ case ASN1_ETYPE_SET_OF: ++ case ASN1_ETYPE_CHOICE: ++ case ASN1_ETYPE_DEFINITIONS: ++ case ASN1_ETYPE_SEQUENCE_OF: ++ case ASN1_ETYPE_SEQUENCE: ++ case ASN1_ETYPE_NULL: ++ break; ++ default: ++ break; ++ } ++ } ++ ++ if (mode == ASN1_PRINT_ALL) ++ { ++ if (p->type & 0x1FFFFF00) ++ { ++ fprintf (out, " attr:"); ++ if (p->type & CONST_UNIVERSAL) ++ fprintf (out, "UNIVERSAL,"); ++ if (p->type & CONST_PRIVATE) ++ fprintf (out, "PRIVATE,"); ++ if (p->type & CONST_APPLICATION) ++ fprintf (out, "APPLICATION,"); ++ if (p->type & CONST_EXPLICIT) ++ fprintf (out, "EXPLICIT,"); ++ if (p->type & CONST_IMPLICIT) ++ fprintf (out, "IMPLICIT,"); ++ if (p->type & CONST_TAG) ++ fprintf (out, "TAG,"); ++ if (p->type & CONST_DEFAULT) ++ fprintf (out, "DEFAULT,"); ++ if (p->type & CONST_TRUE) ++ fprintf (out, "TRUE,"); ++ if (p->type & CONST_FALSE) ++ fprintf (out, "FALSE,"); ++ if (p->type & CONST_LIST) ++ fprintf (out, "LIST,"); ++ if (p->type & CONST_MIN_MAX) ++ fprintf (out, "MIN_MAX,"); ++ if (p->type & CONST_OPTION) ++ fprintf (out, "OPTION,"); ++ if (p->type & CONST_1_PARAM) ++ fprintf (out, "1_PARAM,"); ++ if (p->type & CONST_SIZE) ++ fprintf (out, "SIZE,"); ++ if (p->type & CONST_DEFINED_BY) ++ fprintf (out, "DEF_BY,"); ++ if (p->type & CONST_GENERALIZED) ++ fprintf (out, "GENERALIZED,"); ++ if (p->type & CONST_UTC) ++ fprintf (out, "UTC,"); ++ if (p->type & CONST_SET) ++ fprintf (out, "SET,"); ++ if (p->type & CONST_NOT_USED) ++ fprintf (out, "NOT_USED,"); ++ if (p->type & CONST_ASSIGN) ++ fprintf (out, "ASSIGNMENT,"); ++ } ++ } ++ ++ if (mode == ASN1_PRINT_ALL) ++ { ++ fprintf (out, "\n"); ++ } ++ else ++ { ++ switch (type_field (p->type)) ++ { ++ case ASN1_ETYPE_CONSTANT: ++ case ASN1_ETYPE_TAG: ++ case ASN1_ETYPE_SIZE: ++ break; ++ default: ++ fprintf (out, "\n"); ++ } ++ } ++ ++ if (p->down) ++ { ++ p = p->down; ++ indent += 2; ++ } ++ else if (p == root) ++ { ++ p = NULL; ++ break; ++ } ++ else if (p->right) ++ p = p->right; ++ else ++ { ++ while (1) ++ { ++ p = _asn1_find_up (p); ++ if (p == root) ++ { ++ p = NULL; ++ break; ++ } ++ indent -= 2; ++ if (p->right) ++ { ++ p = p->right; ++ break; ++ } ++ } ++ } ++ } ++} ++ ++ ++ ++/** ++ * asn1_number_of_elements: ++ * @element: pointer to the root of an ASN1 structure. ++ * @name: the name of a sub-structure of ROOT. ++ * @num: pointer to an integer where the result will be stored ++ * ++ * Counts the number of elements of a sub-structure called NAME with ++ * names equal to "?1","?2", ... ++ * ++ * Returns: %ASN1_SUCCESS if successful, %ASN1_ELEMENT_NOT_FOUND if ++ * @name is not known, %ASN1_GENERIC_ERROR if pointer @num is %NULL. ++ **/ ++int ++asn1_number_of_elements (asn1_node_const element, const char *name, int *num) ++{ ++ asn1_node_const node, p; ++ ++ if (num == NULL) ++ return ASN1_GENERIC_ERROR; ++ ++ *num = 0; ++ ++ node = asn1_find_node (element, name); ++ if (node == NULL) ++ return ASN1_ELEMENT_NOT_FOUND; ++ ++ p = node->down; ++ ++ while (p) ++ { ++ if (p->name[0] == '?') ++ (*num)++; ++ p = p->right; ++ } ++ ++ return ASN1_SUCCESS; ++} ++ ++ ++/** ++ * asn1_find_structure_from_oid: ++ * @definitions: ASN1 definitions ++ * @oidValue: value of the OID to search (e.g. "1.2.3.4"). ++ * ++ * Search the structure that is defined just after an OID definition. ++ * ++ * Returns: %NULL when @oidValue not found, otherwise the pointer to a ++ * constant string that contains the element name defined just after ++ * the OID. ++ **/ ++const char * ++asn1_find_structure_from_oid (asn1_node_const definitions, const char *oidValue) ++{ ++ char name[2 * ASN1_MAX_NAME_SIZE + 2]; ++ char value[ASN1_MAX_NAME_SIZE]; ++ asn1_node p; ++ int len; ++ int result; ++ const char *definitionsName; ++ ++ if ((definitions == NULL) || (oidValue == NULL)) ++ return NULL; /* ASN1_ELEMENT_NOT_FOUND; */ ++ ++ definitionsName = definitions->name; ++ ++ /* search the OBJECT_ID into definitions */ ++ p = definitions->down; ++ while (p) ++ { ++ if ((type_field (p->type) == ASN1_ETYPE_OBJECT_ID) && ++ (p->type & CONST_ASSIGN)) ++ { ++ snprintf(name, sizeof(name), "%s.%s", definitionsName, p->name); ++ ++ len = ASN1_MAX_NAME_SIZE; ++ result = asn1_read_value (definitions, name, value, &len); ++ ++ if ((result == ASN1_SUCCESS) && (!strcmp (oidValue, value))) ++ { ++ p = p->right; ++ if (p == NULL) /* reach the end of ASN1 definitions */ ++ return NULL; /* ASN1_ELEMENT_NOT_FOUND; */ ++ ++ return p->name; ++ } ++ } ++ p = p->right; ++ } ++ ++ return NULL; /* ASN1_ELEMENT_NOT_FOUND; */ ++} ++ ++/** ++ * asn1_copy_node: ++ * @dst: Destination asn1 node. ++ * @dst_name: Field name in destination node. ++ * @src: Source asn1 node. ++ * @src_name: Field name in source node. ++ * ++ * Create a deep copy of a asn1_node variable. That ++ * function requires @dst to be expanded using asn1_create_element(). ++ * ++ * Returns: Return %ASN1_SUCCESS on success. ++ **/ ++int ++asn1_copy_node (asn1_node dst, const char *dst_name, ++ asn1_node_const src, const char *src_name) ++{ ++ int result; ++ asn1_node dst_node; ++ void *data = NULL; ++ int size = 0; ++ ++ result = asn1_der_coding (src, src_name, NULL, &size, NULL); ++ if (result != ASN1_MEM_ERROR) ++ return result; ++ ++ data = malloc (size); ++ if (data == NULL) ++ return ASN1_MEM_ERROR; ++ ++ result = asn1_der_coding (src, src_name, data, &size, NULL); ++ if (result != ASN1_SUCCESS) ++ { ++ free (data); ++ return result; ++ } ++ ++ dst_node = asn1_find_node (dst, dst_name); ++ if (dst_node == NULL) ++ { ++ free (data); ++ return ASN1_ELEMENT_NOT_FOUND; ++ } ++ ++ result = asn1_der_decoding (&dst_node, data, size, NULL); ++ ++ free (data); ++ ++ return result; ++} ++ ++/** ++ * asn1_dup_node: ++ * @src: Source asn1 node. ++ * @src_name: Field name in source node. ++ * ++ * Create a deep copy of a asn1_node variable. This function ++ * will return an exact copy of the provided structure. ++ * ++ * Returns: Return %NULL on failure. ++ **/ ++asn1_node ++asn1_dup_node (asn1_node_const src, const char *src_name) ++{ ++ return _asn1_copy_structure2(src, src_name); ++} +diff --git a/grub-core/lib/libtasn1/lib/element.h b/grub-core/lib/libtasn1/lib/element.h +new file mode 100644 +index 00000000000..440a33f4bb1 +--- /dev/null ++++ b/grub-core/lib/libtasn1/lib/element.h +@@ -0,0 +1,40 @@ ++/* ++ * Copyright (C) 2000-2014 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * The LIBTASN1 library is free software; you can redistribute it ++ * and/or modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ++ * 02110-1301, USA ++ */ ++ ++#ifndef _ELEMENT_H ++#define _ELEMENT_H ++ ++ ++struct node_tail_cache_st ++{ ++ asn1_node head; /* the first element of the sequence */ ++ asn1_node tail; ++}; ++ ++int _asn1_append_sequence_set (asn1_node node, struct node_tail_cache_st *pcached); ++ ++int _asn1_convert_integer (const unsigned char *value, ++ unsigned char *value_out, ++ int value_out_size, int *len); ++ ++void _asn1_hierarchical_name (asn1_node_const node, char *name, int name_size); ++ ++#endif +diff --git a/grub-core/lib/libtasn1/lib/gstr.h b/grub-core/lib/libtasn1/lib/gstr.h +new file mode 100644 +index 00000000000..48229844ff3 +--- /dev/null ++++ b/grub-core/lib/libtasn1/lib/gstr.h +@@ -0,0 +1,47 @@ ++/* ++ * Copyright (C) 2002-2014 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * The LIBTASN1 library is free software; you can redistribute it ++ * and/or modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ++ * 02110-1301, USA ++ */ ++ ++#ifndef GSTR_H ++# define GSTR_H ++ ++unsigned int _asn1_str_cpy (char *dest, size_t dest_tot_size, ++ const char *src); ++void _asn1_str_cat (char *dest, size_t dest_tot_size, const char *src); ++ ++#define Estrcpy(x,y) _asn1_str_cpy(x,ASN1_MAX_ERROR_DESCRIPTION_SIZE,y) ++#define Estrcat(x,y) _asn1_str_cat(x,ASN1_MAX_ERROR_DESCRIPTION_SIZE,y) ++ ++inline static ++void safe_memset(void *data, int c, size_t size) ++{ ++ volatile unsigned volatile_zero = 0; ++ volatile char *vdata = (volatile char*)data; ++ ++ /* This is based on a nice trick for safe memset, ++ * sent by David Jacobson in the openssl-dev mailing list. ++ */ ++ ++ if (size > 0) do { ++ memset(data, c, size); ++ } while(vdata[volatile_zero] != c); ++} ++ ++#endif /* GSTR_H */ +diff --git a/grub-core/lib/libtasn1/lib/int.h b/grub-core/lib/libtasn1/lib/int.h +new file mode 100644 +index 00000000000..ea1625786c1 +--- /dev/null ++++ b/grub-core/lib/libtasn1/lib/int.h +@@ -0,0 +1,221 @@ ++/* ++ * Copyright (C) 2002-2014 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * The LIBTASN1 library is free software; you can redistribute it ++ * and/or modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ++ * 02110-1301, USA ++ */ ++ ++#ifndef INT_H ++#define INT_H ++ ++#ifdef HAVE_CONFIG_H ++#include ++#endif ++ ++#include ++#include ++#include ++#include ++ ++#ifdef HAVE_SYS_TYPES_H ++#include ++#endif ++ ++#include ++ ++#define ASN1_SMALL_VALUE_SIZE 16 ++ ++/* This structure is also in libtasn1.h, but then contains less ++ fields. You cannot make any modifications to these first fields ++ without breaking ABI. */ ++struct asn1_node_st ++{ ++ /* public fields: */ ++ char name[ASN1_MAX_NAME_SIZE + 1]; /* Node name */ ++ unsigned int name_hash; ++ unsigned int type; /* Node type */ ++ unsigned char *value; /* Node value */ ++ int value_len; ++ asn1_node down; /* Pointer to the son node */ ++ asn1_node right; /* Pointer to the brother node */ ++ asn1_node left; /* Pointer to the next list element */ ++ /* private fields: */ ++ unsigned char small_value[ASN1_SMALL_VALUE_SIZE]; /* For small values */ ++ ++ /* values used during decoding/coding */ ++ int tmp_ival; ++ unsigned start; /* the start of the DER sequence - if decoded */ ++ unsigned end; /* the end of the DER sequence - if decoded */ ++}; ++ ++typedef struct tag_and_class_st ++{ ++ unsigned tag; ++ unsigned class; ++ const char *desc; ++} tag_and_class_st; ++ ++/* the types that are handled in _asn1_tags */ ++#define CASE_HANDLED_ETYPES \ ++ case ASN1_ETYPE_NULL: \ ++ case ASN1_ETYPE_BOOLEAN: \ ++ case ASN1_ETYPE_INTEGER: \ ++ case ASN1_ETYPE_ENUMERATED: \ ++ case ASN1_ETYPE_OBJECT_ID: \ ++ case ASN1_ETYPE_OCTET_STRING: \ ++ case ASN1_ETYPE_GENERALSTRING: \ ++ case ASN1_ETYPE_NUMERIC_STRING: \ ++ case ASN1_ETYPE_IA5_STRING: \ ++ case ASN1_ETYPE_TELETEX_STRING: \ ++ case ASN1_ETYPE_PRINTABLE_STRING: \ ++ case ASN1_ETYPE_UNIVERSAL_STRING: \ ++ case ASN1_ETYPE_BMP_STRING: \ ++ case ASN1_ETYPE_UTF8_STRING: \ ++ case ASN1_ETYPE_VISIBLE_STRING: \ ++ case ASN1_ETYPE_BIT_STRING: \ ++ case ASN1_ETYPE_SEQUENCE: \ ++ case ASN1_ETYPE_SEQUENCE_OF: \ ++ case ASN1_ETYPE_SET: \ ++ case ASN1_ETYPE_UTC_TIME: \ ++ case ASN1_ETYPE_GENERALIZED_TIME: \ ++ case ASN1_ETYPE_SET_OF ++ ++#define ETYPE_TAG(etype) (_asn1_tags[etype].tag) ++#define ETYPE_CLASS(etype) (_asn1_tags[etype].class) ++#define ETYPE_OK(etype) (((etype) != ASN1_ETYPE_INVALID && \ ++ (etype) <= _asn1_tags_size && \ ++ _asn1_tags[(etype)].desc != NULL)?1:0) ++ ++#define ETYPE_IS_STRING(etype) ((etype == ASN1_ETYPE_GENERALSTRING || \ ++ etype == ASN1_ETYPE_NUMERIC_STRING || etype == ASN1_ETYPE_IA5_STRING || \ ++ etype == ASN1_ETYPE_TELETEX_STRING || etype == ASN1_ETYPE_PRINTABLE_STRING || \ ++ etype == ASN1_ETYPE_UNIVERSAL_STRING || etype == ASN1_ETYPE_BMP_STRING || \ ++ etype == ASN1_ETYPE_UTF8_STRING || etype == ASN1_ETYPE_VISIBLE_STRING || \ ++ etype == ASN1_ETYPE_OCTET_STRING)?1:0) ++ ++extern unsigned int _asn1_tags_size; ++extern const tag_and_class_st _asn1_tags[]; ++ ++#define _asn1_strlen(s) strlen((const char *) s) ++#define _asn1_strtol(n,e,b) strtol((const char *) n, e, b) ++#define _asn1_strtoul(n,e,b) strtoul((const char *) n, e, b) ++#define _asn1_strcmp(a,b) strcmp((const char *)a, (const char *)b) ++#define _asn1_strcpy(a,b) strcpy((char *)a, (const char *)b) ++#define _asn1_strcat(a,b) strcat((char *)a, (const char *)b) ++ ++#if SIZEOF_UNSIGNED_LONG_INT == 8 ++# define _asn1_strtou64(n,e,b) strtoul((const char *) n, e, b) ++#else ++# define _asn1_strtou64(n,e,b) strtoull((const char *) n, e, b) ++#endif ++ ++#define MAX_LOG_SIZE 1024 /* maximum number of characters of a log message */ ++ ++/* Define used for visiting trees. */ ++#define UP 1 ++#define RIGHT 2 ++#define DOWN 3 ++ ++/***********************************************************************/ ++/* List of constants to better specify the type of typedef asn1_node_st. */ ++/***********************************************************************/ ++/* Used with TYPE_TAG */ ++#define CONST_UNIVERSAL (1U<<8) ++#define CONST_PRIVATE (1U<<9) ++#define CONST_APPLICATION (1U<<10) ++#define CONST_EXPLICIT (1U<<11) ++#define CONST_IMPLICIT (1U<<12) ++ ++#define CONST_TAG (1U<<13) /* Used in ASN.1 assignement */ ++#define CONST_OPTION (1U<<14) ++#define CONST_DEFAULT (1U<<15) ++#define CONST_TRUE (1U<<16) ++#define CONST_FALSE (1U<<17) ++ ++#define CONST_LIST (1U<<18) /* Used with TYPE_INTEGER and TYPE_BIT_STRING */ ++#define CONST_MIN_MAX (1U<<19) ++ ++#define CONST_1_PARAM (1U<<20) ++ ++#define CONST_SIZE (1U<<21) ++ ++#define CONST_DEFINED_BY (1U<<22) ++ ++/* Those two are deprecated and used for backwards compatibility */ ++#define CONST_GENERALIZED (1U<<23) ++#define CONST_UTC (1U<<24) ++ ++/* #define CONST_IMPORTS (1U<<25) */ ++ ++#define CONST_NOT_USED (1U<<26) ++#define CONST_SET (1U<<27) ++#define CONST_ASSIGN (1U<<28) ++ ++#define CONST_DOWN (1U<<29) ++#define CONST_RIGHT (1U<<30) ++ ++ ++#define ASN1_ETYPE_TIME 17 ++/****************************************/ ++/* Returns the first 8 bits. */ ++/* Used with the field type of asn1_node_st */ ++/****************************************/ ++inline static unsigned int ++type_field (unsigned int ntype) ++{ ++ return (ntype & 0xff); ++} ++ ++/* To convert old types from a static structure */ ++inline static unsigned int ++convert_old_type (unsigned int ntype) ++{ ++ unsigned int type = ntype & 0xff; ++ if (type == ASN1_ETYPE_TIME) ++ { ++ if (ntype & CONST_UTC) ++ type = ASN1_ETYPE_UTC_TIME; ++ else ++ type = ASN1_ETYPE_GENERALIZED_TIME; ++ ++ ntype &= ~(CONST_UTC | CONST_GENERALIZED); ++ ntype &= 0xffffff00; ++ ntype |= type; ++ ++ return ntype; ++ } ++ else ++ return ntype; ++} ++ ++static inline ++void *_asn1_realloc(void *ptr, size_t size) ++{ ++ void *ret; ++ ++ if (size == 0) ++ return ptr; ++ ++ ret = realloc(ptr, size); ++ if (ret == NULL) ++ { ++ free(ptr); ++ } ++ return ret; ++} ++ ++#endif /* INT_H */ +diff --git a/grub-core/lib/libtasn1/lib/parser_aux.h b/grub-core/lib/libtasn1/lib/parser_aux.h +new file mode 100644 +index 00000000000..598e684b355 +--- /dev/null ++++ b/grub-core/lib/libtasn1/lib/parser_aux.h +@@ -0,0 +1,172 @@ ++/* ++ * Copyright (C) 2000-2014 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * The LIBTASN1 library is free software; you can redistribute it ++ * and/or modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ++ * 02110-1301, USA ++ */ ++ ++#ifndef _PARSER_AUX_H ++#define _PARSER_AUX_H ++ ++/***********************************************/ ++/* Type: list_type */ ++/* Description: type used in the list during */ ++/* the structure creation. */ ++/***********************************************/ ++typedef struct list_struct ++{ ++ asn1_node node; ++ struct list_struct *next; ++} list_type; ++ ++/***************************************/ ++/* Functions used by ASN.1 parser */ ++/***************************************/ ++asn1_node _asn1_add_static_node (list_type **e_list, unsigned int type); ++ ++void _asn1_delete_list (list_type *e_list); ++ ++void _asn1_delete_list_and_nodes (list_type *e_list); ++ ++void _asn1_delete_node_from_list (list_type *list, asn1_node node); ++ ++asn1_node ++_asn1_set_value (asn1_node node, const void *value, unsigned int len); ++ ++asn1_node _asn1_set_value_m (asn1_node node, void *value, unsigned int len); ++ ++asn1_node ++_asn1_set_value_lv (asn1_node node, const void *value, unsigned int len); ++ ++asn1_node ++_asn1_append_value (asn1_node node, const void *value, unsigned int len); ++ ++asn1_node _asn1_set_name (asn1_node node, const char *name); ++ ++asn1_node _asn1_cpy_name (asn1_node dst, asn1_node_const src); ++ ++asn1_node _asn1_set_right (asn1_node node, asn1_node right); ++ ++asn1_node _asn1_get_last_right (asn1_node_const node); ++ ++void _asn1_remove_node (asn1_node node, unsigned int flags); ++ ++/* Max 64-bit integer length is 20 chars + 1 for sign + 1 for null termination */ ++#define LTOSTR_MAX_SIZE 22 ++char *_asn1_ltostr (int64_t v, char str[LTOSTR_MAX_SIZE]); ++ ++asn1_node _asn1_find_up (asn1_node_const node); ++ ++int _asn1_change_integer_value (asn1_node node); ++ ++#define EXPAND_OBJECT_ID_MAX_RECURSION 16 ++int _asn1_expand_object_id (list_type **list, asn1_node node); ++ ++int _asn1_type_set_config (asn1_node node); ++ ++int _asn1_check_identifier (asn1_node_const node); ++ ++int _asn1_set_default_tag (asn1_node node); ++ ++/******************************************************************/ ++/* Function : _asn1_get_right */ ++/* Description: returns the element pointed by the RIGHT field of */ ++/* a NODE_ASN element. */ ++/* Parameters: */ ++/* node: NODE_ASN element pointer. */ ++/* Return: field RIGHT of NODE. */ ++/******************************************************************/ ++inline static asn1_node ++_asn1_get_right (asn1_node_const node) ++{ ++ if (node == NULL) ++ return NULL; ++ return node->right; ++} ++ ++/******************************************************************/ ++/* Function : _asn1_set_down */ ++/* Description: sets the field DOWN in a NODE_ASN element. */ ++/* Parameters: */ ++/* node: element pointer. */ ++/* down: pointer to a NODE_ASN element that you want be pointed */ ++/* by NODE. */ ++/* Return: pointer to *NODE. */ ++/******************************************************************/ ++inline static asn1_node ++_asn1_set_down (asn1_node node, asn1_node down) ++{ ++ if (node == NULL) ++ return node; ++ node->down = down; ++ if (down) ++ down->left = node; ++ return node; ++} ++ ++/******************************************************************/ ++/* Function : _asn1_get_down */ ++/* Description: returns the element pointed by the DOWN field of */ ++/* a NODE_ASN element. */ ++/* Parameters: */ ++/* node: NODE_ASN element pointer. */ ++/* Return: field DOWN of NODE. */ ++/******************************************************************/ ++inline static asn1_node ++_asn1_get_down (asn1_node_const node) ++{ ++ if (node == NULL) ++ return NULL; ++ return node->down; ++} ++ ++/******************************************************************/ ++/* Function : _asn1_get_name */ ++/* Description: returns the name of a NODE_ASN element. */ ++/* Parameters: */ ++/* node: NODE_ASN element pointer. */ ++/* Return: a null terminated string. */ ++/******************************************************************/ ++inline static char * ++_asn1_get_name (asn1_node_const node) ++{ ++ if (node == NULL) ++ return NULL; ++ return (char *) node->name; ++} ++ ++/******************************************************************/ ++/* Function : _asn1_mod_type */ ++/* Description: change the field TYPE of an NODE_ASN element. */ ++/* The new value is the old one | (bitwise or) the */ ++/* paramener VALUE. */ ++/* Parameters: */ ++/* node: NODE_ASN element pointer. */ ++/* value: the integer value that must be or-ed with the current */ ++/* value of field TYPE. */ ++/* Return: NODE pointer. */ ++/******************************************************************/ ++inline static asn1_node ++_asn1_mod_type (asn1_node node, unsigned int value) ++{ ++ if (node == NULL) ++ return node; ++ node->type |= value; ++ return node; ++} ++ ++#endif +diff --git a/grub-core/lib/libtasn1/lib/structure.h b/grub-core/lib/libtasn1/lib/structure.h +new file mode 100644 +index 00000000000..99e685da07a +--- /dev/null ++++ b/grub-core/lib/libtasn1/lib/structure.h +@@ -0,0 +1,45 @@ ++/* ++ * Copyright (C) 2002-2014 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * The LIBTASN1 library is free software; you can redistribute it ++ * and/or modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ++ * 02110-1301, USA ++ */ ++ ++/*************************************************/ ++/* File: structure.h */ ++/* Description: list of exported object by */ ++/* "structure.c" */ ++/*************************************************/ ++ ++#ifndef _STRUCTURE_H ++#define _STRUCTURE_H ++ ++#include "parser_aux.h" // list_type ++ ++int _asn1_create_static_structure (asn1_node_const pointer, ++ char *output_file_name, char *vector_name); ++ ++asn1_node _asn1_copy_structure3 (asn1_node_const source_node); ++ ++asn1_node _asn1_add_single_node (unsigned int type); ++ ++asn1_node _asn1_find_left (asn1_node_const node); ++ ++int ++_asn1_delete_structure (list_type *e_list, asn1_node *structure, unsigned int flags); ++ ++#endif +diff --git a/include/grub/libtasn1.h b/include/grub/libtasn1.h +new file mode 100644 +index 00000000000..6fd7a30dc35 +--- /dev/null ++++ b/include/grub/libtasn1.h +@@ -0,0 +1,588 @@ ++/* ++ * Copyright (C) 2002-2014 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * LIBTASN1 is free software; you can redistribute it and/or modify it ++ * under the terms of the GNU Lesser General Public License as ++ * published by the Free Software Foundation; either version 2.1 of ++ * the License, or (at your option) any later version. ++ * ++ * LIBTASN1 is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with LIBTASN1; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ++ * 02110-1301, USA ++ * ++ */ ++ ++/** ++ * libtasn1:Short_Description: ++ * ++ * GNU ASN.1 library ++ */ ++/** ++ * libtasn1:Long_Description: ++ * ++ * The Libtasn1 library provides Abstract Syntax Notation One (ASN.1, as ++ * specified by the X.680 ITU-T recommendation) parsing and structures ++ * management, and Distinguished Encoding Rules (DER, as per X.690) ++ * encoding and decoding functions. ++ */ ++ ++ ++#ifndef LIBTASN1_H ++#define LIBTASN1_H ++ ++#ifndef ASN1_API ++#if defined ASN1_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY ++#define ASN1_API __attribute__((__visibility__("default"))) ++#elif defined ASN1_BUILDING && defined _MSC_VER && ! defined ASN1_STATIC ++#define ASN1_API __declspec(dllexport) ++#elif defined _MSC_VER && ! defined ASN1_STATIC ++#define ASN1_API __declspec(dllimport) ++#else ++#define ASN1_API ++#endif ++#endif ++ ++#ifdef __GNUC__ ++# define __LIBTASN1_CONST__ __attribute__((const)) ++# define __LIBTASN1_PURE__ __attribute__((pure)) ++#else ++# define __LIBTASN1_CONST__ ++# define __LIBTASN1_PURE__ ++#endif ++ ++#include ++#include ++#include /* for FILE* */ ++ ++#ifdef __cplusplus ++extern "C" ++{ ++#endif ++ ++/** ++ * ASN1_VERSION: ++ * ++ * Version of the library as a string. ++ */ ++#define ASN1_VERSION "4.16.0" ++ ++/** ++ * ASN1_VERSION_MAJOR: ++ * ++ * Major version number of the library. ++ */ ++#define ASN1_VERSION_MAJOR 4 ++ ++/** ++ * ASN1_VERSION_MINOR: ++ * ++ * Minor version number of the library. ++ */ ++#define ASN1_VERSION_MINOR 16 ++ ++/** ++ * ASN1_VERSION_PATCH: ++ * ++ * Patch version number of the library. ++ */ ++#define ASN1_VERSION_PATCH 0 ++ ++/** ++ * ASN1_VERSION_NUMBER: ++ * ++ * Version number of the library as a number. ++ */ ++#define ASN1_VERSION_NUMBER 0x041000 ++ ++ ++#if defined __GNUC__ && !defined ASN1_INTERNAL_BUILD ++# define _ASN1_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) ++# if _ASN1_GCC_VERSION >= 30100 ++# define _ASN1_GCC_ATTR_DEPRECATED __attribute__ ((__deprecated__)) ++# endif ++#endif ++ ++#ifndef _ASN1_GCC_ATTR_DEPRECATED ++#define _ASN1_GCC_ATTR_DEPRECATED ++#endif ++ ++/*****************************************/ ++/* Errors returned by libtasn1 functions */ ++/*****************************************/ ++#define ASN1_SUCCESS 0 ++#define ASN1_FILE_NOT_FOUND 1 ++#define ASN1_ELEMENT_NOT_FOUND 2 ++#define ASN1_IDENTIFIER_NOT_FOUND 3 ++#define ASN1_DER_ERROR 4 ++#define ASN1_VALUE_NOT_FOUND 5 ++#define ASN1_GENERIC_ERROR 6 ++#define ASN1_VALUE_NOT_VALID 7 ++#define ASN1_TAG_ERROR 8 ++#define ASN1_TAG_IMPLICIT 9 ++#define ASN1_ERROR_TYPE_ANY 10 ++#define ASN1_SYNTAX_ERROR 11 ++#define ASN1_MEM_ERROR 12 ++#define ASN1_MEM_ALLOC_ERROR 13 ++#define ASN1_DER_OVERFLOW 14 ++#define ASN1_NAME_TOO_LONG 15 ++#define ASN1_ARRAY_ERROR 16 ++#define ASN1_ELEMENT_NOT_EMPTY 17 ++#define ASN1_TIME_ENCODING_ERROR 18 ++#define ASN1_RECURSION 19 ++ ++/*************************************/ ++/* Constants used in asn1_visit_tree */ ++/*************************************/ ++#define ASN1_PRINT_NAME 1 ++#define ASN1_PRINT_NAME_TYPE 2 ++#define ASN1_PRINT_NAME_TYPE_VALUE 3 ++#define ASN1_PRINT_ALL 4 ++ ++/*****************************************/ ++/* Constants returned by asn1_read_tag */ ++/*****************************************/ ++#define ASN1_CLASS_UNIVERSAL 0x00 /* old: 1 */ ++#define ASN1_CLASS_APPLICATION 0x40 /* old: 2 */ ++#define ASN1_CLASS_CONTEXT_SPECIFIC 0x80 /* old: 3 */ ++#define ASN1_CLASS_PRIVATE 0xC0 /* old: 4 */ ++#define ASN1_CLASS_STRUCTURED 0x20 ++ ++/*****************************************/ ++/* Constants returned by asn1_read_tag */ ++/*****************************************/ ++#define ASN1_TAG_BOOLEAN 0x01 ++#define ASN1_TAG_INTEGER 0x02 ++#define ASN1_TAG_SEQUENCE 0x10 ++#define ASN1_TAG_SET 0x11 ++#define ASN1_TAG_OCTET_STRING 0x04 ++#define ASN1_TAG_BIT_STRING 0x03 ++#define ASN1_TAG_UTCTime 0x17 ++#define ASN1_TAG_GENERALIZEDTime 0x18 ++#define ASN1_TAG_OBJECT_ID 0x06 ++#define ASN1_TAG_ENUMERATED 0x0A ++#define ASN1_TAG_NULL 0x05 ++#define ASN1_TAG_GENERALSTRING 0x1B ++#define ASN1_TAG_NUMERIC_STRING 0x12 ++#define ASN1_TAG_IA5_STRING 0x16 ++#define ASN1_TAG_TELETEX_STRING 0x14 ++#define ASN1_TAG_PRINTABLE_STRING 0x13 ++#define ASN1_TAG_UNIVERSAL_STRING 0x1C ++#define ASN1_TAG_BMP_STRING 0x1E ++#define ASN1_TAG_UTF8_STRING 0x0C ++#define ASN1_TAG_VISIBLE_STRING 0x1A ++ ++/** ++ * asn1_node: ++ * ++ * Structure definition used for the node of the tree ++ * that represents an ASN.1 DEFINITION. ++ */ ++typedef struct asn1_node_st asn1_node_st; ++ ++typedef asn1_node_st *asn1_node; ++typedef const asn1_node_st *asn1_node_const; ++ ++/** ++ * ASN1_MAX_NAME_SIZE: ++ * ++ * Maximum number of characters of a name ++ * inside a file with ASN1 definitions. ++ */ ++#define ASN1_MAX_NAME_SIZE 64 ++ ++ ++/** ++ * asn1_static_node: ++ * @name: Node name ++ * @type: Node typ ++ * @value: Node value ++ * ++ * For the on-disk format of ASN.1 trees, created by asn1_parser2array(). ++ */ ++struct asn1_static_node_st ++{ ++ const char *name; /* Node name */ ++ unsigned int type; /* Node type */ ++ const void *value; /* Node value */ ++}; ++typedef struct asn1_static_node_st asn1_static_node; ++ ++/* List of constants for field type of node_asn */ ++#define ASN1_ETYPE_INVALID 0 ++#define ASN1_ETYPE_CONSTANT 1 ++#define ASN1_ETYPE_IDENTIFIER 2 ++#define ASN1_ETYPE_INTEGER 3 ++#define ASN1_ETYPE_BOOLEAN 4 ++#define ASN1_ETYPE_SEQUENCE 5 ++#define ASN1_ETYPE_BIT_STRING 6 ++#define ASN1_ETYPE_OCTET_STRING 7 ++#define ASN1_ETYPE_TAG 8 ++#define ASN1_ETYPE_DEFAULT 9 ++#define ASN1_ETYPE_SIZE 10 ++#define ASN1_ETYPE_SEQUENCE_OF 11 ++#define ASN1_ETYPE_OBJECT_ID 12 ++#define ASN1_ETYPE_ANY 13 ++#define ASN1_ETYPE_SET 14 ++#define ASN1_ETYPE_SET_OF 15 ++#define ASN1_ETYPE_DEFINITIONS 16 ++#define ASN1_ETYPE_CHOICE 18 ++#define ASN1_ETYPE_IMPORTS 19 ++#define ASN1_ETYPE_NULL 20 ++#define ASN1_ETYPE_ENUMERATED 21 ++#define ASN1_ETYPE_GENERALSTRING 27 ++#define ASN1_ETYPE_NUMERIC_STRING 28 ++#define ASN1_ETYPE_IA5_STRING 29 ++#define ASN1_ETYPE_TELETEX_STRING 30 ++#define ASN1_ETYPE_PRINTABLE_STRING 31 ++#define ASN1_ETYPE_UNIVERSAL_STRING 32 ++#define ASN1_ETYPE_BMP_STRING 33 ++#define ASN1_ETYPE_UTF8_STRING 34 ++#define ASN1_ETYPE_VISIBLE_STRING 35 ++#define ASN1_ETYPE_UTC_TIME 36 ++#define ASN1_ETYPE_GENERALIZED_TIME 37 ++ ++/** ++ * ASN1_DELETE_FLAG_ZEROIZE: ++ * ++ * Used by: asn1_delete_structure2() ++ * ++ * Zeroize values prior to deinitialization. ++ */ ++#define ASN1_DELETE_FLAG_ZEROIZE 1 ++ ++/** ++ * ASN1_DECODE_FLAG_ALLOW_PADDING: ++ * ++ * Used by: asn1_der_decoding2() ++ * ++ * This flag would allow arbitrary data past the DER data. ++ */ ++#define ASN1_DECODE_FLAG_ALLOW_PADDING 1 ++/** ++ * ASN1_DECODE_FLAG_STRICT_DER: ++ * ++ * Used by: asn1_der_decoding2() ++ * ++ * This flag would ensure that no BER decoding takes place. ++ */ ++#define ASN1_DECODE_FLAG_STRICT_DER (1<<1) ++/** ++ * ASN1_DECODE_FLAG_ALLOW_INCORRECT_TIME: ++ * ++ * Used by: asn1_der_decoding2() ++ * ++ * This flag will tolerate Time encoding errors when in strict DER. ++ */ ++#define ASN1_DECODE_FLAG_ALLOW_INCORRECT_TIME (1<<2) ++ ++ ++/** ++ * asn1_data_node_st: ++ * @name: Node name ++ * @value: Node value ++ * @value_len: Node value size ++ * @type: Node value type (ASN1_ETYPE_*) ++ * ++ * Data node inside a #asn1_node structure. ++ */ ++struct asn1_data_node_st ++{ ++ const char *name; /* Node name */ ++ const void *value; /* Node value */ ++ unsigned int value_len; /* Node value size */ ++ unsigned int type; /* Node value type (ASN1_ETYPE_*) */ ++}; ++typedef struct asn1_data_node_st asn1_data_node_st; ++ ++/***********************************/ ++/* Fixed constants */ ++/***********************************/ ++ ++/** ++ * ASN1_MAX_ERROR_DESCRIPTION_SIZE: ++ * ++ * Maximum number of characters ++ * of a description message ++ * (null character included). ++ */ ++#define ASN1_MAX_ERROR_DESCRIPTION_SIZE 128 ++ ++/***********************************/ ++/* Functions definitions */ ++/***********************************/ ++ ++extern ASN1_API int ++ asn1_parser2tree (const char *file, ++ asn1_node * definitions, char *error_desc); ++ ++extern ASN1_API int ++ asn1_parser2array (const char *inputFileName, ++ const char *outputFileName, ++ const char *vectorName, char *error_desc); ++ ++extern ASN1_API int ++ asn1_array2tree (const asn1_static_node * array, ++ asn1_node * definitions, char *errorDescription); ++ ++extern ASN1_API void ++ asn1_print_structure (FILE * out, asn1_node_const structure, ++ const char *name, int mode); ++ ++extern ASN1_API int ++ asn1_create_element (asn1_node_const definitions, ++ const char *source_name, asn1_node * element); ++ ++extern ASN1_API int asn1_delete_structure (asn1_node * structure); ++ ++extern ASN1_API int asn1_delete_structure2 (asn1_node * structure, unsigned int flags); ++ ++extern ASN1_API int ++ asn1_delete_element (asn1_node structure, const char *element_name); ++ ++extern ASN1_API int ++ asn1_write_value (asn1_node node_root, const char *name, ++ const void *ivalue, int len); ++ ++extern ASN1_API int ++ asn1_read_value (asn1_node_const root, const char *name, ++ void *ivalue, int *len); ++ ++extern ASN1_API int ++ asn1_read_value_type (asn1_node_const root, const char *name, ++ void *ivalue, int *len, unsigned int *etype); ++ ++extern ASN1_API int ++ asn1_read_node_value (asn1_node_const node, asn1_data_node_st * data); ++ ++extern ASN1_API int ++ asn1_number_of_elements (asn1_node_const element, const char *name, int *num); ++ ++extern ASN1_API int ++ asn1_der_coding (asn1_node_const element, const char *name, ++ void *ider, int *len, char *ErrorDescription); ++ ++extern ASN1_API int ++ asn1_der_decoding2 (asn1_node *element, const void *ider, ++ int *max_ider_len, unsigned int flags, ++ char *errorDescription); ++ ++extern ASN1_API int ++ asn1_der_decoding (asn1_node * element, const void *ider, ++ int ider_len, char *errorDescription); ++ ++/* Do not use. Use asn1_der_decoding() instead. */ ++extern ASN1_API int ++ asn1_der_decoding_element (asn1_node * structure, ++ const char *elementName, ++ const void *ider, int len, ++ char *errorDescription) _ASN1_GCC_ATTR_DEPRECATED; ++ ++extern ASN1_API int ++ asn1_der_decoding_startEnd (asn1_node element, ++ const void *ider, int ider_len, ++ const char *name_element, ++ int *start, int *end); ++ ++extern ASN1_API int ++ asn1_expand_any_defined_by (asn1_node_const definitions, asn1_node * element); ++ ++extern ASN1_API int ++ asn1_expand_octet_string (asn1_node_const definitions, ++ asn1_node * element, ++ const char *octetName, const char *objectName); ++ ++extern ASN1_API int ++ asn1_read_tag (asn1_node_const root, const char *name, ++ int *tagValue, int *classValue); ++ ++extern ASN1_API const char *asn1_find_structure_from_oid (asn1_node_const ++ definitions, ++ const char ++ *oidValue); ++ ++__LIBTASN1_PURE__ ++extern ASN1_API const char *asn1_check_version (const char *req_version); ++ ++__LIBTASN1_PURE__ ++extern ASN1_API const char *asn1_strerror (int error); ++ ++extern ASN1_API void asn1_perror (int error); ++ ++#define ASN1_MAX_TAG_SIZE 4 ++#define ASN1_MAX_LENGTH_SIZE 9 ++#define ASN1_MAX_TL_SIZE (ASN1_MAX_TAG_SIZE+ASN1_MAX_LENGTH_SIZE) ++extern ASN1_API long ++ asn1_get_length_der (const unsigned char *der, int der_len, int *len); ++ ++extern ASN1_API long ++ asn1_get_length_ber (const unsigned char *ber, int ber_len, int *len); ++ ++extern ASN1_API void ++ asn1_length_der (unsigned long int len, unsigned char *der, int *der_len); ++ ++/* Other utility functions. */ ++ ++extern ASN1_API ++ int asn1_decode_simple_der (unsigned int etype, const unsigned char *der, ++ unsigned int _der_len, ++ const unsigned char **str, ++ unsigned int *str_len); ++ ++extern ASN1_API ++ int asn1_decode_simple_ber (unsigned int etype, const unsigned char *der, ++ unsigned int _der_len, ++ unsigned char **str, ++ unsigned int *str_len, ++ unsigned int *ber_len); ++ ++extern ASN1_API int ++ asn1_encode_simple_der (unsigned int etype, const unsigned char *str, ++ unsigned int str_len, unsigned char *tl, ++ unsigned int *tl_len); ++ ++extern ASN1_API asn1_node ++ asn1_find_node (asn1_node_const pointer, const char *name); ++ ++extern ASN1_API int ++ asn1_copy_node (asn1_node dst, const char *dst_name, ++ asn1_node_const src, const char *src_name); ++extern ASN1_API asn1_node ++ asn1_dup_node (asn1_node_const src, const char *src_name); ++ ++/* Internal and low-level DER utility functions. */ ++ ++extern ASN1_API int ++ asn1_get_tag_der (const unsigned char *der, int der_len, ++ unsigned char *cls, int *len, unsigned long *tag); ++ ++extern ASN1_API void ++ asn1_octet_der (const unsigned char *str, int str_len, ++ unsigned char *der, int *der_len); ++ ++extern ASN1_API int ++ asn1_get_octet_der (const unsigned char *der, int der_len, ++ int *ret_len, unsigned char *str, ++ int str_size, int *str_len); ++ ++extern ASN1_API void asn1_bit_der (const unsigned char *str, int bit_len, ++ unsigned char *der, int *der_len); ++ ++extern ASN1_API int ++ asn1_get_bit_der (const unsigned char *der, int der_len, ++ int *ret_len, unsigned char *str, ++ int str_size, int *bit_len); ++ ++extern ASN1_API int ++ asn1_get_object_id_der (const unsigned char *der, ++ int der_len, int *ret_len, ++ char *str, int str_size); ++ ++extern ASN1_API int ++ asn1_object_id_der (const char *str, unsigned char *der, int *der_len, ++ unsigned flags); ++ ++/* Compatibility types */ ++ ++/** ++ * asn1_retCode: ++ * ++ * Type formerly returned by libtasn1 functions. ++ * ++ * Deprecated: 3.0: Use int instead. ++ */ ++typedef int asn1_retCode; ++ ++/** ++ * node_asn_struct: ++ * ++ * Compat #define. ++ * ++ * Deprecated: 3.0: Use #asn1_node instead. ++ */ ++#define node_asn_struct asn1_node_st ++ ++/** ++ * node_asn: ++ * ++ * Compat #define. ++ * ++ * Deprecated: 3.0: Use #asn1_node instead. ++ */ ++#define node_asn asn1_node_st ++ ++/** ++ * ASN1_TYPE: ++ * ++ * Compat #define. ++ * ++ * Deprecated: 3.0: Use #asn1_node instead. ++ */ ++#define ASN1_TYPE asn1_node ++ ++/** ++ * ASN1_TYPE_EMPTY: ++ * ++ * Compat #define. ++ * ++ * Deprecated: 3.0: Use NULL instead. ++ */ ++#define ASN1_TYPE_EMPTY NULL ++ ++/** ++ * static_struct_asn: ++ * ++ * Compat #define. ++ * ++ * Deprecated: 3.0: Use #asn1_static_node instead. ++ */ ++#define static_struct_asn asn1_static_node_st ++ ++/** ++ * ASN1_ARRAY_TYPE: ++ * ++ * Compat #define. ++ * ++ * Deprecated: 3.0: Use #asn1_static_node instead. ++ */ ++#define ASN1_ARRAY_TYPE asn1_static_node ++ ++/** ++ * asn1_static_node_t: ++ * ++ * Compat #define. ++ * ++ * Deprecated: 3.0: Use #asn1_static_node instead. ++ */ ++#define asn1_static_node_t asn1_static_node ++ ++/** ++ * node_data_struct: ++ * ++ * Compat #define. ++ * ++ * Deprecated: 3.0: Use #asn1_data_node_st instead. ++ */ ++#define node_data_struct asn1_data_node_st ++ ++/** ++ * ASN1_DATA_NODE: ++ * ++ * Compat #define. ++ * ++ * Deprecated: 3.0: Use #asn1_data_node_st instead. ++ */ ++#define ASN1_DATA_NODE asn1_data_node_st ++ ++#ifdef __cplusplus ++} ++#endif ++ ++#endif /* LIBTASN1_H */ +diff --git a/grub-core/lib/libtasn1/LICENSE b/grub-core/lib/libtasn1/LICENSE +new file mode 100644 +index 00000000000..e8b3628db9b +--- /dev/null ++++ b/grub-core/lib/libtasn1/LICENSE +@@ -0,0 +1,16 @@ ++LICENSING ++========= ++ ++The libtasn1 library is released under the GNU Lesser General Public ++License (LGPL) version 2.1 or later; see [COPYING.LESSER](doc/COPYING.LESSER) ++for the license terms. ++ ++The GNU LGPL applies to the main libtasn1 library, while the ++included applications library are under the GNU GPL version 3. ++The libtasn1 library is located in the lib directory, while the applications ++in src/. ++ ++The documentation in doc/ is under the GNU FDL license 1.3. ++ ++For any copyright year range specified as YYYY-ZZZZ in this package ++note that the range specifies every single year in that closed interval. +diff --git a/grub-core/lib/libtasn1/README.md b/grub-core/lib/libtasn1/README.md +new file mode 100644 +index 00000000000..50a8642296c +--- /dev/null ++++ b/grub-core/lib/libtasn1/README.md +@@ -0,0 +1,91 @@ ++|Branch|CI system|Status| ++|:----:|:-------:|-----:| ++|Master|Gitlab|[![build status](https://gitlab.com/gnutls/libtasn1/badges/master/pipeline.svg)](https://gitlab.com/gnutls/libtasn1/commits/master)[![coverage report](https://gitlab.com/gnutls/libtasn1/badges/master/coverage.svg)](https://gnutls.gitlab.io/libtasn1/coverage)| ++ ++# libtasn1 ++ ++This is GNU Libtasn1, a small ASN.1 library. ++ ++The C library (libtasn1.*) is licensed under the GNU Lesser General ++Public License version 2.1 or later. See the file COPYING.LIB. ++ ++The command line tool, self tests, examples, and other auxilliary ++files, are licensed under the GNU General Public License version 3.0 ++or later. See the file COPYING. ++ ++## Building the library ++ ++We require several tools to build the software, including: ++ ++* [Make](https://www.gnu.org/software/make/) ++* [Automake](https://www.gnu.org/software/automake/) (use 1.11.3 or later) ++* [Autoconf](https://www.gnu.org/software/autoconf/) ++* [Libtool](https://www.gnu.org/software/libtool/) ++* [Texinfo](https://www.gnu.org/software/texinfo/) ++* [help2man](http://www.gnu.org/software/help2man/) ++* [Tar](https://www.gnu.org/software/tar/) ++* [Gzip](https://www.gnu.org/software/gzip/) ++* [bison](https://www.gnu.org/software/bison/) ++* [Texlive & epsf](https://www.tug.org/texlive/) (for PDF manual) ++* [GTK-DOC](https://www.gtk.org/gtk-doc/) (for API manual) ++* [Git](https://git-scm.com/) ++* [libabigail](https://pagure.io/libabigail/) (for abi comparison in make dist) ++* [Valgrind](https://valgrind.org/) (optional) ++ ++The required software is typically distributed with your operating ++system, and the instructions for installing them differ. Here are ++some hints: ++ ++gNewSense/Debian/Ubuntu: ++``` ++sudo apt-get install make git-core autoconf automake libtool ++sudo apt-get install texinfo texlive texlive-generic-recommended texlive-extra-utils ++sudo apt-get install help2man gtk-doc-tools valgrind abigail-tools ++``` ++ ++The next step is to run autoreconf, ./configure, etc: ++ ++``` ++$ ./bootstrap ++``` ++ ++Then build the project normally: ++ ++``` ++$ make ++$ make check ++``` ++ ++Happy hacking! ++ ++ ++## Manual ++ ++The manual is in the `doc/` directory of the release. You can also browse ++the manual online at: ++ ++ - https://gnutls.gitlab.io/libtasn1/ ++ ++ ++## Code coverage report ++ ++The coverage report is at: ++ ++ - https://gnutls.gitlab.io/libtasn1/coverage ++ ++ ++## Issue trackers ++ ++ - [Main issue tracker](https://gitlab.com/gnutls/libtasn1/issues) ++ - [oss-fuzz found issues](https://bugs.chromium.org/p/oss-fuzz/issues/list?q=libtasn1&can=2) ++ ++ ++## Homepage ++ ++The project homepage at the gnu site is at: ++ ++http://www.gnu.org/software/libtasn1/ ++ ++ ++For any copyright year range specified as YYYY-ZZZZ in this package ++note that the range specifies every single year in that closed interval. diff --git a/0170-libtasn1-disable-code-not-needed-in-grub.patch b/0170-libtasn1-disable-code-not-needed-in-grub.patch new file mode 100644 index 0000000000000000000000000000000000000000..00f55888d7e83c744e28b78c162d97169c1d324e --- /dev/null +++ b/0170-libtasn1-disable-code-not-needed-in-grub.patch @@ -0,0 +1,307 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Fri, 1 May 2020 17:12:23 +1000 +Subject: [PATCH] libtasn1: disable code not needed in grub + +We don't expect to be able to write ASN.1, only read it, +so we can disable some code. + +Do that with #if 0/#endif, rather than deletion. This means +that the difference between upstream and grub is smaller, +which should make updating libtasn1 easier in the future. + +With these exclusions we also avoid the need for minmax.h, +which is convenient because it means we don't have to +import it from gnulib. + +Signed-off-by: Daniel Axtens +--- + grub-core/lib/libtasn1/lib/coding.c | 12 ++++++++++-- + grub-core/lib/libtasn1/lib/decoding.c | 2 ++ + grub-core/lib/libtasn1/lib/element.c | 4 ++-- + grub-core/lib/libtasn1/lib/errors.c | 3 +++ + grub-core/lib/libtasn1/lib/structure.c | 10 ++++++---- + include/grub/libtasn1.h | 15 +++++++++++++++ + 6 files changed, 38 insertions(+), 8 deletions(-) + +diff --git a/grub-core/lib/libtasn1/lib/coding.c b/grub-core/lib/libtasn1/lib/coding.c +index 245ea64cf0a..52def598368 100644 +--- a/grub-core/lib/libtasn1/lib/coding.c ++++ b/grub-core/lib/libtasn1/lib/coding.c +@@ -30,11 +30,11 @@ + #include "parser_aux.h" + #include + #include "element.h" +-#include "minmax.h" + #include + + #define MAX_TAG_LEN 16 + ++#if 0 + /******************************************************/ + /* Function : _asn1_error_description_value_not_found */ + /* Description: creates the ErrorDescription string */ +@@ -58,6 +58,7 @@ _asn1_error_description_value_not_found (asn1_node node, + Estrcat (ErrorDescription, "' not found"); + + } ++#endif + + /** + * asn1_length_der: +@@ -244,6 +245,7 @@ asn1_encode_simple_der (unsigned int etype, const unsigned char *str, + return ASN1_SUCCESS; + } + ++#if 0 + /******************************************************/ + /* Function : _asn1_time_der */ + /* Description: creates the DER coding for a TIME */ +@@ -281,7 +283,7 @@ _asn1_time_der (unsigned char *str, int str_len, unsigned char *der, + + return ASN1_SUCCESS; + } +- ++#endif + + /* + void +@@ -520,6 +522,7 @@ asn1_bit_der (const unsigned char *str, int bit_len, + } + + ++#if 0 + /******************************************************/ + /* Function : _asn1_complete_explicit_tag */ + /* Description: add the length coding to the EXPLICIT */ +@@ -596,6 +599,7 @@ _asn1_complete_explicit_tag (asn1_node node, unsigned char *der, + + return ASN1_SUCCESS; + } ++#endif + + const tag_and_class_st _asn1_tags[] = { + [ASN1_ETYPE_GENERALSTRING] = +@@ -648,6 +652,8 @@ const tag_and_class_st _asn1_tags[] = { + + unsigned int _asn1_tags_size = sizeof (_asn1_tags) / sizeof (_asn1_tags[0]); + ++ ++#if 0 + /******************************************************/ + /* Function : _asn1_insert_tag_der */ + /* Description: creates the DER coding of tags of one */ +@@ -1413,3 +1419,5 @@ error: + asn1_delete_structure (&node); + return err; + } ++ ++#endif +\ No newline at end of file +diff --git a/grub-core/lib/libtasn1/lib/decoding.c b/grub-core/lib/libtasn1/lib/decoding.c +index ff04eb778cb..42f9a92b5d4 100644 +--- a/grub-core/lib/libtasn1/lib/decoding.c ++++ b/grub-core/lib/libtasn1/lib/decoding.c +@@ -1613,6 +1613,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int ider_len, + return asn1_der_decoding2 (element, ider, &ider_len, 0, errorDescription); + } + ++#if 0 + /** + * asn1_der_decoding_element: + * @structure: pointer to an ASN1 structure +@@ -1643,6 +1644,7 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, + { + return asn1_der_decoding(structure, ider, len, errorDescription); + } ++#endif + + /** + * asn1_der_decoding_startEnd: +diff --git a/grub-core/lib/libtasn1/lib/element.c b/grub-core/lib/libtasn1/lib/element.c +index 997eb2725dc..539008d8e94 100644 +--- a/grub-core/lib/libtasn1/lib/element.c ++++ b/grub-core/lib/libtasn1/lib/element.c +@@ -191,7 +191,7 @@ _asn1_append_sequence_set (asn1_node node, struct node_tail_cache_st *pcache) + return ASN1_SUCCESS; + } + +- ++#if 0 + /** + * asn1_write_value: + * @node_root: pointer to a structure +@@ -645,7 +645,7 @@ asn1_write_value (asn1_node node_root, const char *name, + + return ASN1_SUCCESS; + } +- ++#endif + + #define PUT_VALUE( ptr, ptr_size, data, data_size) \ + *len = data_size; \ +diff --git a/grub-core/lib/libtasn1/lib/errors.c b/grub-core/lib/libtasn1/lib/errors.c +index cee74daf795..42785e8622b 100644 +--- a/grub-core/lib/libtasn1/lib/errors.c ++++ b/grub-core/lib/libtasn1/lib/errors.c +@@ -57,6 +57,8 @@ static const libtasn1_error_entry error_algorithms[] = { + {0, 0} + }; + ++ ++#if 0 + /** + * asn1_perror: + * @error: is an error returned by a libtasn1 function. +@@ -73,6 +75,7 @@ asn1_perror (int error) + const char *str = asn1_strerror (error); + fprintf (stderr, "LIBTASN1 ERROR: %s\n", str ? str : "(null)"); + } ++#endif + + /** + * asn1_strerror: +diff --git a/grub-core/lib/libtasn1/lib/structure.c b/grub-core/lib/libtasn1/lib/structure.c +index 8189c56a4c9..fcfde01a393 100644 +--- a/grub-core/lib/libtasn1/lib/structure.c ++++ b/grub-core/lib/libtasn1/lib/structure.c +@@ -76,7 +76,7 @@ _asn1_find_left (asn1_node_const node) + return node->left; + } + +- ++#if 0 + int + _asn1_create_static_structure (asn1_node_const pointer, char *output_file_name, + char *vector_name) +@@ -155,7 +155,7 @@ _asn1_create_static_structure (asn1_node_const pointer, char *output_file_name, + + return ASN1_SUCCESS; + } +- ++#endif + + /** + * asn1_array2tree: +@@ -718,7 +718,7 @@ asn1_create_element (asn1_node_const definitions, const char *source_name, + return res; + } + +- ++#if 0 + /** + * asn1_print_structure: + * @out: pointer to the output file (e.g. stdout). +@@ -1058,7 +1058,7 @@ asn1_print_structure (FILE * out, asn1_node_const structure, const char *name, + } + } + } +- ++#endif + + + /** +@@ -1153,6 +1153,7 @@ asn1_find_structure_from_oid (asn1_node_const definitions, const char *oidValue) + return NULL; /* ASN1_ELEMENT_NOT_FOUND; */ + } + ++#if 0 + /** + * asn1_copy_node: + * @dst: Destination asn1 node. +@@ -1202,6 +1203,7 @@ asn1_copy_node (asn1_node dst, const char *dst_name, + + return result; + } ++#endif + + /** + * asn1_dup_node: +diff --git a/include/grub/libtasn1.h b/include/grub/libtasn1.h +index 6fd7a30dc35..785eda2ae3f 100644 +--- a/include/grub/libtasn1.h ++++ b/include/grub/libtasn1.h +@@ -319,6 +319,8 @@ typedef struct asn1_data_node_st asn1_data_node_st; + /* Functions definitions */ + /***********************************/ + ++/* These functions are not used in grub and should not be referenced. */ ++#if 0 + extern ASN1_API int + asn1_parser2tree (const char *file, + asn1_node * definitions, char *error_desc); +@@ -327,14 +329,17 @@ extern ASN1_API int + asn1_parser2array (const char *inputFileName, + const char *outputFileName, + const char *vectorName, char *error_desc); ++#endif + + extern ASN1_API int + asn1_array2tree (const asn1_static_node * array, + asn1_node * definitions, char *errorDescription); + ++#if 0 + extern ASN1_API void + asn1_print_structure (FILE * out, asn1_node_const structure, + const char *name, int mode); ++#endif + + extern ASN1_API int + asn1_create_element (asn1_node_const definitions, +@@ -347,9 +352,11 @@ extern ASN1_API int asn1_delete_structure2 (asn1_node * structure, unsigned int + extern ASN1_API int + asn1_delete_element (asn1_node structure, const char *element_name); + ++#if 0 + extern ASN1_API int + asn1_write_value (asn1_node node_root, const char *name, + const void *ivalue, int len); ++#endif + + extern ASN1_API int + asn1_read_value (asn1_node_const root, const char *name, +@@ -365,9 +372,11 @@ extern ASN1_API int + extern ASN1_API int + asn1_number_of_elements (asn1_node_const element, const char *name, int *num); + ++#if 0 + extern ASN1_API int + asn1_der_coding (asn1_node_const element, const char *name, + void *ider, int *len, char *ErrorDescription); ++#endif + + extern ASN1_API int + asn1_der_decoding2 (asn1_node *element, const void *ider, +@@ -378,12 +387,14 @@ extern ASN1_API int + asn1_der_decoding (asn1_node * element, const void *ider, + int ider_len, char *errorDescription); + ++#if 0 + /* Do not use. Use asn1_der_decoding() instead. */ + extern ASN1_API int + asn1_der_decoding_element (asn1_node * structure, + const char *elementName, + const void *ider, int len, + char *errorDescription) _ASN1_GCC_ATTR_DEPRECATED; ++#endif + + extern ASN1_API int + asn1_der_decoding_startEnd (asn1_node element, +@@ -408,13 +419,17 @@ extern ASN1_API const char *asn1_find_structure_from_oid (asn1_node_const + const char + *oidValue); + ++#if 0 + __LIBTASN1_PURE__ + extern ASN1_API const char *asn1_check_version (const char *req_version); ++#endif + + __LIBTASN1_PURE__ + extern ASN1_API const char *asn1_strerror (int error); + ++#if 0 + extern ASN1_API void asn1_perror (int error); ++#endif + + #define ASN1_MAX_TAG_SIZE 4 + #define ASN1_MAX_LENGTH_SIZE 9 diff --git a/0171-libtasn1-changes-for-grub-compatibility.patch b/0171-libtasn1-changes-for-grub-compatibility.patch new file mode 100644 index 0000000000000000000000000000000000000000..9b2275cab19dc1ab55a3e30380e5c2654da263b9 --- /dev/null +++ b/0171-libtasn1-changes-for-grub-compatibility.patch @@ -0,0 +1,202 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Fri, 1 May 2020 20:44:29 +1000 +Subject: [PATCH] libtasn1: changes for grub compatibility + +Do a few things to make libtasn1 compile as part of grub: + + - replace strcat. grub removed strcat so replace it with the appropriate + calls to memcpy and strlen. + + - replace c_isdigit with grub_isdigit (and don't import c-ctype from + gnulib) grub_isdigit provides the same functionality as c_isdigit: it + determines if the input is an ASCII digit without regard for locale. + + - replace GL_ATTRIBUTE_PURE with __attribute__((pure)) which been + supported since gcc-2.96. This avoids messing around with gnulib. + + - adjust libtasn1.h: drop the ASN1_API logic, it's not needed for our + modules. Unconditionally support const and pure attributes and adjust + header paths. + + - adjust header paths to "grub/libtasn1.h". + + - replace a 64 bit division with a call to grub_divmod64, preventing + creation of __udivdi3 calls on 32 bit platforms. + +Signed-off-by: Daniel Axtens +--- + grub-core/lib/libtasn1/lib/decoding.c | 11 ++++++----- + grub-core/lib/libtasn1/lib/element.c | 3 ++- + grub-core/lib/libtasn1/lib/gstr.c | 4 ++-- + grub-core/lib/libtasn1/lib/parser_aux.c | 7 ++++--- + grub-core/lib/libtasn1/lib/int.h | 4 ++-- + include/grub/libtasn1.h | 26 ++++++-------------------- + 6 files changed, 22 insertions(+), 33 deletions(-) + +diff --git a/grub-core/lib/libtasn1/lib/decoding.c b/grub-core/lib/libtasn1/lib/decoding.c +index 42f9a92b5d4..7856858b272 100644 +--- a/grub-core/lib/libtasn1/lib/decoding.c ++++ b/grub-core/lib/libtasn1/lib/decoding.c +@@ -32,7 +32,8 @@ + #include + #include + #include +-#include ++ ++#define c_isdigit grub_isdigit + + #ifdef DEBUG + # define warn() fprintf(stderr, "%s: %d\n", __func__, __LINE__) +@@ -2008,8 +2009,8 @@ asn1_expand_octet_string (asn1_node_const definitions, asn1_node * element, + (p2->type & CONST_ASSIGN)) + { + strcpy (name, definitions->name); +- strcat (name, "."); +- strcat (name, p2->name); ++ memcpy (name + strlen(name), ".", sizeof(" . ")); ++ memcpy (name + strlen(name), p2->name, strlen(p2->name) + 1); + + len = sizeof (value); + result = asn1_read_value (definitions, name, value, &len); +@@ -2026,8 +2027,8 @@ asn1_expand_octet_string (asn1_node_const definitions, asn1_node * element, + if (p2) + { + strcpy (name, definitions->name); +- strcat (name, "."); +- strcat (name, p2->name); ++ memcpy (name + strlen(name), ".", sizeof(" . ")); ++ memcpy (name + strlen(name), p2->name, strlen(p2->name) + 1); + + result = asn1_create_element (definitions, name, &aux); + if (result == ASN1_SUCCESS) +diff --git a/grub-core/lib/libtasn1/lib/element.c b/grub-core/lib/libtasn1/lib/element.c +index 539008d8e94..ed761ff56bd 100644 +--- a/grub-core/lib/libtasn1/lib/element.c ++++ b/grub-core/lib/libtasn1/lib/element.c +@@ -30,9 +30,10 @@ + #include "parser_aux.h" + #include + #include "structure.h" +-#include "c-ctype.h" + #include "element.h" + ++#define c_isdigit grub_isdigit ++ + void + _asn1_hierarchical_name (asn1_node_const node, char *name, int name_size) + { +diff --git a/grub-core/lib/libtasn1/lib/gstr.c b/grub-core/lib/libtasn1/lib/gstr.c +index e91a3a151c0..e33875c2c7c 100644 +--- a/grub-core/lib/libtasn1/lib/gstr.c ++++ b/grub-core/lib/libtasn1/lib/gstr.c +@@ -36,13 +36,13 @@ _asn1_str_cat (char *dest, size_t dest_tot_size, const char *src) + + if (dest_tot_size - dest_size > str_size) + { +- strcat (dest, src); ++ memcpy (dest + dest_size, src, str_size + 1); + } + else + { + if (dest_tot_size - dest_size > 0) + { +- strncat (dest, src, (dest_tot_size - dest_size) - 1); ++ memcpy (dest + dest_size, src, (dest_tot_size - dest_size) - 1); + dest[dest_tot_size - 1] = 0; + } + } +diff --git a/grub-core/lib/libtasn1/lib/parser_aux.c b/grub-core/lib/libtasn1/lib/parser_aux.c +index d5dbbf8765d..89c9be69dc2 100644 +--- a/grub-core/lib/libtasn1/lib/parser_aux.c ++++ b/grub-core/lib/libtasn1/lib/parser_aux.c +@@ -26,7 +26,8 @@ + #include "gstr.h" + #include "structure.h" + #include "element.h" +-#include "c-ctype.h" ++ ++#define c_isdigit grub_isdigit + + char _asn1_identifierMissing[ASN1_MAX_NAME_SIZE + 1]; /* identifier name not found */ + +@@ -40,7 +41,7 @@ char _asn1_identifierMissing[ASN1_MAX_NAME_SIZE + 1]; /* identifier name not fou + #ifdef __clang__ + __attribute__((no_sanitize("integer"))) + #endif +-_GL_ATTRIBUTE_PURE ++__attribute__((__pure__)) + static unsigned int + _asn1_hash_name (const char *x) + { +@@ -634,7 +635,7 @@ _asn1_ltostr (int64_t v, char str[LTOSTR_MAX_SIZE]) + count = 0; + do + { +- d = val / 10; ++ d = grub_divmod64(val, 10, NULL); + r = val - d * 10; + temp[start + count] = '0' + (char) r; + count++; +diff --git a/grub-core/lib/libtasn1/lib/int.h b/grub-core/lib/libtasn1/lib/int.h +index ea1625786c1..4a568efee9c 100644 +--- a/grub-core/lib/libtasn1/lib/int.h ++++ b/grub-core/lib/libtasn1/lib/int.h +@@ -35,7 +35,7 @@ + #include + #endif + +-#include ++#include "grub/libtasn1.h" + + #define ASN1_SMALL_VALUE_SIZE 16 + +@@ -115,7 +115,7 @@ extern const tag_and_class_st _asn1_tags[]; + #define _asn1_strtoul(n,e,b) strtoul((const char *) n, e, b) + #define _asn1_strcmp(a,b) strcmp((const char *)a, (const char *)b) + #define _asn1_strcpy(a,b) strcpy((char *)a, (const char *)b) +-#define _asn1_strcat(a,b) strcat((char *)a, (const char *)b) ++#define _asn1_strcat(a,b) memcpy((char *)a + strlen((const char *)a), (const char *)b, strlen((const char *)b) + 1) + + #if SIZEOF_UNSIGNED_LONG_INT == 8 + # define _asn1_strtou64(n,e,b) strtoul((const char *) n, e, b) +diff --git a/include/grub/libtasn1.h b/include/grub/libtasn1.h +index 785eda2ae3f..28dbf16c4e0 100644 +--- a/include/grub/libtasn1.h ++++ b/include/grub/libtasn1.h +@@ -38,29 +38,15 @@ + #ifndef LIBTASN1_H + #define LIBTASN1_H + +-#ifndef ASN1_API +-#if defined ASN1_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY +-#define ASN1_API __attribute__((__visibility__("default"))) +-#elif defined ASN1_BUILDING && defined _MSC_VER && ! defined ASN1_STATIC +-#define ASN1_API __declspec(dllexport) +-#elif defined _MSC_VER && ! defined ASN1_STATIC +-#define ASN1_API __declspec(dllimport) +-#else ++/* grub: ASN1_API is not used */ + #define ASN1_API +-#endif +-#endif + +-#ifdef __GNUC__ +-# define __LIBTASN1_CONST__ __attribute__((const)) +-# define __LIBTASN1_PURE__ __attribute__((pure)) +-#else +-# define __LIBTASN1_CONST__ +-# define __LIBTASN1_PURE__ +-#endif ++/* grub: all our supported compilers support these attributes */ ++#define __LIBTASN1_CONST__ __attribute__((const)) ++#define __LIBTASN1_PURE__ __attribute__((pure)) + +-#include +-#include +-#include /* for FILE* */ ++#include ++#include + + #ifdef __cplusplus + extern "C" diff --git a/0172-libtasn1-compile-into-asn1-module.patch b/0172-libtasn1-compile-into-asn1-module.patch new file mode 100644 index 0000000000000000000000000000000000000000..67be4e877eae6ed1503768ce0dfc9135c2dcd6d7 --- /dev/null +++ b/0172-libtasn1-compile-into-asn1-module.patch @@ -0,0 +1,70 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Fri, 5 Jun 2020 17:47:25 +1000 +Subject: [PATCH] libtasn1: compile into asn1 module + +Create a wrapper file that specifies the module license. +Set up the makefile so it is built. + +Signed-off-by: Daniel Axtens +--- + grub-core/Makefile.core.def | 15 +++++++++++++++ + grub-core/lib/libtasn1_wrap/wrap.c | 26 ++++++++++++++++++++++++++ + 2 files changed, 41 insertions(+) + create mode 100644 grub-core/lib/libtasn1_wrap/wrap.c + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 97347ae76f9..21d2c541850 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -2576,3 +2576,18 @@ module = { + common = commands/i386/wrmsr.c; + enable = x86; + }; ++ ++module = { ++ name = asn1; ++ common = lib/libtasn1/lib/decoding.c; ++ common = lib/libtasn1/lib/coding.c; ++ common = lib/libtasn1/lib/element.c; ++ common = lib/libtasn1/lib/structure.c; ++ common = lib/libtasn1/lib/parser_aux.c; ++ common = lib/libtasn1/lib/gstr.c; ++ common = lib/libtasn1/lib/errors.c; ++ common = lib/libtasn1_wrap/wrap.c; ++ cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)'; ++ // -Wno-type-limits comes from libtasn1's configure.ac ++ cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/libtasn1/lib -Wno-type-limits'; ++}; +diff --git a/grub-core/lib/libtasn1_wrap/wrap.c b/grub-core/lib/libtasn1_wrap/wrap.c +new file mode 100644 +index 00000000000..622ba942e33 +--- /dev/null ++++ b/grub-core/lib/libtasn1_wrap/wrap.c +@@ -0,0 +1,26 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2020 IBM Corporation ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++ ++/* ++ * libtasn1 is provided under LGPL2.1+, which is compatible ++ * with GPL3+. As Grub as a whole is under GPL3+, this module ++ * is therefore under GPL3+ also. ++ */ ++GRUB_MOD_LICENSE ("GPLv3+"); diff --git a/0173-Fix-undefined-references-for-fdt-when-building-with-.patch b/0173-Fix-undefined-references-for-fdt-when-building-with-.patch deleted file mode 100644 index 7f5bc532dca221e7db9963e2ae26d593afc9cb20..0000000000000000000000000000000000000000 --- a/0173-Fix-undefined-references-for-fdt-when-building-with-.patch +++ /dev/null @@ -1,44 +0,0 @@ -From b7e0553fec4b8e033d794e30b83565f5dd3652c6 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Wed, 1 May 2019 00:36:19 +0200 -Subject: [PATCH 173/220] Fix undefined references for fdt when building with - platform emu - -The fdt module isn't build for this platform, so adding the declarations -with platform emu will lead to the following undefined reference errors: - -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x500): undefined reference to `grub_fdt_add_subnode' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x518): undefined reference to `grub_fdt_check_header' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x530): undefined reference to `grub_fdt_check_header_nosize' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x548): undefined reference to `grub_fdt_create_empty_tree' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x560): undefined reference to `grub_fdt_find_subnode' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x578): undefined reference to `grub_fdt_first_node' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x590): undefined reference to `grub_fdt_get_nodename' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x5a8): undefined reference to `grub_fdt_get_prop' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x5c0): undefined reference to `grub_fdt_next_node' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x5d8): undefined reference to `grub_fdt_set_prop' -BUILDSTDERR: collect2: error: ld returned 1 exit status -BUILDSTDERR: make[1]: *** [Makefile:27093: grub-emu-lite] Error 1 -BUILDSTDERR: make[1]: *** Waiting for unfinished jobs.... - -Signed-off-by: Javier Martinez Canillas ---- - include/grub/fdt.h | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/include/grub/fdt.h b/include/grub/fdt.h -index 22b7c54..2041341 100644 ---- a/include/grub/fdt.h -+++ b/include/grub/fdt.h -@@ -19,7 +19,7 @@ - #ifndef GRUB_FDT_HEADER - #define GRUB_FDT_HEADER 1 - --#if defined(__arm__) || defined(__aarch64__) -+#if !defined(GRUB_MACHINE_EMU) && (defined(__arm__) || defined(__aarch64__)) - - #include - #include --- -1.8.3.1 - diff --git a/0173-test_asn1-test-module-for-libtasn1.patch b/0173-test_asn1-test-module-for-libtasn1.patch new file mode 100644 index 0000000000000000000000000000000000000000..b659558b0273b1e0d47e3bdf85c0ca6e32404de8 --- /dev/null +++ b/0173-test_asn1-test-module-for-libtasn1.patch @@ -0,0 +1,1457 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Wed, 10 Jun 2020 17:48:42 +1000 +Subject: [PATCH] test_asn1: test module for libtasn1 + +Import tests from libtasn1 that don't use functionality we don't +import. I have put them here rather than in the libtasn1 directory +because: + + - They need much more significant changes to run in the grub + context. + + - I don't expect they will need to be changed when updating + libtasn1: I expect the old tests will usually continue to pass on + new versions. + +This doesn't test the full decoder but that will be exercised in +test suites for coming patch sets. + +Signed-off-by: Daniel Axtens +--- + Makefile.util.def | 6 + + grub-core/Makefile.core.def | 13 ++ + .../lib/libtasn1_wrap/tests/CVE-2018-1000654.c | 61 ++++++ + grub-core/lib/libtasn1_wrap/tests/Test_overflow.c | 138 ++++++++++++++ + grub-core/lib/libtasn1_wrap/tests/Test_simple.c | 207 ++++++++++++++++++++ + grub-core/lib/libtasn1_wrap/tests/Test_strings.c | 150 +++++++++++++++ + .../lib/libtasn1_wrap/tests/object-id-decoding.c | 116 +++++++++++ + .../lib/libtasn1_wrap/tests/object-id-encoding.c | 120 ++++++++++++ + grub-core/lib/libtasn1_wrap/tests/octet-string.c | 211 +++++++++++++++++++++ + grub-core/lib/libtasn1_wrap/tests/reproducers.c | 81 ++++++++ + grub-core/lib/libtasn1_wrap/wrap_tests.c | 75 ++++++++ + .../tests/CVE-2018-1000654-1_asn1_tab.h | 32 ++++ + .../tests/CVE-2018-1000654-2_asn1_tab.h | 36 ++++ + grub-core/lib/libtasn1_wrap/wrap_tests.h | 38 ++++ + .gitignore | 1 + + tests/test_asn1.in | 12 ++ + 16 files changed, 1297 insertions(+) + create mode 100644 grub-core/lib/libtasn1_wrap/tests/CVE-2018-1000654.c + create mode 100644 grub-core/lib/libtasn1_wrap/tests/Test_overflow.c + create mode 100644 grub-core/lib/libtasn1_wrap/tests/Test_simple.c + create mode 100644 grub-core/lib/libtasn1_wrap/tests/Test_strings.c + create mode 100644 grub-core/lib/libtasn1_wrap/tests/object-id-decoding.c + create mode 100644 grub-core/lib/libtasn1_wrap/tests/object-id-encoding.c + create mode 100644 grub-core/lib/libtasn1_wrap/tests/octet-string.c + create mode 100644 grub-core/lib/libtasn1_wrap/tests/reproducers.c + create mode 100644 grub-core/lib/libtasn1_wrap/wrap_tests.c + create mode 100644 grub-core/lib/libtasn1_wrap/tests/CVE-2018-1000654-1_asn1_tab.h + create mode 100644 grub-core/lib/libtasn1_wrap/tests/CVE-2018-1000654-2_asn1_tab.h + create mode 100644 grub-core/lib/libtasn1_wrap/wrap_tests.h + create mode 100644 tests/test_asn1.in + +diff --git a/Makefile.util.def b/Makefile.util.def +index 9927c2cfd6a..3f191aa8095 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -1306,6 +1306,12 @@ script = { + common = tests/syslinux_test.in; + }; + ++script = { ++ testcase; ++ name = test_asn1; ++ common = tests/test_asn1.in; ++}; ++ + program = { + testcase; + name = example_unit_test; +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 21d2c541850..b4aaccf7b57 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -2591,3 +2591,16 @@ module = { + // -Wno-type-limits comes from libtasn1's configure.ac + cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/libtasn1/lib -Wno-type-limits'; + }; ++ ++module = { ++ name = test_asn1; ++ common = lib/libtasn1_wrap/tests/CVE-2018-1000654.c; ++ common = lib/libtasn1_wrap/tests/object-id-decoding.c; ++ common = lib/libtasn1_wrap/tests/object-id-encoding.c; ++ common = lib/libtasn1_wrap/tests/octet-string.c; ++ common = lib/libtasn1_wrap/tests/reproducers.c; ++ common = lib/libtasn1_wrap/tests/Test_overflow.c; ++ common = lib/libtasn1_wrap/tests/Test_simple.c; ++ common = lib/libtasn1_wrap/tests/Test_strings.c; ++ common = lib/libtasn1_wrap/wrap_tests.c; ++}; +diff --git a/grub-core/lib/libtasn1_wrap/tests/CVE-2018-1000654.c b/grub-core/lib/libtasn1_wrap/tests/CVE-2018-1000654.c +new file mode 100644 +index 00000000000..534e304521e +--- /dev/null ++++ b/grub-core/lib/libtasn1_wrap/tests/CVE-2018-1000654.c +@@ -0,0 +1,61 @@ ++/* ++ * Copyright (C) 2002-2018 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * This program is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program. If not, see . ++ * ++ */ ++ ++/****************************************************************/ ++/* Description: reproducer for CVE-2018-1000654 */ ++/****************************************************************/ ++ ++#include ++#include ++#include ++#include ++#include ++#include "../wrap_tests.h" ++ ++#include "CVE-2018-1000654-1_asn1_tab.h" ++#include "CVE-2018-1000654-2_asn1_tab.h" ++ ++void ++test_CVE_2018_1000654 (void) ++{ ++ int result; ++ asn1_node definitions = NULL; ++ char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; ++ ++ result = asn1_array2tree (CVE_2018_1000654_1_asn1_tab, &definitions, errorDescription); ++ if (result != ASN1_RECURSION) ++ { ++ grub_fatal ("Error: %s\nErrorDescription = %s\n\n", ++ asn1_strerror (result), errorDescription); ++ return; ++ } ++ ++ asn1_delete_structure (&definitions); ++ ++ result = asn1_array2tree (CVE_2018_1000654_2_asn1_tab, &definitions, errorDescription); ++ if (result != ASN1_RECURSION) ++ { ++ grub_fatal ("Error: %s\nErrorDescription = %s\n\n", ++ asn1_strerror (result), errorDescription); ++ return; ++ } ++ ++ asn1_delete_structure (&definitions); ++} +diff --git a/grub-core/lib/libtasn1_wrap/tests/Test_overflow.c b/grub-core/lib/libtasn1_wrap/tests/Test_overflow.c +new file mode 100644 +index 00000000000..f48aea0ef8b +--- /dev/null ++++ b/grub-core/lib/libtasn1_wrap/tests/Test_overflow.c +@@ -0,0 +1,138 @@ ++/* ++ * Copyright (C) 2012-2014 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * This program is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program. If not, see . ++ * ++ */ ++ ++/* Written by Simon Josefsson */ ++ ++#include ++#include ++#include ++#include ++#include ++#include "../wrap_tests.h" ++ ++void ++test_overflow(void) ++{ ++ /* Test that values larger than long are rejected. This has worked ++ fine with all versions of libtasn1. */ ++ ++ { ++ unsigned char der[] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"; ++ long l; ++ int len; ++ ++ l = asn1_get_length_der (der, sizeof der, &len); ++ ++ if (l != -2L) ++ { ++ grub_fatal ("ERROR: asn1_get_length_der bignum (l %ld len %d)\n", l, len); ++ return; ++ } ++ } ++ ++ /* Test that values larger than int but smaller than long are ++ rejected. This limitation was introduced with libtasn1 2.12. */ ++#if (GRUB_LONG_MAX > GRUB_INT_MAX) ++ { ++ unsigned long num = ((long) GRUB_UINT_MAX) << 2; ++ unsigned char der[20]; ++ int der_len; ++ long l; ++ int len; ++ ++ asn1_length_der (num, der, &der_len); ++ ++ l = asn1_get_length_der (der, der_len, &len); ++ ++ if (l != -2L) ++ { ++ grub_fatal ("ERROR: asn1_get_length_der intnum (l %ld len %d)\n", l, ++ len); ++ return; ++ } ++ } ++#endif ++ ++ /* Test that values larger than would fit in the input string are ++ rejected. This problem was fixed in libtasn1 2.12. */ ++ { ++ unsigned long num = 64; ++ unsigned char der[20]; ++ int der_len; ++ long l; ++ int len; ++ ++ asn1_length_der (num, der, &der_len); ++ ++ der_len = sizeof (der); ++ l = asn1_get_length_der (der, der_len, &len); ++ ++ if (l != -4L) ++ { ++ grub_fatal ("ERROR: asn1_get_length_der overflow-small (l %ld len %d)\n", ++ l, len); ++ return; ++ } ++ } ++ ++ /* Test that values larger than would fit in the input string are ++ rejected. This problem was fixed in libtasn1 2.12. */ ++ { ++ unsigned long num = 1073741824; ++ unsigned char der[20]; ++ int der_len; ++ long l; ++ int len; ++ ++ asn1_length_der (num, der, &der_len); ++ ++ der_len = sizeof (der); ++ l = asn1_get_length_der (der, der_len, &len); ++ ++ if (l != -4L) ++ { ++ grub_fatal ("ERROR: asn1_get_length_der overflow-large1 (l %ld len %d)\n", ++ l, len); ++ return; ++ } ++ } ++ ++ /* Test that values larger than would fit in the input string are ++ rejected. This problem was fixed in libtasn1 2.12. */ ++ { ++ unsigned long num = 2147483649; ++ unsigned char der[20]; ++ int der_len; ++ long l; ++ int len; ++ ++ asn1_length_der (num, der, &der_len); ++ ++ der_len = sizeof (der); ++ l = asn1_get_length_der (der, der_len, &len); ++ ++ if (l != -2L) ++ { ++ grub_fatal ("ERROR: asn1_get_length_der overflow-large2 (l %ld len %d)\n", ++ l, len); ++ return; ++ } ++ } ++} +diff --git a/grub-core/lib/libtasn1_wrap/tests/Test_simple.c b/grub-core/lib/libtasn1_wrap/tests/Test_simple.c +new file mode 100644 +index 00000000000..9f01006ddf4 +--- /dev/null ++++ b/grub-core/lib/libtasn1_wrap/tests/Test_simple.c +@@ -0,0 +1,207 @@ ++/* ++ * Copyright (C) 2011-2014 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * This program is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program. If not, see . ++ * ++ * Written by Simon Josefsson ++ * ++ */ ++ ++#include ++#include ++#include ++#include ++#include "../wrap_tests.h" ++ ++struct tv ++{ ++ int bitlen; ++ const char *bitstr; ++ int derlen; ++ const char *der; ++}; ++ ++static const struct tv tv[] = { ++ {0, "", 2, "\x01\x00"}, ++ {1, "\x00", 3, "\x02\x07\x00"}, ++ {2, "\x00", 3, "\x02\x06\x00"}, ++ {3, "\x00", 3, "\x02\x05\x00"}, ++ {4, "\x00", 3, "\x02\x04\x00"}, ++ {5, "\x00", 3, "\x02\x03\x00"}, ++ {6, "\x00", 3, "\x02\x02\x00"}, ++ {7, "\x00", 3, "\x02\x01\x00"}, ++ {8, "\x00\x00", 3, "\x02\x00\x00"}, ++ {9, "\x00\x00", 4, "\x03\x07\x00\x00"}, ++ {10, "\x00\x00", 4, "\x03\x06\x00\x00"}, ++ {11, "\x00\x00", 4, "\x03\x05\x00\x00"}, ++ {12, "\x00\x00", 4, "\x03\x04\x00\x00"}, ++ {13, "\x00\x00", 4, "\x03\x03\x00\x00"}, ++ {14, "\x00\x00", 4, "\x03\x02\x00\x00"}, ++ {15, "\x00\x00", 4, "\x03\x01\x00\x00"}, ++ {16, "\x00\x00", 4, "\x03\x00\x00\x00"}, ++ {17, "\x00\x00\x00", 5, "\x04\x07\x00\x00\x00"}, ++ {18, "\x00\x00\x00", 5, "\x04\x06\x00\x00\x00"}, ++ {19, "\x00\x00\x00", 5, "\x04\x05\x00\x00\x00"}, ++ {1, "\xFF", 3, "\x02\x07\x80"}, ++ {2, "\xFF", 3, "\x02\x06\xc0"}, ++ {3, "\xFF", 3, "\x02\x05\xe0"}, ++ {4, "\xFF", 3, "\x02\x04\xf0"}, ++ {5, "\xFF", 3, "\x02\x03\xf8"}, ++ {6, "\xFF", 3, "\x02\x02\xfc"}, ++ {7, "\xFF", 3, "\x02\x01\xfe"}, ++ {8, "\xFF\xFF", 3, "\x02\x00\xff"}, ++ {9, "\xFF\xFF", 4, "\x03\x07\xff\x80"}, ++ {10, "\xFF\xFF", 4, "\x03\x06\xff\xc0"}, ++ {11, "\xFF\xFF", 4, "\x03\x05\xff\xe0"}, ++ {12, "\xFF\xFF", 4, "\x03\x04\xff\xf0"}, ++ {13, "\xFF\xFF", 4, "\x03\x03\xff\xf8"}, ++ {14, "\xFF\xFF", 4, "\x03\x02\xff\xfc"}, ++ {15, "\xFF\xFF", 4, "\x03\x01\xff\xfe"}, ++ {16, "\xFF\xFF", 4, "\x03\x00\xff\xff"}, ++ {17, "\xFF\xFF\xFF", 5, "\x04\x07\xff\xff\x80"}, ++ {18, "\xFF\xFF\xFF", 5, "\x04\x06\xff\xff\xc0"}, ++ {19, "\xFF\xFF\xFF", 5, "\x04\x05\xff\xff\xe0"}, ++}; ++ ++void ++test_simple (void) ++{ ++ int result; ++ unsigned char der[100]; ++ unsigned char str[100]; ++ int der_len = sizeof (der); ++ int str_size = sizeof (str); ++ int ret_len, bit_len; ++ grub_size_t i; ++ ++ /* Dummy test */ ++ ++ asn1_bit_der (NULL, 0, der, &der_len); ++ result = asn1_get_bit_der (der, 0, &ret_len, str, str_size, &bit_len); ++ if (result != ASN1_GENERIC_ERROR) ++ { ++ grub_fatal ("asn1_get_bit_der zero\n"); ++ return; ++ } ++ ++ /* Encode short strings with increasing bit lengths */ ++ ++ for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++) ++ { ++ /* Encode */ ++ ++ asn1_bit_der ((const unsigned char *) tv[i].bitstr, tv[i].bitlen, ++ der, &der_len); ++ ++#if 0 ++ { ++ size_t j; ++ for (j = 0; j < der_len; j++) ++ printf ("\\x%02x", der[j]); ++ printf ("\n"); ++ } ++#endif ++ ++ if (der_len != tv[i].derlen || grub_memcmp (der, tv[i].der, der_len) != 0) ++ { ++ grub_fatal ("asn1_bit_der iter %lu\n", (unsigned long) i); ++ return; ++ } ++ ++ /* Decode it */ ++ ++ result = asn1_get_bit_der (der, der_len, &ret_len, str, ++ str_size, &bit_len); ++ if (result != ASN1_SUCCESS || ret_len != tv[i].derlen ++ || bit_len != tv[i].bitlen) ++ { ++ grub_fatal ("asn1_get_bit_der iter %lu, err: %d\n", (unsigned long) i, result); ++ return; ++ } ++ } ++ ++ ++ /* Decode sample from "A Layman's Guide to a Subset of ASN.1, BER, ++ and DER" section 5.4 "BIT STRING": "The BER encoding of the BIT ++ STRING value "011011100101110111" can be any of the following, ++ among others, depending on the choice of padding bits, the form ++ of length octets [...]". ++ */ ++ ++ /* 03 04 06 6e 5d c0 DER encoding */ ++ ++ grub_memcpy (der, "\x04\x06\x6e\x5d\xc0", 5); ++ der_len = 5; ++ ++ result = asn1_get_bit_der (der, der_len, &ret_len, str, str_size, &bit_len); ++ if (result != ASN1_SUCCESS || ret_len != 5 ++ || bit_len != 18 || grub_memcmp (str, "\x6e\x5d\xc0", 3) != 0) ++ { ++ grub_fatal ("asn1_get_bit_der example\n"); ++ return; ++ } ++ ++ der_len = sizeof (der); ++ asn1_bit_der (str, bit_len, der, &der_len); ++ if (der_len != 5 || grub_memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0) ++ { ++ grub_fatal ("asn1_bit_der example roundtrip\n"); ++ return; ++ } ++ ++ /* 03 04 06 6e 5d e0 padded with "100000" */ ++ ++ grub_memcpy (der, "\x04\x06\x6e\x5d\xe0", 5); ++ der_len = 5; ++ ++ result = asn1_get_bit_der (der, der_len, &ret_len, str, str_size, &bit_len); ++ if (result != ASN1_SUCCESS || ret_len != 5 ++ || bit_len != 18 || grub_memcmp (str, "\x6e\x5d\xe0", 3) != 0) ++ { ++ grub_fatal ("asn1_get_bit_der example padded\n"); ++ return; ++ } ++ ++ der_len = sizeof (der); ++ asn1_bit_der (str, bit_len, der, &der_len); ++ if (der_len != 5 || grub_memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0) ++ { ++ grub_fatal ("asn1_bit_der example roundtrip\n"); ++ return; ++ } ++ ++ /* 03 81 04 06 6e 5d c0 long form of length octets */ ++ ++ grub_memcpy (der, "\x81\x04\x06\x6e\x5d\xc0", 6); ++ der_len = 6; ++ ++ result = asn1_get_bit_der (der, der_len, &ret_len, str, str_size, &bit_len); ++ ++ if (result != ASN1_SUCCESS || ret_len != 6 ++ || bit_len != 18 || grub_memcmp (str, "\x6e\x5d\xc0", 3) != 0) ++ { ++ grub_fatal ("asn1_get_bit_der example long form\n"); ++ return; ++ } ++ ++ der_len = sizeof (der); ++ asn1_bit_der (str, bit_len, der, &der_len); ++ if (der_len != 5 || grub_memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0) ++ { ++ grub_fatal ("asn1_bit_der example roundtrip\n"); ++ return; ++ } ++} +diff --git a/grub-core/lib/libtasn1_wrap/tests/Test_strings.c b/grub-core/lib/libtasn1_wrap/tests/Test_strings.c +new file mode 100644 +index 00000000000..dbe1474b204 +--- /dev/null ++++ b/grub-core/lib/libtasn1_wrap/tests/Test_strings.c +@@ -0,0 +1,150 @@ ++/* ++ * Copyright (C) 2012-2014 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * This program is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program. If not, see . ++ * ++ * Written by Simon Josefsson ++ * ++ */ ++ ++#include ++#include ++#include ++#include ++#include "../wrap_tests.h" ++ ++struct tv ++{ ++ unsigned int etype; ++ unsigned int str_len; ++ const void *str; ++ unsigned int der_len; ++ const void *der; ++}; ++ ++static const struct tv tv[] = { ++ {ASN1_ETYPE_IA5_STRING, 20, ++ "\x63\x73\x63\x61\x40\x70\x61\x73\x73\x70\x6f\x72\x74\x2e\x67\x6f\x76\x2e\x67\x72", ++ 22, ++ "\x16\x14\x63\x73\x63\x61\x40\x70\x61\x73\x73\x70\x6f\x72\x74\x2e\x67\x6f\x76\x2e\x67\x72"}, ++ {ASN1_ETYPE_PRINTABLE_STRING, 5, "\x4e\x69\x6b\x6f\x73", ++ 7, "\x13\x05\x4e\x69\x6b\x6f\x73"}, ++ {ASN1_ETYPE_UTF8_STRING, 12, "Αττική", ++ 14, "\x0c\x0c\xce\x91\xcf\x84\xcf\x84\xce\xb9\xce\xba\xce\xae"}, ++ {ASN1_ETYPE_TELETEX_STRING, 15, ++ "\x53\x69\x6d\x6f\x6e\x20\x4a\x6f\x73\x65\x66\x73\x73\x6f\x6e", ++ 17, ++ "\x14\x0f\x53\x69\x6d\x6f\x6e\x20\x4a\x6f\x73\x65\x66\x73\x73\x6f\x6e"}, ++ {ASN1_ETYPE_OCTET_STRING, 36, ++ "\x30\x22\x80\x0F\x32\x30\x31\x31\x30\x38\x32\x31\x30\x38\x30\x30\x30\x36\x5A\x81\x0F\x32\x30\x31\x31\x30\x38\x32\x33\x32\x30\x35\x39\x35\x39\x5A", ++ 38, ++ "\x04\x24\x30\x22\x80\x0F\x32\x30\x31\x31\x30\x38\x32\x31\x30\x38\x30\x30\x30\x36\x5A\x81\x0F\x32\x30\x31\x31\x30\x38\x32\x33\x32\x30\x35\x39\x35\x39\x5A"} ++}; ++ ++#define SSTR(x) sizeof(x)-1,x ++static const struct tv ber[] = { ++ {ASN1_ETYPE_OCTET_STRING, ++ SSTR("\xa0\xa0"), ++ SSTR("\x24\x80\x04\x82\x00\x02\xa0\xa0\x00\x00")}, ++ {ASN1_ETYPE_OCTET_STRING, ++ SSTR("\xa0\xa0\xb0\xb0\xb0"), ++ SSTR("\x24\x80\x04\x82\x00\x02\xa0\xa0\x04\x82\x00\x03\xb0\xb0\xb0\x00\x00")}, ++ {ASN1_ETYPE_OCTET_STRING, ++ SSTR("\xa0\xa0\xb0\xb0\xb0\xa1\xa1"), ++ SSTR("\x24\x80\x04\x82\x00\x02\xa0\xa0\x04\x82\x00\x03\xb0\xb0\xb0\x24\x80\x04\x82\x00\x02\xa1\xa1\x00\x00\x00\x00")}, ++ {ASN1_ETYPE_OCTET_STRING, ++ SSTR("\xa0\xa0\xb0\xb0\xb0\xa1\xa1\xc1"), ++ SSTR("\x24\x80\x04\x82\x00\x02\xa0\xa0\x04\x82\x00\x03\xb0\xb0\xb0\x24\x80\x04\x82\x00\x02\xa1\xa1\x04\x82\x00\x01\xc1\x00\x00\x00\x00")}, ++}; ++ ++void ++test_strings () ++{ ++ int ret; ++ unsigned char tl[ASN1_MAX_TL_SIZE]; ++ unsigned int tl_len, der_len, str_len; ++ const unsigned char *str; ++ unsigned char *b; ++ unsigned int i; ++ ++ /* Dummy test */ ++ ++ for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++) ++ { ++ /* Encode */ ++ tl_len = sizeof (tl); ++ ret = asn1_encode_simple_der (tv[i].etype, tv[i].str, tv[i].str_len, ++ tl, &tl_len); ++ if (ret != ASN1_SUCCESS) ++ { ++ grub_fatal ("Encoding error in %u: %s\n", i, ++ asn1_strerror (ret)); ++ return; ++ } ++ der_len = tl_len + tv[i].str_len; ++ ++ if (der_len != tv[i].der_len || grub_memcmp (tl, tv[i].der, tl_len) != 0) ++ { ++ grub_fatal ( ++ "DER encoding differs in %u! (size: %u, expected: %u)\n", ++ i, der_len, tv[i].der_len); ++ return; ++ } ++ ++ /* decoding */ ++ ret = ++ asn1_decode_simple_der (tv[i].etype, tv[i].der, tv[i].der_len, &str, ++ &str_len); ++ if (ret != ASN1_SUCCESS) ++ { ++ grub_fatal ("Decoding error in %u: %s\n", i, ++ asn1_strerror (ret)); ++ return; ++ } ++ ++ if (str_len != tv[i].str_len || grub_memcmp (str, tv[i].str, str_len) != 0) ++ { ++ grub_fatal ( ++ "DER decoded data differ in %u! (size: %u, expected: %u)\n", ++ i, der_len, tv[i].str_len); ++ return; ++ } ++ } ++ ++ /* BER decoding */ ++ for (i = 0; i < sizeof (ber) / sizeof (ber[0]); i++) ++ { ++ /* decoding */ ++ ret = ++ asn1_decode_simple_ber (ber[i].etype, ber[i].der, ber[i].der_len, &b, ++ &str_len, NULL); ++ if (ret != ASN1_SUCCESS) ++ { ++ grub_fatal ("BER decoding error in %u: %s\n", i, ++ asn1_strerror (ret)); ++ return; ++ } ++ ++ if (str_len != ber[i].str_len || grub_memcmp (b, ber[i].str, str_len) != 0) ++ { ++ grub_fatal ( ++ "BER decoded data differ in %u! (size: %u, expected: %u)\n", ++ i, str_len, ber[i].str_len); ++ return; ++ } ++ grub_free(b); ++ } ++} +diff --git a/grub-core/lib/libtasn1_wrap/tests/object-id-decoding.c b/grub-core/lib/libtasn1_wrap/tests/object-id-decoding.c +new file mode 100644 +index 00000000000..d367bbfb5a7 +--- /dev/null ++++ b/grub-core/lib/libtasn1_wrap/tests/object-id-decoding.c +@@ -0,0 +1,116 @@ ++/* ++ * Copyright (C) 2016 Red Hat, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * This program is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program. If not, see . ++ * ++ */ ++ ++#include ++#include ++#include ++#include ++#include "../wrap_tests.h" ++ ++struct tv ++{ ++ int der_len; ++ const unsigned char *der; ++ const char *oid; ++ int expected_error; ++}; ++ ++static const struct tv tv[] = { ++ {.der_len = 5, ++ .der = (void *) "\x06\x03\x80\x37\x03", ++ .oid = "2.999.3", ++ .expected_error = ASN1_DER_ERROR /* leading 0x80 */ ++ }, ++ {.der_len = 12, ++ .der = (void *) "\x06\x0a\x2b\x06\x01\x80\x01\x92\x08\x09\x05\x01", ++ .oid = "1.3.6.1.4.1.2312.9.5.1", ++ .expected_error = ASN1_DER_ERROR /* leading 0x80 */ ++ }, ++ {.der_len = 6, ++ .der = (void *) "\x06\x04\x01\x02\x03\x04", ++ .oid = "0.1.2.3.4", ++ .expected_error = ASN1_SUCCESS}, ++ {.der_len = 5, ++ .der = (void *) "\x06\x03\x51\x02\x03", ++ .oid = "2.1.2.3", ++ .expected_error = ASN1_SUCCESS}, ++ {.der_len = 5, ++ .der = (void *) "\x06\x03\x88\x37\x03", ++ .oid = "2.999.3", ++ .expected_error = ASN1_SUCCESS}, ++ {.der_len = 12, ++ .der = (void *) "\x06\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x05\x01", ++ .oid = "1.3.6.1.4.1.2312.9.5.1", ++ .expected_error = ASN1_SUCCESS}, ++ {.der_len = 19, ++ .der = (void *) "\x06\x11\xfa\x80\x00\x00\x00\x0e\x01\x0e\xfa\x80\x00\x00\x00\x0e\x63\x6f\x6d", ++ .oid = "2.1998768.0.0.14.1.14.1998848.0.0.14.99.111.109", ++ .expected_error = ASN1_SUCCESS}, ++ {.der_len = 19, ++ .der = ++ (void *) ++ "\x06\x11\x2b\x06\x01\x04\x01\x92\x08\x09\x02\xaa\xda\xbe\xbe\xfa\x72\x01\x07", ++ .oid = "1.3.6.1.4.1.2312.9.2.1467399257458.1.7", ++ .expected_error = ASN1_SUCCESS}, ++}; ++ ++void ++test_object_id_decoding (void) ++{ ++ char str[128]; ++ int ret, ret_len; ++ grub_size_t i; ++ ++ for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++) ++ { ++ /* decode */ ++ ret = ++ asn1_get_object_id_der (tv[i].der+1, ++ tv[i].der_len-1, &ret_len, str, ++ sizeof (str)); ++ if (ret != tv[i].expected_error) ++ { ++ grub_fatal ( ++ "%d: asn1_get_object_id_der iter %lu: got '%s' expected %d\n", ++ __LINE__, (unsigned long) i, asn1_strerror(ret), tv[i].expected_error); ++ return; ++ } ++ ++ if (tv[i].expected_error != ASN1_SUCCESS) ++ continue; ++ ++ if (ret_len != tv[i].der_len-1) ++ { ++ grub_fatal ( ++ "%d: iter %lu: error in DER, length returned is %d, had %d\n", ++ __LINE__, (unsigned long)i, ret_len, tv[i].der_len-1); ++ return; ++ } ++ ++ if (grub_strcmp (tv[i].oid, str) != 0) ++ { ++ grub_fatal ( ++ "%d: strcmp iter %lu: got invalid OID: %s, expected: %s\n", ++ __LINE__, (unsigned long) i, str, tv[i].oid); ++ return; ++ } ++ ++ } ++} +diff --git a/grub-core/lib/libtasn1_wrap/tests/object-id-encoding.c b/grub-core/lib/libtasn1_wrap/tests/object-id-encoding.c +new file mode 100644 +index 00000000000..3a83b58c59f +--- /dev/null ++++ b/grub-core/lib/libtasn1_wrap/tests/object-id-encoding.c +@@ -0,0 +1,120 @@ ++/* ++ * Copyright (C) 2019 Nikos Mavrogiannopoulos ++ * ++ * This file is part of LIBTASN1. ++ * ++ * This program is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program. If not, see . ++ * ++ */ ++ ++#include ++#include ++#include ++#include ++#include "../wrap_tests.h" ++ ++struct tv ++{ ++ int der_len; ++ const unsigned char *der; ++ const char *oid; ++ int expected_error; ++}; ++ ++static const struct tv tv[] = { ++ {.der_len = 0, ++ .der = (void *) "", ++ .oid = "5.999.3", ++ .expected_error = ASN1_VALUE_NOT_VALID /* cannot start with 5 */ ++ }, ++ {.der_len = 0, ++ .der = (void *) "", ++ .oid = "0.48.9", ++ .expected_error = ASN1_VALUE_NOT_VALID /* second field cannot be 48 */ ++ }, ++ {.der_len = 0, ++ .der = (void *) "", ++ .oid = "1.40.9", ++ .expected_error = ASN1_VALUE_NOT_VALID /* second field cannot be 40 */ ++ }, ++ {.der_len = 4, ++ .der = (void *) "\x06\x02\x4f\x63", ++ .oid = "1.39.99", ++ .expected_error = ASN1_SUCCESS, ++ }, ++ {.der_len = 6, ++ .der = (void *) "\x06\x04\x01\x02\x03\x04", ++ .oid = "0.1.2.3.4", ++ .expected_error = ASN1_SUCCESS}, ++ {.der_len = 5, ++ .der = (void *) "\x06\x03\x51\x02\x03", ++ .oid = "2.1.2.3", ++ .expected_error = ASN1_SUCCESS}, ++ {.der_len = 5, ++ .der = (void *) "\x06\x03\x88\x37\x03", ++ .oid = "2.999.3", ++ .expected_error = ASN1_SUCCESS}, ++ {.der_len = 12, ++ .der = (void *) "\x06\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x05\x01", ++ .oid = "1.3.6.1.4.1.2312.9.5.1", ++ .expected_error = ASN1_SUCCESS}, ++ {.der_len = 19, ++ .der = (void *) "\x06\x11\xfa\x80\x00\x00\x00\x0e\x01\x0e\xfa\x80\x00\x00\x00\x0e\x63\x6f\x6d", ++ .oid = "2.1998768.0.0.14.1.14.1998848.0.0.14.99.111.109", ++ .expected_error = ASN1_SUCCESS}, ++ {.der_len = 19, ++ .der = ++ (void *) ++ "\x06\x11\x2b\x06\x01\x04\x01\x92\x08\x09\x02\xaa\xda\xbe\xbe\xfa\x72\x01\x07", ++ .oid = "1.3.6.1.4.1.2312.9.2.1467399257458.1.7", ++ .expected_error = ASN1_SUCCESS}, ++}; ++ ++void ++test_object_id_encoding(void) ++{ ++ unsigned char der[128]; ++ int ret, der_len, i; ++ ++ for (i = 0; i < (int)(sizeof (tv) / sizeof (tv[0])); i++) ++ { ++ der_len = sizeof(der); ++ ret = asn1_object_id_der(tv[i].oid, der, &der_len, 0); ++ if (ret != ASN1_SUCCESS) ++ { ++ if (ret == tv[i].expected_error) ++ continue; ++ grub_fatal ( ++ "%d: iter %lu, encoding of OID failed: %s\n", ++ __LINE__, (unsigned long) i, asn1_strerror(ret)); ++ return; ++ } ++ else if (ret != tv[i].expected_error) ++ { ++ grub_fatal ( ++ "%d: iter %lu, encoding of OID %s succeeded when expecting failure\n", ++ __LINE__, (unsigned long) i, tv[i].oid); ++ return; ++ } ++ ++ if (der_len != tv[i].der_len || grub_memcmp(der, tv[i].der, der_len) != 0) ++ { ++ grub_fatal ( ++ "%d: iter %lu, re-encoding of OID %s resulted to different string (%d vs %d bytes)\n", ++ __LINE__, (unsigned long) i, tv[i].oid, der_len, tv[i].der_len); ++ ++ return; ++ } ++ } ++} +diff --git a/grub-core/lib/libtasn1_wrap/tests/octet-string.c b/grub-core/lib/libtasn1_wrap/tests/octet-string.c +new file mode 100644 +index 00000000000..d8a049e8df0 +--- /dev/null ++++ b/grub-core/lib/libtasn1_wrap/tests/octet-string.c +@@ -0,0 +1,211 @@ ++/* ++ * Copyright (C) 2011-2020 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * This program is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program. If not, see . ++ * ++ * Written by Simon Josefsson and Nikos Mavrogiannopoulos ++ * ++ */ ++ ++#include ++#include ++#include ++#include ++#include "../wrap_tests.h" ++ ++ ++struct tv ++{ ++ const char *name; ++ int der_len; ++ const unsigned char *der_str; ++ int len; ++ const unsigned char *string; ++ int expected_error; ++ int ber; ++}; ++ ++static const struct tv tv[] = { ++ {.name = "primitive octet strings", ++ .der_len = 10, ++ .der_str = ++ (void*)"\x04\x08\x01\x23\x45\x67\x89\xab\xcd\xef", ++ .len = 8, ++ .string = ++ (void*)"\x01\x23\x45\x67\x89\xab\xcd\xef", ++ .ber = 0}, ++ {.der_len = 22, ++ .der_str = ++ (void*)"\x04\x14\x13\x00\xd9\xa8\x47\xf7\xf2\x1c\xf4\xb0\xec\x5f\xc1\x73\xe5\x1b\x25\xc2\x62\x27", ++ .len = 20, ++ .string = ++ (void*)"\x13\x00\xD9\xA8\x47\xF7\xF2\x1C\xF4\xB0\xEC\x5F\xC1\x73\xE5\x1B\x25\xC2\x62\x27"}, ++ ++ {.name = "long type of length", ++ .der_len = 23, ++ .der_str = ++ (void*)"\x04\x81\x14\x13\x00\xd9\xa8\x47\xf7\xf2\x1c\xf4\xb0\xec\x5f\xc1\x73\xe5\x1b\x25\xc2\x62\x27", ++ .len = 20, ++ .string = ++ (void*)"\x13\x00\xD9\xA8\x47\xF7\xF2\x1C\xF4\xB0\xEC\x5F\xC1\x73\xE5\x1B\x25\xC2\x62\x27", ++ .ber = 1}, ++ {.der_len = 11, ++ .der_str = ++ (void*)"\x04\x81\x08\x01\x23\x45\x67\x89\xab\xcd\xef", ++ .len = 8, ++ .string = ++ (void*)"\x01\x23\x45\x67\x89\xab\xcd\xef", ++ .ber = 1}, ++ ++ {.name = "constructed - indefinite", ++ .der_len = 11, ++ .der_str = (void*)"\x24\x80\x04\x05\x01\x02\x03\x04\x05\x00\x00", ++ .len = 5, ++ .string = (void*)"\x01\x02\x03\x04\x05", ++ .ber = 1, ++ }, ++ ++ {.name = "constructed - definite - concat", ++ .der_len = 12, ++ .der_str = (void*)"\x24\x0a\x04\x04\x0a\x0b\x0c\x0d\x04\x02\x0e\x0f", ++ .len = 6, ++ .string = (void*)"\x0a\x0b\x0c\x0d\x0e\x0f", ++ .ber = 1, ++ }, ++ {.name = "constructed - definite - recursive", ++ .der_len = 15, ++ .der_str = (void*)"\x24\x0d\x04\x04\x0a\x0b\x0c\x0d\x24\x05\x04\x00\x04\x01\x0f", ++ .len = 5, ++ .string = (void*)"\x0a\x0b\x0c\x0d\x0f", ++ .ber = 1, ++ }, ++ {.name = "constructed - definite - single", ++ .der_len = 7, ++ .der_str = (void*)"\x24\x05\x04\x03\x01\x02\x03", ++ .len = 3, ++ .string = (void*)"\x01\x02\x03", ++ .ber = 1, ++ }, ++ ++ /* a large amount of recursive indefinite encoding */ ++ {.name = "a large amount of recursive indefinite encoding", ++ .der_len = 29325, ++ .der_str = (void*)"\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80", ++ .len = 0, ++ .ber = 1, ++ .expected_error = ASN1_DER_ERROR ++ } ++}; ++ ++void ++test_octet_string (void) ++{ ++ unsigned char str[100]; ++ unsigned char der[100]; ++ int der_len = sizeof (der); ++ int str_size = sizeof (str); ++ unsigned char *tmp = NULL; ++ int ret, ret_len; ++ grub_size_t i; ++ ++ for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++) ++ { ++ /* Decode */ ++ ++ if (tv[i].ber == 0) ++ { ++ str_size = sizeof (str); ++ ret = ++ asn1_get_octet_der (tv[i].der_str + 1, ++ tv[i].der_len - 1, &ret_len, str, ++ sizeof (str), &str_size); ++ if (ret != tv[i].expected_error) ++ { ++ grub_fatal ( ++ "%d: asn1_get_octet_der: %s: got %d expected %d\n", ++ __LINE__, tv[i].name, ret, ++ tv[i].expected_error); ++ return; ++ } ++ if (tv[i].expected_error) ++ continue; ++ ++ if (ret_len != tv[i].der_len - 1) ++ { ++ grub_fatal ( ++ "%d: error in DER, length returned is %d, had %d\n", ++ __LINE__, ret_len, tv[i].der_len - 1); ++ return; ++ } ++ ++ if (str_size != tv[i].len ++ || grub_memcmp (tv[i].string, str, tv[i].len) != 0) ++ { ++ grub_fatal ( ++ "%d: memcmp: %s: got invalid decoding\n", ++ __LINE__, tv[i].name); ++ ++ return; ++ } ++ ++ /* Encode */ ++ der_len = sizeof (der); ++ asn1_octet_der (str, str_size, der, &der_len); ++ ++ if (der_len != tv[i].der_len - 1 ++ || grub_memcmp (tv[i].der_str + 1, der, tv[i].der_len - 1) != 0) ++ { ++ grub_fatal ( ++ "encoding: %s: got invalid encoding\n", ++ tv[i].name); ++ return; ++ } ++ } ++ ++ ret = ++ asn1_decode_simple_ber (ASN1_ETYPE_OCTET_STRING, ++ tv[i].der_str, tv[i].der_len, ++ &tmp, (unsigned int*)&str_size, (unsigned int*)&der_len); ++ if (ret != tv[i].expected_error) ++ { ++ grub_fatal ( ++ "%d: asn1_decode_simple_ber: %s: got %s expected %s\n", ++ __LINE__, tv[i].name, asn1_strerror(ret), asn1_strerror(tv[i].expected_error)); ++ return; ++ } ++ if (tv[i].expected_error) ++ continue; ++ ++ if (der_len != tv[i].der_len) ++ { ++ grub_fatal ( ++ "%d: error: %s: DER, length returned is %d, had %d\n", ++ __LINE__, tv[i].name, der_len, tv[i].der_len); ++ return; ++ } ++ ++ if (str_size != tv[i].len || grub_memcmp (tv[i].string, tmp, tv[i].len) != 0) ++ { ++ grub_fatal ( ++ "%d: memcmp: %s: got invalid decoding\n", ++ __LINE__, tv[i].name); ++ return; ++ } ++ grub_free (tmp); ++ tmp = NULL; ++ ++ } ++} +diff --git a/grub-core/lib/libtasn1_wrap/tests/reproducers.c b/grub-core/lib/libtasn1_wrap/tests/reproducers.c +new file mode 100644 +index 00000000000..dc7268d4c6c +--- /dev/null ++++ b/grub-core/lib/libtasn1_wrap/tests/reproducers.c +@@ -0,0 +1,81 @@ ++/* ++ * Copyright (C) 2019 Free Software Foundation, Inc. ++ * ++ * This file is part of LIBTASN1. ++ * ++ * This program is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program. If not, see . ++ * ++ */ ++ ++/****************************************************************/ ++/* Description: run reproducers for several fixed issues */ ++/****************************************************************/ ++ ++#include ++#include ++#include ++#include "../wrap_tests.h" ++ ++#define CONST_DOWN (1U<<29) ++ ++/* produces endless loop (fixed by d4b624b2): ++ * The following translates into a single node with all pointers ++ * (right,left,down) set to NULL. */ ++const asn1_static_node endless_asn1_tab[] = { ++ { "TEST_TREE", 536875024, NULL }, ++ { NULL, 0, NULL } ++}; ++ ++/* produces memory leak (fixed by f16d1ff9): ++ * 152 bytes in 1 blocks are definitely lost in loss record 1 of 1 ++ * at 0x4837B65: calloc (vg_replace_malloc.c:762) ++ * by 0x4851C0D: _asn1_add_static_node (parser_aux.c:71) ++ * by 0x4853AAC: asn1_array2tree (structure.c:200) ++ * by 0x10923B: main (single_node.c:67) ++ */ ++const asn1_static_node tab[] = { ++{ "a", CONST_DOWN, "" }, ++{ "b", 0, "" }, ++{ "c", 0, "" }, ++{ NULL, 0, NULL } ++}; ++ ++void ++test_reproducers (void) ++{ ++ int result; ++ asn1_node definitions = NULL; ++ char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; ++ ++ result = asn1_array2tree (endless_asn1_tab, &definitions, errorDescription); ++ if (result != ASN1_SUCCESS) ++ { ++ grub_fatal ("Error: %s\nErrorDescription = %s\n\n", ++ asn1_strerror (result), errorDescription); ++ return; ++ } ++ ++ asn1_delete_structure (&definitions); ++ ++ definitions = NULL; ++ result = asn1_array2tree (tab, &definitions, errorDescription); ++ if (result != ASN1_SUCCESS) ++ { ++ grub_fatal ("Error: %s\nErrorDescription = %s\n\n", ++ asn1_strerror (result), errorDescription); ++ return; ++ } ++ ++ asn1_delete_structure (&definitions); ++} +diff --git a/grub-core/lib/libtasn1_wrap/wrap_tests.c b/grub-core/lib/libtasn1_wrap/wrap_tests.c +new file mode 100644 +index 00000000000..75fcd21f0d5 +--- /dev/null ++++ b/grub-core/lib/libtasn1_wrap/wrap_tests.c +@@ -0,0 +1,75 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2020 IBM Corporation ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include "wrap_tests.h" ++ ++/* ++ * libtasn1 tests - from which this is derived - are provided under GPL3+. ++ */ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++static grub_command_t cmd; ++ ++static grub_err_t ++grub_cmd_asn1test (grub_command_t cmdd __attribute__((unused)), ++ int argc __attribute__((unused)), ++ char **args __attribute__((unused))) ++{ ++ grub_printf ("test_CVE_2018_1000654\n"); ++ test_CVE_2018_1000654 (); ++ ++ grub_printf ("test_object_id_decoding\n"); ++ test_object_id_decoding (); ++ ++ grub_printf ("test_object_id_encoding\n"); ++ test_object_id_encoding (); ++ ++ grub_printf ("test_octet_string\n"); ++ test_octet_string (); ++ ++ grub_printf ("test_overflow\n"); ++ test_overflow (); ++ ++ grub_printf ("test_reproducers\n"); ++ test_overflow (); ++ ++ grub_printf ("test_simple\n"); ++ test_simple (); ++ ++ grub_printf ("test_strings\n"); ++ test_strings (); ++ ++ grub_printf ("ASN.1 self-tests passed\n"); ++ ++ return GRUB_ERR_NONE; ++} ++ ++ ++GRUB_MOD_INIT(test_asn1) ++{ ++ cmd = grub_register_command ("test_asn1", grub_cmd_asn1test, NULL, ++ "Run self-tests for the ASN.1 parser."); ++} ++ ++GRUB_MOD_FINI(test_asn1) ++{ ++ grub_unregister_command (cmd); ++} +diff --git a/grub-core/lib/libtasn1_wrap/tests/CVE-2018-1000654-1_asn1_tab.h b/grub-core/lib/libtasn1_wrap/tests/CVE-2018-1000654-1_asn1_tab.h +new file mode 100644 +index 00000000000..1e7d3d64f55 +--- /dev/null ++++ b/grub-core/lib/libtasn1_wrap/tests/CVE-2018-1000654-1_asn1_tab.h +@@ -0,0 +1,32 @@ ++#if HAVE_CONFIG_H ++# include "config.h" ++#endif ++ ++#include ++ ++const asn1_static_node CVE_2018_1000654_1_asn1_tab[] = { ++ { "TEST_TREE", 536875024, NULL }, ++ { NULL, 1610612748, NULL }, ++ { "iso", 1073741825, "1"}, ++ { "identified-organization", 1073741825, "3"}, ++ { "dod", 1073741825, "6"}, ++ { "internet", 1073741825, "1"}, ++ { "security", 1073741825, "5"}, ++ { "mechanisms", 1073741825, "5"}, ++ { "pkix", 1073741825, "7"}, ++ { "id-mod", 1073741825, "0"}, ++ { "id-pkix1-implicit-88", 1, "2"}, ++ { "id-xnyTest", 1879048204, NULL }, ++ { NULL, 1073741825, "id-ix"}, ++ { NULL, 1073741825, "29"}, ++ { NULL, 1, "1"}, ++ { "id-ix", 1880096780, "OBJECR"}, ++ { NULL, 1073741825, "id-ix"}, ++ { NULL, 1073741825, "29"}, ++ { NULL, 1, "2"}, ++ { "id-xnyTest", 805306380, NULL }, ++ { NULL, 1073741825, "id-ix"}, ++ { NULL, 1073741825, "29"}, ++ { NULL, 1, "1"}, ++ { NULL, 0, NULL } ++}; +diff --git a/grub-core/lib/libtasn1_wrap/tests/CVE-2018-1000654-2_asn1_tab.h b/grub-core/lib/libtasn1_wrap/tests/CVE-2018-1000654-2_asn1_tab.h +new file mode 100644 +index 00000000000..e2561e5ec6d +--- /dev/null ++++ b/grub-core/lib/libtasn1_wrap/tests/CVE-2018-1000654-2_asn1_tab.h +@@ -0,0 +1,36 @@ ++#if HAVE_CONFIG_H ++# include "config.h" ++#endif ++ ++#include ++ ++const asn1_static_node CVE_2018_1000654_2_asn1_tab[] = { ++ { "TEST_TREE", 536875024, NULL }, ++ { NULL, 1610612748, NULL }, ++ { "iso", 1073741825, "1"}, ++ { "identified-organization", 1073741825, "3"}, ++ { "dod", 1073741825, "6"}, ++ { "internet", 1073741825, "1"}, ++ { "security", 1073741825, "5"}, ++ { "mechanisms", 1073741825, "5"}, ++ { "pkix", 1073741825, "7"}, ++ { "id-mod", 1073741825, "0"}, ++ { "id-pkix1-implicit-88", 1, "2"}, ++ { "id-oneTest", 1879048204, NULL }, ++ { NULL, 1073741825, "id-two"}, ++ { NULL, 1073741825, "9"}, ++ { NULL, 1, "1"}, ++ { "id-two", 1879048204, NULL }, ++ { NULL, 1073741825, "id-three"}, ++ { NULL, 1073741825, "2"}, ++ { NULL, 1, "2"}, ++ { "id-three", 1879048204, NULL }, ++ { NULL, 1073741825, "id-four"}, ++ { NULL, 1073741825, "3"}, ++ { NULL, 1, "3"}, ++ { "id-four", 805306380, NULL }, ++ { NULL, 1073741825, "id-two"}, ++ { NULL, 1073741825, "3"}, ++ { NULL, 1, "3"}, ++ { NULL, 0, NULL } ++}; +diff --git a/grub-core/lib/libtasn1_wrap/wrap_tests.h b/grub-core/lib/libtasn1_wrap/wrap_tests.h +new file mode 100644 +index 00000000000..555e56dd202 +--- /dev/null ++++ b/grub-core/lib/libtasn1_wrap/wrap_tests.h +@@ -0,0 +1,38 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2020 IBM Corporation ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#ifndef LIBTASN1_WRAP_TESTS_H ++#define LIBTASN1_WRAP_TESTS_H ++ ++void test_CVE_2018_1000654 (void); ++ ++void test_object_id_encoding (void); ++ ++void test_object_id_decoding (void); ++ ++void test_octet_string (void); ++ ++void test_overflow (void); ++ ++void test_reproducers (void); ++ ++void test_simple (void); ++ ++void test_strings (void); ++ ++#endif +diff --git a/.gitignore b/.gitignore +index 594d0134d33..856e69bc5c1 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -264,6 +264,7 @@ widthspec.bin + /stamp-h1 + /syslinux_test + /tar_test ++/test_asn1 + /test_sha512sum + /test_unset + /tests/syslinux/ubuntu10.04_grub.cfg +diff --git a/tests/test_asn1.in b/tests/test_asn1.in +new file mode 100644 +index 00000000000..8173c5c270e +--- /dev/null ++++ b/tests/test_asn1.in +@@ -0,0 +1,12 @@ ++#! @BUILD_SHEBANG@ ++set -e ++ ++. "@builddir@/grub-core/modinfo.sh" ++ ++out=`echo test_asn1 | @builddir@/grub-shell` ++ ++if [ "$(echo "$out" | tail -n 1)" != "ASN.1 self-tests passed" ]; then ++ echo "ASN.1 test failure: $out" ++ exit 1 ++fi ++ diff --git a/0174-autogen.sh-use-find-wholename-for-long-path-matches.patch b/0174-autogen.sh-use-find-wholename-for-long-path-matches.patch deleted file mode 100644 index e2b3deed668cf6e8aceba98435f7159555d205c9..0000000000000000000000000000000000000000 --- a/0174-autogen.sh-use-find-wholename-for-long-path-matches.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 948006eab0c0414ebb2e197fbbf406808ac3dd10 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 29 Jul 2019 14:01:50 -0400 -Subject: [PATCH 174/220] autogen.sh: use find -wholename for long path matches - -Signed-off-by: Peter Jones ---- - autogen.sh | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/autogen.sh b/autogen.sh -index ef43270..a1783d6 100755 ---- a/autogen.sh -+++ b/autogen.sh -@@ -13,7 +13,7 @@ fi - export LC_COLLATE=C - unset LC_ALL - --find . -iname '*.[ch]' ! -ipath './grub-core/lib/libgcrypt-grub/*' ! -ipath './build-aux/*' ! -ipath './grub-core/lib/libgcrypt/src/misc.c' ! -ipath './grub-core/lib/libgcrypt/src/global.c' ! -ipath './grub-core/lib/libgcrypt/src/secmem.c' ! -ipath './util/grub-gen-widthspec.c' ! -ipath './util/grub-gen-asciih.c' ! -ipath './gnulib/*' ! -iname './grub-core/lib/gnulib/*' |sort > po/POTFILES.in -+find . -iname '*.[ch]' ! -ipath './grub-core/lib/libgcrypt-grub/*' ! -ipath './build-aux/*' ! -ipath './grub-core/lib/libgcrypt/src/misc.c' ! -ipath './grub-core/lib/libgcrypt/src/global.c' ! -ipath './grub-core/lib/libgcrypt/src/secmem.c' ! -ipath './util/grub-gen-widthspec.c' ! -ipath './util/grub-gen-asciih.c' ! -ipath './gnulib/*' ! -wholename './grub-core/lib/gnulib/*' |sort > po/POTFILES.in - find util -iname '*.in' ! -name Makefile.in |sort > po/POTFILES-shell.in - - echo "Importing unicode..." --- -1.8.3.1 - diff --git a/0174-grub-install-support-embedding-x509-certificates.patch b/0174-grub-install-support-embedding-x509-certificates.patch new file mode 100644 index 0000000000000000000000000000000000000000..bd02e6de5ad78f67ce47ae539cafe416cf562e29 --- /dev/null +++ b/0174-grub-install-support-embedding-x509-certificates.patch @@ -0,0 +1,252 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alastair D'Silva +Date: Mon, 6 Jul 2020 13:33:04 +1000 +Subject: [PATCH] grub-install: support embedding x509 certificates + +To support verification of appended signatures, we need a way to +embed the necessary public keys. Existing appended signature schemes +in the Linux kernel use X.509 certificates, so allow certificates to +be embedded in the grub core image in the same way as PGP keys. + +Signed-off-by: Alastair D'Silva +Signed-off-by: Daniel Axtens +--- + grub-core/commands/pgp.c | 2 +- + util/grub-install-common.c | 22 +++++++++++++++++++++- + util/grub-mkimage.c | 15 +++++++++++++-- + util/mkimage.c | 38 ++++++++++++++++++++++++++++++++++++-- + include/grub/kernel.h | 4 +++- + include/grub/util/install.h | 7 +++++-- + 6 files changed, 79 insertions(+), 9 deletions(-) + +diff --git a/grub-core/commands/pgp.c b/grub-core/commands/pgp.c +index 355a43844ac..b81ac0ae46c 100644 +--- a/grub-core/commands/pgp.c ++++ b/grub-core/commands/pgp.c +@@ -944,7 +944,7 @@ GRUB_MOD_INIT(pgp) + grub_memset (&pseudo_file, 0, sizeof (pseudo_file)); + + /* Not an ELF module, skip. */ +- if (header->type != OBJ_TYPE_PUBKEY) ++ if (header->type != OBJ_TYPE_GPG_PUBKEY) + continue; + + pseudo_file.fs = &pseudo_fs; +diff --git a/util/grub-install-common.c b/util/grub-install-common.c +index aab2a941f85..422f82362c7 100644 +--- a/util/grub-install-common.c ++++ b/util/grub-install-common.c +@@ -460,6 +460,8 @@ static char **pubkeys; + static size_t npubkeys; + static char *sbat; + static int disable_shim_lock; ++static char **x509keys; ++static size_t nx509keys; + static grub_compression_t compression; + static size_t appsig_size; + +@@ -500,6 +502,11 @@ grub_install_parse (int key, char *arg) + return 1; + case GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK: + disable_shim_lock = 1; ++ case 'x': ++ x509keys = xrealloc (x509keys, ++ sizeof (x509keys[0]) ++ * (nx509keys + 1)); ++ x509keys[nx509keys++] = xstrdup (arg); + return 1; + + case GRUB_INSTALL_OPTIONS_VERBOSITY: +@@ -627,6 +634,9 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, + for (pk = pubkeys; pk < pubkeys + npubkeys; pk++) + slen += 20 + grub_strlen (*pk); + ++ for (pk = x509keys; pk < x509keys + nx509keys; pk++) ++ slen += 10 + grub_strlen (*pk); ++ + for (md = modules.entries; *md; md++) + { + slen += 10 + grub_strlen (*md); +@@ -655,6 +665,14 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, + *p++ = ' '; + } + ++ for (pk = x509keys; pk < x509keys + nx509keys; pk++) ++ { ++ p = grub_stpcpy (p, "--x509 '"); ++ p = grub_stpcpy (p, *pk); ++ *p++ = '\''; ++ *p++ = ' '; ++ } ++ + for (md = modules.entries; *md; md++) + { + *p++ = '\''; +@@ -688,7 +706,9 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, + + grub_install_generate_image (dir, prefix, fp, outname, + modules.entries, memdisk_path, +- pubkeys, npubkeys, config_path, tgt, ++ pubkeys, npubkeys, ++ x509keys, nx509keys, ++ config_path, tgt, + note, appsig_size, compression, dtb, sbat, + disable_shim_lock); + while (dc--) +diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c +index 8a53310548b..e1f1112784a 100644 +--- a/util/grub-mkimage.c ++++ b/util/grub-mkimage.c +@@ -75,7 +75,8 @@ static struct argp_option options[] = { + /* TRANSLATORS: "embed" is a verb (command description). "*/ + {"config", 'c', N_("FILE"), 0, N_("embed FILE as an early config"), 0}, + /* TRANSLATORS: "embed" is a verb (command description). "*/ +- {"pubkey", 'k', N_("FILE"), 0, N_("embed FILE as public key for signature checking"), 0}, ++ {"pubkey", 'k', N_("FILE"), 0, N_("embed FILE as public key for PGP signature checking"), 0}, ++ {"x509", 'x', N_("FILE"), 0, N_("embed FILE as an x509 certificate for appended signature checking"), 0}, + /* TRANSLATORS: NOTE is a name of segment. */ + {"note", 'n', 0, 0, N_("add NOTE segment for CHRP IEEE1275"), 0}, + {"output", 'o', N_("FILE"), 0, N_("output a generated image to FILE [default=stdout]"), 0}, +@@ -124,6 +125,8 @@ struct arguments + char *dtb; + char **pubkeys; + size_t npubkeys; ++ char **x509keys; ++ size_t nx509keys; + char *font; + char *config; + char *sbat; +@@ -206,6 +209,13 @@ argp_parser (int key, char *arg, struct argp_state *state) + arguments->pubkeys[arguments->npubkeys++] = xstrdup (arg); + break; + ++ case 'x': ++ arguments->x509keys = xrealloc (arguments->x509keys, ++ sizeof (arguments->x509keys[0]) ++ * (arguments->nx509keys + 1)); ++ arguments->x509keys[arguments->nx509keys++] = xstrdup (arg); ++ break; ++ + case 'c': + if (arguments->config) + free (arguments->config); +@@ -332,7 +342,8 @@ main (int argc, char *argv[]) + grub_install_generate_image (arguments.dir, arguments.prefix, fp, + arguments.output, arguments.modules, + arguments.memdisk, arguments.pubkeys, +- arguments.npubkeys, arguments.config, ++ arguments.npubkeys, arguments.x509keys, ++ arguments.nx509keys, arguments.config, + arguments.image_target, arguments.note, + arguments.appsig_size, arguments.comp, + arguments.dtb, arguments.sbat, +diff --git a/util/mkimage.c b/util/mkimage.c +index bab12276010..8319e8dfbde 100644 +--- a/util/mkimage.c ++++ b/util/mkimage.c +@@ -867,7 +867,8 @@ void + grub_install_generate_image (const char *dir, const char *prefix, + FILE *out, const char *outname, char *mods[], + char *memdisk_path, char **pubkey_paths, +- size_t npubkeys, char *config_path, ++ size_t npubkeys, char **x509key_paths, ++ size_t nx509keys, char *config_path, + const struct grub_install_image_target_desc *image_target, + int note, size_t appsig_size, grub_compression_t comp, + const char *dtb_path, const char *sbat_path, +@@ -913,6 +914,19 @@ grub_install_generate_image (const char *dir, const char *prefix, + } + } + ++ { ++ size_t i; ++ for (i = 0; i < nx509keys; i++) ++ { ++ size_t curs; ++ curs = ALIGN_ADDR (grub_util_get_image_size (x509key_paths[i])); ++ grub_util_info ("the size of x509 public key %u is 0x%" ++ GRUB_HOST_PRIxLONG_LONG, ++ (unsigned) i, (unsigned long long) curs); ++ total_module_size += curs + sizeof (struct grub_module_header); ++ } ++ } ++ + if (memdisk_path) + { + memdisk_size = ALIGN_UP(grub_util_get_image_size (memdisk_path), 512); +@@ -1034,7 +1048,7 @@ grub_install_generate_image (const char *dir, const char *prefix, + curs = grub_util_get_image_size (pubkey_paths[i]); + + header = (struct grub_module_header *) (kernel_img + offset); +- header->type = grub_host_to_target32 (OBJ_TYPE_PUBKEY); ++ header->type = grub_host_to_target32 (OBJ_TYPE_GPG_PUBKEY); + header->size = grub_host_to_target32 (curs + sizeof (*header)); + offset += sizeof (*header); + +@@ -1043,6 +1057,26 @@ grub_install_generate_image (const char *dir, const char *prefix, + } + } + ++ { ++ size_t i; ++ for (i = 0; i < nx509keys; i++) ++ { ++ size_t curs; ++ struct grub_module_header *header; ++ ++ curs = grub_util_get_image_size (x509key_paths[i]); ++ ++ header = (struct grub_module_header *) (kernel_img + offset); ++ header->type = grub_host_to_target32 (OBJ_TYPE_X509_PUBKEY); ++ header->size = grub_host_to_target32 (curs + sizeof (*header)); ++ offset += sizeof (*header); ++ ++ grub_util_load_image (x509key_paths[i], kernel_img + offset); ++ offset += ALIGN_ADDR (curs); ++ } ++ } ++ ++ + if (memdisk_path) + { + struct grub_module_header *header; +diff --git a/include/grub/kernel.h b/include/grub/kernel.h +index 55849777eaa..98edc0863f6 100644 +--- a/include/grub/kernel.h ++++ b/include/grub/kernel.h +@@ -30,7 +30,9 @@ enum + OBJ_TYPE_PREFIX, + OBJ_TYPE_PUBKEY, + OBJ_TYPE_DTB, +- OBJ_TYPE_DISABLE_SHIM_LOCK ++ OBJ_TYPE_DISABLE_SHIM_LOCK, ++ OBJ_TYPE_GPG_PUBKEY, ++ OBJ_TYPE_X509_PUBKEY, + }; + + /* The module header. */ +diff --git a/include/grub/util/install.h b/include/grub/util/install.h +index cf4531e02b6..51f3b13ac13 100644 +--- a/include/grub/util/install.h ++++ b/include/grub/util/install.h +@@ -67,6 +67,8 @@ + N_("SBAT metadata"), 0 }, \ + { "disable-shim-lock", GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK, 0, 0, \ + N_("disable shim_lock verifier"), 0 }, \ ++ { "x509key", 'x', N_("FILE"), 0, \ ++ N_("embed FILE as an x509 certificate for signature checking"), 0}, \ + { "appended-signature-size", GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE,\ + "SIZE", 0, N_("Add a note segment reserving SIZE bytes for an appended signature"), \ + 1}, \ +@@ -188,8 +190,9 @@ void + grub_install_generate_image (const char *dir, const char *prefix, + FILE *out, + const char *outname, char *mods[], +- char *memdisk_path, char **pubkey_paths, +- size_t npubkeys, ++ char *memdisk_path, ++ char **pubkey_paths, size_t npubkeys, ++ char **x509key_paths, size_t nx509keys, + char *config_path, + const struct grub_install_image_target_desc *image_target, + int note, size_t appsig_size, diff --git a/0175-Fix-build-error-with-the-fdt-module-on-risc-v.patch b/0175-Fix-build-error-with-the-fdt-module-on-risc-v.patch deleted file mode 100644 index dee1042ec9990b955b68e42ba2c66db00dd5489d..0000000000000000000000000000000000000000 --- a/0175-Fix-build-error-with-the-fdt-module-on-risc-v.patch +++ /dev/null @@ -1,43 +0,0 @@ -From 0982a417f60eeb8f117ae4d2931947c0f4515934 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 27 Aug 2019 10:34:24 +0200 -Subject: [PATCH 175/220] Fix build error with the fdt module on risc-v - -The risc-v architecture also uses Device Trees, but the symbols in the -fdt header aren't defined for this arch which lead to following error: - -BUILDSTDERR: ../../grub-core/loader/efi/fdt.c: In function 'grub_fdt_load': -BUILDSTDERR: ../../grub-core/loader/efi/fdt.c:48:39: warning: implicit declaration of function 'grub_fdt_get_totalsize' [-Wimplicit-function-declaration] -BUILDSTDERR: 48 | size = GRUB_EFI_BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt)); - -Signed-off-by: Javier Martinez Canillas ---- - include/grub/fdt.h | 6 ++++-- - 1 file changed, 4 insertions(+), 2 deletions(-) - -diff --git a/include/grub/fdt.h b/include/grub/fdt.h -index 2041341..3514aa4 100644 ---- a/include/grub/fdt.h -+++ b/include/grub/fdt.h -@@ -19,7 +19,8 @@ - #ifndef GRUB_FDT_HEADER - #define GRUB_FDT_HEADER 1 - --#if !defined(GRUB_MACHINE_EMU) && (defined(__arm__) || defined(__aarch64__)) -+#if !defined(GRUB_MACHINE_EMU) && \ -+ (defined(__arm__) || defined(__aarch64__) || defined(__riscv)) - - #include - #include -@@ -146,6 +147,7 @@ int EXPORT_FUNC(grub_fdt_set_prop) (void *fdt, unsigned int nodeoffset, const ch - grub_fdt_set_prop ((fdt), (nodeoffset), "reg", reg_64, 16); \ - }) - --#endif /* defined(__arm__) || defined(__aarch64__) */ -+#endif /* !defined(GRUB_MACHINE_EMU) && \ -+ (defined(__arm__) || defined(__aarch64__) || defined(__riscv)) */ - - #endif /* ! GRUB_FDT_HEADER */ --- -1.8.3.1 - diff --git a/0175-appended-signatures-import-GNUTLS-s-ASN.1-descriptio.patch b/0175-appended-signatures-import-GNUTLS-s-ASN.1-descriptio.patch new file mode 100644 index 0000000000000000000000000000000000000000..7b7d70c48a5f2d9286e7c1afbe4cc44a7375ac94 --- /dev/null +++ b/0175-appended-signatures-import-GNUTLS-s-ASN.1-descriptio.patch @@ -0,0 +1,639 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Thu, 30 Jul 2020 01:35:10 +1000 +Subject: [PATCH] appended signatures: import GNUTLS's ASN.1 description files + +In order to parse PKCS#7 messages and X.509 certificates with libtasn1, +we need some information about how they are encoded. + +We get these from GNUTLS, which has the benefit that they support the +features we need and are well tested. + +The GNUTLS license is LGPLv2.1+, which is GPLv3 compatible, allowing +us to import it without issue. + +Signed-off-by: Daniel Axtens +--- + grub-core/commands/appendedsig/gnutls_asn1_tab.c | 121 ++++++ + grub-core/commands/appendedsig/pkix_asn1_tab.c | 484 +++++++++++++++++++++++ + 2 files changed, 605 insertions(+) + create mode 100644 grub-core/commands/appendedsig/gnutls_asn1_tab.c + create mode 100644 grub-core/commands/appendedsig/pkix_asn1_tab.c + +diff --git a/grub-core/commands/appendedsig/gnutls_asn1_tab.c b/grub-core/commands/appendedsig/gnutls_asn1_tab.c +new file mode 100644 +index 00000000000..ddd1314e63b +--- /dev/null ++++ b/grub-core/commands/appendedsig/gnutls_asn1_tab.c +@@ -0,0 +1,121 @@ ++#include ++#include ++ ++const asn1_static_node gnutls_asn1_tab[] = { ++ { "GNUTLS", 536872976, NULL }, ++ { NULL, 1073741836, NULL }, ++ { "RSAPublicKey", 1610612741, NULL }, ++ { "modulus", 1073741827, NULL }, ++ { "publicExponent", 3, NULL }, ++ { "RSAPrivateKey", 1610612741, NULL }, ++ { "version", 1073741827, NULL }, ++ { "modulus", 1073741827, NULL }, ++ { "publicExponent", 1073741827, NULL }, ++ { "privateExponent", 1073741827, NULL }, ++ { "prime1", 1073741827, NULL }, ++ { "prime2", 1073741827, NULL }, ++ { "exponent1", 1073741827, NULL }, ++ { "exponent2", 1073741827, NULL }, ++ { "coefficient", 1073741827, NULL }, ++ { "otherPrimeInfos", 16386, "OtherPrimeInfos"}, ++ { "ProvableSeed", 1610612741, NULL }, ++ { "algorithm", 1073741836, NULL }, ++ { "seed", 7, NULL }, ++ { "OtherPrimeInfos", 1612709899, NULL }, ++ { "MAX", 1074266122, "1"}, ++ { NULL, 2, "OtherPrimeInfo"}, ++ { "OtherPrimeInfo", 1610612741, NULL }, ++ { "prime", 1073741827, NULL }, ++ { "exponent", 1073741827, NULL }, ++ { "coefficient", 3, NULL }, ++ { "AlgorithmIdentifier", 1610612741, NULL }, ++ { "algorithm", 1073741836, NULL }, ++ { "parameters", 541081613, NULL }, ++ { "algorithm", 1, NULL }, ++ { "DigestInfo", 1610612741, NULL }, ++ { "digestAlgorithm", 1073741826, "DigestAlgorithmIdentifier"}, ++ { "digest", 7, NULL }, ++ { "DigestAlgorithmIdentifier", 1073741826, "AlgorithmIdentifier"}, ++ { "DSAPublicKey", 1073741827, NULL }, ++ { "DSAParameters", 1610612741, NULL }, ++ { "p", 1073741827, NULL }, ++ { "q", 1073741827, NULL }, ++ { "g", 3, NULL }, ++ { "DSASignatureValue", 1610612741, NULL }, ++ { "r", 1073741827, NULL }, ++ { "s", 3, NULL }, ++ { "DSAPrivateKey", 1610612741, NULL }, ++ { "version", 1073741827, NULL }, ++ { "p", 1073741827, NULL }, ++ { "q", 1073741827, NULL }, ++ { "g", 1073741827, NULL }, ++ { "Y", 1073741827, NULL }, ++ { "priv", 3, NULL }, ++ { "DHParameter", 1610612741, NULL }, ++ { "prime", 1073741827, NULL }, ++ { "base", 1073741827, NULL }, ++ { "privateValueLength", 16387, NULL }, ++ { "ECParameters", 1610612754, NULL }, ++ { "namedCurve", 12, NULL }, ++ { "ECPrivateKey", 1610612741, NULL }, ++ { "Version", 1073741827, NULL }, ++ { "privateKey", 1073741831, NULL }, ++ { "parameters", 1610637314, "ECParameters"}, ++ { NULL, 2056, "0"}, ++ { "publicKey", 536895494, NULL }, ++ { NULL, 2056, "1"}, ++ { "PrincipalName", 1610612741, NULL }, ++ { "name-type", 1610620931, NULL }, ++ { NULL, 2056, "0"}, ++ { "name-string", 536879115, NULL }, ++ { NULL, 1073743880, "1"}, ++ { NULL, 27, NULL }, ++ { "KRB5PrincipalName", 1610612741, NULL }, ++ { "realm", 1610620955, NULL }, ++ { NULL, 2056, "0"}, ++ { "principalName", 536879106, "PrincipalName"}, ++ { NULL, 2056, "1"}, ++ { "RSAPSSParameters", 1610612741, NULL }, ++ { "hashAlgorithm", 1610637314, "AlgorithmIdentifier"}, ++ { NULL, 2056, "0"}, ++ { "maskGenAlgorithm", 1610637314, "AlgorithmIdentifier"}, ++ { NULL, 2056, "1"}, ++ { "saltLength", 1610653699, NULL }, ++ { NULL, 1073741833, "20"}, ++ { NULL, 2056, "2"}, ++ { "trailerField", 536911875, NULL }, ++ { NULL, 1073741833, "1"}, ++ { NULL, 2056, "3"}, ++ { "GOSTParameters", 1610612741, NULL }, ++ { "publicKeyParamSet", 1073741836, NULL }, ++ { "digestParamSet", 16396, NULL }, ++ { "GOSTParametersOld", 1610612741, NULL }, ++ { "publicKeyParamSet", 1073741836, NULL }, ++ { "digestParamSet", 1073741836, NULL }, ++ { "encryptionParamSet", 16396, NULL }, ++ { "GOSTPrivateKey", 1073741831, NULL }, ++ { "GOSTPrivateKeyOld", 1073741827, NULL }, ++ { "IssuerSignTool", 1610612741, NULL }, ++ { "signTool", 1073741858, NULL }, ++ { "cATool", 1073741858, NULL }, ++ { "signToolCert", 1073741858, NULL }, ++ { "cAToolCert", 34, NULL }, ++ { "Gost28147-89-EncryptedKey", 1610612741, NULL }, ++ { "encryptedKey", 1073741831, NULL }, ++ { "maskKey", 1610637319, NULL }, ++ { NULL, 4104, "0"}, ++ { "macKey", 7, NULL }, ++ { "SubjectPublicKeyInfo", 1610612741, NULL }, ++ { "algorithm", 1073741826, "AlgorithmIdentifier"}, ++ { "subjectPublicKey", 6, NULL }, ++ { "GostR3410-TransportParameters", 1610612741, NULL }, ++ { "encryptionParamSet", 1073741836, NULL }, ++ { "ephemeralPublicKey", 1610637314, "SubjectPublicKeyInfo"}, ++ { NULL, 4104, "0"}, ++ { "ukm", 7, NULL }, ++ { "GostR3410-KeyTransport", 536870917, NULL }, ++ { "sessionEncryptedKey", 1073741826, "Gost28147-89-EncryptedKey"}, ++ { "transportParameters", 536895490, "GostR3410-TransportParameters"}, ++ { NULL, 4104, "0"}, ++ { NULL, 0, NULL } ++}; +diff --git a/grub-core/commands/appendedsig/pkix_asn1_tab.c b/grub-core/commands/appendedsig/pkix_asn1_tab.c +new file mode 100644 +index 00000000000..adef69d95ce +--- /dev/null ++++ b/grub-core/commands/appendedsig/pkix_asn1_tab.c +@@ -0,0 +1,484 @@ ++#include ++#include ++ ++const asn1_static_node pkix_asn1_tab[] = { ++ { "PKIX1", 536875024, NULL }, ++ { NULL, 1073741836, NULL }, ++ { "PrivateKeyUsagePeriod", 1610612741, NULL }, ++ { "notBefore", 1610637349, NULL }, ++ { NULL, 4104, "0"}, ++ { "notAfter", 536895525, NULL }, ++ { NULL, 4104, "1"}, ++ { "AuthorityKeyIdentifier", 1610612741, NULL }, ++ { "keyIdentifier", 1610637319, NULL }, ++ { NULL, 4104, "0"}, ++ { "authorityCertIssuer", 1610637314, "GeneralNames"}, ++ { NULL, 4104, "1"}, ++ { "authorityCertSerialNumber", 536895490, "CertificateSerialNumber"}, ++ { NULL, 4104, "2"}, ++ { "SubjectKeyIdentifier", 1073741831, NULL }, ++ { "KeyUsage", 1073741830, NULL }, ++ { "DirectoryString", 1610612754, NULL }, ++ { "teletexString", 1612709918, NULL }, ++ { "MAX", 524298, "1"}, ++ { "printableString", 1612709919, NULL }, ++ { "MAX", 524298, "1"}, ++ { "universalString", 1612709920, NULL }, ++ { "MAX", 524298, "1"}, ++ { "utf8String", 1612709922, NULL }, ++ { "MAX", 524298, "1"}, ++ { "bmpString", 1612709921, NULL }, ++ { "MAX", 524298, "1"}, ++ { "ia5String", 538968093, NULL }, ++ { "MAX", 524298, "1"}, ++ { "SubjectAltName", 1073741826, "GeneralNames"}, ++ { "GeneralNames", 1612709899, NULL }, ++ { "MAX", 1074266122, "1"}, ++ { NULL, 2, "GeneralName"}, ++ { "GeneralName", 1610612754, NULL }, ++ { "otherName", 1610620930, "AnotherName"}, ++ { NULL, 4104, "0"}, ++ { "rfc822Name", 1610620957, NULL }, ++ { NULL, 4104, "1"}, ++ { "dNSName", 1610620957, NULL }, ++ { NULL, 4104, "2"}, ++ { "x400Address", 1610620941, NULL }, ++ { NULL, 4104, "3"}, ++ { "directoryName", 1610620939, NULL }, ++ { NULL, 1073743880, "4"}, ++ { NULL, 2, "RelativeDistinguishedName"}, ++ { "ediPartyName", 1610620941, NULL }, ++ { NULL, 4104, "5"}, ++ { "uniformResourceIdentifier", 1610620957, NULL }, ++ { NULL, 4104, "6"}, ++ { "iPAddress", 1610620935, NULL }, ++ { NULL, 4104, "7"}, ++ { "registeredID", 536879116, NULL }, ++ { NULL, 4104, "8"}, ++ { "AnotherName", 1610612741, NULL }, ++ { "type-id", 1073741836, NULL }, ++ { "value", 541073421, NULL }, ++ { NULL, 1073743880, "0"}, ++ { "type-id", 1, NULL }, ++ { "IssuerAltName", 1073741826, "GeneralNames"}, ++ { "BasicConstraints", 1610612741, NULL }, ++ { "cA", 1610645508, NULL }, ++ { NULL, 131081, NULL }, ++ { "pathLenConstraint", 537411587, NULL }, ++ { "0", 10, "MAX"}, ++ { "CRLDistributionPoints", 1612709899, NULL }, ++ { "MAX", 1074266122, "1"}, ++ { NULL, 2, "DistributionPoint"}, ++ { "DistributionPoint", 1610612741, NULL }, ++ { "distributionPoint", 1610637314, "DistributionPointName"}, ++ { NULL, 2056, "0"}, ++ { "reasons", 1610637314, "ReasonFlags"}, ++ { NULL, 4104, "1"}, ++ { "cRLIssuer", 536895490, "GeneralNames"}, ++ { NULL, 4104, "2"}, ++ { "DistributionPointName", 1610612754, NULL }, ++ { "fullName", 1610620930, "GeneralNames"}, ++ { NULL, 4104, "0"}, ++ { "nameRelativeToCRLIssuer", 536879106, "RelativeDistinguishedName"}, ++ { NULL, 4104, "1"}, ++ { "ReasonFlags", 1073741830, NULL }, ++ { "ExtKeyUsageSyntax", 1612709899, NULL }, ++ { "MAX", 1074266122, "1"}, ++ { NULL, 12, NULL }, ++ { "AuthorityInfoAccessSyntax", 1612709899, NULL }, ++ { "MAX", 1074266122, "1"}, ++ { NULL, 2, "AccessDescription"}, ++ { "AccessDescription", 1610612741, NULL }, ++ { "accessMethod", 1073741836, NULL }, ++ { "accessLocation", 2, "GeneralName"}, ++ { "Attribute", 1610612741, NULL }, ++ { "type", 1073741836, NULL }, ++ { "values", 536870927, NULL }, ++ { NULL, 13, NULL }, ++ { "AttributeTypeAndValue", 1610612741, NULL }, ++ { "type", 1073741836, NULL }, ++ { "value", 13, NULL }, ++ { "Name", 1610612754, NULL }, ++ { "rdnSequence", 536870923, NULL }, ++ { NULL, 2, "RelativeDistinguishedName"}, ++ { "DistinguishedName", 1610612747, NULL }, ++ { NULL, 2, "RelativeDistinguishedName"}, ++ { "RelativeDistinguishedName", 1612709903, NULL }, ++ { "MAX", 1074266122, "1"}, ++ { NULL, 2, "AttributeTypeAndValue"}, ++ { "Certificate", 1610612741, NULL }, ++ { "tbsCertificate", 1073741826, "TBSCertificate"}, ++ { "signatureAlgorithm", 1073741826, "AlgorithmIdentifier"}, ++ { "signature", 6, NULL }, ++ { "TBSCertificate", 1610612741, NULL }, ++ { "version", 1610653699, NULL }, ++ { NULL, 1073741833, "0"}, ++ { NULL, 2056, "0"}, ++ { "serialNumber", 1073741826, "CertificateSerialNumber"}, ++ { "signature", 1073741826, "AlgorithmIdentifier"}, ++ { "issuer", 1073741826, "Name"}, ++ { "validity", 1073741826, "Validity"}, ++ { "subject", 1073741826, "Name"}, ++ { "subjectPublicKeyInfo", 1073741826, "SubjectPublicKeyInfo"}, ++ { "issuerUniqueID", 1610637314, "UniqueIdentifier"}, ++ { NULL, 4104, "1"}, ++ { "subjectUniqueID", 1610637314, "UniqueIdentifier"}, ++ { NULL, 4104, "2"}, ++ { "extensions", 536895490, "Extensions"}, ++ { NULL, 2056, "3"}, ++ { "CertificateSerialNumber", 1073741827, NULL }, ++ { "Validity", 1610612741, NULL }, ++ { "notBefore", 1073741826, "Time"}, ++ { "notAfter", 2, "Time"}, ++ { "Time", 1610612754, NULL }, ++ { "utcTime", 1073741860, NULL }, ++ { "generalTime", 37, NULL }, ++ { "UniqueIdentifier", 1073741830, NULL }, ++ { "SubjectPublicKeyInfo", 1610612741, NULL }, ++ { "algorithm", 1073741826, "AlgorithmIdentifier"}, ++ { "subjectPublicKey", 6, NULL }, ++ { "Extensions", 1612709899, NULL }, ++ { "MAX", 1074266122, "1"}, ++ { NULL, 2, "Extension"}, ++ { "Extension", 1610612741, NULL }, ++ { "extnID", 1073741836, NULL }, ++ { "critical", 1610645508, NULL }, ++ { NULL, 131081, NULL }, ++ { "extnValue", 7, NULL }, ++ { "CertificateList", 1610612741, NULL }, ++ { "tbsCertList", 1073741826, "TBSCertList"}, ++ { "signatureAlgorithm", 1073741826, "AlgorithmIdentifier"}, ++ { "signature", 6, NULL }, ++ { "TBSCertList", 1610612741, NULL }, ++ { "version", 1073758211, NULL }, ++ { "signature", 1073741826, "AlgorithmIdentifier"}, ++ { "issuer", 1073741826, "Name"}, ++ { "thisUpdate", 1073741826, "Time"}, ++ { "nextUpdate", 1073758210, "Time"}, ++ { "revokedCertificates", 1610629131, NULL }, ++ { NULL, 536870917, NULL }, ++ { "userCertificate", 1073741826, "CertificateSerialNumber"}, ++ { "revocationDate", 1073741826, "Time"}, ++ { "crlEntryExtensions", 16386, "Extensions"}, ++ { "crlExtensions", 536895490, "Extensions"}, ++ { NULL, 2056, "0"}, ++ { "AlgorithmIdentifier", 1610612741, NULL }, ++ { "algorithm", 1073741836, NULL }, ++ { "parameters", 541081613, NULL }, ++ { "algorithm", 1, NULL }, ++ { "Dss-Sig-Value", 1610612741, NULL }, ++ { "r", 1073741827, NULL }, ++ { "s", 3, NULL }, ++ { "Dss-Parms", 1610612741, NULL }, ++ { "p", 1073741827, NULL }, ++ { "q", 1073741827, NULL }, ++ { "g", 3, NULL }, ++ { "pkcs-7-ContentInfo", 1610612741, NULL }, ++ { "contentType", 1073741836, NULL }, ++ { "content", 541073421, NULL }, ++ { NULL, 1073743880, "0"}, ++ { "contentType", 1, NULL }, ++ { "pkcs-7-DigestInfo", 1610612741, NULL }, ++ { "digestAlgorithm", 1073741826, "AlgorithmIdentifier"}, ++ { "digest", 7, NULL }, ++ { "pkcs-7-SignedData", 1610612741, NULL }, ++ { "version", 1073741827, NULL }, ++ { "digestAlgorithms", 1073741826, "pkcs-7-DigestAlgorithmIdentifiers"}, ++ { "encapContentInfo", 1073741826, "pkcs-7-EncapsulatedContentInfo"}, ++ { "certificates", 1610637314, "pkcs-7-CertificateSet"}, ++ { NULL, 4104, "0"}, ++ { "crls", 1610637314, "pkcs-7-CertificateRevocationLists"}, ++ { NULL, 4104, "1"}, ++ { "signerInfos", 2, "pkcs-7-SignerInfos"}, ++ { "pkcs-7-DigestAlgorithmIdentifiers", 1610612751, NULL }, ++ { NULL, 2, "AlgorithmIdentifier"}, ++ { "pkcs-7-EncapsulatedContentInfo", 1610612741, NULL }, ++ { "eContentType", 1073741836, NULL }, ++ { "eContent", 536895501, NULL }, ++ { NULL, 2056, "0"}, ++ { "pkcs-7-CertificateRevocationLists", 1610612751, NULL }, ++ { NULL, 13, NULL }, ++ { "pkcs-7-CertificateChoices", 1610612754, NULL }, ++ { "certificate", 13, NULL }, ++ { "pkcs-7-CertificateSet", 1610612751, NULL }, ++ { NULL, 2, "pkcs-7-CertificateChoices"}, ++ { "IssuerAndSerialNumber", 1610612741, NULL }, ++ { "issuer", 1073741826, "Name"}, ++ { "serialNumber", 2, "CertificateSerialNumber"}, ++ { "pkcs-7-SignerInfo", 1610612741, NULL }, ++ { "version", 1073741827, NULL }, ++ { "sid", 1073741826, "SignerIdentifier"}, ++ { "digestAlgorithm", 1073741826, "AlgorithmIdentifier"}, ++ { "signedAttrs", 1610637314, "SignedAttributes"}, ++ { NULL, 4104, "0"}, ++ { "signatureAlgorithm", 1073741826, "AlgorithmIdentifier"}, ++ { "signature", 1073741831, NULL }, ++ { "unsignedAttrs", 536895490, "SignedAttributes"}, ++ { NULL, 4104, "1"}, ++ { "SignedAttributes", 1612709903, NULL }, ++ { "MAX", 1074266122, "1"}, ++ { NULL, 2, "Attribute"}, ++ { "SignerIdentifier", 1610612754, NULL }, ++ { "issuerAndSerialNumber", 1073741826, "IssuerAndSerialNumber"}, ++ { "subjectKeyIdentifier", 536879111, NULL }, ++ { NULL, 4104, "0"}, ++ { "pkcs-7-SignerInfos", 1610612751, NULL }, ++ { NULL, 2, "pkcs-7-SignerInfo"}, ++ { "pkcs-10-CertificationRequestInfo", 1610612741, NULL }, ++ { "version", 1073741827, NULL }, ++ { "subject", 1073741826, "Name"}, ++ { "subjectPKInfo", 1073741826, "SubjectPublicKeyInfo"}, ++ { "attributes", 536879106, "Attributes"}, ++ { NULL, 4104, "0"}, ++ { "Attributes", 1610612751, NULL }, ++ { NULL, 2, "Attribute"}, ++ { "pkcs-10-CertificationRequest", 1610612741, NULL }, ++ { "certificationRequestInfo", 1073741826, "pkcs-10-CertificationRequestInfo"}, ++ { "signatureAlgorithm", 1073741826, "AlgorithmIdentifier"}, ++ { "signature", 6, NULL }, ++ { "pkcs-9-at-challengePassword", 1879048204, NULL }, ++ { "iso", 1073741825, "1"}, ++ { "member-body", 1073741825, "2"}, ++ { "us", 1073741825, "840"}, ++ { "rsadsi", 1073741825, "113549"}, ++ { "pkcs", 1073741825, "1"}, ++ { NULL, 1073741825, "9"}, ++ { NULL, 1, "7"}, ++ { "pkcs-9-challengePassword", 1610612754, NULL }, ++ { "printableString", 1073741855, NULL }, ++ { "utf8String", 34, NULL }, ++ { "pkcs-9-localKeyId", 1073741831, NULL }, ++ { "pkcs-8-PrivateKeyInfo", 1610612741, NULL }, ++ { "version", 1073741827, NULL }, ++ { "privateKeyAlgorithm", 1073741826, "AlgorithmIdentifier"}, ++ { "privateKey", 1073741831, NULL }, ++ { "attributes", 536895490, "Attributes"}, ++ { NULL, 4104, "0"}, ++ { "pkcs-8-EncryptedPrivateKeyInfo", 1610612741, NULL }, ++ { "encryptionAlgorithm", 1073741826, "AlgorithmIdentifier"}, ++ { "encryptedData", 2, "pkcs-8-EncryptedData"}, ++ { "pkcs-8-EncryptedData", 1073741831, NULL }, ++ { "pkcs-5-des-CBC-params", 1612709895, NULL }, ++ { NULL, 1048586, "8"}, ++ { "pkcs-5-des-EDE3-CBC-params", 1612709895, NULL }, ++ { NULL, 1048586, "8"}, ++ { "pkcs-5-aes128-CBC-params", 1612709895, NULL }, ++ { NULL, 1048586, "16"}, ++ { "pkcs-5-aes192-CBC-params", 1612709895, NULL }, ++ { NULL, 1048586, "16"}, ++ { "pkcs-5-aes256-CBC-params", 1612709895, NULL }, ++ { NULL, 1048586, "16"}, ++ { "Gost28147-89-Parameters", 1610612741, NULL }, ++ { "iv", 1073741831, NULL }, ++ { "encryptionParamSet", 12, NULL }, ++ { "pkcs-5-PBE-params", 1610612741, NULL }, ++ { "salt", 1073741831, NULL }, ++ { "iterationCount", 3, NULL }, ++ { "pkcs-5-PBES2-params", 1610612741, NULL }, ++ { "keyDerivationFunc", 1073741826, "AlgorithmIdentifier"}, ++ { "encryptionScheme", 2, "AlgorithmIdentifier"}, ++ { "pkcs-5-PBKDF2-params", 1610612741, NULL }, ++ { "salt", 1610612754, NULL }, ++ { "specified", 1073741831, NULL }, ++ { "otherSource", 2, "AlgorithmIdentifier"}, ++ { "iterationCount", 1611137027, NULL }, ++ { "1", 10, "MAX"}, ++ { "keyLength", 1611153411, NULL }, ++ { "1", 10, "MAX"}, ++ { "prf", 16386, "AlgorithmIdentifier"}, ++ { "pkcs-12-PFX", 1610612741, NULL }, ++ { "version", 1610874883, NULL }, ++ { "v3", 1, "3"}, ++ { "authSafe", 1073741826, "pkcs-7-ContentInfo"}, ++ { "macData", 16386, "pkcs-12-MacData"}, ++ { "pkcs-12-PbeParams", 1610612741, NULL }, ++ { "salt", 1073741831, NULL }, ++ { "iterations", 3, NULL }, ++ { "pkcs-12-MacData", 1610612741, NULL }, ++ { "mac", 1073741826, "pkcs-7-DigestInfo"}, ++ { "macSalt", 1073741831, NULL }, ++ { "iterations", 536903683, NULL }, ++ { NULL, 9, "1"}, ++ { "pkcs-12-AuthenticatedSafe", 1610612747, NULL }, ++ { NULL, 2, "pkcs-7-ContentInfo"}, ++ { "pkcs-12-SafeContents", 1610612747, NULL }, ++ { NULL, 2, "pkcs-12-SafeBag"}, ++ { "pkcs-12-SafeBag", 1610612741, NULL }, ++ { "bagId", 1073741836, NULL }, ++ { "bagValue", 1614815245, NULL }, ++ { NULL, 1073743880, "0"}, ++ { "badId", 1, NULL }, ++ { "bagAttributes", 536887311, NULL }, ++ { NULL, 2, "Attribute"}, ++ { "pkcs-12-CertBag", 1610612741, NULL }, ++ { "certId", 1073741836, NULL }, ++ { "certValue", 541073421, NULL }, ++ { NULL, 1073743880, "0"}, ++ { "certId", 1, NULL }, ++ { "pkcs-12-CRLBag", 1610612741, NULL }, ++ { "crlId", 1073741836, NULL }, ++ { "crlValue", 541073421, NULL }, ++ { NULL, 1073743880, "0"}, ++ { "crlId", 1, NULL }, ++ { "pkcs-12-SecretBag", 1610612741, NULL }, ++ { "secretTypeId", 1073741836, NULL }, ++ { "secretValue", 541073421, NULL }, ++ { NULL, 1073743880, "0"}, ++ { "secretTypeId", 1, NULL }, ++ { "pkcs-7-Data", 1073741831, NULL }, ++ { "pkcs-7-EncryptedData", 1610612741, NULL }, ++ { "version", 1073741827, NULL }, ++ { "encryptedContentInfo", 1073741826, "pkcs-7-EncryptedContentInfo"}, ++ { "unprotectedAttrs", 536895490, "pkcs-7-UnprotectedAttributes"}, ++ { NULL, 4104, "1"}, ++ { "pkcs-7-EncryptedContentInfo", 1610612741, NULL }, ++ { "contentType", 1073741836, NULL }, ++ { "contentEncryptionAlgorithm", 1073741826, "pkcs-7-ContentEncryptionAlgorithmIdentifier"}, ++ { "encryptedContent", 536895495, NULL }, ++ { NULL, 4104, "0"}, ++ { "pkcs-7-ContentEncryptionAlgorithmIdentifier", 1073741826, "AlgorithmIdentifier"}, ++ { "pkcs-7-UnprotectedAttributes", 1612709903, NULL }, ++ { "MAX", 1074266122, "1"}, ++ { NULL, 2, "Attribute"}, ++ { "ProxyCertInfo", 1610612741, NULL }, ++ { "pCPathLenConstraint", 1611153411, NULL }, ++ { "0", 10, "MAX"}, ++ { "proxyPolicy", 2, "ProxyPolicy"}, ++ { "ProxyPolicy", 1610612741, NULL }, ++ { "policyLanguage", 1073741836, NULL }, ++ { "policy", 16391, NULL }, ++ { "certificatePolicies", 1612709899, NULL }, ++ { "MAX", 1074266122, "1"}, ++ { NULL, 2, "PolicyInformation"}, ++ { "PolicyInformation", 1610612741, NULL }, ++ { "policyIdentifier", 1073741836, NULL }, ++ { "policyQualifiers", 538984459, NULL }, ++ { "MAX", 1074266122, "1"}, ++ { NULL, 2, "PolicyQualifierInfo"}, ++ { "PolicyQualifierInfo", 1610612741, NULL }, ++ { "policyQualifierId", 1073741836, NULL }, ++ { "qualifier", 541065229, NULL }, ++ { "policyQualifierId", 1, NULL }, ++ { "CPSuri", 1073741853, NULL }, ++ { "UserNotice", 1610612741, NULL }, ++ { "noticeRef", 1073758210, "NoticeReference"}, ++ { "explicitText", 16386, "DisplayText"}, ++ { "NoticeReference", 1610612741, NULL }, ++ { "organization", 1073741826, "DisplayText"}, ++ { "noticeNumbers", 536870923, NULL }, ++ { NULL, 3, NULL }, ++ { "DisplayText", 1610612754, NULL }, ++ { "ia5String", 1612709917, NULL }, ++ { "200", 524298, "1"}, ++ { "visibleString", 1612709923, NULL }, ++ { "200", 524298, "1"}, ++ { "bmpString", 1612709921, NULL }, ++ { "200", 524298, "1"}, ++ { "utf8String", 538968098, NULL }, ++ { "200", 524298, "1"}, ++ { "OCSPRequest", 1610612741, NULL }, ++ { "tbsRequest", 1073741826, "TBSRequest"}, ++ { "optionalSignature", 536895490, "Signature"}, ++ { NULL, 2056, "0"}, ++ { "TBSRequest", 1610612741, NULL }, ++ { "version", 1610653699, NULL }, ++ { NULL, 1073741833, "0"}, ++ { NULL, 2056, "0"}, ++ { "requestorName", 1610637314, "GeneralName"}, ++ { NULL, 2056, "1"}, ++ { "requestList", 1610612747, NULL }, ++ { NULL, 2, "Request"}, ++ { "requestExtensions", 536895490, "Extensions"}, ++ { NULL, 2056, "2"}, ++ { "Signature", 1610612741, NULL }, ++ { "signatureAlgorithm", 1073741826, "AlgorithmIdentifier"}, ++ { "signature", 1073741830, NULL }, ++ { "certs", 536895499, NULL }, ++ { NULL, 1073743880, "0"}, ++ { NULL, 2, "Certificate"}, ++ { "Request", 1610612741, NULL }, ++ { "reqCert", 1073741826, "CertID"}, ++ { "singleRequestExtensions", 536895490, "Extensions"}, ++ { NULL, 2056, "0"}, ++ { "CertID", 1610612741, NULL }, ++ { "hashAlgorithm", 1073741826, "AlgorithmIdentifier"}, ++ { "issuerNameHash", 1073741831, NULL }, ++ { "issuerKeyHash", 1073741831, NULL }, ++ { "serialNumber", 2, "CertificateSerialNumber"}, ++ { "OCSPResponse", 1610612741, NULL }, ++ { "responseStatus", 1073741826, "OCSPResponseStatus"}, ++ { "responseBytes", 536895490, "ResponseBytes"}, ++ { NULL, 2056, "0"}, ++ { "OCSPResponseStatus", 1610874901, NULL }, ++ { "successful", 1073741825, "0"}, ++ { "malformedRequest", 1073741825, "1"}, ++ { "internalError", 1073741825, "2"}, ++ { "tryLater", 1073741825, "3"}, ++ { "sigRequired", 1073741825, "5"}, ++ { "unauthorized", 1, "6"}, ++ { "ResponseBytes", 1610612741, NULL }, ++ { "responseType", 1073741836, NULL }, ++ { "response", 7, NULL }, ++ { "BasicOCSPResponse", 1610612741, NULL }, ++ { "tbsResponseData", 1073741826, "ResponseData"}, ++ { "signatureAlgorithm", 1073741826, "AlgorithmIdentifier"}, ++ { "signature", 1073741830, NULL }, ++ { "certs", 536895499, NULL }, ++ { NULL, 1073743880, "0"}, ++ { NULL, 2, "Certificate"}, ++ { "ResponseData", 1610612741, NULL }, ++ { "version", 1610653699, NULL }, ++ { NULL, 1073741833, "0"}, ++ { NULL, 2056, "0"}, ++ { "responderID", 1073741826, "ResponderID"}, ++ { "producedAt", 1073741861, NULL }, ++ { "responses", 1610612747, NULL }, ++ { NULL, 2, "SingleResponse"}, ++ { "responseExtensions", 536895490, "Extensions"}, ++ { NULL, 2056, "1"}, ++ { "ResponderID", 1610612754, NULL }, ++ { "byName", 1610620939, NULL }, ++ { NULL, 1073743880, "1"}, ++ { NULL, 2, "RelativeDistinguishedName"}, ++ { "byKey", 536879111, NULL }, ++ { NULL, 2056, "2"}, ++ { "SingleResponse", 1610612741, NULL }, ++ { "certID", 1073741826, "CertID"}, ++ { "certStatus", 1073741826, "CertStatus"}, ++ { "thisUpdate", 1073741861, NULL }, ++ { "nextUpdate", 1610637349, NULL }, ++ { NULL, 2056, "0"}, ++ { "singleExtensions", 536895490, "Extensions"}, ++ { NULL, 2056, "1"}, ++ { "CertStatus", 1610612754, NULL }, ++ { "good", 1610620948, NULL }, ++ { NULL, 4104, "0"}, ++ { "revoked", 1610620930, "RevokedInfo"}, ++ { NULL, 4104, "1"}, ++ { "unknown", 536879106, "UnknownInfo"}, ++ { NULL, 4104, "2"}, ++ { "RevokedInfo", 1610612741, NULL }, ++ { "revocationTime", 1073741861, NULL }, ++ { "revocationReason", 537157653, NULL }, ++ { NULL, 1073743880, "0"}, ++ { "unspecified", 1, "0"}, ++ { "UnknownInfo", 1073741844, NULL }, ++ { "NameConstraints", 1610612741, NULL }, ++ { "permittedSubtrees", 1610637314, "GeneralSubtrees"}, ++ { NULL, 4104, "0"}, ++ { "excludedSubtrees", 536895490, "GeneralSubtrees"}, ++ { NULL, 4104, "1"}, ++ { "GeneralSubtrees", 1612709899, NULL }, ++ { "MAX", 1074266122, "1"}, ++ { NULL, 2, "GeneralSubtree"}, ++ { "GeneralSubtree", 1610612741, NULL }, ++ { "base", 1073741826, "GeneralName"}, ++ { "minimum", 1610653699, NULL }, ++ { NULL, 1073741833, "0"}, ++ { NULL, 4104, "0"}, ++ { "maximum", 536895491, NULL }, ++ { NULL, 4104, "1"}, ++ { "TlsFeatures", 536870923, NULL }, ++ { NULL, 3, NULL }, ++ { NULL, 0, NULL } ++}; diff --git a/0176-RISC-V-Fix-computation-of-pc-relative-relocation-off.patch b/0176-RISC-V-Fix-computation-of-pc-relative-relocation-off.patch deleted file mode 100644 index 89f42c585aa0bd5faca689418fa04245585a3623..0000000000000000000000000000000000000000 --- a/0176-RISC-V-Fix-computation-of-pc-relative-relocation-off.patch +++ /dev/null @@ -1,40 +0,0 @@ -From bad3d7b8f5b050898b20f0ca10894e6d1c5bb161 Mon Sep 17 00:00:00 2001 -From: Andreas Schwab -Date: Wed, 26 Jun 2019 16:50:03 +0200 -Subject: [PATCH 176/220] RISC-V: Fix computation of pc-relative relocation - offset - -The offset calculation was missing the relocation addend. - -Signed-off-by: Andreas Schwab -Tested-by: Chester Lin -Reviewed-by: Daniel Kiper ---- - util/grub-mkimagexx.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c -index bc087c2..d16ec63 100644 ---- a/util/grub-mkimagexx.c -+++ b/util/grub-mkimagexx.c -@@ -1232,8 +1232,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, - grub_uint32_t *t32 = (grub_uint32_t *) target; - grub_uint16_t *t16 = (grub_uint16_t *) target; - grub_uint8_t *t8 = (grub_uint8_t *) target; -- grub_int64_t off = (long)sym_addr - target_section_addr - offset -- - image_target->vaddr_offset; -+ grub_int64_t off; - - /* - * Instructions and instruction encoding are documented in the RISC-V -@@ -1243,6 +1242,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, - */ - - sym_addr += addend; -+ off = sym_addr - target_section_addr - offset - image_target->vaddr_offset; - - switch (ELF_R_TYPE (info)) - { --- -1.8.3.1 - diff --git a/0176-appended-signatures-parse-PKCS-7-signedData-and-X.50.patch b/0176-appended-signatures-parse-PKCS-7-signedData-and-X.50.patch new file mode 100644 index 0000000000000000000000000000000000000000..04bf1df4523208fd8b3a2770aa114b34a129ed72 --- /dev/null +++ b/0176-appended-signatures-parse-PKCS-7-signedData-and-X.50.patch @@ -0,0 +1,1528 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Thu, 30 Jul 2020 01:33:46 +1000 +Subject: [PATCH] appended signatures: parse PKCS#7 signedData and X.509 + certificates + +This code allows us to parse: + + - PKCS#7 signedData messages. Only a single signerInfo is supported, + which is all that the Linux sign-file utility supports creating + out-of-the-box. Only RSA, SHA-256 and SHA-512 are supported. + Any certificate embedded in the PKCS#7 message will be ignored. + + - X.509 certificates: at least enough to verify the signatures on the + PKCS#7 messages. We expect that the certificates embedded in grub will + be leaf certificates, not CA certificates. The parser enforces this. + +Signed-off-by: Daniel Axtens +--- + grub-core/commands/appendedsig/asn1util.c | 102 +++ + grub-core/commands/appendedsig/pkcs7.c | 305 +++++++++ + grub-core/commands/appendedsig/x509.c | 958 +++++++++++++++++++++++++++ + grub-core/commands/appendedsig/appendedsig.h | 110 +++ + 4 files changed, 1475 insertions(+) + create mode 100644 grub-core/commands/appendedsig/asn1util.c + create mode 100644 grub-core/commands/appendedsig/pkcs7.c + create mode 100644 grub-core/commands/appendedsig/x509.c + create mode 100644 grub-core/commands/appendedsig/appendedsig.h + +diff --git a/grub-core/commands/appendedsig/asn1util.c b/grub-core/commands/appendedsig/asn1util.c +new file mode 100644 +index 00000000000..eff095a9df2 +--- /dev/null ++++ b/grub-core/commands/appendedsig/asn1util.c +@@ -0,0 +1,102 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2020 IBM Corporation. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "appendedsig.h" ++ ++asn1_node _gnutls_gnutls_asn = ASN1_TYPE_EMPTY; ++asn1_node _gnutls_pkix_asn = ASN1_TYPE_EMPTY; ++ ++extern const ASN1_ARRAY_TYPE gnutls_asn1_tab[]; ++extern const ASN1_ARRAY_TYPE pkix_asn1_tab[]; ++ ++/* ++ * Read a value from an ASN1 node, allocating memory to store it. ++ * ++ * It will work for anything where the size libtasn1 returns is right: ++ * - Integers ++ * - Octet strings ++ * - DER encoding of other structures ++ * It will _not_ work for things where libtasn1 size requires adjustment: ++ * - Strings that require an extra NULL byte at the end ++ * - Bit strings because libtasn1 returns the length in bits, not bytes. ++ * ++ * If the function returns a non-NULL value, the caller must free it. ++ */ ++void * ++grub_asn1_allocate_and_read (asn1_node node, const char *name, ++ const char *friendly_name, int *content_size) ++{ ++ int result; ++ grub_uint8_t *tmpstr = NULL; ++ int tmpstr_size = 0; ++ ++ result = asn1_read_value (node, name, NULL, &tmpstr_size); ++ if (result != ASN1_MEM_ERROR) ++ { ++ grub_snprintf (grub_errmsg, sizeof (grub_errmsg), ++ _ ++ ("Reading size of %s did not return expected status: %s"), ++ friendly_name, asn1_strerror (result)); ++ grub_errno = GRUB_ERR_BAD_FILE_TYPE; ++ return NULL; ++ } ++ ++ tmpstr = grub_malloc (tmpstr_size); ++ if (tmpstr == NULL) ++ { ++ grub_snprintf (grub_errmsg, sizeof (grub_errmsg), ++ "Could not allocate memory to store %s", friendly_name); ++ grub_errno = GRUB_ERR_OUT_OF_MEMORY; ++ return NULL; ++ } ++ ++ result = asn1_read_value (node, name, tmpstr, &tmpstr_size); ++ if (result != ASN1_SUCCESS) ++ { ++ grub_free (tmpstr); ++ grub_snprintf (grub_errmsg, sizeof (grub_errmsg), ++ "Error reading %s: %s", ++ friendly_name, asn1_strerror (result)); ++ grub_errno = GRUB_ERR_BAD_FILE_TYPE; ++ return NULL; ++ } ++ ++ *content_size = tmpstr_size; ++ ++ return tmpstr; ++} ++ ++int ++asn1_init (void) ++{ ++ int res; ++ res = asn1_array2tree (gnutls_asn1_tab, &_gnutls_gnutls_asn, NULL); ++ if (res != ASN1_SUCCESS) ++ { ++ return res; ++ } ++ res = asn1_array2tree (pkix_asn1_tab, &_gnutls_pkix_asn, NULL); ++ return res; ++} +diff --git a/grub-core/commands/appendedsig/pkcs7.c b/grub-core/commands/appendedsig/pkcs7.c +new file mode 100644 +index 00000000000..dc6afe203f7 +--- /dev/null ++++ b/grub-core/commands/appendedsig/pkcs7.c +@@ -0,0 +1,305 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2020 IBM Corporation. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include "appendedsig.h" ++#include ++#include ++#include ++ ++ ++static char asn1_error[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; ++ ++/* ++ * RFC 5652 s 5.1 ++ */ ++const char *signedData_oid = "1.2.840.113549.1.7.2"; ++ ++/* ++ * RFC 4055 s 2.1 ++ */ ++const char *sha256_oid = "2.16.840.1.101.3.4.2.1"; ++const char *sha512_oid = "2.16.840.1.101.3.4.2.3"; ++ ++static grub_err_t ++process_content (grub_uint8_t * content, int size, ++ struct pkcs7_signedData *msg) ++{ ++ int res; ++ asn1_node signed_part; ++ grub_err_t err = GRUB_ERR_NONE; ++ char algo_oid[MAX_OID_LEN]; ++ int algo_oid_size = sizeof (algo_oid); ++ int algo_count; ++ char version; ++ int version_size = sizeof (version); ++ grub_uint8_t *result_buf; ++ int result_size = 0; ++ int crls_size = 0; ++ gcry_error_t gcry_err; ++ ++ res = asn1_create_element (_gnutls_pkix_asn, "PKIX1.pkcs-7-SignedData", ++ &signed_part); ++ if (res != ASN1_SUCCESS) ++ { ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "Could not create ASN.1 structure for PKCS#7 signed part."); ++ } ++ ++ res = asn1_der_decoding2 (&signed_part, content, &size, ++ ASN1_DECODE_FLAG_STRICT_DER, asn1_error); ++ if (res != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_SIGNATURE, ++ "Error reading PKCS#7 signed data: %s", asn1_error); ++ goto cleanup_signed_part; ++ } ++ ++ /* SignedData ::= SEQUENCE { ++ * version CMSVersion, ++ * digestAlgorithms DigestAlgorithmIdentifiers, ++ * encapContentInfo EncapsulatedContentInfo, ++ * certificates [0] IMPLICIT CertificateSet OPTIONAL, ++ * crls [1] IMPLICIT RevocationInfoChoices OPTIONAL, ++ * signerInfos SignerInfos } ++ */ ++ ++ /* version per the algo in 5.1, must be 1 */ ++ res = asn1_read_value (signed_part, "version", &version, &version_size); ++ if (res != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_SIGNATURE, ++ "Error reading signedData version: %s", ++ asn1_strerror (res)); ++ goto cleanup_signed_part; ++ } ++ ++ if (version != 1) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_SIGNATURE, ++ "Unexpected signature version v%d, only v1 supported", ++ version); ++ goto cleanup_signed_part; ++ } ++ ++ /* ++ * digestAlgorithms DigestAlgorithmIdentifiers ++ * ++ * DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier ++ * DigestAlgorithmIdentifer is an X.509 AlgorithmIdentifier (10.1.1) ++ * ++ * RFC 4055 s 2.1: ++ * sha256Identifier AlgorithmIdentifier ::= { id-sha256, NULL } ++ * sha512Identifier AlgorithmIdentifier ::= { id-sha512, NULL } ++ * ++ * We only support 1 element in the set, and we do not check parameters atm. ++ */ ++ res = ++ asn1_number_of_elements (signed_part, "digestAlgorithms", &algo_count); ++ if (res != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_SIGNATURE, ++ "Error counting number of digest algorithms: %s", ++ asn1_strerror (res)); ++ goto cleanup_signed_part; ++ } ++ ++ if (algo_count != 1) ++ { ++ err = ++ grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, ++ "Only 1 digest algorithm is supported"); ++ goto cleanup_signed_part; ++ } ++ ++ res = ++ asn1_read_value (signed_part, "digestAlgorithms.?1.algorithm", algo_oid, ++ &algo_oid_size); ++ if (res != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_SIGNATURE, ++ "Error reading digest algorithm: %s", ++ asn1_strerror (res)); ++ goto cleanup_signed_part; ++ } ++ ++ if (grub_strncmp (sha512_oid, algo_oid, algo_oid_size) == 0) ++ { ++ msg->hash = grub_crypto_lookup_md_by_name ("sha512"); ++ } ++ else if (grub_strncmp (sha256_oid, algo_oid, algo_oid_size) == 0) ++ { ++ msg->hash = grub_crypto_lookup_md_by_name ("sha256"); ++ } ++ else ++ { ++ err = ++ grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, ++ "Only SHA-256 and SHA-512 hashes are supported, found OID %s", ++ algo_oid); ++ goto cleanup_signed_part; ++ } ++ ++ if (!msg->hash) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_SIGNATURE, ++ "Hash algorithm for OID %s not loaded", algo_oid); ++ goto cleanup_signed_part; ++ } ++ ++ /* ++ * We ignore the certificates, but we don't permit CRLs. ++ * A CRL entry might be revoking the certificate we're using, and we have ++ * no way of dealing with that at the moment. ++ */ ++ res = asn1_read_value (signed_part, "crls", NULL, &crls_size); ++ if (res != ASN1_ELEMENT_NOT_FOUND) ++ { ++ err = ++ grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, ++ "PKCS#7 messages with embedded CRLs are not supported"); ++ goto cleanup_signed_part; ++ } ++ ++ /* read the signature */ ++ result_buf = ++ grub_asn1_allocate_and_read (signed_part, "signerInfos.?1.signature", ++ "signature data", &result_size); ++ if (!result_buf) ++ { ++ err = grub_errno; ++ goto cleanup_signed_part; ++ } ++ ++ gcry_err = ++ gcry_mpi_scan (&(msg->sig_mpi), GCRYMPI_FMT_USG, result_buf, result_size, ++ NULL); ++ if (gcry_err != GPG_ERR_NO_ERROR) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_SIGNATURE, ++ "Error loading signature into MPI structure: %d", ++ gcry_err); ++ goto cleanup_result; ++ } ++ ++cleanup_result: ++ grub_free (result_buf); ++cleanup_signed_part: ++ asn1_delete_structure (&signed_part); ++ ++ return err; ++} ++ ++grub_err_t ++parse_pkcs7_signedData (void *sigbuf, grub_size_t data_size, ++ struct pkcs7_signedData *msg) ++{ ++ int res; ++ asn1_node content_info; ++ grub_err_t err = GRUB_ERR_NONE; ++ char content_oid[MAX_OID_LEN]; ++ grub_uint8_t *content; ++ int content_size; ++ int content_oid_size = sizeof (content_oid); ++ int size; ++ ++ if (data_size > GRUB_INT_MAX) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, ++ "Cannot parse a PKCS#7 message where data size > INT_MAX"); ++ size = (int) data_size; ++ ++ res = asn1_create_element (_gnutls_pkix_asn, ++ "PKIX1.pkcs-7-ContentInfo", &content_info); ++ if (res != ASN1_SUCCESS) ++ { ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "Could not create ASN.1 structure for PKCS#7 data: %s", ++ asn1_strerror (res)); ++ } ++ ++ res = asn1_der_decoding2 (&content_info, sigbuf, &size, ++ ASN1_DECODE_FLAG_STRICT_DER, asn1_error); ++ if (res != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_SIGNATURE, ++ "Error decoding PKCS#7 message DER: %s", asn1_error); ++ goto cleanup; ++ } ++ ++ /* ++ * ContentInfo ::= SEQUENCE { ++ * contentType ContentType, ++ * content [0] EXPLICIT ANY DEFINED BY contentType } ++ * ++ * ContentType ::= OBJECT IDENTIFIER ++ */ ++ res = ++ asn1_read_value (content_info, "contentType", content_oid, ++ &content_oid_size); ++ if (res != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_SIGNATURE, ++ "Error reading PKCS#7 content type: %s", ++ asn1_strerror (res)); ++ goto cleanup; ++ } ++ ++ /* OID for SignedData defined in 5.1 */ ++ if (grub_strncmp (signedData_oid, content_oid, content_oid_size) != 0) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_SIGNATURE, ++ "Unexpected content type in PKCS#7 message: OID %s", ++ content_oid); ++ goto cleanup; ++ } ++ ++ content = ++ grub_asn1_allocate_and_read (content_info, "content", ++ "PKCS#7 message content", &content_size); ++ if (!content) ++ { ++ err = grub_errno; ++ goto cleanup; ++ } ++ ++ err = process_content (content, content_size, msg); ++ grub_free (content); ++ ++cleanup: ++ asn1_delete_structure (&content_info); ++ return err; ++} ++ ++/* ++ * Release all the storage associated with the PKCS#7 message. ++ * If the caller dynamically allocated the message, it must free it. ++ */ ++void ++pkcs7_signedData_release (struct pkcs7_signedData *msg) ++{ ++ gcry_mpi_release (msg->sig_mpi); ++} +diff --git a/grub-core/commands/appendedsig/x509.c b/grub-core/commands/appendedsig/x509.c +new file mode 100644 +index 00000000000..2b38b3670a2 +--- /dev/null ++++ b/grub-core/commands/appendedsig/x509.c +@@ -0,0 +1,958 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2020 IBM Corporation. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "appendedsig.h" ++ ++static char asn1_error[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; ++ ++/* ++ * RFC 3279 2.3.1 RSA Keys ++ */ ++const char *rsaEncryption_oid = "1.2.840.113549.1.1.1"; ++ ++/* ++ * RFC 5280 Appendix A ++ */ ++const char *commonName_oid = "2.5.4.3"; ++ ++/* ++ * RFC 5280 4.2.1.3 Key Usage ++ */ ++const char *keyUsage_oid = "2.5.29.15"; ++ ++/* ++ * RFC 5280 4.2.1.9 Basic Constraints ++ */ ++const char *basicConstraints_oid = "2.5.29.19"; ++ ++/* ++ * RFC 3279 2.3.1 ++ * ++ * The RSA public key MUST be encoded using the ASN.1 type RSAPublicKey: ++ * ++ * RSAPublicKey ::= SEQUENCE { ++ * modulus INTEGER, -- n ++ * publicExponent INTEGER } -- e ++ * ++ * where modulus is the modulus n, and publicExponent is the public ++ * exponent e. ++ */ ++static grub_err_t ++grub_parse_rsa_pubkey (grub_uint8_t * der, int dersize, ++ struct x509_certificate *certificate) ++{ ++ int result; ++ asn1_node spk = ASN1_TYPE_EMPTY; ++ grub_uint8_t *m_data, *e_data; ++ int m_size, e_size; ++ grub_err_t err = GRUB_ERR_NONE; ++ gcry_error_t gcry_err; ++ ++ result = ++ asn1_create_element (_gnutls_gnutls_asn, "GNUTLS.RSAPublicKey", &spk); ++ if (result != ASN1_SUCCESS) ++ { ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "Cannot create storage for public key ASN.1 data"); ++ } ++ ++ result = asn1_der_decoding2 (&spk, der, &dersize, ++ ASN1_DECODE_FLAG_STRICT_DER, asn1_error); ++ if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Cannot decode certificate public key DER: %s", ++ asn1_error); ++ goto cleanup; ++ } ++ ++ m_data = ++ grub_asn1_allocate_and_read (spk, "modulus", "RSA modulus", &m_size); ++ if (!m_data) ++ { ++ err = grub_errno; ++ goto cleanup; ++ } ++ ++ e_data = ++ grub_asn1_allocate_and_read (spk, "publicExponent", "RSA public exponent", ++ &e_size); ++ if (!e_data) ++ { ++ err = grub_errno; ++ goto cleanup_m_data; ++ } ++ ++ /* ++ * convert m, e to mpi ++ * ++ * nscanned is not set for FMT_USG, it's only set for FMT_PGP, ++ * so we can't verify it ++ */ ++ gcry_err = ++ gcry_mpi_scan (&certificate->mpis[0], GCRYMPI_FMT_USG, m_data, m_size, ++ NULL); ++ if (gcry_err != GPG_ERR_NO_ERROR) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error loading RSA modulus into MPI structure: %d", ++ gcry_err); ++ goto cleanup_e_data; ++ } ++ ++ gcry_err = ++ gcry_mpi_scan (&certificate->mpis[1], GCRYMPI_FMT_USG, e_data, e_size, ++ NULL); ++ if (gcry_err != GPG_ERR_NO_ERROR) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error loading RSA exponent into MPI structure: %d", ++ gcry_err); ++ goto cleanup_m_mpi; ++ } ++ ++ grub_free (e_data); ++ grub_free (m_data); ++ asn1_delete_structure (&spk); ++ return GRUB_ERR_NONE; ++ ++cleanup_m_mpi: ++ gcry_mpi_release (certificate->mpis[0]); ++cleanup_e_data: ++ grub_free (e_data); ++cleanup_m_data: ++ grub_free (m_data); ++cleanup: ++ asn1_delete_structure (&spk); ++ return err; ++} ++ ++ ++/* ++ * RFC 5280: ++ * SubjectPublicKeyInfo ::= SEQUENCE { ++ * algorithm AlgorithmIdentifier, ++ * subjectPublicKey BIT STRING } ++ * ++ * AlgorithmIdentifiers come from RFC 3279, we are not strictly compilant as we ++ * only support RSA Encryption. ++ */ ++ ++static grub_err_t ++grub_x509_read_subject_public_key (asn1_node asn, ++ struct x509_certificate *results) ++{ ++ int result; ++ grub_err_t err; ++ const char *algo_name = ++ "tbsCertificate.subjectPublicKeyInfo.algorithm.algorithm"; ++ const char *params_name = ++ "tbsCertificate.subjectPublicKeyInfo.algorithm.parameters"; ++ const char *pk_name = ++ "tbsCertificate.subjectPublicKeyInfo.subjectPublicKey"; ++ char algo_oid[MAX_OID_LEN]; ++ int algo_size = sizeof (algo_oid); ++ char params_value[2]; ++ int params_size = sizeof (params_value); ++ grub_uint8_t *key_data = NULL; ++ int key_size = 0; ++ unsigned int key_type; ++ ++ /* algorithm: see notes for rsaEncryption_oid */ ++ result = asn1_read_value (asn, algo_name, algo_oid, &algo_size); ++ if (result != ASN1_SUCCESS) ++ { ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error reading x509 public key algorithm: %s", ++ asn1_strerror (result)); ++ } ++ ++ if (grub_strncmp (algo_oid, rsaEncryption_oid, sizeof (rsaEncryption_oid)) ++ != 0) ++ { ++ return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, ++ "Unsupported x509 public key algorithm: %s", ++ algo_oid); ++ } ++ ++ /* ++ * RFC 3279 2.3.1 ++ * The rsaEncryption OID is intended to be used in the algorithm field ++ * of a value of type AlgorithmIdentifier. The parameters field MUST ++ * have ASN.1 type NULL for this algorithm identifier. ++ */ ++ result = asn1_read_value (asn, params_name, params_value, ¶ms_size); ++ if (result != ASN1_SUCCESS) ++ { ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error reading x509 public key parameters: %s", ++ asn1_strerror (result)); ++ } ++ ++ if (params_value[0] != ASN1_TAG_NULL) ++ { ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Invalid x509 public key parameters: expected NULL"); ++ } ++ ++ /* ++ * RFC 3279 2.3.1: The DER encoded RSAPublicKey is the value of the BIT ++ * STRING subjectPublicKey. ++ */ ++ result = asn1_read_value_type (asn, pk_name, NULL, &key_size, &key_type); ++ if (result != ASN1_MEM_ERROR) ++ { ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error reading size of x509 public key: %s", ++ asn1_strerror (result)); ++ } ++ if (key_type != ASN1_ETYPE_BIT_STRING) ++ { ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Unexpected ASN.1 type when reading x509 public key: %x", ++ key_type); ++ } ++ ++ /* length is in bits */ ++ key_size = (key_size + 7) / 8; ++ ++ key_data = grub_malloc (key_size); ++ if (!key_data) ++ { ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "Out of memory for x509 public key"); ++ } ++ ++ result = asn1_read_value (asn, pk_name, key_data, &key_size); ++ if (result != ASN1_SUCCESS) ++ { ++ grub_free (key_data); ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error reading public key data"); ++ } ++ key_size = (key_size + 7) / 8; ++ ++ err = grub_parse_rsa_pubkey (key_data, key_size, results); ++ grub_free (key_data); ++ ++ return err; ++} ++ ++/* Decode a string as defined in Appendix A */ ++static grub_err_t ++decode_string (char *der, int der_size, char **string, ++ grub_size_t * string_size) ++{ ++ asn1_node strasn; ++ int result; ++ char *choice; ++ int choice_size = 0; ++ int tmp_size = 0; ++ grub_err_t err = GRUB_ERR_NONE; ++ ++ result = ++ asn1_create_element (_gnutls_pkix_asn, "PKIX1.DirectoryString", &strasn); ++ if (result != ASN1_SUCCESS) ++ { ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "Could not create ASN.1 structure for certificate: %s", ++ asn1_strerror (result)); ++ } ++ ++ result = asn1_der_decoding2 (&strasn, der, &der_size, ++ ASN1_DECODE_FLAG_STRICT_DER, asn1_error); ++ if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Could not parse DER for DirectoryString: %s", ++ asn1_error); ++ goto cleanup; ++ } ++ ++ choice = ++ grub_asn1_allocate_and_read (strasn, "", "DirectoryString choice", ++ &choice_size); ++ if (!choice) ++ { ++ err = grub_errno; ++ goto cleanup; ++ } ++ ++ if (grub_strncmp ("utf8String", choice, choice_size)) ++ { ++ err = ++ grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, ++ "Only UTF-8 DirectoryStrings are supported, got %s", ++ choice); ++ goto cleanup_choice; ++ } ++ ++ result = asn1_read_value (strasn, "utf8String", NULL, &tmp_size); ++ if (result != ASN1_MEM_ERROR) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error reading size of UTF-8 string: %s", ++ asn1_strerror (result)); ++ goto cleanup_choice; ++ } ++ ++ /* read size does not include trailing null */ ++ tmp_size++; ++ ++ *string = grub_malloc (tmp_size); ++ if (!*string) ++ { ++ err = ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "Cannot allocate memory for DirectoryString contents"); ++ goto cleanup_choice; ++ } ++ ++ result = asn1_read_value (strasn, "utf8String", *string, &tmp_size); ++ if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error reading out UTF-8 string in DirectoryString: %s", ++ asn1_strerror (result)); ++ grub_free (*string); ++ goto cleanup_choice; ++ } ++ *string_size = tmp_size + 1; ++ (*string)[tmp_size] = '\0'; ++ ++cleanup_choice: ++ grub_free (choice); ++cleanup: ++ asn1_delete_structure (&strasn); ++ return err; ++} ++ ++/* ++ * TBSCertificate ::= SEQUENCE { ++ * version [0] EXPLICIT Version DEFAULT v1, ++ * ... ++ * ++ * Version ::= INTEGER { v1(0), v2(1), v3(2) } ++ */ ++static grub_err_t ++check_version (asn1_node certificate) ++{ ++ int rc; ++ const char *name = "tbsCertificate.version"; ++ grub_uint8_t version; ++ int len = 1; ++ ++ rc = asn1_read_value (certificate, name, &version, &len); ++ ++ /* require version 3 */ ++ if (rc != ASN1_SUCCESS || len != 1) ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error reading certificate version"); ++ ++ if (version != 0x02) ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Invalid x509 certificate version, expected v3 (0x02), got 0x%02x", ++ version); ++ ++ return GRUB_ERR_NONE; ++} ++ ++/* ++ * This is an X.501 Name, which is complex. ++ * ++ * For simplicity, we extract only the CN. ++ */ ++static grub_err_t ++read_name (asn1_node asn, const char *name_path, char **name, ++ grub_size_t * name_size) ++{ ++ int seq_components, set_components; ++ int result; ++ int i, j; ++ char *top_path, *set_path, *type_path, *val_path; ++ char type[MAX_OID_LEN]; ++ int type_len = sizeof (type); ++ int string_size = 0; ++ char *string_der; ++ grub_err_t err; ++ ++ *name = NULL; ++ ++ top_path = grub_xasprintf ("%s.rdnSequence", name_path); ++ if (!top_path) ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "Could not allocate memory for %s name parsing path", ++ name_path); ++ ++ result = asn1_number_of_elements (asn, top_path, &seq_components); ++ if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error counting name components: %s", ++ asn1_strerror (result)); ++ goto cleanup; ++ } ++ ++ for (i = 1; i <= seq_components; i++) ++ { ++ set_path = grub_xasprintf ("%s.?%d", top_path, i); ++ if (!set_path) ++ { ++ err = ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "Could not allocate memory for %s name set parsing path", ++ name_path); ++ goto cleanup_set; ++ } ++ /* this brings us, hopefully, to a set */ ++ result = asn1_number_of_elements (asn, set_path, &set_components); ++ if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error counting name sub-components components (element %d): %s", ++ i, asn1_strerror (result)); ++ goto cleanup_set; ++ } ++ for (j = 1; j <= set_components; j++) ++ { ++ type_path = grub_xasprintf ("%s.?%d.?%d.type", top_path, i, j); ++ if (!type_path) ++ { ++ err = ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "Could not allocate memory for %s name component type path", ++ name_path); ++ goto cleanup_set; ++ } ++ type_len = sizeof (type); ++ result = asn1_read_value (asn, type_path, type, &type_len); ++ if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error reading %s name component type: %s", ++ name_path, asn1_strerror (result)); ++ goto cleanup_type; ++ } ++ ++ if (grub_strncmp (type, commonName_oid, type_len) != 0) ++ { ++ grub_free (type_path); ++ continue; ++ } ++ ++ val_path = grub_xasprintf ("%s.?%d.?%d.value", top_path, i, j); ++ if (!val_path) ++ { ++ err = ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "Could not allocate memory for %s name component value path", ++ name_path); ++ goto cleanup_set; ++ } ++ ++ string_der = ++ grub_asn1_allocate_and_read (asn, val_path, name_path, ++ &string_size); ++ if (!string_der) ++ { ++ err = grub_errno; ++ goto cleanup_val_path; ++ } ++ ++ err = decode_string (string_der, string_size, name, name_size); ++ if (err) ++ goto cleanup_string; ++ ++ grub_free (string_der); ++ grub_free (type_path); ++ grub_free (val_path); ++ break; ++ } ++ grub_free (set_path); ++ ++ if (*name) ++ break; ++ } ++ ++ return GRUB_ERR_NONE; ++ ++cleanup_string: ++ grub_free (string_der); ++cleanup_val_path: ++ grub_free (val_path); ++cleanup_type: ++ grub_free (type_path); ++cleanup_set: ++ grub_free (set_path); ++cleanup: ++ grub_free (top_path); ++ return err; ++} ++ ++/* ++ * details here ++ */ ++static grub_err_t ++verify_key_usage (grub_uint8_t * value, int value_size) ++{ ++ asn1_node usageasn; ++ int result; ++ grub_err_t err = GRUB_ERR_NONE; ++ grub_uint8_t usage = 0xff; ++ int usage_size = 1; ++ ++ result = ++ asn1_create_element (_gnutls_pkix_asn, "PKIX1.KeyUsage", &usageasn); ++ if (result != ASN1_SUCCESS) ++ { ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "Could not create ASN.1 structure for key usage"); ++ } ++ ++ result = asn1_der_decoding2 (&usageasn, value, &value_size, ++ ASN1_DECODE_FLAG_STRICT_DER, asn1_error); ++ if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error parsing DER for Key Usage: %s", asn1_error); ++ goto cleanup; ++ } ++ ++ result = asn1_read_value (usageasn, "", &usage, &usage_size); ++ if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error reading Key Usage value: %s", ++ asn1_strerror (result)); ++ goto cleanup; ++ } ++ ++ /* Only the first bit is permitted to be set */ ++ if (usage != 0x80) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, "Unexpected Key Usage value: %x", ++ usage); ++ goto cleanup; ++ } ++ ++cleanup: ++ asn1_delete_structure (&usageasn); ++ return err; ++} ++ ++/* ++ * BasicConstraints ::= SEQUENCE { ++ * cA BOOLEAN DEFAULT FALSE, ++ * pathLenConstraint INTEGER (0..MAX) OPTIONAL } ++ */ ++static grub_err_t ++verify_basic_constraints (grub_uint8_t * value, int value_size) ++{ ++ asn1_node basicasn; ++ int result; ++ grub_err_t err = GRUB_ERR_NONE; ++ char cA[6]; /* FALSE or TRUE */ ++ int cA_size = sizeof (cA); ++ ++ result = ++ asn1_create_element (_gnutls_pkix_asn, "PKIX1.BasicConstraints", ++ &basicasn); ++ if (result != ASN1_SUCCESS) ++ { ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "Could not create ASN.1 structure for Basic Constraints"); ++ } ++ ++ result = asn1_der_decoding2 (&basicasn, value, &value_size, ++ ASN1_DECODE_FLAG_STRICT_DER, asn1_error); ++ if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error parsing DER for Basic Constraints: %s", ++ asn1_error); ++ goto cleanup; ++ } ++ ++ result = asn1_read_value (basicasn, "cA", cA, &cA_size); ++ if (result == ASN1_ELEMENT_NOT_FOUND) ++ { ++ /* Not present, default is False, so this is OK */ ++ err = GRUB_ERR_NONE; ++ goto cleanup; ++ } ++ else if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error reading Basic Constraints cA value: %s", ++ asn1_strerror (result)); ++ goto cleanup; ++ } ++ ++ /* The certificate must not be a CA certificate */ ++ if (grub_strncmp ("FALSE", cA, cA_size) != 0) ++ { ++ err = grub_error (GRUB_ERR_BAD_FILE_TYPE, "Unexpected CA value: %s", ++ cA); ++ goto cleanup; ++ } ++ ++cleanup: ++ asn1_delete_structure (&basicasn); ++ return err; ++} ++ ++ ++/* ++ * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension ++ * ++ * Extension ::= SEQUENCE { ++ * extnID OBJECT IDENTIFIER, ++ * critical BOOLEAN DEFAULT FALSE, ++ * extnValue OCTET STRING ++ * -- contains the DER encoding of an ASN.1 value ++ * -- corresponding to the extension type identified ++ * -- by extnID ++ * } ++ * ++ * We require that a certificate: ++ * - contain the Digital Signature usage only ++ * - not be a CA ++ * - MUST not contain any other critical extensions (RFC 5280 s 4.2) ++ */ ++static grub_err_t ++verify_extensions (asn1_node cert) ++{ ++ int result; ++ int ext, num_extensions = 0; ++ int usage_present = 0, constraints_present = 0; ++ char *oid_path, *critical_path, *value_path; ++ char extnID[MAX_OID_LEN]; ++ int extnID_size; ++ grub_err_t err; ++ char critical[6]; /* we get either "TRUE" or "FALSE" */ ++ int critical_size; ++ grub_uint8_t *value; ++ int value_size; ++ ++ result = ++ asn1_number_of_elements (cert, "tbsCertificate.extensions", ++ &num_extensions); ++ if (result != ASN1_SUCCESS) ++ { ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error counting number of extensions: %s", ++ asn1_strerror (result)); ++ } ++ ++ if (num_extensions < 2) ++ { ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Insufficient number of extensions for certificate, need at least 2, got %d", ++ num_extensions); ++ } ++ ++ for (ext = 1; ext <= num_extensions; ext++) ++ { ++ oid_path = grub_xasprintf ("tbsCertificate.extensions.?%d.extnID", ext); ++ ++ extnID_size = sizeof (extnID); ++ result = asn1_read_value (cert, oid_path, extnID, &extnID_size); ++ if (result != GRUB_ERR_NONE) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error reading extension OID: %s", ++ asn1_strerror (result)); ++ goto cleanup_oid_path; ++ } ++ ++ critical_path = ++ grub_xasprintf ("tbsCertificate.extensions.?%d.critical", ext); ++ critical_size = sizeof (critical); ++ result = ++ asn1_read_value (cert, critical_path, critical, &critical_size); ++ if (result == ASN1_ELEMENT_NOT_FOUND) ++ { ++ critical[0] = '\0'; ++ } ++ else if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error reading extension criticality: %s", ++ asn1_strerror (result)); ++ goto cleanup_critical_path; ++ } ++ ++ value_path = ++ grub_xasprintf ("tbsCertificate.extensions.?%d.extnValue", ext); ++ value = ++ grub_asn1_allocate_and_read (cert, value_path, ++ "certificate extension value", ++ &value_size); ++ if (!value) ++ { ++ err = grub_errno; ++ goto cleanup_value_path; ++ } ++ ++ /* ++ * Now we must see if we recognise the OID. ++ * If we have an unrecognised critical extension we MUST bail. ++ */ ++ if (grub_strncmp (keyUsage_oid, extnID, extnID_size) == 0) ++ { ++ err = verify_key_usage (value, value_size); ++ if (err != GRUB_ERR_NONE) ++ { ++ goto cleanup_value; ++ } ++ usage_present++; ++ } ++ else if (grub_strncmp (basicConstraints_oid, extnID, extnID_size) == 0) ++ { ++ err = verify_basic_constraints (value, value_size); ++ if (err != GRUB_ERR_NONE) ++ { ++ goto cleanup_value; ++ } ++ constraints_present++; ++ } ++ else if (grub_strncmp ("TRUE", critical, critical_size) == 0) ++ { ++ /* ++ * per the RFC, we must not process a certificate with ++ * a critical extension we do not understand. ++ */ ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Unhandled critical x509 extension with OID %s", ++ extnID); ++ goto cleanup_value; ++ } ++ ++ grub_free (value); ++ grub_free (value_path); ++ grub_free (critical_path); ++ grub_free (oid_path); ++ } ++ ++ if (usage_present != 1) ++ { ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Unexpected number of Key Usage extensions - expected 1, got %d", ++ usage_present); ++ } ++ if (constraints_present != 1) ++ { ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Unexpected number of basic constraints extensions - expected 1, got %d", ++ constraints_present); ++ } ++ return GRUB_ERR_NONE; ++ ++cleanup_value: ++ grub_free (value); ++cleanup_value_path: ++ grub_free (value_path); ++cleanup_critical_path: ++ grub_free (critical_path); ++cleanup_oid_path: ++ grub_free (oid_path); ++ return err; ++} ++ ++/* ++ * Parse a certificate whose DER-encoded form is in @data, of size @data_size. ++ * Return the results in @results, which must point to an allocated x509 certificate. ++ */ ++grub_err_t ++certificate_import (void *data, grub_size_t data_size, ++ struct x509_certificate *results) ++{ ++ int result = 0; ++ asn1_node cert; ++ grub_err_t err; ++ int size; ++ int tmp_size; ++ ++ if (data_size > GRUB_INT_MAX) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, ++ "Cannot parse a certificate where data size > INT_MAX"); ++ size = (int) data_size; ++ ++ result = asn1_create_element (_gnutls_pkix_asn, "PKIX1.Certificate", &cert); ++ if (result != ASN1_SUCCESS) ++ { ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "Could not create ASN.1 structure for certificate: %s", ++ asn1_strerror (result)); ++ } ++ ++ result = asn1_der_decoding2 (&cert, data, &size, ++ ASN1_DECODE_FLAG_STRICT_DER, asn1_error); ++ if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Could not parse DER for certificate: %s", asn1_error); ++ goto cleanup; ++ } ++ ++ /* ++ * TBSCertificate ::= SEQUENCE { ++ * version [0] EXPLICIT Version DEFAULT v1 ++ */ ++ err = check_version (cert); ++ if (err != GRUB_ERR_NONE) ++ { ++ goto cleanup; ++ } ++ ++ /* ++ * serialNumber CertificateSerialNumber, ++ * ++ * CertificateSerialNumber ::= INTEGER ++ */ ++ results->serial = ++ grub_asn1_allocate_and_read (cert, "tbsCertificate.serialNumber", ++ "certificate serial number", &tmp_size); ++ if (!results->serial) ++ { ++ err = grub_errno; ++ goto cleanup; ++ } ++ /* ++ * It's safe to cast the signed int to an unsigned here, we know ++ * length is non-negative ++ */ ++ results->serial_len = tmp_size; ++ ++ /* ++ * signature AlgorithmIdentifier, ++ * ++ * We don't load the signature or issuer at the moment, ++ * as we don't attempt x509 verification. ++ */ ++ ++ /* ++ * issuer Name, ++ * ++ * The RFC only requires the serial number to be unique within ++ * issuers, so to avoid ambiguity we _technically_ ought to make ++ * this available. ++ */ ++ ++ /* ++ * validity Validity, ++ * ++ * Validity ::= SEQUENCE { ++ * notBefore Time, ++ * notAfter Time } ++ * ++ * We can't validate this reasonably, we have no true time source on several ++ * platforms. For now we do not parse them. ++ */ ++ ++ /* ++ * subject Name, ++ * ++ * This is an X501 name, we parse out just the CN. ++ */ ++ err = ++ read_name (cert, "tbsCertificate.subject", &results->subject, ++ &results->subject_len); ++ if (err != GRUB_ERR_NONE) ++ goto cleanup_serial; ++ ++ /* ++ * TBSCertificate ::= SEQUENCE { ++ * ... ++ * subjectPublicKeyInfo SubjectPublicKeyInfo, ++ * ... ++ */ ++ err = grub_x509_read_subject_public_key (cert, results); ++ if (err != GRUB_ERR_NONE) ++ goto cleanup_name; ++ ++ /* ++ * TBSCertificate ::= SEQUENCE { ++ * ... ++ * extensions [3] EXPLICIT Extensions OPTIONAL ++ * -- If present, version MUST be v3 ++ * } ++ */ ++ ++ err = verify_extensions (cert); ++ if (err != GRUB_ERR_NONE) ++ goto cleanup_name; ++ ++ ++ /* ++ * We do not read or check the signature on the certificate: ++ * as discussed we do not try to validate the certificate but trust ++ * it implictly. ++ */ ++ ++ asn1_delete_structure (&cert); ++ return GRUB_ERR_NONE; ++ ++ ++cleanup_name: ++ grub_free (results->subject); ++cleanup_serial: ++ grub_free (results->serial); ++cleanup: ++ asn1_delete_structure (&cert); ++ return err; ++} ++ ++/* ++ * Release all the storage associated with the x509 certificate. ++ * If the caller dynamically allocated the certificate, it must free it. ++ * The caller is also responsible for maintenance of the linked list. ++ */ ++void ++certificate_release (struct x509_certificate *cert) ++{ ++ grub_free (cert->subject); ++ grub_free (cert->serial); ++ gcry_mpi_release (cert->mpis[0]); ++ gcry_mpi_release (cert->mpis[1]); ++} +diff --git a/grub-core/commands/appendedsig/appendedsig.h b/grub-core/commands/appendedsig/appendedsig.h +new file mode 100644 +index 00000000000..9792ef3901e +--- /dev/null ++++ b/grub-core/commands/appendedsig/appendedsig.h +@@ -0,0 +1,110 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2020 IBM Corporation. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++ ++extern asn1_node _gnutls_gnutls_asn; ++extern asn1_node _gnutls_pkix_asn; ++ ++#define MAX_OID_LEN 32 ++ ++/* ++ * One or more x509 certificates. ++ * ++ * We do limited parsing: extracting only the serial, CN and RSA public key. ++ */ ++struct x509_certificate ++{ ++ struct x509_certificate *next; ++ ++ grub_uint8_t *serial; ++ grub_size_t serial_len; ++ ++ char *subject; ++ grub_size_t subject_len; ++ ++ /* We only support RSA public keys. This encodes [modulus, publicExponent] */ ++ gcry_mpi_t mpis[2]; ++}; ++ ++/* ++ * A PKCS#7 signedData message. ++ * ++ * We make no attempt to match intelligently, so we don't save any info about ++ * the signer. We also support only 1 signerInfo, so we only store a single ++ * MPI for the signature. ++ */ ++struct pkcs7_signedData ++{ ++ const gcry_md_spec_t *hash; ++ gcry_mpi_t sig_mpi; ++}; ++ ++ ++/* Do libtasn1 init */ ++int asn1_init (void); ++ ++/* ++ * Import a DER-encoded certificate at 'data', of size 'size'. ++ * ++ * Place the results into 'results', which must be already allocated. ++ */ ++grub_err_t ++certificate_import (void *data, grub_size_t size, ++ struct x509_certificate *results); ++ ++/* ++ * Release all the storage associated with the x509 certificate. ++ * If the caller dynamically allocated the certificate, it must free it. ++ * The caller is also responsible for maintenance of the linked list. ++ */ ++void certificate_release (struct x509_certificate *cert); ++ ++/* ++ * Parse a PKCS#7 message, which must be a signedData message. ++ * ++ * The message must be in 'sigbuf' and of size 'data_size'. The result is ++ * placed in 'msg', which must already be allocated. ++ */ ++grub_err_t ++parse_pkcs7_signedData (void *sigbuf, grub_size_t data_size, ++ struct pkcs7_signedData *msg); ++ ++/* ++ * Release all the storage associated with the PKCS#7 message. ++ * If the caller dynamically allocated the message, it must free it. ++ */ ++void pkcs7_signedData_release (struct pkcs7_signedData *msg); ++ ++/* ++ * Read a value from an ASN1 node, allocating memory to store it. ++ * ++ * It will work for anything where the size libtasn1 returns is right: ++ * - Integers ++ * - Octet strings ++ * - DER encoding of other structures ++ * It will _not_ work for things where libtasn1 size requires adjustment: ++ * - Strings that require an extra NULL byte at the end ++ * - Bit strings because libtasn1 returns the length in bits, not bytes. ++ * ++ * If the function returns a non-NULL value, the caller must free it. ++ */ ++void *grub_asn1_allocate_and_read (asn1_node node, const char *name, ++ const char *friendly_name, ++ int *content_size); diff --git a/0177-appended-signatures-support-verifying-appended-signa.patch b/0177-appended-signatures-support-verifying-appended-signa.patch new file mode 100644 index 0000000000000000000000000000000000000000..262efc0df50b414f27662b970c6bf841e2259e54 --- /dev/null +++ b/0177-appended-signatures-support-verifying-appended-signa.patch @@ -0,0 +1,716 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Thu, 30 Jul 2020 01:35:43 +1000 +Subject: [PATCH] appended signatures: support verifying appended signatures + +Building on the parsers and the ability to embed x509 certificates, as +well as the existing gcrypt functionality, add a module for verifying +appended signatures. + +This includes a verifier that requires that Linux kernels and grub modules +have appended signatures, and commands to manage the list of trusted +certificates for verification. + +Verification must be enabled by setting check_appended_signatures. If +GRUB is locked down when the module is loaded, verification will be +enabled and locked automatically. + +As with the PGP verifier, it is not a complete secure-boot solution: +other mechanisms, such as a password or lockdown, must be used to ensure +that a user cannot drop to the grub shell and disable verification. + +Signed-off-by: Daniel Axtens +--- + grub-core/Makefile.core.def | 12 + + grub-core/commands/appendedsig/appendedsig.c | 645 +++++++++++++++++++++++++++ + include/grub/file.h | 2 + + 3 files changed, 659 insertions(+) + create mode 100644 grub-core/commands/appendedsig/appendedsig.c + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index b4aaccf7b57..77321d218c8 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -980,6 +980,18 @@ module = { + cppflags = '-I$(srcdir)/lib/posix_wrap'; + }; + ++module = { ++ name = appendedsig; ++ common = commands/appendedsig/appendedsig.c; ++ common = commands/appendedsig/x509.c; ++ common = commands/appendedsig/pkcs7.c; ++ common = commands/appendedsig/asn1util.c; ++ common = commands/appendedsig/gnutls_asn1_tab.c; ++ common = commands/appendedsig/pkix_asn1_tab.c; ++ cflags = '$(CFLAGS_POSIX)'; ++ cppflags = '-I$(srcdir)/lib/posix_wrap'; ++}; ++ + module = { + name = hdparm; + common = commands/hdparm.c; +diff --git a/grub-core/commands/appendedsig/appendedsig.c b/grub-core/commands/appendedsig/appendedsig.c +new file mode 100644 +index 00000000000..dc294cd339e +--- /dev/null ++++ b/grub-core/commands/appendedsig/appendedsig.c +@@ -0,0 +1,645 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2020-2021 IBM Corporation. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "appendedsig.h" ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++const char magic[] = "~Module signature appended~\n"; ++ ++/* ++ * This structure is extracted from scripts/sign-file.c in the linux kernel ++ * source. It was licensed as LGPLv2.1+, which is GPLv3+ compatible. ++ */ ++struct module_signature ++{ ++ grub_uint8_t algo; /* Public-key crypto algorithm [0] */ ++ grub_uint8_t hash; /* Digest algorithm [0] */ ++ grub_uint8_t id_type; /* Key identifier type [PKEY_ID_PKCS7] */ ++ grub_uint8_t signer_len; /* Length of signer's name [0] */ ++ grub_uint8_t key_id_len; /* Length of key identifier [0] */ ++ grub_uint8_t __pad[3]; ++ grub_uint32_t sig_len; /* Length of signature data */ ++} GRUB_PACKED; ++ ++ ++/* This represents an entire, parsed, appended signature */ ++struct grub_appended_signature ++{ ++ grub_size_t signature_len; /* Length of PKCS#7 data + ++ * metadata + magic */ ++ ++ struct module_signature sig_metadata; /* Module signature metadata */ ++ struct pkcs7_signedData pkcs7; /* Parsed PKCS#7 data */ ++}; ++ ++/* Trusted certificates for verifying appended signatures */ ++struct x509_certificate *grub_trusted_key; ++ ++/* ++ * Force gcry_rsa to be a module dependency. ++ * ++ * If we use grub_crypto_pk_rsa, then then the gcry_rsa module won't be built ++ * in if you add 'appendedsig' to grub-install --modules. You would need to ++ * add 'gcry_rsa' too. That's confusing and seems suboptimal, especially when ++ * we only support RSA. ++ * ++ * Dynamic loading also causes some concerns. We can't load gcry_rsa from the ++ * the filesystem after we install the verifier - we won't be able to verify ++ * it without having it already present. We also shouldn't load it before we ++ * install the verifier, because that would mean it wouldn't be verified - an ++ * attacker could insert any code they wanted into the module. ++ * ++ * So instead, reference the internal symbol from gcry_rsa. That creates a ++ * direct dependency on gcry_rsa, so it will be built in when this module ++ * is built in. Being built in (assuming the core image is itself signed!) ++ * also resolves our concerns about loading from the filesystem. ++ */ ++extern gcry_pk_spec_t _gcry_pubkey_spec_rsa; ++ ++static int check_sigs = 0; ++ ++static const char * ++grub_env_read_sec (struct grub_env_var *var __attribute__ ((unused)), ++ const char *val __attribute__ ((unused))) ++{ ++ if (check_sigs == 2) ++ return "forced"; ++ else if (check_sigs == 1) ++ return "enforce"; ++ else ++ return "no"; ++} ++ ++static char * ++grub_env_write_sec (struct grub_env_var *var __attribute__((unused)), ++ const char *val) ++{ ++ /* Do not allow the value to be changed if set to forced */ ++ if (check_sigs == 2) ++ return grub_strdup ("forced"); ++ ++ if ((*val == '2') || (*val == 'f')) ++ check_sigs = 2; ++ else if ((*val == '1') || (*val == 'e')) ++ check_sigs = 1; ++ else if ((*val == '0') || (*val == 'n')) ++ check_sigs = 0; ++ ++ return grub_strdup (grub_env_read_sec (NULL, NULL)); ++} ++ ++static grub_err_t ++read_cert_from_file (grub_file_t f, struct x509_certificate *certificate) ++{ ++ grub_err_t err; ++ grub_uint8_t *buf = NULL; ++ grub_ssize_t read_size; ++ grub_off_t total_read_size = 0; ++ grub_off_t file_size = grub_file_size (f); ++ ++ ++ if (file_size == GRUB_FILE_SIZE_UNKNOWN) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, ++ N_("Cannot parse a certificate file of unknown size")); ++ ++ buf = grub_zalloc (file_size); ++ if (!buf) ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ N_("Could not allocate buffer for certificate file contents")); ++ ++ while (total_read_size < file_size) ++ { ++ read_size = ++ grub_file_read (f, &buf[total_read_size], ++ file_size - total_read_size); ++ if (read_size < 0) ++ { ++ err = grub_error (GRUB_ERR_READ_ERROR, ++ N_("Error reading certificate file")); ++ goto cleanup_buf; ++ } ++ total_read_size += read_size; ++ } ++ ++ err = certificate_import (buf, total_read_size, certificate); ++ if (err != GRUB_ERR_NONE) ++ goto cleanup_buf; ++ ++ return GRUB_ERR_NONE; ++ ++cleanup_buf: ++ grub_free (buf); ++ return err; ++} ++ ++static grub_err_t ++extract_appended_signature (grub_uint8_t * buf, grub_size_t bufsize, ++ struct grub_appended_signature *sig) ++{ ++ grub_err_t err; ++ grub_size_t pkcs7_size; ++ grub_size_t remaining_len; ++ grub_uint8_t *appsigdata = buf + bufsize - grub_strlen (magic); ++ ++ if (bufsize < grub_strlen (magic)) ++ return grub_error (GRUB_ERR_BAD_SIGNATURE, ++ N_("File too short for signature magic")); ++ ++ if (grub_memcmp (appsigdata, (grub_uint8_t *) magic, grub_strlen (magic))) ++ return grub_error (GRUB_ERR_BAD_SIGNATURE, ++ N_("Missing or invalid signature magic")); ++ ++ remaining_len = bufsize - grub_strlen (magic); ++ ++ if (remaining_len < sizeof (struct module_signature)) ++ return grub_error (GRUB_ERR_BAD_SIGNATURE, ++ N_("File too short for signature metadata")); ++ ++ appsigdata -= sizeof (struct module_signature); ++ ++ /* extract the metadata */ ++ grub_memcpy (&(sig->sig_metadata), appsigdata, ++ sizeof (struct module_signature)); ++ ++ remaining_len -= sizeof (struct module_signature); ++ ++ if (sig->sig_metadata.id_type != 2) ++ return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("Wrong signature type")); ++ ++#ifdef GRUB_TARGET_WORDS_BIGENDIAN ++ pkcs7_size = sig->sig_metadata.sig_len; ++#else ++ pkcs7_size = __builtin_bswap32 (sig->sig_metadata.sig_len); ++#endif ++ ++ if (pkcs7_size > remaining_len) ++ return grub_error (GRUB_ERR_BAD_SIGNATURE, ++ N_("File too short for PKCS#7 message")); ++ ++ grub_dprintf ("appendedsig", "sig len %" PRIuGRUB_SIZE "\n", pkcs7_size); ++ ++ sig->signature_len = ++ grub_strlen (magic) + sizeof (struct module_signature) + pkcs7_size; ++ ++ /* rewind pointer and parse pkcs7 data */ ++ appsigdata -= pkcs7_size; ++ ++ err = parse_pkcs7_signedData (appsigdata, pkcs7_size, &sig->pkcs7); ++ if (err != GRUB_ERR_NONE) ++ return err; ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_verify_appended_signature (grub_uint8_t * buf, grub_size_t bufsize) ++{ ++ grub_err_t err = GRUB_ERR_NONE; ++ grub_size_t datasize; ++ void *context; ++ unsigned char *hash; ++ gcry_mpi_t hashmpi; ++ gcry_err_code_t rc; ++ struct x509_certificate *pk; ++ struct grub_appended_signature sig; ++ ++ if (!grub_trusted_key) ++ return grub_error (GRUB_ERR_BAD_SIGNATURE, ++ N_("No trusted keys to verify against")); ++ ++ err = extract_appended_signature (buf, bufsize, &sig); ++ if (err != GRUB_ERR_NONE) ++ return err; ++ ++ datasize = bufsize - sig.signature_len; ++ ++ context = grub_zalloc (sig.pkcs7.hash->contextsize); ++ if (!context) ++ return grub_errno; ++ ++ sig.pkcs7.hash->init (context); ++ sig.pkcs7.hash->write (context, buf, datasize); ++ sig.pkcs7.hash->final (context); ++ hash = sig.pkcs7.hash->read (context); ++ grub_dprintf ("appendedsig", ++ "data size %" PRIxGRUB_SIZE ", hash %02x%02x%02x%02x...\n", ++ datasize, hash[0], hash[1], hash[2], hash[3]); ++ ++ err = GRUB_ERR_BAD_SIGNATURE; ++ for (pk = grub_trusted_key; pk; pk = pk->next) ++ { ++ rc = grub_crypto_rsa_pad (&hashmpi, hash, sig.pkcs7.hash, pk->mpis[0]); ++ if (rc) ++ { ++ err = grub_error (GRUB_ERR_BAD_SIGNATURE, ++ N_("Error padding hash for RSA verification: %d"), ++ rc); ++ goto cleanup; ++ } ++ ++ rc = _gcry_pubkey_spec_rsa.verify (0, hashmpi, &sig.pkcs7.sig_mpi, ++ pk->mpis, NULL, NULL); ++ gcry_mpi_release (hashmpi); ++ ++ if (rc == 0) ++ { ++ grub_dprintf ("appendedsig", "verify with key '%s' succeeded\n", ++ pk->subject); ++ err = GRUB_ERR_NONE; ++ break; ++ } ++ ++ grub_dprintf ("appendedsig", "verify with key '%s' failed with %d\n", ++ pk->subject, rc); ++ } ++ ++ /* If we didn't verify, provide a neat message */ ++ if (err != GRUB_ERR_NONE) ++ err = grub_error (GRUB_ERR_BAD_SIGNATURE, ++ N_("Failed to verify signature against a trusted key")); ++ ++cleanup: ++ grub_free (context); ++ pkcs7_signedData_release (&sig.pkcs7); ++ ++ return err; ++} ++ ++static grub_err_t ++grub_cmd_verify_signature (grub_command_t cmd __attribute__((unused)), ++ int argc, char **args) ++{ ++ grub_file_t f; ++ grub_err_t err = GRUB_ERR_NONE; ++ grub_uint8_t *data; ++ grub_ssize_t read_size; ++ grub_off_t file_size, total_read_size = 0; ++ ++ if (argc < 1) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); ++ ++ grub_dprintf ("appendedsig", "verifying %s\n", args[0]); ++ ++ f = grub_file_open (args[0], GRUB_FILE_TYPE_VERIFY_SIGNATURE); ++ if (!f) ++ { ++ err = grub_errno; ++ goto cleanup; ++ } ++ ++ file_size = grub_file_size (f); ++ if (file_size == GRUB_FILE_SIZE_UNKNOWN) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, ++ N_("Cannot verify the signature of a file of unknown size")); ++ ++ data = grub_malloc (file_size); ++ if (!data) ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ N_("Could not allocate data buffer size " ++ PRIuGRUB_UINT64_T " for verification"), file_size); ++ ++ while (total_read_size < file_size) ++ { ++ read_size = ++ grub_file_read (f, &data[total_read_size], ++ file_size - total_read_size); ++ if (read_size < 0) ++ { ++ err = grub_error (GRUB_ERR_READ_ERROR, ++ N_("Error reading file to verify")); ++ goto cleanup_data; ++ } ++ total_read_size += read_size; ++ } ++ ++ err = grub_verify_appended_signature (data, file_size); ++ ++cleanup_data: ++ grub_free (data); ++cleanup: ++ if (f) ++ grub_file_close (f); ++ return err; ++} ++ ++static grub_err_t ++grub_cmd_distrust (grub_command_t cmd __attribute__((unused)), ++ int argc, char **args) ++{ ++ unsigned long cert_num, i; ++ struct x509_certificate *cert, *prev; ++ ++ if (argc != 1) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("One argument expected")); ++ ++ grub_errno = GRUB_ERR_NONE; ++ cert_num = grub_strtoul (args[0], NULL, 10); ++ if (grub_errno != GRUB_ERR_NONE) ++ return grub_errno; ++ ++ if (cert_num < 1) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, ++ N_("Certificate number too small - numbers start at 1")); ++ ++ if (cert_num == 1) ++ { ++ cert = grub_trusted_key; ++ grub_trusted_key = cert->next; ++ ++ certificate_release (cert); ++ grub_free (cert); ++ return GRUB_ERR_NONE; ++ } ++ i = 2; ++ prev = grub_trusted_key; ++ cert = grub_trusted_key->next; ++ while (cert) ++ { ++ if (i == cert_num) ++ { ++ prev->next = cert->next; ++ certificate_release (cert); ++ grub_free (cert); ++ return GRUB_ERR_NONE; ++ } ++ i++; ++ prev = cert; ++ cert = cert->next; ++ } ++ ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, ++ N_("No certificate number %d found - only %d certificates in the store"), ++ cert_num, i - 1); ++} ++ ++static grub_err_t ++grub_cmd_trust (grub_command_t cmd __attribute__((unused)), ++ int argc, char **args) ++{ ++ grub_file_t certf; ++ struct x509_certificate *cert = NULL; ++ grub_err_t err; ++ ++ if (argc != 1) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); ++ ++ certf = grub_file_open (args[0], ++ GRUB_FILE_TYPE_CERTIFICATE_TRUST ++ | GRUB_FILE_TYPE_NO_DECOMPRESS); ++ if (!certf) ++ return grub_errno; ++ ++ ++ cert = grub_zalloc (sizeof (struct x509_certificate)); ++ if (!cert) ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ N_("Could not allocate memory for certificate")); ++ ++ err = read_cert_from_file (certf, cert); ++ grub_file_close (certf); ++ if (err != GRUB_ERR_NONE) ++ { ++ grub_free (cert); ++ return err; ++ } ++ grub_dprintf ("appendedsig", "Loaded certificate with CN: %s\n", ++ cert->subject); ++ ++ cert->next = grub_trusted_key; ++ grub_trusted_key = cert; ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_cmd_list (grub_command_t cmd __attribute__((unused)), ++ int argc __attribute__((unused)), ++ char **args __attribute__((unused))) ++{ ++ struct x509_certificate *cert; ++ int cert_num = 1; ++ grub_size_t i; ++ ++ for (cert = grub_trusted_key; cert; cert = cert->next) ++ { ++ grub_printf (N_("Certificate %d:\n"), cert_num); ++ ++ grub_printf (N_("\tSerial: ")); ++ for (i = 0; i < cert->serial_len - 1; i++) ++ { ++ grub_printf ("%02x:", cert->serial[i]); ++ } ++ grub_printf ("%02x\n", cert->serial[cert->serial_len - 1]); ++ ++ grub_printf ("\tCN: %s\n\n", cert->subject); ++ cert_num++; ++ ++ } ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++appendedsig_init (grub_file_t io __attribute__((unused)), ++ enum grub_file_type type, ++ void **context __attribute__((unused)), ++ enum grub_verify_flags *flags) ++{ ++ if (!check_sigs) ++ { ++ *flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION; ++ return GRUB_ERR_NONE; ++ } ++ ++ switch (type & GRUB_FILE_TYPE_MASK) ++ { ++ case GRUB_FILE_TYPE_CERTIFICATE_TRUST: ++ /* ++ * This is a certificate to add to trusted keychain. ++ * ++ * This needs to be verified or blocked. Ideally we'd write an x509 ++ * verifier, but we lack the hubris required to take this on. Instead, ++ * require that it have an appended signature. ++ */ ++ ++ /* Fall through */ ++ ++ case GRUB_FILE_TYPE_LINUX_KERNEL: ++ case GRUB_FILE_TYPE_GRUB_MODULE: ++ /* ++ * Appended signatures are only defined for ELF binaries. ++ * Out of an abundance of caution, we only verify Linux kernels and ++ * GRUB modules at this point. ++ */ ++ *flags = GRUB_VERIFY_FLAGS_SINGLE_CHUNK; ++ return GRUB_ERR_NONE; ++ ++ case GRUB_FILE_TYPE_ACPI_TABLE: ++ case GRUB_FILE_TYPE_DEVICE_TREE_IMAGE: ++ /* ++ * It is possible to use appended signature verification without ++ * lockdown - like the PGP verifier. When combined with an embedded ++ * config file in a signed grub binary, this could still be a meaningful ++ * secure-boot chain - so long as it isn't subverted by something like a ++ * rouge ACPI table or DT image. Defer them explicitly. ++ */ ++ *flags = GRUB_VERIFY_FLAGS_DEFER_AUTH; ++ return GRUB_ERR_NONE; ++ ++ default: ++ *flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION; ++ return GRUB_ERR_NONE; ++ } ++} ++ ++static grub_err_t ++appendedsig_write (void *ctxt __attribute__((unused)), ++ void *buf, grub_size_t size) ++{ ++ return grub_verify_appended_signature (buf, size); ++} ++ ++struct grub_file_verifier grub_appendedsig_verifier = { ++ .name = "appendedsig", ++ .init = appendedsig_init, ++ .write = appendedsig_write, ++}; ++ ++static grub_ssize_t ++pseudo_read (struct grub_file *file, char *buf, grub_size_t len) ++{ ++ grub_memcpy (buf, (grub_uint8_t *) file->data + file->offset, len); ++ return len; ++} ++ ++/* Filesystem descriptor. */ ++static struct grub_fs pseudo_fs = { ++ .name = "pseudo", ++ .fs_read = pseudo_read ++}; ++ ++static grub_command_t cmd_verify, cmd_list, cmd_distrust, cmd_trust; ++ ++GRUB_MOD_INIT (appendedsig) ++{ ++ int rc; ++ struct grub_module_header *header; ++ ++ /* If in lockdown, immediately enter forced mode */ ++ if (grub_is_lockdown () == GRUB_LOCKDOWN_ENABLED) ++ check_sigs = 2; ++ ++ grub_trusted_key = NULL; ++ ++ grub_register_variable_hook ("check_appended_signatures", ++ grub_env_read_sec, ++ grub_env_write_sec); ++ grub_env_export ("check_appended_signatures"); ++ ++ rc = asn1_init (); ++ if (rc) ++ grub_fatal ("Error initing ASN.1 data structures: %d: %s\n", rc, ++ asn1_strerror (rc)); ++ ++ FOR_MODULES (header) ++ { ++ struct grub_file pseudo_file; ++ struct x509_certificate *pk = NULL; ++ grub_err_t err; ++ ++ /* Not an ELF module, skip. */ ++ if (header->type != OBJ_TYPE_X509_PUBKEY) ++ continue; ++ ++ grub_memset (&pseudo_file, 0, sizeof (pseudo_file)); ++ pseudo_file.fs = &pseudo_fs; ++ pseudo_file.size = header->size - sizeof (struct grub_module_header); ++ pseudo_file.data = (char *) header + sizeof (struct grub_module_header); ++ ++ grub_dprintf ("appendedsig", ++ "Found an x509 key, size=%" PRIuGRUB_UINT64_T "\n", ++ pseudo_file.size); ++ ++ pk = grub_zalloc (sizeof (struct x509_certificate)); ++ if (!pk) ++ { ++ grub_fatal ("Out of memory loading initial certificates"); ++ } ++ ++ err = read_cert_from_file (&pseudo_file, pk); ++ if (err != GRUB_ERR_NONE) ++ grub_fatal ("Error loading initial key: %s", grub_errmsg); ++ ++ grub_dprintf ("appendedsig", "loaded certificate CN='%s'\n", pk->subject); ++ ++ pk->next = grub_trusted_key; ++ grub_trusted_key = pk; ++ } ++ ++ cmd_trust = ++ grub_register_command ("trust_certificate", grub_cmd_trust, ++ N_("X509_CERTIFICATE"), ++ N_("Add X509_CERTIFICATE to trusted certificates.")); ++ cmd_list = ++ grub_register_command ("list_certificates", grub_cmd_list, 0, ++ N_("Show the list of trusted x509 certificates.")); ++ cmd_verify = ++ grub_register_command ("verify_appended", grub_cmd_verify_signature, ++ N_("FILE"), ++ N_("Verify FILE against the trusted x509 certificates.")); ++ cmd_distrust = ++ grub_register_command ("distrust_certificate", grub_cmd_distrust, ++ N_("CERT_NUMBER"), ++ N_("Remove CERT_NUMBER (as listed by list_certificates) from trusted certificates.")); ++ ++ grub_verifier_register (&grub_appendedsig_verifier); ++ grub_dl_set_persistent (mod); ++} ++ ++GRUB_MOD_FINI (appendedsig) ++{ ++ /* ++ * grub_dl_set_persistent should prevent this from actually running, but ++ * it does still run under emu. ++ */ ++ ++ grub_verifier_unregister (&grub_appendedsig_verifier); ++ grub_unregister_command (cmd_verify); ++ grub_unregister_command (cmd_list); ++ grub_unregister_command (cmd_trust); ++ grub_unregister_command (cmd_distrust); ++} +diff --git a/include/grub/file.h b/include/grub/file.h +index 31567483ccf..96827a4f896 100644 +--- a/include/grub/file.h ++++ b/include/grub/file.h +@@ -80,6 +80,8 @@ enum grub_file_type + GRUB_FILE_TYPE_PUBLIC_KEY, + /* File holding public key to add to trused keys. */ + GRUB_FILE_TYPE_PUBLIC_KEY_TRUST, ++ /* File holding x509 certificiate to add to trusted keys. */ ++ GRUB_FILE_TYPE_CERTIFICATE_TRUST, + /* File of which we intend to print a blocklist to the user. */ + GRUB_FILE_TYPE_PRINT_BLOCKLIST, + /* File we intend to use for test loading or testing speed. */ diff --git a/0177-blscfg-Add-support-for-the-devicetree-field.patch b/0177-blscfg-Add-support-for-the-devicetree-field.patch deleted file mode 100644 index e0065d507d5fca6f1097c96d24297c5aed378936..0000000000000000000000000000000000000000 --- a/0177-blscfg-Add-support-for-the-devicetree-field.patch +++ /dev/null @@ -1,135 +0,0 @@ -From a2d218b17e33e56829b9a23f73dded07ae5839a8 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Sun, 15 Sep 2019 09:37:45 +0200 -Subject: [PATCH 177/220] blscfg: Add support for the devicetree field - -The BootLoaderSpec mentions that a devicetree field can be used to pass a -Device Tree (DT) to the kernel, for the platforms that use it to describe -information about the hardware. - -Allow the blscfg module to parse this field and call the grub2 devicetree -command in that case. If there is a devicetree grub2 environment variable -defined, this will be used if the field is not defined in the BLS snippet. - -Resolves: rhbz#1751307 - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/commands/blscfg.c | 60 ++++++++++++++++++++++++++++++++++++++++++--- - 1 file changed, 57 insertions(+), 3 deletions(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 54458b1..1ec8987 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -698,6 +698,8 @@ static void create_entry (struct bls_entry *entry) - const char *early_initrd = NULL; - char **early_initrds = NULL; - char *initrd_prefix = NULL; -+ char *devicetree = NULL; -+ char *dt = NULL; - char *id = entry->filename; - char *dotconf = id; - char *hotkey = NULL; -@@ -709,6 +711,7 @@ static void create_entry (struct bls_entry *entry) - - char *src = NULL; - int i, index; -+ bool add_dt_prefix = false; - - grub_dprintf("blscfg", "%s got here\n", __func__); - clinux = bls_get_val (entry, "linux", NULL); -@@ -736,6 +739,14 @@ static void create_entry (struct bls_entry *entry) - - initrds = bls_make_list (entry, "initrd", NULL); - -+ devicetree = expand_val (bls_get_val (entry, "devicetree", NULL)); -+ -+ if (!devicetree) -+ { -+ devicetree = expand_val (grub_env_get("devicetree")); -+ add_dt_prefix = true; -+ } -+ - hotkey = bls_get_val (entry, "grub_hotkey", NULL); - users = expand_val (bls_get_val (entry, "grub_users", NULL)); - classes = bls_make_list (entry, "grub_class", NULL); -@@ -801,7 +812,6 @@ static void create_entry (struct bls_entry *entry) - goto finish; - } - -- - tmp = grub_stpcpy(initrd, "initrd"); - for (i = 0; early_initrds != NULL && early_initrds[i] != NULL; i++) - { -@@ -821,21 +831,65 @@ static void create_entry (struct bls_entry *entry) - tmp = grub_stpcpy (tmp, "\n"); - } - -+ if (devicetree) -+ { -+ char *prefix = NULL; -+ int dt_size; -+ -+ if (add_dt_prefix) -+ { -+ prefix = grub_strrchr (clinux, '/'); -+ prefix = grub_strndup(clinux, prefix - clinux + 1); -+ if (!prefix) -+ { -+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); -+ goto finish; -+ } -+ } -+ -+ dt_size = sizeof("devicetree " GRUB_BOOT_DEVICE) + grub_strlen(devicetree) + 1; -+ -+ if (add_dt_prefix) -+ { -+ dt_size += grub_strlen(prefix); -+ } -+ -+ dt = grub_malloc (dt_size); -+ if (!dt) -+ { -+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); -+ goto finish; -+ } -+ char *tmp = dt; -+ tmp = grub_stpcpy (dt, "devicetree"); -+ tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE); -+ if (add_dt_prefix) -+ tmp = grub_stpcpy (tmp, prefix); -+ tmp = grub_stpcpy (tmp, devicetree); -+ tmp = grub_stpcpy (tmp, "\n"); -+ -+ grub_free(prefix); -+ } -+ -+ grub_dprintf ("blscfg2", "devicetree %s for id:\"%s\"\n", dt, id); -+ - src = grub_xasprintf ("load_video\n" - "set gfxpayload=keep\n" - "insmod gzio\n" - "linux %s%s%s%s\n" -- "%s", -+ "%s%s", - GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "", -- initrd ? initrd : ""); -+ initrd ? initrd : "", dt ? dt : ""); - - grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0, &index, entry); - grub_dprintf ("blscfg", "Added entry %d id:\"%s\"\n", index, id); - - finish: -+ grub_free (dt); - grub_free (initrd); - grub_free (initrd_prefix); - grub_free (early_initrds); -+ grub_free (devicetree); - grub_free (initrds); - grub_free (options); - grub_free (classes); --- -1.8.3.1 - diff --git a/0178-Set-a-devicetree-var-in-a-BLS-config-if-GRUB_DEFAULT.patch b/0178-Set-a-devicetree-var-in-a-BLS-config-if-GRUB_DEFAULT.patch deleted file mode 100644 index 21f7bf16c55f93783341a2d4b35637a727d6f501..0000000000000000000000000000000000000000 --- a/0178-Set-a-devicetree-var-in-a-BLS-config-if-GRUB_DEFAULT.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 6af4cfe6059cdce1ff72db3c72e77097e1285cc0 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Sun, 15 Sep 2019 10:05:29 +0200 -Subject: [PATCH 178/220] Set a devicetree var in a BLS config if - GRUB_DEFAULT_DTB is present - -The BootLoaderSpec mentions that a devicetree field can be used to pass a -Device Tree (DT) to the kernel, for the platforms that use it to describe -information about the hardware. - -The blscfg module supports parsing the field from the BLS snippets but it -allows to set a DT for all the entries if a devicetree env var is defined. - -Make the grub2-mkconfig tool to set this variable if GRUB_DEFAULT_DTB was -defined in the /etc/default/grub file. - -Resolves: rhbz#1751307 - -Signed-off-by: Javier Martinez Canillas ---- - util/grub.d/10_linux.in | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 301594a..1520b7e 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -138,6 +138,10 @@ EOF - if [ -n "${GRUB_EARLY_INITRD_LINUX_CUSTOM}" ]; then - ${grub_editenv} - set early_initrd="${GRUB_EARLY_INITRD_LINUX_CUSTOM}" - fi -+ -+ if [ -n "${GRUB_DEFAULT_DTB}" ]; then -+ ${grub_editenv} - set devicetree="${GRUB_DEFAULT_DTB}" -+ fi - fi - - exit 0 --- -1.8.3.1 - diff --git a/0178-appended-signatures-verification-tests.patch b/0178-appended-signatures-verification-tests.patch new file mode 100644 index 0000000000000000000000000000000000000000..9f6c3c62d250045d5d3ae9b7bfc175f6a90b205f --- /dev/null +++ b/0178-appended-signatures-verification-tests.patch @@ -0,0 +1,897 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Thu, 30 Jul 2020 01:31:02 +1000 +Subject: [PATCH] appended signatures: verification tests + +These tests are run through all_functional_test and test a range +of commands and behaviours. + +Signed-off-by: Daniel Axtens +--- + grub-core/Makefile.core.def | 6 + + grub-core/tests/appended_signature_test.c | 281 +++++++++++++++ + grub-core/tests/lib/functional_test.c | 1 + + grub-core/tests/appended_signatures.h | 557 ++++++++++++++++++++++++++++++ + 4 files changed, 845 insertions(+) + create mode 100644 grub-core/tests/appended_signature_test.c + create mode 100644 grub-core/tests/appended_signatures.h + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 77321d218c8..6bddc841b85 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -2161,6 +2161,12 @@ module = { + common = tests/setjmp_test.c; + }; + ++module = { ++ name = appended_signature_test; ++ common = tests/appended_signature_test.c; ++ common = tests/appended_signatures.h; ++}; ++ + module = { + name = signature_test; + common = tests/signature_test.c; +diff --git a/grub-core/tests/appended_signature_test.c b/grub-core/tests/appended_signature_test.c +new file mode 100644 +index 00000000000..88a485200d8 +--- /dev/null ++++ b/grub-core/tests/appended_signature_test.c +@@ -0,0 +1,281 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2020 IBM Corporation. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "appended_signatures.h" ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++#define DEFINE_TEST_CASE(case_name) \ ++static char * \ ++get_ ## case_name (grub_size_t *sz) \ ++{ \ ++ char *ret; \ ++ *sz = case_name ## _len; \ ++ ret = grub_malloc (*sz); \ ++ if (ret) \ ++ grub_memcpy (ret, case_name, *sz); \ ++ return ret; \ ++} \ ++\ ++static struct grub_procfs_entry case_name ## _entry = \ ++{ \ ++ .name = #case_name, \ ++ .get_contents = get_ ## case_name \ ++} ++ ++#define DO_TEST(case_name, is_valid) \ ++{ \ ++ grub_procfs_register (#case_name, &case_name ## _entry); \ ++ do_verify ("(proc)/" #case_name, is_valid); \ ++ grub_procfs_unregister (&case_name ## _entry); \ ++} ++ ++ ++DEFINE_TEST_CASE (hi_signed); ++DEFINE_TEST_CASE (hi_signed_sha256); ++DEFINE_TEST_CASE (hj_signed); ++DEFINE_TEST_CASE (short_msg); ++DEFINE_TEST_CASE (unsigned_msg); ++DEFINE_TEST_CASE (hi_signed_2nd); ++ ++static char * ++get_certificate_der (grub_size_t * sz) ++{ ++ char *ret; ++ *sz = certificate_der_len; ++ ret = grub_malloc (*sz); ++ if (ret) ++ grub_memcpy (ret, certificate_der, *sz); ++ return ret; ++} ++ ++static struct grub_procfs_entry certificate_der_entry = { ++ .name = "certificate.der", ++ .get_contents = get_certificate_der ++}; ++ ++static char * ++get_certificate2_der (grub_size_t * sz) ++{ ++ char *ret; ++ *sz = certificate2_der_len; ++ ret = grub_malloc (*sz); ++ if (ret) ++ grub_memcpy (ret, certificate2_der, *sz); ++ return ret; ++} ++ ++static struct grub_procfs_entry certificate2_der_entry = { ++ .name = "certificate2.der", ++ .get_contents = get_certificate2_der ++}; ++ ++static char * ++get_certificate_printable_der (grub_size_t * sz) ++{ ++ char *ret; ++ *sz = certificate_printable_der_len; ++ ret = grub_malloc (*sz); ++ if (ret) ++ grub_memcpy (ret, certificate_printable_der, *sz); ++ return ret; ++} ++ ++static struct grub_procfs_entry certificate_printable_der_entry = { ++ .name = "certificate_printable.der", ++ .get_contents = get_certificate_printable_der ++}; ++ ++ ++static void ++do_verify (const char *f, int is_valid) ++{ ++ grub_command_t cmd; ++ char *args[] = { (char *) f, NULL }; ++ grub_err_t err; ++ ++ cmd = grub_command_find ("verify_appended"); ++ if (!cmd) ++ { ++ grub_test_assert (0, "can't find command `%s'", "verify_appended"); ++ return; ++ } ++ err = (cmd->func) (cmd, 1, args); ++ if (is_valid) ++ { ++ grub_test_assert (err == GRUB_ERR_NONE, ++ "verification of %s failed: %d: %s", f, grub_errno, ++ grub_errmsg); ++ } ++ else ++ { ++ grub_test_assert (err == GRUB_ERR_BAD_SIGNATURE, ++ "verification of %s unexpectedly succeeded", f); ++ } ++ grub_errno = GRUB_ERR_NONE; ++ ++} ++ ++static void ++appended_signature_test (void) ++{ ++ grub_command_t cmd_trust, cmd_distrust; ++ char *trust_args[] = { (char *) "(proc)/certificate.der", NULL }; ++ char *trust_args2[] = { (char *) "(proc)/certificate2.der", NULL }; ++ char *trust_args_printable[] = { (char *) "(proc)/certificate_printable.der", ++ NULL }; ++ char *distrust_args[] = { (char *) "1", NULL }; ++ char *distrust2_args[] = { (char *) "2", NULL }; ++ grub_err_t err; ++ ++ grub_procfs_register ("certificate.der", &certificate_der_entry); ++ grub_procfs_register ("certificate2.der", &certificate2_der_entry); ++ grub_procfs_register ("certificate_printable.der", ++ &certificate_printable_der_entry); ++ ++ cmd_trust = grub_command_find ("trust_certificate"); ++ if (!cmd_trust) ++ { ++ grub_test_assert (0, "can't find command `%s'", "trust_certificate"); ++ return; ++ } ++ err = (cmd_trust->func) (cmd_trust, 1, trust_args); ++ ++ grub_test_assert (err == GRUB_ERR_NONE, ++ "loading certificate failed: %d: %s", grub_errno, ++ grub_errmsg); ++ ++ /* If we have no certificate the remainder of the tests are meaningless */ ++ if (err != GRUB_ERR_NONE) ++ return; ++ ++ /* ++ * Reload the command: this works around some 'interesting' behaviour in the ++ * dynamic command dispatcher. The first time you call cmd->func you get a ++ * dispatcher that loads the module, finds the real cmd, calls it, and then ++ * releases some internal storage. This means it's not safe to call a second ++ * time and we need to reload it. ++ */ ++ cmd_trust = grub_command_find ("trust_certificate"); ++ ++ DO_TEST (hi_signed, 1); ++ DO_TEST (hi_signed_sha256, 1); ++ DO_TEST (hj_signed, 0); ++ DO_TEST (short_msg, 0); ++ DO_TEST (unsigned_msg, 0); ++ ++ /* ++ * in enforcing mode, we shouldn't be able to load a certificate that isn't ++ * signed by an existing trusted key. ++ * ++ * However, procfs files automatically skip the verification test, so we can't ++ * easily test this. ++ */ ++ ++ /* ++ * verify that testing with 2 trusted certs works ++ */ ++ DO_TEST (hi_signed_2nd, 0); ++ ++ err = (cmd_trust->func) (cmd_trust, 1, trust_args2); ++ ++ grub_test_assert (err == GRUB_ERR_NONE, ++ "loading certificate 2 failed: %d: %s", grub_errno, ++ grub_errmsg); ++ ++ if (err != GRUB_ERR_NONE) ++ return; ++ ++ DO_TEST (hi_signed_2nd, 1); ++ DO_TEST (hi_signed, 1); ++ ++ /* ++ * Check certificate removal. They're added to the _top_ of the list and ++ * removed by position in the list. Current the list looks like [#2, #1]. ++ * ++ * First test removing the second certificate in the list, which is ++ * certificate #1, giving us just [#2]. ++ */ ++ cmd_distrust = grub_command_find ("distrust_certificate"); ++ if (!cmd_distrust) ++ { ++ grub_test_assert (0, "can't find command `%s'", "distrust_certificate"); ++ return; ++ } ++ ++ err = (cmd_distrust->func) (cmd_distrust, 1, distrust2_args); ++ grub_test_assert (err == GRUB_ERR_NONE, ++ "distrusting certificate 1 failed: %d: %s", grub_errno, ++ grub_errmsg); ++ DO_TEST (hi_signed_2nd, 1); ++ DO_TEST (hi_signed, 0); ++ ++ /* ++ * Now reload certificate #1. This will make the list look like [#1, #2] ++ */ ++ err = (cmd_trust->func) (cmd_trust, 1, trust_args); ++ ++ grub_test_assert (err == GRUB_ERR_NONE, ++ "reloading certificate 1 failed: %d: %s", grub_errno, ++ grub_errmsg); ++ DO_TEST (hi_signed, 1); ++ ++ /* Remove the first certificate in the list, giving us just [#2] */ ++ err = (cmd_distrust->func) (cmd_distrust, 1, distrust_args); ++ grub_test_assert (err == GRUB_ERR_NONE, ++ "distrusting certificate 1 (first time) failed: %d: %s", ++ grub_errno, grub_errmsg); ++ DO_TEST (hi_signed_2nd, 1); ++ DO_TEST (hi_signed, 0); ++ ++ /* ++ * Remove the first certificate again, giving an empty list. ++ * ++ * verify_appended should fail if there are no certificates to verify against. ++ */ ++ err = (cmd_distrust->func) (cmd_distrust, 1, distrust_args); ++ grub_test_assert (err == GRUB_ERR_NONE, ++ "distrusting certificate 1 (second time) failed: %d: %s", ++ grub_errno, grub_errmsg); ++ DO_TEST (hi_signed_2nd, 0); ++ ++ /* ++ * Lastly, check a certificate that uses printableString rather than ++ * utf8String loads properly. ++ */ ++ err = (cmd_trust->func) (cmd_trust, 1, trust_args_printable); ++ grub_test_assert (err == GRUB_ERR_NONE, ++ "distrusting printable certificate failed: %d: %s", ++ grub_errno, grub_errmsg); ++ ++ grub_procfs_unregister (&certificate_der_entry); ++ grub_procfs_unregister (&certificate2_der_entry); ++ grub_procfs_unregister (&certificate_printable_der_entry); ++} ++ ++GRUB_FUNCTIONAL_TEST (appended_signature_test, appended_signature_test); +diff --git a/grub-core/tests/lib/functional_test.c b/grub-core/tests/lib/functional_test.c +index 96781fb39b5..403fa5c789a 100644 +--- a/grub-core/tests/lib/functional_test.c ++++ b/grub-core/tests/lib/functional_test.c +@@ -73,6 +73,7 @@ grub_functional_all_tests (grub_extcmd_context_t ctxt __attribute__ ((unused)), + grub_dl_load ("xnu_uuid_test"); + grub_dl_load ("pbkdf2_test"); + grub_dl_load ("signature_test"); ++ grub_dl_load ("appended_signature_test"); + grub_dl_load ("sleep_test"); + grub_dl_load ("bswap_test"); + grub_dl_load ("ctz_test"); +diff --git a/grub-core/tests/appended_signatures.h b/grub-core/tests/appended_signatures.h +new file mode 100644 +index 00000000000..aa3dc6278e3 +--- /dev/null ++++ b/grub-core/tests/appended_signatures.h +@@ -0,0 +1,557 @@ ++unsigned char certificate_der[] = { ++ 0x30, 0x82, 0x03, 0x88, 0x30, 0x82, 0x02, 0x70, 0xa0, 0x03, 0x02, 0x01, ++ 0x02, 0x02, 0x14, 0x25, 0x2e, 0xb8, 0xfd, 0x12, 0x62, 0x2e, 0xcd, 0x5d, ++ 0xa7, 0x53, 0xd2, 0x0b, 0xc2, 0x61, 0x7c, 0x14, 0xe0, 0x0f, 0x5c, 0x30, ++ 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, ++ 0x05, 0x00, 0x30, 0x49, 0x31, 0x28, 0x30, 0x26, 0x06, 0x03, 0x55, 0x04, ++ 0x03, 0x0c, 0x1f, 0x47, 0x72, 0x75, 0x62, 0x20, 0x41, 0x70, 0x70, 0x65, ++ 0x6e, 0x64, 0x65, 0x64, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, ++ 0x72, 0x65, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1d, ++ 0x30, 0x1b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, ++ 0x01, 0x16, 0x0e, 0x64, 0x6a, 0x61, 0x40, 0x61, 0x78, 0x74, 0x65, 0x6e, ++ 0x73, 0x2e, 0x6e, 0x65, 0x74, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x30, 0x30, ++ 0x37, 0x30, 0x39, 0x30, 0x36, 0x32, 0x32, 0x30, 0x37, 0x5a, 0x18, 0x0f, ++ 0x32, 0x31, 0x32, 0x30, 0x30, 0x36, 0x31, 0x35, 0x30, 0x36, 0x32, 0x32, ++ 0x30, 0x37, 0x5a, 0x30, 0x52, 0x31, 0x31, 0x30, 0x2f, 0x06, 0x03, 0x55, ++ 0x04, 0x03, 0x0c, 0x28, 0x47, 0x72, 0x75, 0x62, 0x20, 0x41, 0x70, 0x70, ++ 0x65, 0x6e, 0x64, 0x65, 0x64, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, ++ 0x75, 0x72, 0x65, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x69, 0x67, ++ 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x4b, 0x65, 0x79, 0x31, 0x1d, 0x30, 0x1b, ++ 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, ++ 0x0e, 0x64, 0x6a, 0x61, 0x40, 0x61, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x2e, ++ 0x6e, 0x65, 0x74, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, ++ 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, ++ 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, ++ 0xcd, 0xe8, 0x1c, 0x08, 0x68, 0x2e, 0xcb, 0xfe, 0x8c, 0x4b, 0x3b, 0x61, ++ 0xe7, 0x8e, 0x80, 0x58, 0x85, 0x85, 0xea, 0xc8, 0x3b, 0x42, 0xba, 0x72, ++ 0x84, 0x65, 0x20, 0xbc, 0x48, 0xa2, 0x25, 0x49, 0x6e, 0x1c, 0xb9, 0x7d, ++ 0xeb, 0xc1, 0x0c, 0xa8, 0xb7, 0xcc, 0x13, 0x78, 0xba, 0x11, 0xa4, 0x98, ++ 0xd7, 0xd0, 0x7c, 0xdd, 0xf5, 0x5a, 0xb7, 0xcd, 0x31, 0x0e, 0xcd, 0x9e, ++ 0xa7, 0x19, 0xf0, 0xbd, 0x0f, 0xa6, 0xfe, 0x8a, 0x11, 0x97, 0xed, 0x8b, ++ 0xe5, 0x16, 0xa6, 0x21, 0x13, 0x36, 0xad, 0x05, 0x49, 0xec, 0x29, 0x12, ++ 0x38, 0xa7, 0x4b, 0x0f, 0xa1, 0xfb, 0x72, 0xc0, 0xc0, 0x09, 0x67, 0x78, ++ 0xa8, 0xb6, 0xd6, 0x1a, 0x39, 0xc0, 0xa8, 0xbf, 0x5f, 0x14, 0x89, 0x5c, ++ 0xbc, 0x41, 0x0c, 0x0c, 0x5d, 0x42, 0x2e, 0x1c, 0xdf, 0x1f, 0x1d, 0xc9, ++ 0x43, 0x94, 0x5b, 0x6e, 0x8f, 0x15, 0x8c, 0x8f, 0x94, 0x73, 0x4f, 0x97, ++ 0x54, 0xf1, 0x86, 0x8a, 0xbc, 0xe4, 0xe4, 0x93, 0xc1, 0x5e, 0xc2, 0x3e, ++ 0x31, 0x5e, 0xd4, 0x85, 0x57, 0x14, 0xd0, 0x11, 0x07, 0x65, 0xf4, 0x7c, ++ 0x8f, 0x07, 0x57, 0xe1, 0x22, 0xd4, 0x78, 0x47, 0x65, 0x4e, 0xa9, 0xb3, ++ 0xaa, 0xce, 0xc7, 0x36, 0xfe, 0xda, 0x66, 0x02, 0xb6, 0x8d, 0x18, 0x2f, ++ 0x3b, 0x41, 0x8d, 0x02, 0x08, 0x72, 0x4b, 0x69, 0xbd, 0x1e, 0x58, 0xfc, ++ 0x1b, 0x64, 0x04, 0x52, 0x35, 0x35, 0xe2, 0x3d, 0x3e, 0xde, 0xd6, 0x64, ++ 0xf4, 0xec, 0x57, 0x7e, 0x65, 0x59, 0x00, 0xa6, 0xd3, 0x4b, 0x09, 0x93, ++ 0x2a, 0x95, 0x0f, 0x30, 0xb6, 0xa1, 0x8c, 0xe7, 0x8b, 0x49, 0xa4, 0x1d, ++ 0x25, 0x2d, 0x65, 0x48, 0x8a, 0x0f, 0xcf, 0x2a, 0xa2, 0xe1, 0xef, 0x72, ++ 0x92, 0xc3, 0xf5, 0x21, 0x37, 0x83, 0x9b, 0x6d, 0x0b, 0x1b, 0xb3, 0xa2, ++ 0x32, 0x38, 0x11, 0xb1, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x5d, 0x30, ++ 0x5b, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, ++ 0x02, 0x30, 0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, ++ 0x03, 0x02, 0x07, 0x80, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, ++ 0x16, 0x04, 0x14, 0xe5, 0x2a, 0x4f, 0xf2, 0x84, 0x91, 0x57, 0x91, 0xaf, ++ 0x12, 0xd2, 0xf1, 0xa1, 0x87, 0x73, 0x0f, 0x90, 0x25, 0xa0, 0x7a, 0x30, ++ 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, ++ 0x56, 0xd1, 0xfd, 0xe2, 0x1e, 0x7e, 0x1c, 0x63, 0x4f, 0x47, 0xdb, 0xe4, ++ 0xc4, 0x51, 0x04, 0x03, 0x9a, 0x48, 0x35, 0x6e, 0x30, 0x0d, 0x06, 0x09, ++ 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, ++ 0x82, 0x01, 0x01, 0x00, 0x65, 0x82, 0xd5, 0x88, 0x30, 0xe2, 0x2c, 0x47, ++ 0xf3, 0x31, 0x39, 0xa1, 0x75, 0x9a, 0xb0, 0x8a, 0x6c, 0x4b, 0xac, 0xdf, ++ 0x09, 0x7b, 0x90, 0xb6, 0x9e, 0x76, 0x62, 0x94, 0xc1, 0x3a, 0x99, 0x49, ++ 0x68, 0x29, 0x47, 0x42, 0xc3, 0x06, 0xcb, 0x88, 0x75, 0xe6, 0x79, 0x13, ++ 0x8c, 0x4b, 0x49, 0x6a, 0xb5, 0x56, 0x95, 0xc0, 0x42, 0x21, 0x9b, 0xd4, ++ 0x61, 0xd0, 0x02, 0x41, 0xdd, 0x20, 0x61, 0xe5, 0x91, 0xdf, 0x75, 0x00, ++ 0x25, 0x0e, 0x99, 0x65, 0x5c, 0x54, 0x49, 0x32, 0xa3, 0xe2, 0xcd, 0xa1, ++ 0x5f, 0x40, 0xf3, 0xc5, 0x81, 0xd9, 0x3c, 0xa3, 0x63, 0x5a, 0x38, 0x79, ++ 0xab, 0x77, 0x98, 0xde, 0x8f, 0x4e, 0x9e, 0x26, 0xbc, 0x4e, 0x80, 0x9e, ++ 0x8f, 0xbe, 0xf1, 0x00, 0xb3, 0x78, 0xb9, 0x4b, 0x1d, 0xc7, 0xa4, 0x83, ++ 0x59, 0x56, 0x11, 0xd1, 0x11, 0x1e, 0x50, 0x39, 0xd5, 0x78, 0x14, 0xf3, ++ 0xb9, 0x1d, 0xda, 0xe4, 0xc4, 0x63, 0x74, 0x26, 0xab, 0xa3, 0xfd, 0x9d, ++ 0x58, 0xa2, 0xee, 0x7b, 0x28, 0x34, 0xa3, 0xbe, 0x85, 0x7e, 0xaa, 0x97, ++ 0xb7, 0x5b, 0x9d, 0xa9, 0x4d, 0x96, 0xdb, 0x6b, 0x21, 0xe1, 0x96, 0x5d, ++ 0xc7, 0xad, 0x23, 0x03, 0x9a, 0x16, 0xdb, 0xa4, 0x1f, 0x63, 0xef, 0xaf, ++ 0x1e, 0x4f, 0xf8, 0x27, 0xdc, 0x4b, 0xfc, 0x2b, 0x68, 0x2e, 0xa0, 0xd3, ++ 0xae, 0xf2, 0xce, 0xf5, 0xfc, 0x97, 0x92, 0xd2, 0x29, 0x0f, 0x4f, 0x4b, ++ 0x29, 0xeb, 0x06, 0xcb, 0xf8, 0x21, 0x6e, 0xbc, 0x8b, 0x5c, 0xc5, 0xc9, ++ 0xf7, 0xe2, 0x7c, 0x47, 0xcd, 0x43, 0x98, 0xc4, 0xa3, 0x9a, 0xd7, 0x3e, ++ 0xdc, 0x01, 0x13, 0x28, 0x96, 0xc4, 0x60, 0x83, 0xe2, 0x79, 0xa1, 0x46, ++ 0xef, 0xf5, 0xa4, 0x7b, 0x00, 0xe3, 0x3d, 0x7d, 0xbc, 0xa8, 0x98, 0x49, ++ 0xa8, 0xcf, 0x3b, 0x41, 0xb6, 0x09, 0x97, 0x07 ++}; ++unsigned int certificate_der_len = 908; ++ ++unsigned char hi_signed[] = { ++ 0x68, 0x69, 0x0a, 0x30, 0x82, 0x01, 0xc0, 0x06, 0x09, 0x2a, 0x86, 0x48, ++ 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 0x82, 0x01, 0xb1, 0x30, 0x82, ++ 0x01, 0xad, 0x02, 0x01, 0x01, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x09, 0x60, ++ 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x30, 0x0b, 0x06, 0x09, ++ 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0x31, 0x82, 0x01, ++ 0x8a, 0x30, 0x82, 0x01, 0x86, 0x02, 0x01, 0x01, 0x30, 0x61, 0x30, 0x49, ++ 0x31, 0x28, 0x30, 0x26, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x1f, 0x47, ++ 0x72, 0x75, 0x62, 0x20, 0x41, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x64, ++ 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, ++ 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1d, 0x30, 0x1b, 0x06, 0x09, ++ 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x0e, 0x64, ++ 0x6a, 0x61, 0x40, 0x61, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x2e, 0x6e, 0x65, ++ 0x74, 0x02, 0x14, 0x25, 0x2e, 0xb8, 0xfd, 0x12, 0x62, 0x2e, 0xcd, 0x5d, ++ 0xa7, 0x53, 0xd2, 0x0b, 0xc2, 0x61, 0x7c, 0x14, 0xe0, 0x0f, 0x5c, 0x30, ++ 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, ++ 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, ++ 0x01, 0x05, 0x00, 0x04, 0x82, 0x01, 0x00, 0xc7, 0x69, 0x35, 0x21, 0x66, ++ 0x4d, 0x50, 0xd4, 0x73, 0xde, 0xbd, 0x3a, 0xf6, 0x45, 0xe3, 0xe4, 0xd0, ++ 0xb6, 0xa1, 0xe7, 0xc0, 0xa2, 0xc9, 0xf4, 0xf0, 0x05, 0x8c, 0xa4, 0x16, ++ 0x9e, 0x81, 0x0d, 0x21, 0x68, 0xf3, 0xfe, 0x03, 0x96, 0x77, 0x31, 0x69, ++ 0x01, 0xd8, 0x26, 0xd9, 0x48, 0x95, 0xcf, 0xd1, 0x17, 0xb1, 0x0b, 0x6b, ++ 0x2c, 0xf1, 0xb0, 0xab, 0x65, 0x65, 0x56, 0xf8, 0x0c, 0xa7, 0xf7, 0xbb, ++ 0xf6, 0x5a, 0x55, 0x98, 0x14, 0x07, 0x8d, 0x2a, 0xbc, 0x16, 0x48, 0x94, ++ 0xab, 0x2f, 0x85, 0x97, 0x90, 0x51, 0x78, 0xa0, 0xda, 0x60, 0xb5, 0x41, ++ 0x4b, 0xe8, 0x78, 0xc5, 0xa6, 0x04, 0x9d, 0x54, 0x2a, 0x85, 0xfd, 0x86, ++ 0x0b, 0x6d, 0xc2, 0xd2, 0xad, 0x07, 0xff, 0x16, 0x42, 0x82, 0xe3, 0x5c, ++ 0xaa, 0x22, 0x59, 0x78, 0x92, 0xea, 0x94, 0xc3, 0x41, 0xb7, 0xa1, 0x86, ++ 0x44, 0xea, 0xd1, 0xdb, 0xe5, 0xac, 0x30, 0x32, 0xfb, 0x7d, 0x3f, 0xf7, ++ 0x8b, 0x11, 0x7f, 0x80, 0x3b, 0xe5, 0xc7, 0x82, 0x0f, 0x92, 0x07, 0x14, ++ 0x66, 0x01, 0x6e, 0x85, 0xab, 0x3a, 0x14, 0xcf, 0x76, 0xd1, 0x7e, 0x14, ++ 0x85, 0xca, 0x01, 0x73, 0x72, 0x38, 0xdc, 0xde, 0x30, 0x5c, 0xfb, 0xc0, ++ 0x3d, 0x93, 0xef, 0x9c, 0xbc, 0xf8, 0xcc, 0xd2, 0xbf, 0x47, 0xec, 0xf8, ++ 0x88, 0x9b, 0xe1, 0x43, 0xbe, 0xa7, 0x47, 0x96, 0xb6, 0x5d, 0x46, 0x0e, ++ 0x7a, 0x78, 0x38, 0x19, 0xbc, 0xb5, 0xbc, 0x9b, 0x3c, 0x39, 0x92, 0x70, ++ 0x0d, 0x9d, 0x8a, 0x35, 0xaf, 0xb4, 0x9e, 0xf4, 0xef, 0xc1, 0xb8, 0x25, ++ 0xd0, 0x14, 0x91, 0xd6, 0xc2, 0xb6, 0xc7, 0x3c, 0x72, 0x91, 0x0f, 0xad, ++ 0xde, 0xb2, 0x36, 0xf8, 0x4e, 0x59, 0xd4, 0xa4, 0x21, 0x9f, 0x03, 0x95, ++ 0x48, 0x01, 0xb4, 0x05, 0xc3, 0x39, 0x60, 0x51, 0x08, 0xd0, 0xbe, 0x00, ++ 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc4, 0x7e, ++ 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x20, 0x73, 0x69, 0x67, 0x6e, 0x61, ++ 0x74, 0x75, 0x72, 0x65, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x65, ++ 0x64, 0x7e, 0x0a ++}; ++unsigned int hi_signed_len = 495; ++ ++unsigned char hj_signed[] = { ++ 0x68, 0x6a, 0x0a, 0x30, 0x82, 0x01, 0xc0, 0x06, 0x09, 0x2a, 0x86, 0x48, ++ 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 0x82, 0x01, 0xb1, 0x30, 0x82, ++ 0x01, 0xad, 0x02, 0x01, 0x01, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x09, 0x60, ++ 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x30, 0x0b, 0x06, 0x09, ++ 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0x31, 0x82, 0x01, ++ 0x8a, 0x30, 0x82, 0x01, 0x86, 0x02, 0x01, 0x01, 0x30, 0x61, 0x30, 0x49, ++ 0x31, 0x28, 0x30, 0x26, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x1f, 0x47, ++ 0x72, 0x75, 0x62, 0x20, 0x41, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x64, ++ 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, ++ 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1d, 0x30, 0x1b, 0x06, 0x09, ++ 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x0e, 0x64, ++ 0x6a, 0x61, 0x40, 0x61, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x2e, 0x6e, 0x65, ++ 0x74, 0x02, 0x14, 0x25, 0x2e, 0xb8, 0xfd, 0x12, 0x62, 0x2e, 0xcd, 0x5d, ++ 0xa7, 0x53, 0xd2, 0x0b, 0xc2, 0x61, 0x7c, 0x14, 0xe0, 0x0f, 0x5c, 0x30, ++ 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, ++ 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, ++ 0x01, 0x05, 0x00, 0x04, 0x82, 0x01, 0x00, 0xc7, 0x69, 0x35, 0x21, 0x66, ++ 0x4d, 0x50, 0xd4, 0x73, 0xde, 0xbd, 0x3a, 0xf6, 0x45, 0xe3, 0xe4, 0xd0, ++ 0xb6, 0xa1, 0xe7, 0xc0, 0xa2, 0xc9, 0xf4, 0xf0, 0x05, 0x8c, 0xa4, 0x16, ++ 0x9e, 0x81, 0x0d, 0x21, 0x68, 0xf3, 0xfe, 0x03, 0x96, 0x77, 0x31, 0x69, ++ 0x01, 0xd8, 0x26, 0xd9, 0x48, 0x95, 0xcf, 0xd1, 0x17, 0xb1, 0x0b, 0x6b, ++ 0x2c, 0xf1, 0xb0, 0xab, 0x65, 0x65, 0x56, 0xf8, 0x0c, 0xa7, 0xf7, 0xbb, ++ 0xf6, 0x5a, 0x55, 0x98, 0x14, 0x07, 0x8d, 0x2a, 0xbc, 0x16, 0x48, 0x94, ++ 0xab, 0x2f, 0x85, 0x97, 0x90, 0x51, 0x78, 0xa0, 0xda, 0x60, 0xb5, 0x41, ++ 0x4b, 0xe8, 0x78, 0xc5, 0xa6, 0x04, 0x9d, 0x54, 0x2a, 0x85, 0xfd, 0x86, ++ 0x0b, 0x6d, 0xc2, 0xd2, 0xad, 0x07, 0xff, 0x16, 0x42, 0x82, 0xe3, 0x5c, ++ 0xaa, 0x22, 0x59, 0x78, 0x92, 0xea, 0x94, 0xc3, 0x41, 0xb7, 0xa1, 0x86, ++ 0x44, 0xea, 0xd1, 0xdb, 0xe5, 0xac, 0x30, 0x32, 0xfb, 0x7d, 0x3f, 0xf7, ++ 0x8b, 0x11, 0x7f, 0x80, 0x3b, 0xe5, 0xc7, 0x82, 0x0f, 0x92, 0x07, 0x14, ++ 0x66, 0x01, 0x6e, 0x85, 0xab, 0x3a, 0x14, 0xcf, 0x76, 0xd1, 0x7e, 0x14, ++ 0x85, 0xca, 0x01, 0x73, 0x72, 0x38, 0xdc, 0xde, 0x30, 0x5c, 0xfb, 0xc0, ++ 0x3d, 0x93, 0xef, 0x9c, 0xbc, 0xf8, 0xcc, 0xd2, 0xbf, 0x47, 0xec, 0xf8, ++ 0x88, 0x9b, 0xe1, 0x43, 0xbe, 0xa7, 0x47, 0x96, 0xb6, 0x5d, 0x46, 0x0e, ++ 0x7a, 0x78, 0x38, 0x19, 0xbc, 0xb5, 0xbc, 0x9b, 0x3c, 0x39, 0x92, 0x70, ++ 0x0d, 0x9d, 0x8a, 0x35, 0xaf, 0xb4, 0x9e, 0xf4, 0xef, 0xc1, 0xb8, 0x25, ++ 0xd0, 0x14, 0x91, 0xd6, 0xc2, 0xb6, 0xc7, 0x3c, 0x72, 0x91, 0x0f, 0xad, ++ 0xde, 0xb2, 0x36, 0xf8, 0x4e, 0x59, 0xd4, 0xa4, 0x21, 0x9f, 0x03, 0x95, ++ 0x48, 0x01, 0xb4, 0x05, 0xc3, 0x39, 0x60, 0x51, 0x08, 0xd0, 0xbe, 0x00, ++ 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc4, 0x7e, ++ 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x20, 0x73, 0x69, 0x67, 0x6e, 0x61, ++ 0x74, 0x75, 0x72, 0x65, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x65, ++ 0x64, 0x7e, 0x0a ++}; ++unsigned int hj_signed_len = 495; ++ ++unsigned char hi_signed_sha256[] = { ++ 0x68, 0x69, 0x0a, 0x30, 0x82, 0x01, 0xc0, 0x06, 0x09, 0x2a, 0x86, 0x48, ++ 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 0x82, 0x01, 0xb1, 0x30, 0x82, ++ 0x01, 0xad, 0x02, 0x01, 0x01, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x09, 0x60, ++ 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x30, 0x0b, 0x06, 0x09, ++ 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0x31, 0x82, 0x01, ++ 0x8a, 0x30, 0x82, 0x01, 0x86, 0x02, 0x01, 0x01, 0x30, 0x61, 0x30, 0x49, ++ 0x31, 0x28, 0x30, 0x26, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x1f, 0x47, ++ 0x72, 0x75, 0x62, 0x20, 0x41, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x64, ++ 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, ++ 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1d, 0x30, 0x1b, 0x06, 0x09, ++ 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x0e, 0x64, ++ 0x6a, 0x61, 0x40, 0x61, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x2e, 0x6e, 0x65, ++ 0x74, 0x02, 0x14, 0x25, 0x2e, 0xb8, 0xfd, 0x12, 0x62, 0x2e, 0xcd, 0x5d, ++ 0xa7, 0x53, 0xd2, 0x0b, 0xc2, 0x61, 0x7c, 0x14, 0xe0, 0x0f, 0x5c, 0x30, ++ 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, ++ 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, ++ 0x01, 0x05, 0x00, 0x04, 0x82, 0x01, 0x00, 0x7b, 0x5e, 0x82, 0x1d, 0x21, ++ 0xb6, 0x40, 0xd3, 0x33, 0x79, 0xa7, 0x52, 0x2b, 0xfc, 0x46, 0x51, 0x26, ++ 0xfe, 0x0f, 0x81, 0x90, 0x81, 0xab, 0x57, 0x5e, 0xf6, 0x45, 0x41, 0xa3, ++ 0x7b, 0x48, 0xdd, 0xd6, 0x59, 0x60, 0x51, 0x31, 0x14, 0x14, 0x7b, 0xb4, ++ 0x55, 0x7b, 0x4d, 0xfe, 0x09, 0x7a, 0x5d, 0xae, 0xc4, 0x58, 0x50, 0x80, ++ 0x75, 0xf2, 0x23, 0x20, 0x62, 0xe3, 0x7c, 0x26, 0x1d, 0x2a, 0x4d, 0x9f, ++ 0x89, 0xf0, 0x4f, 0x95, 0x8a, 0x80, 0x6e, 0x1a, 0xea, 0x87, 0xdb, 0x1f, ++ 0xf3, 0xda, 0x04, 0x91, 0x37, 0xea, 0x0a, 0xfb, 0x6c, 0xc9, 0x3d, 0x73, ++ 0xf9, 0x58, 0x7c, 0x15, 0x6b, 0xa2, 0x52, 0x5a, 0x97, 0xff, 0xd6, 0xb0, ++ 0xf1, 0xbf, 0xa5, 0x04, 0x6d, 0x91, 0xc1, 0x54, 0x05, 0xdc, 0x7f, 0x5d, ++ 0x19, 0xaf, 0x55, 0xec, 0x51, 0xfb, 0x66, 0x0a, 0xa4, 0x4e, 0x96, 0x47, ++ 0x43, 0x54, 0x7c, 0x64, 0xa8, 0xaa, 0xb4, 0x90, 0x02, 0xf3, 0xa7, 0x0b, ++ 0xb7, 0xbf, 0x06, 0xdb, 0x5e, 0x9c, 0x32, 0x6d, 0x45, 0x14, 0x1c, 0xaf, ++ 0x46, 0x30, 0x08, 0x55, 0x49, 0x78, 0xfa, 0x57, 0xda, 0x3d, 0xf5, 0xa0, ++ 0xef, 0x11, 0x0a, 0x81, 0x0d, 0x82, 0xcd, 0xaf, 0xdb, 0xda, 0x0e, 0x1a, ++ 0x44, 0xd1, 0xee, 0xc4, 0xb8, 0xde, 0x97, 0xb4, 0xda, 0xb4, 0x8b, 0x4f, ++ 0x58, 0x24, 0x59, 0xc0, 0xe0, 0x08, 0x97, 0x14, 0x68, 0xbe, 0x31, 0x09, ++ 0x5e, 0x67, 0x45, 0xf0, 0xcb, 0x81, 0x4f, 0x17, 0x44, 0x61, 0xe0, 0xe2, ++ 0xf0, 0xfc, 0x1e, 0xb9, 0x73, 0xaf, 0x42, 0xff, 0x33, 0xde, 0x61, 0x6b, ++ 0x7f, 0xc2, 0x69, 0x0d, 0x66, 0x54, 0xae, 0xf6, 0xde, 0x20, 0x47, 0x44, ++ 0x9b, 0x73, 0xd1, 0x07, 0x6e, 0x77, 0x37, 0x0a, 0xbb, 0x7f, 0xa0, 0x93, ++ 0x2d, 0x8d, 0x44, 0xba, 0xe2, 0xdd, 0x34, 0x32, 0xd7, 0x56, 0x71, 0x00, ++ 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc4, 0x7e, ++ 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x20, 0x73, 0x69, 0x67, 0x6e, 0x61, ++ 0x74, 0x75, 0x72, 0x65, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x65, ++ 0x64, 0x7e, 0x0a ++}; ++unsigned int hi_signed_sha256_len = 495; ++ ++unsigned char short_msg[] = { ++ 0x68, 0x69, 0x0a ++}; ++unsigned int short_msg_len = 3; ++ ++unsigned char unsigned_msg[] = { ++ 0x53, 0x65, 0x64, 0x20, 0x75, 0x74, 0x20, 0x70, 0x65, 0x72, 0x73, 0x70, ++ 0x69, 0x63, 0x69, 0x61, 0x74, 0x69, 0x73, 0x20, 0x75, 0x6e, 0x64, 0x65, ++ 0x20, 0x6f, 0x6d, 0x6e, 0x69, 0x73, 0x20, 0x69, 0x73, 0x74, 0x65, 0x20, ++ 0x6e, 0x61, 0x74, 0x75, 0x73, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, ++ 0x73, 0x69, 0x74, 0x20, 0x76, 0x6f, 0x6c, 0x75, 0x70, 0x74, 0x61, 0x74, ++ 0x65, 0x6d, 0x20, 0x61, 0x63, 0x63, 0x75, 0x73, 0x61, 0x6e, 0x74, 0x69, ++ 0x75, 0x6d, 0x20, 0x64, 0x6f, 0x6c, 0x6f, 0x72, 0x65, 0x6d, 0x71, 0x75, ++ 0x65, 0x20, 0x6c, 0x61, 0x75, 0x64, 0x61, 0x6e, 0x74, 0x69, 0x75, 0x6d, ++ 0x2c, 0x20, 0x74, 0x6f, 0x74, 0x61, 0x6d, 0x20, 0x72, 0x65, 0x6d, 0x20, ++ 0x61, 0x70, 0x65, 0x72, 0x69, 0x61, 0x6d, 0x2c, 0x20, 0x65, 0x61, 0x71, ++ 0x75, 0x65, 0x20, 0x69, 0x70, 0x73, 0x61, 0x20, 0x71, 0x75, 0x61, 0x65, ++ 0x20, 0x61, 0x62, 0x20, 0x69, 0x6c, 0x6c, 0x6f, 0x20, 0x69, 0x6e, 0x76, ++ 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x65, 0x20, 0x76, 0x65, 0x72, 0x69, 0x74, ++ 0x61, 0x74, 0x69, 0x73, 0x20, 0x65, 0x74, 0x20, 0x71, 0x75, 0x61, 0x73, ++ 0x69, 0x20, 0x61, 0x72, 0x63, 0x68, 0x69, 0x74, 0x65, 0x63, 0x74, 0x6f, ++ 0x20, 0x62, 0x65, 0x61, 0x74, 0x61, 0x65, 0x20, 0x76, 0x69, 0x74, 0x61, ++ 0x65, 0x20, 0x64, 0x69, 0x63, 0x74, 0x61, 0x20, 0x73, 0x75, 0x6e, 0x74, ++ 0x20, 0x65, 0x78, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x62, 0x6f, 0x2e, 0x20, ++ 0x4e, 0x65, 0x6d, 0x6f, 0x20, 0x65, 0x6e, 0x69, 0x6d, 0x20, 0x69, 0x70, ++ 0x73, 0x61, 0x6d, 0x20, 0x76, 0x6f, 0x6c, 0x75, 0x70, 0x74, 0x61, 0x74, ++ 0x65, 0x6d, 0x20, 0x71, 0x75, 0x69, 0x61, 0x20, 0x76, 0x6f, 0x6c, 0x75, ++ 0x70, 0x74, 0x61, 0x73, 0x20, 0x73, 0x69, 0x74, 0x20, 0x61, 0x73, 0x70, ++ 0x65, 0x72, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x20, 0x61, 0x75, 0x74, 0x20, ++ 0x6f, 0x64, 0x69, 0x74, 0x20, 0x61, 0x75, 0x74, 0x20, 0x66, 0x75, 0x67, ++ 0x69, 0x74, 0x2c, 0x20, 0x73, 0x65, 0x64, 0x20, 0x71, 0x75, 0x69, 0x61, ++ 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x71, 0x75, 0x75, 0x6e, 0x74, 0x75, ++ 0x72, 0x20, 0x6d, 0x61, 0x67, 0x6e, 0x69, 0x20, 0x64, 0x6f, 0x6c, 0x6f, ++ 0x72, 0x65, 0x73, 0x20, 0x65, 0x6f, 0x73, 0x20, 0x71, 0x75, 0x69, 0x20, ++ 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x65, 0x20, 0x76, 0x6f, 0x6c, 0x75, ++ 0x70, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x20, 0x73, 0x65, 0x71, 0x75, 0x69, ++ 0x20, 0x6e, 0x65, 0x73, 0x63, 0x69, 0x75, 0x6e, 0x74, 0x2e, 0x20, 0x4e, ++ 0x65, 0x71, 0x75, 0x65, 0x20, 0x70, 0x6f, 0x72, 0x72, 0x6f, 0x20, 0x71, ++ 0x75, 0x69, 0x73, 0x71, 0x75, 0x61, 0x6d, 0x20, 0x65, 0x73, 0x74, 0x2c, ++ 0x20, 0x71, 0x75, 0x69, 0x20, 0x64, 0x6f, 0x6c, 0x6f, 0x72, 0x65, 0x6d, ++ 0x20, 0x69, 0x70, 0x73, 0x75, 0x6d, 0x20, 0x71, 0x75, 0x69, 0x61, 0x20, ++ 0x64, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x73, 0x69, 0x74, 0x20, 0x61, 0x6d, ++ 0x65, 0x74, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x63, 0x74, 0x65, ++ 0x74, 0x75, 0x72, 0x2c, 0x20, 0x61, 0x64, 0x69, 0x70, 0x69, 0x73, 0x63, ++ 0x69, 0x20, 0x76, 0x65, 0x6c, 0x69, 0x74, 0x2c, 0x20, 0x73, 0x65, 0x64, ++ 0x20, 0x71, 0x75, 0x69, 0x61, 0x20, 0x6e, 0x6f, 0x6e, 0x20, 0x6e, 0x75, ++ 0x6d, 0x71, 0x75, 0x61, 0x6d, 0x20, 0x65, 0x69, 0x75, 0x73, 0x20, 0x6d, ++ 0x6f, 0x64, 0x69, 0x20, 0x74, 0x65, 0x6d, 0x70, 0x6f, 0x72, 0x61, 0x20, ++ 0x69, 0x6e, 0x63, 0x69, 0x64, 0x75, 0x6e, 0x74, 0x20, 0x75, 0x74, 0x20, ++ 0x6c, 0x61, 0x62, 0x6f, 0x72, 0x65, 0x20, 0x65, 0x74, 0x20, 0x64, 0x6f, ++ 0x6c, 0x6f, 0x72, 0x65, 0x20, 0x6d, 0x61, 0x67, 0x6e, 0x61, 0x6d, 0x20, ++ 0x61, 0x6c, 0x69, 0x71, 0x75, 0x61, 0x6d, 0x20, 0x71, 0x75, 0x61, 0x65, ++ 0x72, 0x61, 0x74, 0x20, 0x76, 0x6f, 0x6c, 0x75, 0x70, 0x74, 0x61, 0x74, ++ 0x65, 0x6d, 0x2e, 0x20, 0x55, 0x74, 0x20, 0x65, 0x6e, 0x69, 0x6d, 0x20, ++ 0x61, 0x64, 0x20, 0x6d, 0x69, 0x6e, 0x69, 0x6d, 0x61, 0x20, 0x76, 0x65, ++ 0x6e, 0x69, 0x61, 0x6d, 0x2c, 0x20, 0x71, 0x75, 0x69, 0x73, 0x20, 0x6e, ++ 0x6f, 0x73, 0x74, 0x72, 0x75, 0x6d, 0x20, 0x65, 0x78, 0x65, 0x72, 0x63, ++ 0x69, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x65, 0x6d, 0x20, 0x75, 0x6c, ++ 0x6c, 0x61, 0x6d, 0x20, 0x63, 0x6f, 0x72, 0x70, 0x6f, 0x72, 0x69, 0x73, ++ 0x20, 0x73, 0x75, 0x73, 0x63, 0x69, 0x70, 0x69, 0x74, 0x20, 0x6c, 0x61, ++ 0x62, 0x6f, 0x72, 0x69, 0x6f, 0x73, 0x61, 0x6d, 0x2c, 0x20, 0x6e, 0x69, ++ 0x73, 0x69, 0x20, 0x75, 0x74, 0x20, 0x61, 0x6c, 0x69, 0x71, 0x75, 0x69, ++ 0x64, 0x20, 0x65, 0x78, 0x20, 0x65, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x6d, ++ 0x6f, 0x64, 0x69, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x71, 0x75, 0x61, ++ 0x74, 0x75, 0x72, 0x3f, 0x20, 0x51, 0x75, 0x69, 0x73, 0x20, 0x61, 0x75, ++ 0x74, 0x65, 0x6d, 0x20, 0x76, 0x65, 0x6c, 0x20, 0x65, 0x75, 0x6d, 0x20, ++ 0x69, 0x75, 0x72, 0x65, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x68, 0x65, ++ 0x6e, 0x64, 0x65, 0x72, 0x69, 0x74, 0x20, 0x71, 0x75, 0x69, 0x20, 0x69, ++ 0x6e, 0x20, 0x65, 0x61, 0x20, 0x76, 0x6f, 0x6c, 0x75, 0x70, 0x74, 0x61, ++ 0x74, 0x65, 0x20, 0x76, 0x65, 0x6c, 0x69, 0x74, 0x20, 0x65, 0x73, 0x73, ++ 0x65, 0x20, 0x71, 0x75, 0x61, 0x6d, 0x20, 0x6e, 0x69, 0x68, 0x69, 0x6c, ++ 0x20, 0x6d, 0x6f, 0x6c, 0x65, 0x73, 0x74, 0x69, 0x61, 0x65, 0x20, 0x63, ++ 0x6f, 0x6e, 0x73, 0x65, 0x71, 0x75, 0x61, 0x74, 0x75, 0x72, 0x2c, 0x20, ++ 0x76, 0x65, 0x6c, 0x20, 0x69, 0x6c, 0x6c, 0x75, 0x6d, 0x20, 0x71, 0x75, ++ 0x69, 0x20, 0x64, 0x6f, 0x6c, 0x6f, 0x72, 0x65, 0x6d, 0x20, 0x65, 0x75, ++ 0x6d, 0x20, 0x66, 0x75, 0x67, 0x69, 0x61, 0x74, 0x20, 0x71, 0x75, 0x6f, ++ 0x20, 0x76, 0x6f, 0x6c, 0x75, 0x70, 0x74, 0x61, 0x73, 0x20, 0x6e, 0x75, ++ 0x6c, 0x6c, 0x61, 0x20, 0x70, 0x61, 0x72, 0x69, 0x61, 0x74, 0x75, 0x72, ++ 0x3f, 0x0a ++}; ++unsigned int unsigned_msg_len = 866; ++ ++unsigned char certificate2_der[] = { ++ 0x30, 0x82, 0x05, 0x52, 0x30, 0x82, 0x03, 0x3a, 0xa0, 0x03, 0x02, 0x01, ++ 0x02, 0x02, 0x14, 0x5b, 0x5e, 0x59, 0xf2, 0x5f, 0x75, 0x4c, 0x8e, 0xc5, ++ 0x3a, 0x91, 0x07, 0xe9, 0xe7, 0x6d, 0x3c, 0xd0, 0x7f, 0x91, 0xff, 0x30, ++ 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, ++ 0x05, 0x00, 0x30, 0x3a, 0x31, 0x38, 0x30, 0x36, 0x06, 0x03, 0x55, 0x04, ++ 0x03, 0x0c, 0x2f, 0x47, 0x72, 0x75, 0x62, 0x20, 0x32, 0x6e, 0x64, 0x20, ++ 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x20, ++ 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, ++ 0x63, 0x61, 0x74, 0x65, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, ++ 0x74, 0x79, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x30, 0x30, 0x37, 0x32, 0x38, ++ 0x31, 0x33, 0x32, 0x34, 0x32, 0x39, 0x5a, 0x18, 0x0f, 0x32, 0x31, 0x32, ++ 0x30, 0x30, 0x37, 0x30, 0x34, 0x31, 0x33, 0x32, 0x34, 0x32, 0x39, 0x5a, ++ 0x30, 0x2b, 0x31, 0x29, 0x30, 0x27, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, ++ 0x20, 0x47, 0x72, 0x75, 0x62, 0x20, 0x32, 0x6e, 0x64, 0x20, 0x43, 0x65, ++ 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x20, 0x53, 0x69, ++ 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x4b, 0x65, 0x79, 0x30, 0x82, 0x02, ++ 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, ++ 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x02, 0x0f, 0x00, 0x30, 0x82, 0x02, ++ 0x0a, 0x02, 0x82, 0x02, 0x01, 0x00, 0xb0, 0x2f, 0x50, 0x01, 0x9c, 0x0e, ++ 0xd6, 0x8c, 0x07, 0xca, 0xc1, 0xcf, 0xbc, 0x03, 0xdd, 0xd3, 0xfa, 0xe3, ++ 0x4f, 0x71, 0xc1, 0x30, 0xaa, 0x09, 0x96, 0xe4, 0xd0, 0x6c, 0x42, 0x93, ++ 0xdb, 0x35, 0xf6, 0x7e, 0x1b, 0x67, 0xc0, 0xc2, 0x2d, 0x5b, 0xec, 0xca, ++ 0x35, 0x06, 0x32, 0x6c, 0x7b, 0x2c, 0xd3, 0x71, 0x2b, 0xe9, 0x7a, 0x19, ++ 0xd1, 0xf2, 0xa0, 0x7f, 0xd7, 0x4d, 0x6e, 0x28, 0xbb, 0xae, 0x49, 0x4a, ++ 0xbc, 0xea, 0x47, 0x67, 0xb8, 0x36, 0xa6, 0xf5, 0x0d, 0x0e, 0x20, 0x14, ++ 0x0c, 0x66, 0x67, 0x28, 0xb5, 0x97, 0x8b, 0x1f, 0x5e, 0x32, 0x06, 0x29, ++ 0x9c, 0x99, 0x92, 0x0f, 0x73, 0xac, 0xfd, 0xd2, 0x1d, 0xf2, 0xa8, 0x55, ++ 0x9d, 0x1b, 0xd8, 0x3d, 0xb0, 0x76, 0x9a, 0xb6, 0x6c, 0x9f, 0x62, 0x37, ++ 0x2f, 0xc0, 0xef, 0x44, 0xb3, 0x0d, 0x4a, 0x3e, 0x4f, 0x7d, 0xbd, 0xdb, ++ 0xd8, 0x75, 0x5f, 0x68, 0xe3, 0xf0, 0xec, 0x82, 0x66, 0x7c, 0x31, 0x70, ++ 0xa9, 0xa1, 0x6f, 0x38, 0x9f, 0xdf, 0xf5, 0xf0, 0x7d, 0x23, 0x9d, 0x34, ++ 0xa5, 0x85, 0xd3, 0xdf, 0x68, 0x41, 0xfc, 0x4f, 0x89, 0x45, 0x3c, 0x24, ++ 0x81, 0xa6, 0xf2, 0x3c, 0x02, 0x26, 0x09, 0x48, 0xdd, 0xfe, 0x4b, 0xb6, ++ 0x66, 0xbf, 0x8f, 0xe5, 0x5f, 0xf0, 0x5d, 0x8a, 0x61, 0x2e, 0x5f, 0x9f, ++ 0x80, 0xd9, 0xd5, 0xe6, 0x41, 0xd8, 0x10, 0x5e, 0x7a, 0xc6, 0xdb, 0x89, ++ 0xc7, 0xca, 0x6c, 0x5b, 0xb1, 0x4e, 0x7d, 0x0c, 0x03, 0xfd, 0x50, 0xca, ++ 0xbf, 0xbb, 0xe2, 0x69, 0x4b, 0x4e, 0xc2, 0x3d, 0x75, 0xfa, 0xd1, 0xcc, ++ 0xd6, 0xf9, 0x39, 0xb9, 0xdc, 0x53, 0xad, 0x62, 0xfb, 0x1b, 0x94, 0x26, ++ 0x7f, 0x21, 0x54, 0x5c, 0xb7, 0xdc, 0xe7, 0x96, 0x8c, 0xce, 0x75, 0xe0, ++ 0x17, 0x01, 0x3a, 0x3c, 0x77, 0x6e, 0xa4, 0x8b, 0x7a, 0x83, 0x28, 0x7a, ++ 0xf7, 0xb0, 0x5f, 0xfc, 0x7f, 0x2d, 0x2e, 0xec, 0xf5, 0xeb, 0x9c, 0x63, ++ 0x74, 0xd0, 0xe5, 0xdc, 0x19, 0xe4, 0x71, 0xc5, 0x4a, 0x8a, 0x54, 0xa4, ++ 0xe0, 0x7d, 0x4e, 0xbf, 0x53, 0x30, 0xaf, 0xd0, 0xeb, 0x96, 0xc3, 0xbb, ++ 0x65, 0xf7, 0x67, 0xf5, 0xae, 0xd3, 0x96, 0xf2, 0x63, 0xc8, 0x69, 0xf7, ++ 0x47, 0xcb, 0x27, 0x79, 0xe1, 0xff, 0x2f, 0x68, 0xdf, 0x1e, 0xb3, 0xb8, ++ 0x0c, 0xc5, 0x58, 0x73, 0xcc, 0xfe, 0x8c, 0xda, 0x4e, 0x3b, 0x01, 0x04, ++ 0xcd, 0xcb, 0xb8, 0x3e, 0x06, 0xfd, 0x4c, 0x0a, 0x9f, 0x5e, 0x76, 0x8c, ++ 0x0c, 0x83, 0x75, 0x09, 0x08, 0xb2, 0xdb, 0xf4, 0x49, 0x4e, 0xa0, 0xf2, ++ 0x0c, 0x7b, 0x87, 0x38, 0x9e, 0x22, 0x67, 0xbd, 0xd1, 0x97, 0x57, 0x24, ++ 0xf1, 0x46, 0x07, 0xf9, 0xd2, 0x1b, 0xec, 0x25, 0x5e, 0x67, 0xd9, 0x66, ++ 0x23, 0x1b, 0xd3, 0xe4, 0xaa, 0xec, 0x88, 0xf0, 0x7e, 0x15, 0x83, 0x51, ++ 0x31, 0x67, 0x51, 0x76, 0x5f, 0x55, 0xd7, 0x36, 0xdf, 0x4a, 0x84, 0x0b, ++ 0x6f, 0x5c, 0xbb, 0x5b, 0x8f, 0x37, 0x23, 0x7f, 0xf8, 0x17, 0x84, 0xa2, ++ 0x70, 0x20, 0x07, 0x0c, 0x90, 0x3a, 0x04, 0xfd, 0xf0, 0x08, 0x4a, 0xb1, ++ 0x16, 0x0f, 0xe6, 0xf6, 0x40, 0x51, 0x83, 0xd2, 0x87, 0x40, 0x9c, 0x1c, ++ 0x9f, 0x13, 0x38, 0x17, 0xd3, 0x34, 0x58, 0xad, 0x05, 0x71, 0xa0, 0x73, ++ 0xca, 0x40, 0xa6, 0xa4, 0x81, 0x02, 0xee, 0xa8, 0x72, 0x41, 0xa1, 0x41, ++ 0x18, 0x64, 0x8a, 0x86, 0x8a, 0x5d, 0xe6, 0x4f, 0x0a, 0xc5, 0x95, 0x98, ++ 0xf9, 0x78, 0xfe, 0x19, 0x0d, 0xc9, 0xb3, 0x89, 0xc1, 0x2b, 0x09, 0xbe, ++ 0xf1, 0xd2, 0x04, 0x5d, 0xcc, 0x28, 0xf5, 0x4b, 0xd2, 0x20, 0x4f, 0xc5, ++ 0x41, 0x9d, 0x8c, 0x85, 0xd8, 0xb0, 0x68, 0x5e, 0xc1, 0x0c, 0xb7, 0x24, ++ 0x4d, 0x67, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x5d, 0x30, 0x5b, 0x30, ++ 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, ++ 0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02, ++ 0x07, 0x80, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, ++ 0x14, 0xac, 0xf5, 0x47, 0x17, 0xd9, 0x7d, 0xc1, 0xb1, 0xc4, 0x41, 0xe1, ++ 0x41, 0x60, 0xcb, 0x37, 0x11, 0x60, 0x28, 0x78, 0x5f, 0x30, 0x1f, 0x06, ++ 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x21, 0x94, ++ 0xfb, 0xf9, 0xb2, 0x43, 0xe9, 0x33, 0xd7, 0x50, 0x7d, 0xc7, 0x37, 0xdb, ++ 0xd5, 0x82, 0x5a, 0x4e, 0xbe, 0x1b, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, ++ 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x02, ++ 0x01, 0x00, 0x96, 0x70, 0x65, 0x26, 0x42, 0xf8, 0xdc, 0x69, 0xde, 0xcf, ++ 0x41, 0x3a, 0x2e, 0x7f, 0x5b, 0xf1, 0xf9, 0x3b, 0x9b, 0xd2, 0x4e, 0x64, ++ 0x48, 0x81, 0xe4, 0x5d, 0x1e, 0x22, 0xce, 0x68, 0x63, 0x62, 0xe5, 0x1b, ++ 0x9b, 0xf2, 0xc7, 0x12, 0xda, 0x1e, 0x9b, 0x90, 0x84, 0x79, 0x48, 0x12, ++ 0xe6, 0x21, 0x6f, 0x2f, 0x7e, 0x18, 0x77, 0xdb, 0x8c, 0xc4, 0xd1, 0x0d, ++ 0x91, 0xbf, 0x39, 0x22, 0x0f, 0x64, 0xcf, 0x25, 0x2e, 0x8c, 0x1f, 0x91, ++ 0x81, 0xb5, 0xe9, 0x6c, 0x02, 0x3a, 0xf8, 0x07, 0xa2, 0x6f, 0x46, 0x5d, ++ 0x7b, 0xfd, 0x43, 0xff, 0x41, 0x0f, 0xe2, 0x57, 0x1c, 0xbd, 0x48, 0x60, ++ 0x53, 0x11, 0x48, 0x87, 0x88, 0x9d, 0x13, 0x82, 0x40, 0x68, 0x44, 0x2c, ++ 0xc6, 0xc8, 0x95, 0x27, 0x4f, 0xb6, 0xb9, 0x4a, 0x22, 0x0a, 0xfd, 0xe4, ++ 0x46, 0x8f, 0x35, 0x12, 0x98, 0x5a, 0x34, 0x6f, 0x2b, 0x57, 0x62, 0xa1, ++ 0x4d, 0x8d, 0x79, 0x37, 0xe4, 0x6b, 0x8a, 0x32, 0x5b, 0xcb, 0xef, 0x79, ++ 0x11, 0xed, 0xa7, 0xf8, 0x7a, 0x1c, 0xbd, 0x86, 0xdc, 0x0e, 0x2e, 0xfd, ++ 0xd3, 0x51, 0xbb, 0x73, 0xad, 0x00, 0xa0, 0x1b, 0xf9, 0x1d, 0xd1, 0x4a, ++ 0xe4, 0xd4, 0x02, 0x63, 0x2b, 0x39, 0x5f, 0x18, 0x08, 0x2f, 0x42, 0xb7, ++ 0x23, 0x4b, 0x48, 0x46, 0x1f, 0x63, 0x87, 0xae, 0x6d, 0xd5, 0xdb, 0x60, ++ 0xf8, 0x5f, 0xd3, 0x13, 0xec, 0xca, 0xdd, 0x60, 0x60, 0x79, 0x52, 0x70, ++ 0x47, 0xae, 0x1d, 0x38, 0x78, 0x71, 0xcf, 0xb3, 0x04, 0x03, 0xbe, 0xba, ++ 0x81, 0xba, 0x74, 0xb1, 0x30, 0x35, 0xdc, 0xea, 0x21, 0x4a, 0x9b, 0x70, ++ 0xfb, 0xd6, 0x60, 0x59, 0x78, 0x0c, 0x4d, 0x39, 0x19, 0x1d, 0xe5, 0x75, ++ 0xba, 0x07, 0xf4, 0x22, 0x37, 0x64, 0xb7, 0xf2, 0x9a, 0xc9, 0x11, 0x2d, ++ 0x8e, 0x58, 0xa6, 0xcf, 0x83, 0xf1, 0xcb, 0x6c, 0x7f, 0x02, 0xbd, 0xda, ++ 0x03, 0x92, 0xa9, 0x45, 0x24, 0x56, 0xc5, 0xbd, 0x41, 0xd1, 0x20, 0x86, ++ 0xc0, 0xb6, 0xb7, 0xe8, 0xa7, 0xb2, 0x46, 0xf7, 0x8e, 0xa9, 0x38, 0x0e, ++ 0x23, 0x77, 0x3c, 0x0d, 0x66, 0x83, 0x6a, 0x1a, 0x6b, 0x7f, 0x54, 0x11, ++ 0x58, 0x0d, 0x4a, 0xb5, 0x74, 0x60, 0xca, 0xed, 0xff, 0x91, 0x47, 0xd9, ++ 0x29, 0xe0, 0xaa, 0x8c, 0xa8, 0x8f, 0x10, 0x4c, 0x15, 0x7d, 0xce, 0x95, ++ 0xf9, 0x87, 0x1e, 0x18, 0x38, 0x18, 0xfc, 0xcc, 0xaf, 0x91, 0x17, 0x3f, ++ 0xfa, 0xf0, 0x8a, 0x09, 0x6f, 0xba, 0x4e, 0x53, 0xf7, 0xfa, 0x4f, 0x20, ++ 0xa3, 0xf4, 0x4a, 0x5a, 0xde, 0x17, 0x1c, 0x29, 0x6a, 0x6f, 0x03, 0x48, ++ 0xdf, 0xad, 0x4f, 0xe4, 0xbc, 0x71, 0xc4, 0x72, 0x32, 0x11, 0x84, 0xac, ++ 0x09, 0xd2, 0x18, 0x44, 0x35, 0xf1, 0xcd, 0xaf, 0xa8, 0x98, 0xe0, 0x8b, ++ 0xec, 0xa0, 0x83, 0x37, 0xc3, 0x35, 0x85, 0xd6, 0xd8, 0x1b, 0xe0, 0x75, ++ 0xdc, 0xfd, 0xde, 0xc9, 0xeb, 0xd5, 0x18, 0x0f, 0xd3, 0x4c, 0x2f, 0x71, ++ 0xdc, 0x48, 0xe3, 0x14, 0xeb, 0xda, 0x00, 0x24, 0x24, 0x9e, 0xa3, 0x8e, ++ 0x3e, 0x08, 0x6f, 0x22, 0x24, 0xd6, 0xc4, 0x85, 0x8f, 0x68, 0x00, 0x4a, ++ 0x82, 0x4c, 0x33, 0x6e, 0xa5, 0x35, 0x7b, 0xeb, 0x4b, 0xdc, 0xa0, 0xa6, ++ 0x65, 0x6f, 0x5a, 0x7a, 0xdf, 0x8a, 0x01, 0x52, 0xa1, 0x6c, 0xff, 0x59, ++ 0x22, 0x7f, 0xe1, 0x96, 0x1b, 0x19, 0xb8, 0xf9, 0x5d, 0x44, 0x9f, 0x91, ++ 0x03, 0x3c, 0x3d, 0xa1, 0x2a, 0xb6, 0x5a, 0x51, 0xa0, 0xce, 0x4a, 0x88, ++ 0x22, 0x72, 0x9c, 0xdc, 0xc0, 0x47, 0x76, 0x35, 0x84, 0x75, 0x9b, 0x87, ++ 0x5c, 0xd3, 0xcf, 0xe7, 0xdd, 0xa3, 0x57, 0x14, 0xdf, 0x00, 0xfd, 0x19, ++ 0x2a, 0x7d, 0x89, 0x27, 0x1c, 0x78, 0x97, 0x04, 0x58, 0x48 ++}; ++unsigned int certificate2_der_len = 1366; ++ ++unsigned char hi_signed_2nd[] = { ++ 0x68, 0x69, 0x0a, 0x30, 0x82, 0x02, 0xb1, 0x06, 0x09, 0x2a, 0x86, 0x48, ++ 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 0x82, 0x02, 0xa2, 0x30, 0x82, ++ 0x02, 0x9e, 0x02, 0x01, 0x01, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x09, 0x60, ++ 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x30, 0x0b, 0x06, 0x09, ++ 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0x31, 0x82, 0x02, ++ 0x7b, 0x30, 0x82, 0x02, 0x77, 0x02, 0x01, 0x01, 0x30, 0x52, 0x30, 0x3a, ++ 0x31, 0x38, 0x30, 0x36, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x2f, 0x47, ++ 0x72, 0x75, 0x62, 0x20, 0x32, 0x6e, 0x64, 0x20, 0x43, 0x65, 0x72, 0x74, ++ 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x20, 0x54, 0x65, 0x73, 0x74, ++ 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, ++ 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x02, 0x14, ++ 0x5b, 0x5e, 0x59, 0xf2, 0x5f, 0x75, 0x4c, 0x8e, 0xc5, 0x3a, 0x91, 0x07, ++ 0xe9, 0xe7, 0x6d, 0x3c, 0xd0, 0x7f, 0x91, 0xff, 0x30, 0x0b, 0x06, 0x09, ++ 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x30, 0x0d, 0x06, ++ 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, ++ 0x04, 0x82, 0x02, 0x00, 0x0e, 0xc2, 0x30, 0x38, 0x81, 0x23, 0x68, 0x90, ++ 0xae, 0x5f, 0xce, 0xf7, 0x27, 0xb1, 0x8c, 0x2e, 0x12, 0x10, 0xc6, 0x99, ++ 0xdc, 0x4d, 0x4b, 0x79, 0xda, 0xe4, 0x32, 0x10, 0x46, 0x1c, 0x16, 0x07, ++ 0x87, 0x66, 0x55, 0xff, 0x64, 0x1c, 0x61, 0x25, 0xd5, 0xb9, 0xe1, 0xfe, ++ 0xea, 0x5a, 0xcd, 0x56, 0xa5, 0xc3, 0xbe, 0xb1, 0x61, 0xc7, 0x6f, 0x5f, ++ 0x69, 0x20, 0x64, 0x50, 0x6f, 0x12, 0x78, 0xb6, 0x0c, 0x72, 0x44, 0x4f, ++ 0x60, 0x0f, 0x9f, 0xa2, 0x83, 0x3b, 0xc2, 0x83, 0xd5, 0x14, 0x1f, 0x6f, ++ 0x3e, 0xb2, 0x47, 0xb5, 0x58, 0xc5, 0xa7, 0xb4, 0x82, 0x53, 0x2e, 0x53, ++ 0x95, 0x4e, 0x3d, 0xe4, 0x62, 0xe8, 0xa1, 0xaf, 0xae, 0xbf, 0xa9, 0xd2, ++ 0x22, 0x07, 0xbe, 0x71, 0x37, 0x2c, 0x5a, 0xa7, 0x6c, 0xaf, 0x14, 0xc0, ++ 0x6c, 0x2f, 0xbf, 0x4f, 0x15, 0xc2, 0x0f, 0x8b, 0xdc, 0x68, 0x45, 0xdf, ++ 0xf3, 0xa5, 0x7f, 0x11, 0x6a, 0x54, 0xcd, 0x67, 0xb9, 0x2e, 0x7d, 0x05, ++ 0xe3, 0x1c, 0x1d, 0xcc, 0x77, 0x8e, 0x97, 0xb1, 0xa0, 0x11, 0x09, 0x3d, ++ 0x90, 0x54, 0xfc, 0x7e, 0xbb, 0xbb, 0x21, 0x23, 0x03, 0x44, 0xbf, 0x7d, ++ 0x2c, 0xc9, 0x15, 0x42, 0xe5, 0xa0, 0x3b, 0xa2, 0xd1, 0x5b, 0x73, 0x81, ++ 0xff, 0xfa, 0x90, 0xfc, 0x27, 0x7b, 0x2f, 0x86, 0x9c, 0x1d, 0x14, 0x36, ++ 0x94, 0xa2, 0x6e, 0xe8, 0x9d, 0xa0, 0x5f, 0xfc, 0x5a, 0x0d, 0xa4, 0xd5, ++ 0x2f, 0x8d, 0xd6, 0x00, 0xfa, 0x93, 0x5b, 0x09, 0x7f, 0x42, 0x78, 0xcc, ++ 0x8c, 0x49, 0xda, 0xd9, 0xf6, 0x43, 0xe7, 0xe1, 0x3c, 0xa2, 0xe2, 0x70, ++ 0xe2, 0x6a, 0x99, 0xc5, 0xd6, 0xa2, 0xe3, 0x0b, 0xd4, 0x09, 0xac, 0x94, ++ 0xaf, 0xb7, 0xf0, 0xb3, 0x0c, 0x1e, 0xf5, 0x16, 0x4f, 0x53, 0x9a, 0xe3, ++ 0xcc, 0xe2, 0x0c, 0x4a, 0xb9, 0xe6, 0x06, 0xbb, 0xf7, 0x41, 0x43, 0x20, ++ 0x04, 0xee, 0x99, 0x2f, 0xd8, 0x9f, 0xda, 0x3f, 0xfd, 0x49, 0xb8, 0xc2, ++ 0xbd, 0xd9, 0xc5, 0x72, 0xfd, 0xe3, 0xce, 0x1c, 0xbc, 0xe4, 0x39, 0xac, ++ 0x2a, 0x99, 0xe9, 0xb4, 0x3e, 0x74, 0x10, 0xeb, 0xd5, 0x14, 0xcc, 0xdb, ++ 0xf1, 0x04, 0x63, 0x36, 0xfb, 0x1f, 0x2b, 0xe2, 0x73, 0xd4, 0xd8, 0x49, ++ 0x31, 0xa8, 0x55, 0xcc, 0xa7, 0x76, 0x36, 0x6e, 0x18, 0xdc, 0xb9, 0xb0, ++ 0x29, 0x99, 0xcf, 0x49, 0xbf, 0xf9, 0xdb, 0x7f, 0x24, 0x42, 0x02, 0xcb, ++ 0xc1, 0xaa, 0xcb, 0xba, 0x18, 0x85, 0x86, 0xc7, 0xf4, 0x1c, 0x62, 0x76, ++ 0xbc, 0x73, 0xfb, 0xe4, 0x15, 0xb8, 0xdd, 0x5d, 0xa6, 0x68, 0x39, 0xa5, ++ 0x3d, 0x33, 0xaf, 0xd5, 0x92, 0x4d, 0x48, 0xdb, 0x22, 0xc0, 0xdc, 0x49, ++ 0x5f, 0x7b, 0xa8, 0xd2, 0x62, 0x2d, 0xa7, 0x39, 0x93, 0x48, 0xe7, 0x6b, ++ 0x23, 0xba, 0xd4, 0xe0, 0xc1, 0x29, 0x55, 0xc4, 0x34, 0xe3, 0xac, 0x25, ++ 0xa7, 0x15, 0xad, 0xab, 0xb3, 0xb7, 0x25, 0xca, 0x37, 0x88, 0x40, 0x2e, ++ 0x47, 0x6e, 0x92, 0x20, 0x09, 0x2e, 0x5a, 0xec, 0xf2, 0xfb, 0xb3, 0xa0, ++ 0x16, 0xb6, 0x93, 0xf2, 0xf5, 0x8b, 0xfe, 0xaf, 0x25, 0xee, 0x2e, 0x98, ++ 0x6c, 0x0a, 0xfe, 0xae, 0x0b, 0x57, 0xf5, 0x9f, 0x3c, 0x80, 0xe9, 0x8b, ++ 0xaf, 0x92, 0x8a, 0xad, 0xe7, 0xa0, 0xe4, 0xe6, 0x0a, 0xa0, 0xc7, 0x83, ++ 0xb5, 0x48, 0x58, 0x5f, 0x55, 0x9e, 0x9b, 0x27, 0xcd, 0x31, 0x1f, 0x3e, ++ 0x50, 0x5a, 0x91, 0xad, 0x21, 0x1b, 0x97, 0x5b, 0xe8, 0xfa, 0x29, 0x8a, ++ 0xa4, 0x17, 0xe8, 0xab, 0x87, 0x02, 0xd6, 0x18, 0x8c, 0x9f, 0x65, 0xb7, ++ 0x2a, 0xfa, 0xde, 0x5f, 0x77, 0x30, 0x6c, 0x04, 0x22, 0xe6, 0x58, 0x26, ++ 0x14, 0x0d, 0x9c, 0x41, 0x0a, 0x82, 0x77, 0xdb, 0x40, 0xa1, 0x58, 0xac, ++ 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xb5, ++ 0x7e, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x20, 0x73, 0x69, 0x67, 0x6e, ++ 0x61, 0x74, 0x75, 0x72, 0x65, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, ++ 0x65, 0x64, 0x7e, 0x0a ++}; ++unsigned int hi_signed_2nd_len = 736; ++ ++unsigned char certificate_printable_der[] = { ++ 0x30, 0x82, 0x03, 0x39, 0x30, 0x82, 0x02, 0x21, 0xa0, 0x03, 0x02, 0x01, ++ 0x02, 0x02, 0x09, 0x00, 0xde, 0xf6, 0x22, 0xc4, 0xf2, 0xf1, 0x86, 0x02, ++ 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, ++ 0x0b, 0x05, 0x00, 0x30, 0x2a, 0x31, 0x28, 0x30, 0x26, 0x06, 0x03, 0x55, ++ 0x04, 0x03, 0x13, 0x1f, 0x52, 0x65, 0x64, 0x20, 0x48, 0x61, 0x74, 0x20, ++ 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x20, 0x42, 0x6f, 0x6f, 0x74, 0x20, ++ 0x43, 0x41, 0x20, 0x32, 0x20, 0x28, 0x62, 0x65, 0x74, 0x61, 0x29, 0x30, ++ 0x1e, 0x17, 0x0d, 0x31, 0x34, 0x31, 0x30, 0x33, 0x31, 0x31, 0x34, 0x31, ++ 0x39, 0x32, 0x33, 0x5a, 0x17, 0x0d, 0x33, 0x37, 0x31, 0x30, 0x32, 0x35, ++ 0x31, 0x34, 0x31, 0x39, 0x32, 0x33, 0x5a, 0x30, 0x2f, 0x31, 0x2d, 0x30, ++ 0x2b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x24, 0x52, 0x65, 0x64, 0x20, ++ 0x48, 0x61, 0x74, 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x20, 0x42, ++ 0x6f, 0x6f, 0x74, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x20, ++ 0x33, 0x20, 0x28, 0x62, 0x65, 0x74, 0x61, 0x29, 0x30, 0x82, 0x01, 0x22, ++ 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, ++ 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, ++ 0x02, 0x82, 0x01, 0x01, 0x00, 0xbd, 0xda, 0xa1, 0xed, 0x8d, 0x8e, 0x15, ++ 0x5c, 0xf8, 0x01, 0x77, 0x48, 0x4a, 0x60, 0x96, 0xf9, 0x27, 0xfa, 0xe2, ++ 0xb1, 0x69, 0x0f, 0x51, 0x19, 0x52, 0x7e, 0xc4, 0x34, 0x8e, 0xe1, 0x9b, ++ 0x9c, 0xa4, 0xb1, 0x5c, 0xd6, 0x81, 0x98, 0x78, 0xfe, 0xa9, 0xe5, 0x0b, ++ 0x00, 0xba, 0x9c, 0x64, 0x7e, 0xc7, 0xcc, 0x72, 0xb1, 0x73, 0x4b, 0x11, ++ 0x07, 0x52, 0xf0, 0x20, 0x96, 0x8b, 0x99, 0x39, 0xde, 0xdb, 0xfa, 0x3d, ++ 0x45, 0xe2, 0x98, 0x7b, 0x0c, 0x41, 0xe4, 0x0c, 0xb5, 0x5d, 0x92, 0x74, ++ 0x39, 0x96, 0xe1, 0x97, 0x97, 0xa1, 0xad, 0x2e, 0xcc, 0xd0, 0x1b, 0x4d, ++ 0x9d, 0xbd, 0x3e, 0xa9, 0x36, 0x8e, 0xcc, 0xc7, 0x5f, 0x6a, 0x7d, 0x39, ++ 0x5e, 0x0b, 0x8d, 0xca, 0xe4, 0x83, 0xe9, 0x3b, 0x5c, 0x86, 0x47, 0xd4, ++ 0xba, 0x7d, 0x98, 0x26, 0xa1, 0xf4, 0xe8, 0x90, 0x6b, 0x0f, 0xf1, 0x6b, ++ 0x8c, 0xe3, 0xa2, 0x80, 0x3c, 0x96, 0xf1, 0x0a, 0xb6, 0x66, 0xc0, 0x4b, ++ 0x61, 0xf7, 0x74, 0xcd, 0xd3, 0x7b, 0x8e, 0x5e, 0x39, 0xda, 0x99, 0x20, ++ 0x33, 0x93, 0xd3, 0xf0, 0x7f, 0xad, 0x35, 0xe9, 0x88, 0x8d, 0x9c, 0xbf, ++ 0x65, 0xf1, 0x47, 0x02, 0xf9, 0x7c, 0xed, 0x27, 0x5f, 0x4a, 0x65, 0x3c, ++ 0xcf, 0x5f, 0x0e, 0x88, 0x95, 0x74, 0xde, 0xfb, 0x9e, 0x2e, 0x91, 0x9b, ++ 0x45, 0x37, 0xc8, 0x85, 0xff, 0xe3, 0x41, 0x70, 0xfe, 0xd5, 0xef, 0x0e, ++ 0x82, 0x22, 0x08, 0xb7, 0x3b, 0x44, 0x3e, 0xdc, 0x5b, 0x7f, 0xba, 0xbf, ++ 0xe6, 0x58, 0x9d, 0x02, 0x6e, 0x75, 0xbf, 0x50, 0xec, 0xcf, 0x3f, 0xa5, ++ 0x91, 0x0a, 0xe2, 0x59, 0x2c, 0xc3, 0xe7, 0x05, 0x03, 0xe8, 0xf2, 0x6f, ++ 0x2a, 0x04, 0x68, 0x9a, 0x31, 0x32, 0x8f, 0x04, 0x35, 0xcd, 0x1f, 0x34, ++ 0xcc, 0x4f, 0x79, 0x5a, 0x99, 0x8d, 0x9d, 0x5c, 0xf5, 0x02, 0x03, 0x01, ++ 0x00, 0x01, 0xa3, 0x5d, 0x30, 0x5b, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, ++ 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x0b, 0x06, 0x03, ++ 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, 0x30, 0x1d, 0x06, ++ 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x65, 0xc5, 0xbe, 0xca, ++ 0xe6, 0x59, 0x6a, 0xfd, 0x6c, 0x71, 0xc4, 0xa7, 0x98, 0xc6, 0x25, 0x8d, ++ 0x7b, 0x67, 0x05, 0xd0, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, ++ 0x18, 0x30, 0x16, 0x80, 0x14, 0x81, 0xf8, 0xee, 0x47, 0x5c, 0x3e, 0xed, ++ 0xfb, 0xce, 0xa5, 0x84, 0xbe, 0xd7, 0xae, 0xdb, 0xd3, 0x7d, 0x64, 0xb3, ++ 0x2a, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, ++ 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x66, 0x1e, 0x3d, ++ 0x1d, 0x53, 0x33, 0xde, 0x4e, 0xc7, 0xc4, 0xf4, 0xdf, 0xda, 0x18, 0x19, ++ 0x8a, 0xa9, 0xff, 0xe2, 0x63, 0x2b, 0xbe, 0xf2, 0x61, 0x63, 0xe2, 0xf6, ++ 0xed, 0x47, 0x1a, 0x71, 0x02, 0xec, 0x2a, 0xef, 0x89, 0x77, 0xe3, 0xfd, ++ 0x86, 0x69, 0xf1, 0x3f, 0x0d, 0xf9, 0x6e, 0xf9, 0x3b, 0xad, 0x26, 0x47, ++ 0xb7, 0xf2, 0x0d, 0xad, 0x23, 0xa3, 0x67, 0x3b, 0xcb, 0x6d, 0x9e, 0x03, ++ 0x0f, 0xbc, 0x69, 0x73, 0x9f, 0xd4, 0xa5, 0x0f, 0x6f, 0xf8, 0xab, 0x4d, ++ 0x36, 0xd1, 0xe0, 0xe0, 0x5d, 0x20, 0x43, 0x90, 0xc4, 0x65, 0x61, 0x93, ++ 0xe2, 0x0f, 0x51, 0x59, 0x0a, 0xf7, 0x88, 0x70, 0x57, 0xb9, 0x04, 0xa9, ++ 0x32, 0x57, 0x9c, 0xb3, 0x57, 0x38, 0x8b, 0x8e, 0x46, 0xc8, 0x32, 0x6c, ++ 0xb4, 0xf3, 0x96, 0x7f, 0x4b, 0xf0, 0x88, 0xf9, 0x7f, 0xe2, 0x71, 0xe1, ++ 0x8b, 0xe2, 0x14, 0xf1, 0x4b, 0x25, 0x00, 0x48, 0x1c, 0x7e, 0xe5, 0x8d, ++ 0x65, 0x2d, 0xeb, 0x72, 0x4f, 0x92, 0x44, 0xf3, 0xe6, 0xe0, 0xd0, 0xdf, ++ 0x85, 0xa8, 0x13, 0x4a, 0xfb, 0x99, 0xca, 0x14, 0x2c, 0x97, 0x80, 0x93, ++ 0x27, 0xd3, 0x20, 0xf8, 0x6d, 0x29, 0x28, 0x2c, 0xb9, 0x77, 0xea, 0xb1, ++ 0x63, 0xbd, 0x7d, 0x53, 0xfd, 0x4a, 0x62, 0x64, 0x0b, 0x98, 0xa8, 0xae, ++ 0x11, 0xfc, 0x6e, 0x8d, 0x63, 0xd4, 0x15, 0x55, 0xc6, 0x4c, 0x74, 0xf5, ++ 0x5f, 0xa0, 0xb9, 0x2c, 0x2d, 0x9a, 0x7a, 0x87, 0x6e, 0xf0, 0x5e, 0x25, ++ 0xed, 0xfc, 0xd8, 0xc4, 0x34, 0x33, 0x32, 0xad, 0x01, 0xd4, 0x4b, 0x49, ++ 0x51, 0xc2, 0x07, 0x7f, 0x90, 0x6d, 0xea, 0xf5, 0x4c, 0x41, 0x71, 0x64, ++ 0xeb, 0x1f, 0x29, 0xa3, 0x1f, 0x64, 0xa2, 0x1e, 0x0e, 0x6f, 0xa1, 0x67, ++ 0x99, 0x8d, 0x98, 0x1c, 0xb8, 0x53, 0x9d, 0x30, 0x1d, 0xae, 0x32, 0x56, ++ 0xd2 ++}; ++unsigned int certificate_printable_der_len = 829; diff --git a/0179-Don-t-add-a-class-option-to-menu-entries-generated-f.patch b/0179-Don-t-add-a-class-option-to-menu-entries-generated-f.patch deleted file mode 100644 index 26ad7360f9b0e4a6f70d6b4a744b70885f73dfb8..0000000000000000000000000000000000000000 --- a/0179-Don-t-add-a-class-option-to-menu-entries-generated-f.patch +++ /dev/null @@ -1,81 +0,0 @@ -From 4207465e5a4866df6afde297e356057454c3d946 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Fri, 4 Oct 2019 16:43:05 +0200 -Subject: [PATCH 179/220] Don't add a class option to menu entries generated - for ppc64le - -For ppc64le a grub config file with menuentry commands is still generated -even when BLS support is enabled. That's because BLS support was added to -Petitboot 1.8.0 and any previous version won't be able to parse BLS files. - -To make the BLS snippets the source of truth, these are used to generate -the menuentry commands in the grub config file. - -And to keep it consistent across all ppc64le machines regardless of the -firmware used, the grub config file is also generated for machines with -OF that use grub2 and would have BLS support. - -The BLS snippets created by the kernel package have fields that are used -to specify the generated menuentry command users and class options. These -fields are not present in BLS snippets created by OSTree though, so the -script generating the menuentry commands will add options with an empty -argument which will lead to grub failing to parse them. - -We could check if the field is defined before attempting to add those, but -since the grub2 blscfg module also supports setting these to variables, it -could lead to an empty argument even if was defined in the BLS snippet if -the variable doesn't exist. - -So to make more robust, just don't add a class to the menuentry commands -generated by the script. It's better to not have a class for the menuentry -than grub2 failing to parse the command and not populating the boot menu. - -Resolves: rhbz#1758225 - -Signed-off-by: Javier Martinez Canillas ---- - util/grub.d/10_linux_bls.in | 10 +--------- - 1 file changed, 1 insertion(+), 9 deletions(-) - -diff --git a/util/grub.d/10_linux_bls.in b/util/grub.d/10_linux_bls.in -index 1b75364..68fbedf 100644 ---- a/util/grub.d/10_linux_bls.in -+++ b/util/grub.d/10_linux_bls.in -@@ -127,9 +127,7 @@ read_config() - initrd="" - options="" - linux="" -- grub_users="" - grub_arg="" -- grub_class="" - - while read -r line - do -@@ -148,15 +146,9 @@ read_config() - "options") - options=${value} - ;; -- "grub_users") -- grub_users=${value} -- ;; - "grub_arg") - grub_arg=${value} - ;; -- "grub_class") -- grub_class=${value} -- ;; - esac - done < ${config_file} - } -@@ -180,7 +172,7 @@ populate_menu() - for bls in "${files[@]}" ; do - read_config "${blsdir}/${bls}.conf" - -- menu="${menu}menuentry '${title}' --class ${grub_class} ${grub_arg} --id=${bls} {\n" -+ menu="${menu}menuentry '${title}' ${grub_arg} --id=${bls} {\n" - menu="${menu}\t linux ${linux} ${options}\n" - if [ -n "${initrd}" ] ; then - menu="${menu}\t initrd ${boot_prefix}${initrd}\n" --- -1.8.3.1 - diff --git a/0179-appended-signatures-documentation.patch b/0179-appended-signatures-documentation.patch new file mode 100644 index 0000000000000000000000000000000000000000..864cfa3198e02b1ccfc59fd49cdbda13e7818035 --- /dev/null +++ b/0179-appended-signatures-documentation.patch @@ -0,0 +1,341 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Thu, 1 Oct 2020 13:02:09 +1000 +Subject: [PATCH] appended signatures: documentation + +This explains how appended signatures can be used to form part of +a secure boot chain, and documents the commands and variables +introduced. + +Signed-off-by: Daniel Axtens +--- + docs/grub.texi | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- + 1 file changed, 182 insertions(+), 17 deletions(-) + +diff --git a/docs/grub.texi b/docs/grub.texi +index afbde7c1f7b..4816be85611 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -3214,6 +3214,7 @@ These variables have special meaning to GRUB. + + @menu + * biosnum:: ++* check_appended_signatures:: + * check_signatures:: + * chosen:: + * cmdpath:: +@@ -3273,11 +3274,18 @@ For an alternative approach which also changes BIOS drive mappings for the + chain-loaded system, @pxref{drivemap}. + + ++@node check_appended_signatures ++@subsection check_appended_signatures ++ ++This variable controls whether GRUB enforces appended signature validation on ++certain loaded files. @xref{Using appended signatures}. ++ ++ + @node check_signatures + @subsection check_signatures + +-This variable controls whether GRUB enforces digital signature +-validation on loaded files. @xref{Using digital signatures}. ++This variable controls whether GRUB enforces GPG-style digital signature ++validation on loaded files. @xref{Using GPG-style digital signatures}. + + @node chosen + @subsection chosen +@@ -3994,6 +4002,7 @@ you forget a command, you can run the command @command{help} + * date:: Display or set current date and time + * devicetree:: Load a device tree blob + * distrust:: Remove a pubkey from trusted keys ++* distrust_certificate:: Remove a certificate from the list of trusted certificates + * drivemap:: Map a drive to another + * echo:: Display a line of text + * eval:: Evaluate agruments as GRUB commands +@@ -4010,6 +4019,7 @@ you forget a command, you can run the command @command{help} + * keystatus:: Check key modifier status + * linux:: Load a Linux kernel + * linux16:: Load a Linux kernel (16-bit mode) ++* list_certificates:: List trusted certificates + * list_env:: List variables in environment block + * list_trusted:: List trusted public keys + * load_env:: Load variables from environment block +@@ -4047,8 +4057,10 @@ you forget a command, you can run the command @command{help} + * test:: Check file types and compare values + * true:: Do nothing, successfully + * trust:: Add public key to list of trusted keys ++* trust_certificate:: Add an x509 certificate to the list of trusted certificates + * unset:: Unset an environment variable + @comment * vbeinfo:: List available video modes ++* verify_appended:: Verify appended digital signature + * verify_detached:: Verify detached digital signature + * videoinfo:: List available video modes + @comment * xen_*:: Xen boot commands for AArch64 +@@ -4376,9 +4388,28 @@ These keys are used to validate signatures when environment variable + @code{check_signatures} is set to @code{enforce} + (@pxref{check_signatures}), and by some invocations of + @command{verify_detached} (@pxref{verify_detached}). @xref{Using +-digital signatures}, for more information. ++GPG-style digital signatures}, for more information. + @end deffn + ++ ++@node distrust_certificate ++@subsection distrust_certificate ++ ++@deffn Command distrust_certificate cert_number ++Remove the x509 certificate numbered @var{cert_number} from GRUB's keyring of ++trusted x509 certificates for verifying appended signatures. ++ ++@var{cert_number} is the certificate number as listed by ++@command{list_certificates} (@pxref{list_certificates}). ++ ++These certificates are used to validate appended signatures when environment ++variable @code{check_appended_signatures} is set to @code{enforce} or ++@code{forced} (@pxref{check_appended_signatures}), and by ++@command{verify_appended} (@pxref{verify_appended}). See ++@xref{Using appended signatures} for more information. ++@end deffn ++ ++ + @node drivemap + @subsection drivemap + +@@ -4636,6 +4667,21 @@ This command is only available on x86 systems. + @end deffn + + ++@node list_certificates ++@subsection list_certificates ++ ++@deffn Command list_certificates ++List all x509 certificates trusted by GRUB for validating appended signatures. ++The output is a numbered list of certificates, showing the certificate's serial ++number and Common Name. ++ ++The certificate number can be used as an argument to ++@command{distrust_certificate} (@pxref{distrust_certificate}). ++ ++See @xref{Using appended signatures} for more information. ++@end deffn ++ ++ + @node list_env + @subsection list_env + +@@ -4655,7 +4701,7 @@ The output is in GPG's v4 key fingerprint format (i.e., the output of + @code{gpg --fingerprint}). The least significant four bytes (last + eight hexadecimal digits) can be used as an argument to + @command{distrust} (@pxref{distrust}). +-@xref{Using digital signatures}, for more information about uses for ++@xref{Using GPG-style digital signatures}, for more information about uses for + these keys. + @end deffn + +@@ -4690,8 +4736,13 @@ When used with care, @option{--skip-sig} and the whitelist enable an + administrator to configure a system to boot only signed + configurations, but to allow the user to select from among multiple + configurations, and to enable ``one-shot'' boot attempts and +-``savedefault'' behavior. @xref{Using digital signatures}, for more ++``savedefault'' behavior. @xref{Using GPG-style digital signatures}, for more + information. ++ ++Extra care should be taken when combining this command with appended signatures ++(@pxref{Using appended signatures}), as this file is not validated by an ++appended signature and could set @code{check_appended_signatures=no} if GRUB is ++not in @pxref{Lockdown} mode. + @end deffn + + +@@ -4987,7 +5038,7 @@ read. It is possible to modify a digitally signed environment block + file from within GRUB using this command, such that its signature will + no longer be valid on subsequent boots. Care should be taken in such + advanced configurations to avoid rendering the system +-unbootable. @xref{Using digital signatures}, for more information. ++unbootable. @xref{Using GPG-style digital signatures}, for more information. + @end deffn + + +@@ -5387,11 +5438,32 @@ signatures when environment variable @code{check_signatures} is set to + must itself be properly signed. The @option{--skip-sig} option can be + used to disable signature-checking when reading @var{pubkey_file} + itself. It is expected that @option{--skip-sig} is useful for testing +-and manual booting. @xref{Using digital signatures}, for more ++and manual booting. @xref{Using GPG-style digital signatures}, for more + information. + @end deffn + + ++@node trust_certificate ++@subsection trust_certificate ++ ++@deffn Command trust_certificate x509_certificate ++Read an DER-formatted x509 certificate from the file @var{x509_certificate} ++and add it to GRUB's internal list of trusted x509 certificates. These ++certificates are used to validate appended signatures when the environment ++variable @code{check_appended_signatures} is set to @code{enforce} or ++@code{forced}. ++ ++Note that if @code{check_appended_signatures} is set to @code{enforce} or ++@code{forced} when @command{trust_certificate} is executed, then ++@var{x509_certificate} must itself bear an appended signature. (It is not ++sufficient that @var{x509_certificate} be signed by a trusted certificate ++according to the x509 rules: grub does not include support for validating ++signatures within x509 certificates themselves.) ++ ++See @xref{Using appended signatures} for more information. ++@end deffn ++ ++ + @node unset + @subsection unset + +@@ -5410,6 +5482,18 @@ only on PC BIOS platforms. + @end deffn + @end ignore + ++@node verify_appended ++@subsection verify_appended ++ ++@deffn Command verify_appended file ++Verifies an appended signature on @var{file} against the trusted certificates ++known to GRUB (See @pxref{list_certificates}, @pxref{trust_certificate}, and ++@pxref{distrust_certificate}). ++ ++Exit code @code{$?} is set to 0 if the signature validates ++successfully. If validation fails, it is set to a non-zero value. ++See @xref{Using appended signatures}, for more information. ++@end deffn + + @node verify_detached + @subsection verify_detached +@@ -5428,7 +5512,7 @@ tried. + + Exit code @code{$?} is set to 0 if the signature validates + successfully. If validation fails, it is set to a non-zero value. +-@xref{Using digital signatures}, for more information. ++@xref{Using GPG-style digital signatures}, for more information. + @end deffn + + @node videoinfo +@@ -5811,13 +5895,14 @@ environment variables and commands are listed in the same order. + @chapter Security + + @menu +-* Authentication and authorisation:: Users and access control +-* Using digital signatures:: Booting digitally signed code +-* UEFI secure boot and shim:: Booting digitally signed PE files +-* Secure Boot Advanced Targeting:: Embedded information for generation number based revocation +-* Measured Boot:: Measuring boot components +-* Lockdown:: Lockdown when booting on a secure setup +-* Signing GRUB itself:: Ensuring the integrity of the GRUB core image ++* Authentication and authorisation:: Users and access control ++* Using GPG-style digital signatures:: Booting digitally signed code ++* Using appended signatures:: An alternative approach to booting digitally signed code ++* UEFI secure boot and shim:: Booting digitally signed PE files ++* Secure Boot Advanced Targeting:: Embedded information for generation number based revocation ++* Measured Boot:: Measuring boot components ++* Lockdown:: Lockdown when booting on a secure setup ++* Signing GRUB itself:: Ensuring the integrity of the GRUB core image + @end menu + + @node Authentication and authorisation +@@ -5891,8 +5976,8 @@ generating configuration files with authentication. You can use + adding @kbd{set superusers=} and @kbd{password} or @kbd{password_pbkdf2} + commands. + +-@node Using digital signatures +-@section Using digital signatures in GRUB ++@node Using GPG-style digital signatures ++@section Using GPG-style digital signatures in GRUB + + GRUB's @file{core.img} can optionally provide enforcement that all files + subsequently read from disk are covered by a valid digital signature. +@@ -5985,6 +6070,86 @@ or BIOS) configuration to cause the machine to boot from a different + (attacker-controlled) device. GRUB is at best only one link in a + secure boot chain. + ++@node Using appended signatures ++@section Using appended signatures in GRUB ++ ++GRUB supports verifying Linux-style 'appended signatures' for secure boot. ++Appended signatures are PKCS#7 messages containing a signature over the ++contents of a file, plus some metadata, appended to the end of a file. A file ++with an appended signature ends with the magic string: ++ ++@example ++~Module signature appended~\n ++@end example ++ ++where @code{\n} represents the line-feed character, @code{0x0a}. ++ ++Certificates can be managed at boot time using the @pxref{trust_certificate}, ++@pxref{distrust_certificate} and @pxref{list_certificates} commands. ++Certificates can also be built in to the core image using the @code{--x509} ++parameter to @command{grub-install} or @command{grub-mkimage}. ++ ++A file can be explictly verified using the @pxref{verify_appended} command. ++ ++Only signatures made with the SHA-256 or SHA-512 hash algorithm are supported, ++and only RSA signatures are supported. ++ ++A file can be signed with the @command{sign-file} utility supplied with the ++Linux kernel source. For example, if you have @code{signing.key} as the private ++key and @code{certificate.der} as the x509 certificate containing the public key: ++ ++@example ++sign-file SHA256 signing.key certificate.der vmlinux vmlinux.signed ++@end example ++ ++Enforcement of signature verification is controlled by the ++@code{check_appended_signatures} variable. ++ ++@itemize ++@item @samp{no}: no verification is performed. This is the default when GRUB ++ is not in @pxref{Lockdown} mode. ++@item @samp{enforce}: verification is performed. Verification can be disabled ++ by setting the variable back to @samp{no}. ++@item @samp{forced}: verification is performed and cannot be disabled. This is ++ set when GRUB is in Lockdown when the appendedsig module is loaded. ++@end itemize ++ ++Unlike GPG-style signatures, not all files loaded by GRUB are required to be ++signed. Once verification is turned on, the following file types will have ++appended signatures verified: ++ ++@itemize ++@item Linux kernels ++@item GRUB modules, except those built into the core image ++@item Any new certificate files to be trusted ++@end itemize ++ ++ACPI tables and Device Tree images will not be checked for appended signatures ++but must be verified by another mechanism such as GPG-style signatures before ++they will be loaded. ++ ++Unless lockdown mode is enabled, signature checking does @strong{not} ++stop an attacker with console access from dropping manually to the GRUB ++console and executing: ++ ++@example ++set check_appended_signatures=no ++@end example ++ ++Refer to the section on password-protecting GRUB (@pxref{Authentication ++and authorisation}) for more information on preventing this. ++ ++Additionally, unless lockdown mode is enabled: ++ ++@itemize ++@item Special care must be taken around the @command{loadenv} command, which ++ can be used to turn off @code{check_appended_signature}. ++ ++@item If the grub configuration file is loaded from the disk, anyone who can ++ modify the file on disk can turn off @code{check_appended_signature}. ++ Consider embedding the configuration into the core grub image. ++@end itemize ++ + @node UEFI secure boot and shim + @section UEFI secure boot and shim support + diff --git a/0180-10_linux.in-Also-use-GRUB_CMDLINE_LINUX_DEFAULT-to-s.patch b/0180-10_linux.in-Also-use-GRUB_CMDLINE_LINUX_DEFAULT-to-s.patch deleted file mode 100644 index d40d7d1f16ed34462640eb196885efd2fde704cc..0000000000000000000000000000000000000000 --- a/0180-10_linux.in-Also-use-GRUB_CMDLINE_LINUX_DEFAULT-to-s.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 867888c0e7570ed08c47ce546ccdc61b63e2a449 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 15 Oct 2019 09:08:25 +0200 -Subject: [PATCH 180/220] 10_linux.in: Also use GRUB_CMDLINE_LINUX_DEFAULT to - set kernelopts - -The GRUB documentation mentions that there are two variables to set the -linux kernel cmdline: GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT. - -The former is added to all the menuentry commands and the latter is not -added to the recovery mode menu entries. But the blscfg module doesn't -populate recovery entries from the BLS snippets, so the values set in the -GRUB_CMDLINE_LINUX_DEFAULT variable should also be included in kernelopts. - -This is needed because the GRUB_CMDLINE_LINUX_DEFAULT option is mentioned -in the GRUB documentation so users assume that the kernel cmdline options -can be changed by setting this option and running the grub2-mkconfig tool. - -Signed-off-by: Javier Martinez Canillas ---- - util/grub.d/10_linux.in | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 1520b7e..0471464 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -118,7 +118,7 @@ if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then - populate_header_warn - - cat << EOF --set default_kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX}" -+set default_kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" - - insmod blscfg - blscfg -@@ -134,7 +134,7 @@ EOF - fi - fi - -- ${grub_editenv} - set kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX}" -+ ${grub_editenv} - set kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" - if [ -n "${GRUB_EARLY_INITRD_LINUX_CUSTOM}" ]; then - ${grub_editenv} - set early_initrd="${GRUB_EARLY_INITRD_LINUX_CUSTOM}" - fi --- -1.8.3.1 - diff --git a/0180-ieee1275-enter-lockdown-based-on-ibm-secure-boot.patch b/0180-ieee1275-enter-lockdown-based-on-ibm-secure-boot.patch new file mode 100644 index 0000000000000000000000000000000000000000..40c3b3e843aeb8ae83d43012f63e5d9bae11606c --- /dev/null +++ b/0180-ieee1275-enter-lockdown-based-on-ibm-secure-boot.patch @@ -0,0 +1,109 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Mon, 28 Sep 2020 11:11:17 +1000 +Subject: [PATCH] ieee1275: enter lockdown based on /ibm,secure-boot + +If the 'ibm,secure-boot' property of the root node is 2 or greater, +enter lockdown. + +Signed-off-by: Daniel Axtens +--- + grub-core/Makefile.core.def | 1 + + grub-core/kern/ieee1275/init.c | 27 +++++++++++++++++++++++++++ + include/grub/lockdown.h | 3 ++- + docs/grub.texi | 4 ++-- + 4 files changed, 32 insertions(+), 3 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 6bddc841b85..3f3459b2c70 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -323,6 +323,7 @@ kernel = { + powerpc_ieee1275 = kern/powerpc/cache.S; + powerpc_ieee1275 = kern/powerpc/dl.c; + powerpc_ieee1275 = kern/powerpc/compiler-rt.S; ++ powerpc_ieee1275 = kern/lockdown.c; + + sparc64_ieee1275 = kern/sparc64/cache.S; + sparc64_ieee1275 = kern/sparc64/dl.c; +diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c +index 937c1bc44cb..fc7d9712729 100644 +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -44,6 +44,7 @@ + #ifdef __sparc__ + #include + #endif ++#include + + /* The minimal heap size we can live with. */ + #define HEAP_MIN_SIZE (unsigned long) (2 * 1024 * 1024) +@@ -271,6 +272,30 @@ grub_parse_cmdline (void) + } + } + ++static void ++grub_get_ieee1275_secure_boot (void) ++{ ++ grub_ieee1275_phandle_t root; ++ int rc; ++ grub_uint32_t is_sb; ++ ++ grub_ieee1275_finddevice ("/", &root); ++ ++ rc = grub_ieee1275_get_integer_property (root, "ibm,secure-boot", &is_sb, ++ sizeof (is_sb), 0); ++ ++ /* ibm,secure-boot: ++ * 0 - disabled ++ * 1 - audit ++ * 2 - enforce ++ * 3 - enforce + OS-specific behaviour ++ * ++ * We only support enforce. ++ */ ++ if (rc >= 0 && is_sb >= 2) ++ grub_lockdown (); ++} ++ + grub_addr_t grub_modbase; + + void +@@ -296,6 +321,8 @@ grub_machine_init (void) + #else + grub_install_get_time_ms (grub_rtc_get_time_ms); + #endif ++ ++ grub_get_ieee1275_secure_boot (); + } + + void +diff --git a/include/grub/lockdown.h b/include/grub/lockdown.h +index 40531fa823b..ebfee4bf06e 100644 +--- a/include/grub/lockdown.h ++++ b/include/grub/lockdown.h +@@ -24,7 +24,8 @@ + #define GRUB_LOCKDOWN_DISABLED 0 + #define GRUB_LOCKDOWN_ENABLED 1 + +-#ifdef GRUB_MACHINE_EFI ++#if defined(GRUB_MACHINE_EFI) || \ ++ (defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275)) + extern void + EXPORT_FUNC (grub_lockdown) (void); + extern int +diff --git a/docs/grub.texi b/docs/grub.texi +index 4816be85611..a4da9c2a1b9 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -6227,8 +6227,8 @@ Measured boot is currently only supported on EFI platforms. + @section Lockdown when booting on a secure setup + + The GRUB can be locked down when booted on a secure boot environment, for example +-if the UEFI secure boot is enabled. On a locked down configuration, the GRUB will +-be restricted and some operations/commands cannot be executed. ++if UEFI or Power secure boot is enabled. On a locked down configuration, the ++GRUB will be restricted and some operations/commands cannot be executed. + + The @samp{lockdown} variable is set to @samp{y} when the GRUB is locked down. + Otherwise it does not exit. diff --git a/0181-blscfg-Don-t-hardcode-an-env-var-as-fallback-for-the.patch b/0181-blscfg-Don-t-hardcode-an-env-var-as-fallback-for-the.patch deleted file mode 100644 index bce20a17887e2c9ce4af3bdf48062c5fb6b64f64..0000000000000000000000000000000000000000 --- a/0181-blscfg-Don-t-hardcode-an-env-var-as-fallback-for-the.patch +++ /dev/null @@ -1,66 +0,0 @@ -From aefccfaac8af45dba1b9f08ecbf95c7343d8b4b6 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Mon, 14 Oct 2019 17:37:26 +0200 -Subject: [PATCH 181/220] blscfg: Don't hardcode an env var as fallback for the - BLS options field - -If the BLS fragments don't have an options field or if this was set to an -environment variable that was not defined in the grubenv file, the blscfg -module searches for an default_kernelopts variable that is defined in the -grub.cfg file. - -But the blscfg module shouldn't hardcode fallbacks variables and instead -this logic should be handled in the GRUB config file itself. - -Also, add a comment explaining where the kernelopts variable is supposed -to be defined and what is the process for the user to change its value. - -Resolves: rhbz#1710483 - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/commands/blscfg.c | 4 ---- - util/grub.d/10_linux.in | 12 +++++++++++- - 2 files changed, 11 insertions(+), 5 deletions(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 1ec8987..471975f 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -733,10 +733,6 @@ static void create_entry (struct bls_entry *entry) - - title = bls_get_val (entry, "title", NULL); - options = expand_val (bls_get_val (entry, "options", NULL)); -- -- if (!options) -- options = expand_val (grub_env_get("default_kernelopts")); -- - initrds = bls_make_list (entry, "initrd", NULL); - - devicetree = expand_val (bls_get_val (entry, "devicetree", NULL)); -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 0471464..21a6915 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -118,7 +118,17 @@ if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then - populate_header_warn - - cat << EOF --set default_kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" -+# The kernelopts variable should be defined in the grubenv file. But to ensure that menu -+# entries populated from BootLoaderSpec files that use this variable work correctly even -+# without a grubenv file, define a fallback kernelopts variable if this has not been set. -+# -+# The kernelopts variable in the grubenv file can be modified using the grubby tool or by -+# executing the grub2-mkconfig tool. For the latter, the values of the GRUB_CMDLINE_LINUX -+# and GRUB_CMDLINE_LINUX_DEFAULT options from /etc/default/grub file are used to set both -+# the kernelopts variable in the grubenv file and the fallback kernelopts variable. -+if [ -z "\${kernelopts}" ]; then -+ set kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" -+fi - - insmod blscfg - blscfg --- -1.8.3.1 - diff --git a/0181-ieee1275-drop-HEAP_MAX_ADDR-HEAP_MIN_SIZE.patch b/0181-ieee1275-drop-HEAP_MAX_ADDR-HEAP_MIN_SIZE.patch new file mode 100644 index 0000000000000000000000000000000000000000..52fa9d23ad87b40be5fd125a7df1ecac8726751c --- /dev/null +++ b/0181-ieee1275-drop-HEAP_MAX_ADDR-HEAP_MIN_SIZE.patch @@ -0,0 +1,75 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Wed, 14 Apr 2021 20:10:23 +1000 +Subject: [PATCH] ieee1275: drop HEAP_MAX_ADDR, HEAP_MIN_SIZE + +HEAP_MAX_ADDR is confusing. Currently it is set to 32MB, except +on ieee1275 on x86, where it is 64MB. + +There is a comment which purports to explain it: + +/* If possible, we will avoid claiming heap above this address, because it + seems to cause relocation problems with OSes that link at 4 MiB */ + +This doesn't make a lot of sense when the constants are well above 4MB +already. It was not always this way. Prior to +commit 7b5d0fe4440c ("Increase heap limit") in 2010, HEAP_MAX_SIZE and +HEAP_MAX_ADDR were indeed 4MB. However, when the constants were increased +the comment was left unchanged. + +It's been over a decade. It doesn't seem like we have problems with +claims over 4MB on powerpc or x86 ieee1275. (sparc does things completely +differently and never used the constant.) + +Drop the constant and the check. + +The only use of HEAP_MIN_SIZE was to potentially override the +HEAP_MAX_ADDR check. It is now unused. Remove it. + +Signed-off-by: Daniel Axtens +--- + grub-core/kern/ieee1275/init.c | 17 ----------------- + 1 file changed, 17 deletions(-) + +diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c +index fc7d9712729..0dcd114ce54 100644 +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -46,9 +46,6 @@ + #endif + #include + +-/* The minimal heap size we can live with. */ +-#define HEAP_MIN_SIZE (unsigned long) (2 * 1024 * 1024) +- + /* The maximum heap size we're going to claim */ + #ifdef __i386__ + #define HEAP_MAX_SIZE (unsigned long) (64 * 1024 * 1024) +@@ -56,14 +53,6 @@ + #define HEAP_MAX_SIZE (unsigned long) (32 * 1024 * 1024) + #endif + +-/* If possible, we will avoid claiming heap above this address, because it +- seems to cause relocation problems with OSes that link at 4 MiB */ +-#ifdef __i386__ +-#define HEAP_MAX_ADDR (unsigned long) (64 * 1024 * 1024) +-#else +-#define HEAP_MAX_ADDR (unsigned long) (32 * 1024 * 1024) +-#endif +- + extern char _end[]; + + #ifdef __sparc__ +@@ -185,12 +174,6 @@ heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, + if (*total + len > HEAP_MAX_SIZE) + len = HEAP_MAX_SIZE - *total; + +- /* Avoid claiming anything above HEAP_MAX_ADDR, if possible. */ +- if ((addr < HEAP_MAX_ADDR) && /* if it's too late, don't bother */ +- (addr + len > HEAP_MAX_ADDR) && /* if it wasn't available anyway, don't bother */ +- (*total + (HEAP_MAX_ADDR - addr) > HEAP_MIN_SIZE)) /* only limit ourselves when we can afford to */ +- len = HEAP_MAX_ADDR - addr; +- + /* In theory, firmware should already prevent this from happening by not + listing our own image in /memory/available. The check below is intended + as a safeguard in case that doesn't happen. However, it doesn't protect diff --git a/0182-ieee1275-claim-more-memory.patch b/0182-ieee1275-claim-more-memory.patch new file mode 100644 index 0000000000000000000000000000000000000000..001a9df04b0b8148294a459f0235ea83ae393d0d --- /dev/null +++ b/0182-ieee1275-claim-more-memory.patch @@ -0,0 +1,252 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Wed, 15 Apr 2020 23:28:29 +1000 +Subject: [PATCH] ieee1275: claim more memory + +On powerpc-ieee1275, we are running out of memory trying to verify +anything. This is because: + + - we have to load an entire file into memory to verify it. This is + extremely difficult to change with appended signatures. + - We only have 32MB of heap. + - Distro kernels are now often around 30MB. + +So we want to claim more memory from OpenFirmware for our heap. + +There are some complications: + + - The grub mm code isn't the only thing that will make claims on + memory from OpenFirmware: + + * PFW/SLOF will have claimed some for their own use. + + * The ieee1275 loader will try to find other bits of memory that we + haven't claimed to place the kernel and initrd when we go to boot. + + * Once we load Linux, it will also try to claim memory. It claims + memory without any reference to /memory/available, it just starts + at min(top of RMO, 768MB) and works down. So we need to avoid this + area. See arch/powerpc/kernel/prom_init.c as of v5.11. + + - The smallest amount of memory a ppc64 KVM guest can have is 256MB. + It doesn't work with distro kernels but can work with custom kernels. + We should maintain support for that. (ppc32 can boot with even less, + and we shouldn't break that either.) + + - Even if a VM has more memory, the memory OpenFirmware makes available + as Real Memory Area can be restricted. A freshly created LPAR on a + PowerVM machine is likely to have only 256MB available to OpenFirmware + even if it has many gigabytes of memory allocated. + +EFI systems will attempt to allocate 1/4th of the available memory, +clamped to between 1M and 1600M. That seems like a good sort of +approach, we just need to figure out if 1/4 is the right fraction +for us. + +We don't know in advance how big the kernel and initrd are going to be, +which makes figuring out how much memory we can take a bit tricky. + +To figure out how much memory we should leave unused, I looked at: + + - an Ubuntu 20.04.1 ppc64le pseries KVM guest: + vmlinux: ~30MB + initrd: ~50MB + + - a RHEL8.2 ppc64le pseries KVM guest: + vmlinux: ~30MB + initrd: ~30MB + +Ubuntu VMs struggle to boot with just 256MB under SLOF. +RHEL likewise has a higher minimum supported memory figure. +So lets first consider a distro kernel and 512MB of addressible memory. +(This is the default case for anything booting under PFW.) Say we lose +131MB to PFW (based on some tests). This leaves us 381MB. 1/4 of 381MB +is ~95MB. That should be enough to verify a 30MB vmlinux and should +leave plenty of space to load Linux and the initrd. + +If we consider 256MB of RMA under PFW, we have just 125MB remaining. 1/4 +of that is a smidge under 32MB, which gives us very poor odds of verifying +a distro-sized kernel. However, if we need 80MB just to put the kernel +and initrd in memory, we can't claim any more than 45MB anyway. So 1/4 +will do. We'll come back to this later. + +grub is always built as a 32-bit binary, even if it's loading a ppc64 +kernel. So we can't address memory beyond 4GB. This gives a natural cap +of 1GB for powerpc-ieee1275. + +Also apply this 1/4 approach to i386-ieee1275, but keep the 32MB cap. + +make check still works for both i386 and powerpc and I've booted +powerpc grub with this change under SLOF and PFW. + +Signed-off-by: Daniel Axtens +--- + grub-core/kern/ieee1275/init.c | 81 +++++++++++++++++++++++++++++++++--------- + docs/grub-dev.texi | 6 ++-- + 2 files changed, 69 insertions(+), 18 deletions(-) + +diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c +index 0dcd114ce54..c61d91a0285 100644 +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -46,11 +46,12 @@ + #endif + #include + +-/* The maximum heap size we're going to claim */ ++/* The maximum heap size we're going to claim. Not used by sparc. ++ We allocate 1/4 of the available memory under 4G, up to this limit. */ + #ifdef __i386__ + #define HEAP_MAX_SIZE (unsigned long) (64 * 1024 * 1024) +-#else +-#define HEAP_MAX_SIZE (unsigned long) (32 * 1024 * 1024) ++#else // __powerpc__ ++#define HEAP_MAX_SIZE (unsigned long) (1 * 1024 * 1024 * 1024) + #endif + + extern char _end[]; +@@ -147,16 +148,45 @@ grub_claim_heap (void) + + GRUB_KERNEL_MACHINE_STACK_SIZE), 0x200000); + } + #else +-/* Helper for grub_claim_heap. */ ++/* Helper for grub_claim_heap on powerpc. */ ++static int ++heap_size (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, ++ void *data) ++{ ++ grub_uint32_t total = *(grub_uint32_t *)data; ++ ++ if (type != GRUB_MEMORY_AVAILABLE) ++ return 0; ++ ++ /* Do not consider memory beyond 4GB */ ++ if (addr > 0xffffffffUL) ++ return 0; ++ ++ if (addr + len > 0xffffffffUL) ++ len = 0xffffffffUL - addr; ++ ++ total += len; ++ *(grub_uint32_t *)data = total; ++ ++ return 0; ++} ++ + static int + heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, + void *data) + { +- unsigned long *total = data; ++ grub_uint32_t total = *(grub_uint32_t *)data; + + if (type != GRUB_MEMORY_AVAILABLE) + return 0; + ++ /* Do not consider memory beyond 4GB */ ++ if (addr > 0xffffffffUL) ++ return 0; ++ ++ if (addr + len > 0xffffffffUL) ++ len = 0xffffffffUL - addr; ++ + if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM)) + { + if (addr + len <= 0x180000) +@@ -170,10 +200,6 @@ heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, + } + len -= 1; /* Required for some firmware. */ + +- /* Never exceed HEAP_MAX_SIZE */ +- if (*total + len > HEAP_MAX_SIZE) +- len = HEAP_MAX_SIZE - *total; +- + /* In theory, firmware should already prevent this from happening by not + listing our own image in /memory/available. The check below is intended + as a safeguard in case that doesn't happen. However, it doesn't protect +@@ -185,6 +211,18 @@ heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, + len = 0; + } + ++ /* If this block contains 0x30000000 (768MB), do not claim below that. ++ Linux likes to claim memory at min(RMO top, 768MB) and works down ++ without reference to /memory/available. */ ++ if ((addr < 0x30000000) && ((addr + len) > 0x30000000)) ++ { ++ len = len - (0x30000000 - addr); ++ addr = 0x30000000; ++ } ++ ++ if (len > total) ++ len = total; ++ + if (len) + { + grub_err_t err; +@@ -193,10 +231,12 @@ heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, + if (err) + return err; + grub_mm_init_region ((void *) (grub_addr_t) addr, len); ++ total -= len; + } + +- *total += len; +- if (*total >= HEAP_MAX_SIZE) ++ *(grub_uint32_t *)data = total; ++ ++ if (total == 0) + return 1; + + return 0; +@@ -205,13 +245,22 @@ heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, + static void + grub_claim_heap (void) + { +- unsigned long total = 0; ++ grub_uint32_t total = 0; + + if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_FORCE_CLAIM)) +- heap_init (GRUB_IEEE1275_STATIC_HEAP_START, GRUB_IEEE1275_STATIC_HEAP_LEN, +- 1, &total); +- else +- grub_machine_mmap_iterate (heap_init, &total); ++ { ++ heap_init (GRUB_IEEE1275_STATIC_HEAP_START, GRUB_IEEE1275_STATIC_HEAP_LEN, ++ 1, &total); ++ return; ++ } ++ ++ grub_machine_mmap_iterate (heap_size, &total); ++ ++ total = total / 4; ++ if (total > HEAP_MAX_SIZE) ++ total = HEAP_MAX_SIZE; ++ ++ grub_machine_mmap_iterate (heap_init, &total); + } + #endif + +diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi +index 19f708ee662..90083772c8a 100644 +--- a/docs/grub-dev.texi ++++ b/docs/grub-dev.texi +@@ -1047,7 +1047,9 @@ space is limited to 4GiB. GRUB allocates pages from EFI for its heap, at most + 1.6 GiB. + + On i386-ieee1275 and powerpc-ieee1275 GRUB uses same stack as IEEE1275. +-It allocates at most 32MiB for its heap. ++ ++On i386-ieee1275, GRUB allocates at most 32MiB for its heap. On ++powerpc-ieee1275, GRUB allocates up to 1GiB. + + On sparc64-ieee1275 stack is 256KiB and heap is 2MiB. + +@@ -1075,7 +1077,7 @@ In short: + @item i386-qemu @tab 60 KiB @tab < 4 GiB + @item *-efi @tab ? @tab < 1.6 GiB + @item i386-ieee1275 @tab ? @tab < 32 MiB +-@item powerpc-ieee1275 @tab ? @tab < 32 MiB ++@item powerpc-ieee1275 @tab ? @tab < 1 GiB + @item sparc64-ieee1275 @tab 256KiB @tab 2 MiB + @item arm-uboot @tab 256KiB @tab 2 MiB + @item mips(el)-qemu_mips @tab 2MiB @tab 253 MiB diff --git a/0183-ieee1275-request-memory-with-ibm-client-architecture.patch b/0183-ieee1275-request-memory-with-ibm-client-architecture.patch new file mode 100644 index 0000000000000000000000000000000000000000..6e6c1f0cf798dc4c9c7a5aca77cb1c9e6e26465f --- /dev/null +++ b/0183-ieee1275-request-memory-with-ibm-client-architecture.patch @@ -0,0 +1,268 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Fri, 16 Apr 2021 11:48:46 +1000 +Subject: [PATCH] ieee1275: request memory with ibm,client-architecture-support + +On PowerVM, the first time we boot a Linux partition, we may only get +256MB of real memory area, even if the partition has more memory. + +This isn't really enough. Fortunately, the Power Architecture Platform +Reference (PAPR) defines a method we can call to ask for more memory. +This is part of the broad and powerful ibm,client-architecture-support +(CAS) method. + +CAS can do an enormous amount of things on a PAPR platform: as well as +asking for memory, you can set the supported processor level, the interrupt +controller, hash vs radix mmu, and so on. We want to touch as little of +this as possible because we don't want to step on the toes of the future OS. + +If: + + - we are running under what we think is PowerVM (compatible property of / + begins with "IBM"), and + + - the full amount of RMA is less than 512MB (as determined by the reg + property of /memory) + +then call CAS as follows: (refer to the Linux on Power Architecture +Reference, LoPAR, which is public, at B.5.2.3): + + - Use the "any" PVR value and supply 2 option vectors. + + - Set option vector 1 (PowerPC Server Processor Architecture Level) + to "ignore". + + - Set option vector 2 with default or Linux-like options, including a + min-rma-size of 512MB. + +This will cause a CAS reboot and the partition will restart with 512MB +of RMA. Grub will notice the 512MB and not call CAS again. + +(A partition can be configured with only 256MB of memory, which would +mean this request couldn't be satisfied, but PFW refuses to load with +only 256MB of memory, so it's a bit moot. SLOF will run fine with 256MB, +but we will never call CAS under qemu/SLOF because /compatible won't +begin with "IBM".) + +One of the first things Linux does while still running under OpenFirmware +is to call CAS with a much fuller set of options (including asking for +512MB of memory). This includes a much more restrictive set of PVR values +and processor support levels, and this will induce another reboot. On this +reboot grub will again notice the higher RMA, and not call CAS. We will get +to Linux, Linux will call CAS but because the values are now set for Linux +this will not induce another CAS reboot and we will finally boot. + +On all subsequent boots, everything will be configured with 512MB of RMA +and all the settings Linux likes, so there will be no further CAS reboots. + +(phyp is super sticky with the RMA size - it persists even on cold boots. +So if you've ever booted Linux in a partition, you'll probably never have +grub call CAS. It'll only ever fire the first time a partition loads grub, +or if you deliberately lower the amount of memory your partition has below +512MB.) + +Signed-off-by: Daniel Axtens +--- + grub-core/kern/ieee1275/cmain.c | 3 + + grub-core/kern/ieee1275/init.c | 144 ++++++++++++++++++++++++++++++++++++++- + include/grub/ieee1275/ieee1275.h | 8 ++- + 3 files changed, 152 insertions(+), 3 deletions(-) + +diff --git a/grub-core/kern/ieee1275/cmain.c b/grub-core/kern/ieee1275/cmain.c +index 04df9d2c667..6435628ec57 100644 +--- a/grub-core/kern/ieee1275/cmain.c ++++ b/grub-core/kern/ieee1275/cmain.c +@@ -127,6 +127,9 @@ grub_ieee1275_find_options (void) + break; + } + } ++ ++ if (grub_strncmp (tmp, "IBM,", 4) == 0) ++ grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CAN_TRY_CAS_FOR_MORE_MEMORY); + } + + if (is_smartfirmware) +diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c +index c61d91a0285..9704715c837 100644 +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -242,6 +242,135 @@ heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, + return 0; + } + ++/* How much memory does OF believe it has? (regardless of whether ++ it's accessible or not) */ ++static grub_err_t ++grub_ieee1275_total_mem (grub_uint64_t *total) ++{ ++ grub_ieee1275_phandle_t root; ++ grub_ieee1275_phandle_t memory; ++ grub_uint32_t reg[4]; ++ grub_ssize_t reg_size; ++ grub_uint32_t address_cells = 1; ++ grub_uint32_t size_cells = 1; ++ grub_uint64_t size; ++ ++ /* If we fail to get to the end, report 0. */ ++ *total = 0; ++ ++ /* Determine the format of each entry in `reg'. */ ++ grub_ieee1275_finddevice ("/", &root); ++ grub_ieee1275_get_integer_property (root, "#address-cells", &address_cells, ++ sizeof address_cells, 0); ++ grub_ieee1275_get_integer_property (root, "#size-cells", &size_cells, ++ sizeof size_cells, 0); ++ ++ if (size_cells > address_cells) ++ address_cells = size_cells; ++ ++ /* Load `/memory/reg'. */ ++ if (grub_ieee1275_finddevice ("/memory", &memory)) ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, ++ "couldn't find /memory node"); ++ if (grub_ieee1275_get_integer_property (memory, "reg", reg, ++ sizeof reg, ®_size)) ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, ++ "couldn't examine /memory/reg property"); ++ if (reg_size < 0 || (grub_size_t) reg_size > sizeof (reg)) ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, ++ "/memory response buffer exceeded"); ++ ++ if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS)) ++ { ++ address_cells = 1; ++ size_cells = 1; ++ } ++ ++ /* Decode only the size */ ++ size = reg[address_cells]; ++ if (size_cells == 2) ++ size = (size << 32) | reg[address_cells + 1]; ++ ++ *total = size; ++ ++ return grub_errno; ++} ++ ++/* Based on linux - arch/powerpc/kernel/prom_init.c */ ++struct option_vector2 { ++ grub_uint8_t byte1; ++ grub_uint16_t reserved; ++ grub_uint32_t real_base; ++ grub_uint32_t real_size; ++ grub_uint32_t virt_base; ++ grub_uint32_t virt_size; ++ grub_uint32_t load_base; ++ grub_uint32_t min_rma; ++ grub_uint32_t min_load; ++ grub_uint8_t min_rma_percent; ++ grub_uint8_t max_pft_size; ++} __attribute__((packed)); ++ ++struct pvr_entry { ++ grub_uint32_t mask; ++ grub_uint32_t entry; ++}; ++ ++struct cas_vector { ++ struct { ++ struct pvr_entry terminal; ++ } pvr_list; ++ grub_uint8_t num_vecs; ++ grub_uint8_t vec1_size; ++ grub_uint8_t vec1; ++ grub_uint8_t vec2_size; ++ struct option_vector2 vec2; ++} __attribute__((packed)); ++ ++/* Call ibm,client-architecture-support to try to get more RMA. ++ We ask for 512MB which should be enough to verify a distro kernel. ++ We ignore most errors: if we don't succeed we'll proceed with whatever ++ memory we have. */ ++static void ++grub_ieee1275_ibm_cas (void) ++{ ++ int rc; ++ grub_ieee1275_ihandle_t root; ++ struct cas_args { ++ struct grub_ieee1275_common_hdr common; ++ grub_ieee1275_cell_t method; ++ grub_ieee1275_ihandle_t ihandle; ++ grub_ieee1275_cell_t cas_addr; ++ grub_ieee1275_cell_t result; ++ } args; ++ struct cas_vector vector = { ++ .pvr_list = { { 0x00000000, 0xffffffff } }, /* any processor */ ++ .num_vecs = 2 - 1, ++ .vec1_size = 0, ++ .vec1 = 0x80, /* ignore */ ++ .vec2_size = 1 + sizeof(struct option_vector2) - 2, ++ .vec2 = { ++ 0, 0, -1, -1, -1, -1, -1, 512, -1, 0, 48 ++ }, ++ }; ++ ++ INIT_IEEE1275_COMMON (&args.common, "call-method", 3, 2); ++ args.method = (grub_ieee1275_cell_t)"ibm,client-architecture-support"; ++ rc = grub_ieee1275_open("/", &root); ++ if (rc) { ++ grub_error (GRUB_ERR_IO, "could not open root when trying to call CAS"); ++ return; ++ } ++ args.ihandle = root; ++ args.cas_addr = (grub_ieee1275_cell_t)&vector; ++ ++ grub_printf("Calling ibm,client-architecture-support..."); ++ IEEE1275_CALL_ENTRY_FN (&args); ++ grub_printf("done\n"); ++ ++ grub_ieee1275_close(root); ++} ++ + static void + grub_claim_heap (void) + { +@@ -249,11 +378,22 @@ grub_claim_heap (void) + + if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_FORCE_CLAIM)) + { +- heap_init (GRUB_IEEE1275_STATIC_HEAP_START, GRUB_IEEE1275_STATIC_HEAP_LEN, +- 1, &total); ++ heap_init (GRUB_IEEE1275_STATIC_HEAP_START, ++ GRUB_IEEE1275_STATIC_HEAP_LEN, 1, &total); + return; + } + ++ if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CAN_TRY_CAS_FOR_MORE_MEMORY)) ++ { ++ grub_uint64_t rma_size; ++ grub_err_t err; ++ ++ err = grub_ieee1275_total_mem (&rma_size); ++ /* if we have an error, don't call CAS, just hope for the best */ ++ if (!err && rma_size < (512 * 1024 * 1024)) ++ grub_ieee1275_ibm_cas(); ++ } ++ + grub_machine_mmap_iterate (heap_size, &total); + + total = total / 4; +diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h +index b5a1d49bbc3..e0a6c2ce1e6 100644 +--- a/include/grub/ieee1275/ieee1275.h ++++ b/include/grub/ieee1275/ieee1275.h +@@ -149,7 +149,13 @@ enum grub_ieee1275_flag + + GRUB_IEEE1275_FLAG_RAW_DEVNAMES, + +- GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT ++ GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT, ++ ++ /* On PFW, the first time we boot a Linux partition, we may only get 256MB ++ of real memory area, even if the partition has more memory. Set this flag ++ if we think we're running under PFW. Then, if this flag is set, and the ++ RMA is only 256MB in size, try asking for more with CAS. */ ++ GRUB_IEEE1275_FLAG_CAN_TRY_CAS_FOR_MORE_MEMORY, + }; + + extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag); diff --git a/0184-appendedsig-x509-Also-handle-the-Extended-Key-Usage-.patch b/0184-appendedsig-x509-Also-handle-the-Extended-Key-Usage-.patch new file mode 100644 index 0000000000000000000000000000000000000000..a237a217af6c59c4de2a6f39131349acb18922d7 --- /dev/null +++ b/0184-appendedsig-x509-Also-handle-the-Extended-Key-Usage-.patch @@ -0,0 +1,315 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Sat, 8 May 2021 02:27:58 +0200 +Subject: [PATCH] appendedsig/x509: Also handle the Extended Key Usage + extension + +Red Hat certificates have both Key Usage and Extended Key Usage extensions +present, but the appended signatures x509 parser doesn't handle the latter +and so buils due finding an unrecognised critical extension: + +Error loading initial key: +../../grub-core/commands/appendedsig/x509.c:780:Unhandled critical x509 extension with OID 2.5.29.37 + +Fix this by also parsing the Extended Key Usage extension and handle it by +verifying that the certificate has a single purpose, that is code signing. + +Signed-off-by: Javier Martinez Canillas +Signed-off-by: Daniel Axtens +--- + grub-core/commands/appendedsig/x509.c | 94 ++++++++++++++++++++++++++++++- + grub-core/tests/appended_signature_test.c | 29 +++++++++- + grub-core/tests/appended_signatures.h | 81 ++++++++++++++++++++++++++ + 3 files changed, 201 insertions(+), 3 deletions(-) + +diff --git a/grub-core/commands/appendedsig/x509.c b/grub-core/commands/appendedsig/x509.c +index 2b38b3670a2..42ec65c54aa 100644 +--- a/grub-core/commands/appendedsig/x509.c ++++ b/grub-core/commands/appendedsig/x509.c +@@ -47,6 +47,12 @@ const char *keyUsage_oid = "2.5.29.15"; + */ + const char *basicConstraints_oid = "2.5.29.19"; + ++/* ++ * RFC 5280 4.2.1.12 Extended Key Usage ++ */ ++const char *extendedKeyUsage_oid = "2.5.29.37"; ++const char *codeSigningUsage_oid = "1.3.6.1.5.5.7.3.3"; ++ + /* + * RFC 3279 2.3.1 + * +@@ -637,6 +643,77 @@ cleanup: + return err; + } + ++/* ++ * ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId ++ * ++ * KeyPurposeId ::= OBJECT IDENTIFIER ++ */ ++static grub_err_t ++verify_extended_key_usage (grub_uint8_t * value, int value_size) ++{ ++ asn1_node extendedasn; ++ int result, count; ++ grub_err_t err = GRUB_ERR_NONE; ++ char usage[MAX_OID_LEN]; ++ int usage_size = sizeof (usage); ++ ++ result = ++ asn1_create_element (_gnutls_pkix_asn, "PKIX1.ExtKeyUsageSyntax", ++ &extendedasn); ++ if (result != ASN1_SUCCESS) ++ { ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "Could not create ASN.1 structure for Extended Key Usage"); ++ } ++ ++ result = asn1_der_decoding2 (&extendedasn, value, &value_size, ++ ASN1_DECODE_FLAG_STRICT_DER, asn1_error); ++ if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error parsing DER for Extended Key Usage: %s", ++ asn1_error); ++ goto cleanup; ++ } ++ ++ /* ++ * If EKUs are present, there must be exactly 1 and it must be a ++ * codeSigning usage. ++ */ ++ result = asn1_number_of_elements(extendedasn, "", &count); ++ if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error counting number of Extended Key Usages: %s", ++ asn1_strerror (result)); ++ goto cleanup; ++ } ++ ++ result = asn1_read_value (extendedasn, "?1", usage, &usage_size); ++ if (result != ASN1_SUCCESS) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Error reading Extended Key Usage: %s", ++ asn1_strerror (result)); ++ goto cleanup; ++ } ++ ++ if (grub_strncmp (codeSigningUsage_oid, usage, usage_size) != 0) ++ { ++ err = ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Unexpected Extended Key Usage OID, got: %s", ++ usage); ++ goto cleanup; ++ } ++ ++cleanup: ++ asn1_delete_structure (&extendedasn); ++ return err; ++} + + /* + * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension +@@ -660,7 +737,7 @@ verify_extensions (asn1_node cert) + { + int result; + int ext, num_extensions = 0; +- int usage_present = 0, constraints_present = 0; ++ int usage_present = 0, constraints_present = 0, extended_usage_present = 0; + char *oid_path, *critical_path, *value_path; + char extnID[MAX_OID_LEN]; + int extnID_size; +@@ -754,6 +831,15 @@ verify_extensions (asn1_node cert) + } + constraints_present++; + } ++ else if (grub_strncmp (extendedKeyUsage_oid, extnID, extnID_size) == 0) ++ { ++ err = verify_extended_key_usage (value, value_size); ++ if (err != GRUB_ERR_NONE) ++ { ++ goto cleanup_value; ++ } ++ extended_usage_present++; ++ } + else if (grub_strncmp ("TRUE", critical, critical_size) == 0) + { + /* +@@ -785,6 +871,12 @@ verify_extensions (asn1_node cert) + "Unexpected number of basic constraints extensions - expected 1, got %d", + constraints_present); + } ++ if (extended_usage_present > 1) ++ { ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "Unexpected number of Extended Key Usage extensions - expected 0 or 1, got %d", ++ extended_usage_present); ++ } + return GRUB_ERR_NONE; + + cleanup_value: +diff --git a/grub-core/tests/appended_signature_test.c b/grub-core/tests/appended_signature_test.c +index 88a485200d8..dbba0616621 100644 +--- a/grub-core/tests/appended_signature_test.c ++++ b/grub-core/tests/appended_signature_test.c +@@ -111,6 +111,22 @@ static struct grub_procfs_entry certificate_printable_der_entry = { + .get_contents = get_certificate_printable_der + }; + ++static char * ++get_certificate_eku_der (grub_size_t * sz) ++{ ++ char *ret; ++ *sz = certificate_eku_der_len; ++ ret = grub_malloc (*sz); ++ if (ret) ++ grub_memcpy (ret, certificate_eku_der, *sz); ++ return ret; ++} ++ ++static struct grub_procfs_entry certificate_eku_der_entry = { ++ .name = "certificate_eku.der", ++ .get_contents = get_certificate_eku_der ++}; ++ + + static void + do_verify (const char *f, int is_valid) +@@ -149,6 +165,7 @@ appended_signature_test (void) + char *trust_args2[] = { (char *) "(proc)/certificate2.der", NULL }; + char *trust_args_printable[] = { (char *) "(proc)/certificate_printable.der", + NULL }; ++ char *trust_args_eku[] = { (char *) "(proc)/certificate_eku.der", NULL }; + char *distrust_args[] = { (char *) "1", NULL }; + char *distrust2_args[] = { (char *) "2", NULL }; + grub_err_t err; +@@ -157,6 +174,7 @@ appended_signature_test (void) + grub_procfs_register ("certificate2.der", &certificate2_der_entry); + grub_procfs_register ("certificate_printable.der", + &certificate_printable_der_entry); ++ grub_procfs_register ("certificate_eku.der", &certificate_eku_der_entry); + + cmd_trust = grub_command_find ("trust_certificate"); + if (!cmd_trust) +@@ -266,16 +284,23 @@ appended_signature_test (void) + + /* + * Lastly, check a certificate that uses printableString rather than +- * utf8String loads properly. ++ * utf8String loads properly, and that a certificate with an appropriate ++ * extended key usage loads. + */ + err = (cmd_trust->func) (cmd_trust, 1, trust_args_printable); + grub_test_assert (err == GRUB_ERR_NONE, +- "distrusting printable certificate failed: %d: %s", ++ "trusting printable certificate failed: %d: %s", ++ grub_errno, grub_errmsg); ++ ++ err = (cmd_trust->func) (cmd_trust, 1, trust_args_eku); ++ grub_test_assert (err == GRUB_ERR_NONE, ++ "trusting certificate with extended key usage failed: %d: %s", + grub_errno, grub_errmsg); + + grub_procfs_unregister (&certificate_der_entry); + grub_procfs_unregister (&certificate2_der_entry); + grub_procfs_unregister (&certificate_printable_der_entry); ++ grub_procfs_unregister (&certificate_eku_der_entry); + } + + GRUB_FUNCTIONAL_TEST (appended_signature_test, appended_signature_test); +diff --git a/grub-core/tests/appended_signatures.h b/grub-core/tests/appended_signatures.h +index aa3dc6278e3..2e5ebd7d8bd 100644 +--- a/grub-core/tests/appended_signatures.h ++++ b/grub-core/tests/appended_signatures.h +@@ -555,3 +555,84 @@ unsigned char certificate_printable_der[] = { + 0xd2 + }; + unsigned int certificate_printable_der_len = 829; ++ ++unsigned char certificate_eku_der[] = { ++ 0x30, 0x82, 0x03, 0x90, 0x30, 0x82, 0x02, 0x78, 0xa0, 0x03, 0x02, 0x01, ++ 0x02, 0x02, 0x09, 0x00, 0xd3, 0x9c, 0x41, 0x33, 0xdd, 0x6b, 0x5f, 0x45, ++ 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, ++ 0x0b, 0x05, 0x00, 0x30, 0x47, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, ++ 0x04, 0x03, 0x0c, 0x18, 0x52, 0x65, 0x64, 0x20, 0x48, 0x61, 0x74, 0x20, ++ 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x20, 0x42, 0x6f, 0x6f, 0x74, 0x20, ++ 0x43, 0x41, 0x20, 0x36, 0x31, 0x22, 0x30, 0x20, 0x06, 0x09, 0x2a, 0x86, ++ 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x13, 0x73, 0x65, 0x63, ++ 0x61, 0x6c, 0x65, 0x72, 0x74, 0x40, 0x72, 0x65, 0x64, 0x68, 0x61, 0x74, ++ 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x32, ++ 0x31, 0x35, 0x31, 0x34, 0x30, 0x30, 0x34, 0x34, 0x5a, 0x17, 0x0d, 0x33, ++ 0x38, 0x30, 0x31, 0x31, 0x37, 0x31, 0x34, 0x30, 0x30, 0x34, 0x34, 0x5a, ++ 0x30, 0x4e, 0x31, 0x28, 0x30, 0x26, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, ++ 0x1f, 0x52, 0x65, 0x64, 0x20, 0x48, 0x61, 0x74, 0x20, 0x53, 0x65, 0x63, ++ 0x75, 0x72, 0x65, 0x20, 0x42, 0x6f, 0x6f, 0x74, 0x20, 0x53, 0x69, 0x67, ++ 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x36, 0x30, 0x32, 0x31, 0x22, 0x30, 0x20, ++ 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, ++ 0x13, 0x73, 0x65, 0x63, 0x61, 0x6c, 0x65, 0x72, 0x74, 0x40, 0x72, 0x65, ++ 0x64, 0x68, 0x61, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x82, 0x01, 0x22, ++ 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, ++ 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, ++ 0x02, 0x82, 0x01, 0x01, 0x00, 0xaa, 0x6f, 0xbb, 0x92, 0x77, 0xd7, 0x15, ++ 0xef, 0x88, 0x80, 0x88, 0xc0, 0xe7, 0x89, 0xeb, 0x35, 0x76, 0xf4, 0x85, ++ 0x05, 0x0f, 0x19, 0xe4, 0x5f, 0x25, 0xdd, 0xc1, 0xa2, 0xe5, 0x5c, 0x06, ++ 0xfb, 0xf1, 0x06, 0xb5, 0x65, 0x45, 0xcb, 0xbd, 0x19, 0x33, 0x54, 0xb5, ++ 0x1a, 0xcd, 0xe4, 0xa8, 0x35, 0x2a, 0xfe, 0x9c, 0x53, 0xf4, 0xc6, 0x76, ++ 0xdb, 0x1f, 0x8a, 0xd4, 0x7b, 0x18, 0x11, 0xaf, 0xa3, 0x90, 0xd4, 0xdd, ++ 0x4d, 0xd5, 0x42, 0xcc, 0x14, 0x9a, 0x64, 0x6b, 0xc0, 0x7f, 0xaa, 0x1c, ++ 0x94, 0x47, 0x4d, 0x79, 0xbd, 0x57, 0x9a, 0xbf, 0x99, 0x4e, 0x96, 0xa9, ++ 0x31, 0x2c, 0xa9, 0xe7, 0x14, 0x65, 0x86, 0xc8, 0xac, 0x79, 0x5e, 0x78, ++ 0xa4, 0x3c, 0x00, 0x24, 0xd3, 0xf7, 0xe1, 0xf5, 0x12, 0xad, 0xa0, 0x29, ++ 0xe5, 0xfe, 0x80, 0xae, 0xf8, 0xaa, 0x60, 0x36, 0xe7, 0xe8, 0x94, 0xcb, ++ 0xe9, 0xd1, 0xcc, 0x0b, 0x4d, 0xf7, 0xde, 0xeb, 0x52, 0xd2, 0x73, 0x09, ++ 0x28, 0xdf, 0x48, 0x99, 0x53, 0x9f, 0xc5, 0x9a, 0xd4, 0x36, 0xa3, 0xc6, ++ 0x5e, 0x8d, 0xbe, 0xd5, 0xdc, 0x76, 0xb4, 0x74, 0xb8, 0x26, 0x18, 0x27, ++ 0xfb, 0xf2, 0xfb, 0xd0, 0x9b, 0x3d, 0x7f, 0x10, 0xe2, 0xab, 0x44, 0xc7, ++ 0x88, 0x7f, 0xb4, 0x3d, 0x3e, 0xa3, 0xff, 0x6d, 0x06, 0x4b, 0x3e, 0x55, ++ 0xb2, 0x84, 0xf4, 0xad, 0x54, 0x88, 0x81, 0xc3, 0x9c, 0xf8, 0xb6, 0x68, ++ 0x96, 0x38, 0x8b, 0xcd, 0x90, 0x6d, 0x25, 0x4b, 0xbf, 0x0c, 0x44, 0x90, ++ 0xa5, 0x5b, 0x98, 0xd0, 0x40, 0x2f, 0xbb, 0x0d, 0xa8, 0x4b, 0x8a, 0x62, ++ 0x82, 0x46, 0x46, 0x18, 0x38, 0xae, 0x82, 0x07, 0xd0, 0xb4, 0x2f, 0x16, ++ 0x79, 0x55, 0x9f, 0x1b, 0xc5, 0x08, 0x6d, 0x85, 0xdf, 0x3f, 0xa9, 0x9b, ++ 0x4b, 0xc6, 0x28, 0xd3, 0x58, 0x72, 0x3d, 0x37, 0x11, 0x02, 0x03, 0x01, ++ 0x00, 0x01, 0xa3, 0x78, 0x30, 0x76, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, ++ 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x0e, 0x06, 0x03, ++ 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, ++ 0x30, 0x16, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01, 0xff, 0x04, 0x0c, ++ 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x03, ++ 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x6c, ++ 0xe4, 0x6c, 0x27, 0xaa, 0xcd, 0x0d, 0x4b, 0x74, 0x21, 0xa4, 0xf6, 0x5f, ++ 0x87, 0xb5, 0x31, 0xfe, 0x10, 0xbb, 0xa7, 0x30, 0x1f, 0x06, 0x03, 0x55, ++ 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xe8, 0x6a, 0x1c, 0xab, ++ 0x2c, 0x48, 0xf9, 0x60, 0x36, 0xa2, 0xf0, 0x7b, 0x8e, 0xd2, 0x9d, 0xb4, ++ 0x2a, 0x28, 0x98, 0xc8, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, ++ 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, ++ 0x55, 0x34, 0xe2, 0xfa, 0xf6, 0x89, 0x86, 0xad, 0x92, 0x21, 0xec, 0xb9, ++ 0x54, 0x0e, 0x18, 0x47, 0x0d, 0x1b, 0xa7, 0x58, 0xad, 0x69, 0xe4, 0xef, ++ 0x3b, 0xe6, 0x8d, 0xdd, 0xda, 0x0c, 0x45, 0xf6, 0xe8, 0x96, 0xa4, 0x29, ++ 0x0f, 0xbb, 0xcf, 0x16, 0xae, 0x93, 0xd0, 0xcb, 0x2a, 0x26, 0x1a, 0x7b, ++ 0xfc, 0x51, 0x22, 0x76, 0x98, 0x31, 0xa7, 0x0f, 0x29, 0x35, 0x79, 0xbf, ++ 0xe2, 0x4f, 0x0f, 0x14, 0xf5, 0x1f, 0xcb, 0xbf, 0x87, 0x65, 0x13, 0x32, ++ 0xa3, 0x19, 0x4a, 0xd1, 0x3f, 0x45, 0xd4, 0x4b, 0xe2, 0x00, 0x26, 0xa9, ++ 0x3e, 0xd7, 0xa5, 0x37, 0x9f, 0xf5, 0xad, 0x61, 0xe2, 0x40, 0xa9, 0x74, ++ 0x24, 0x53, 0xf2, 0x78, 0xeb, 0x10, 0x9b, 0x2c, 0x27, 0x88, 0x46, 0xcb, ++ 0xe4, 0x60, 0xca, 0xf5, 0x06, 0x24, 0x40, 0x2a, 0x97, 0x3a, 0xcc, 0xd0, ++ 0x81, 0xb1, 0x15, 0xa3, 0x4f, 0xd0, 0x2b, 0x4f, 0xca, 0x6e, 0xaa, 0x24, ++ 0x31, 0xb3, 0xac, 0xa6, 0x75, 0x05, 0xfe, 0x8a, 0xf4, 0x41, 0xc4, 0x06, ++ 0x8a, 0xc7, 0x0a, 0x83, 0x4e, 0x49, 0xd4, 0x3f, 0x83, 0x50, 0xec, 0x57, ++ 0x04, 0x97, 0x14, 0x49, 0xf5, 0xe1, 0xb1, 0x7a, 0x9c, 0x09, 0x4f, 0x61, ++ 0x87, 0xc3, 0x97, 0x22, 0x17, 0xc2, 0xeb, 0xcc, 0x32, 0x81, 0x31, 0x21, ++ 0x3f, 0x10, 0x57, 0x5b, 0x43, 0xbe, 0xcd, 0x68, 0x82, 0xbe, 0xe5, 0xc1, ++ 0x65, 0x94, 0x7e, 0xc2, 0x34, 0x76, 0x2b, 0xcf, 0x89, 0x3c, 0x2b, 0x81, ++ 0x23, 0x72, 0x95, 0xcf, 0xc9, 0x67, 0x19, 0x2a, 0xd5, 0x5c, 0xca, 0xa3, ++ 0x46, 0xbd, 0x48, 0x06, 0x0b, 0xa6, 0xa3, 0x96, 0x50, 0x28, 0xc7, 0x7e, ++ 0xcf, 0x62, 0xf2, 0xfa, 0xc4, 0xf2, 0x53, 0xe3, 0xc9, 0xe8, 0x2e, 0xdd, ++ 0x29, 0x37, 0x07, 0x47, 0xff, 0xff, 0x8a, 0x32, 0xbd, 0xa2, 0xb7, 0x21, ++ 0x89, 0xa0, 0x55, 0xf7 ++}; ++unsigned int certificate_eku_der_len = 916; diff --git a/0184-blscfg-add-a-space-char-when-appending-fields-for-va.patch b/0184-blscfg-add-a-space-char-when-appending-fields-for-va.patch deleted file mode 100644 index 9f1eff986064e590700e022e6247e8d927540984..0000000000000000000000000000000000000000 --- a/0184-blscfg-add-a-space-char-when-appending-fields-for-va.patch +++ /dev/null @@ -1,79 +0,0 @@ -From b6c9be5bfcfc8b7724f8a30b032ee1dcf58607d1 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 26 Nov 2019 09:51:41 +0100 -Subject: [PATCH 184/220] blscfg: add a space char when appending fields for - variable expansion - -The GRUB variables are expanded and replaced by their values before adding -menu entries, but they didn't include space characters after the values so -the result was not correct. - -For the common case this wasn't a problem but it is if there are variables -that are part of the values of other variables. - -Resolves: rhbz#1669252 - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/commands/blscfg.c | 31 ++++++++++++++++++------------- - 1 file changed, 18 insertions(+), 13 deletions(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 471975f..d78cff7 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -593,26 +593,29 @@ static char **bls_make_list (struct bls_entry *entry, const char *key, int *num) - - static char *field_append(bool is_var, char *buffer, char *start, char *end) - { -- char *temp = grub_strndup(start, end - start + 1); -- const char *field = temp; -+ char *tmp = grub_strndup(start, end - start + 1); -+ const char *field = tmp; -+ int term = is_var ? 2 : 1; - - if (is_var) { -- field = grub_env_get (temp); -+ field = grub_env_get (tmp); - if (!field) - return buffer; - } - -- if (!buffer) { -- buffer = grub_strdup(field); -- if (!buffer) -- return NULL; -- } else { -- buffer = grub_realloc (buffer, grub_strlen(buffer) + grub_strlen(field)); -- if (!buffer) -- return NULL; -+ if (!buffer) -+ buffer = grub_zalloc (grub_strlen(field) + term); -+ else -+ buffer = grub_realloc (buffer, grub_strlen(buffer) + grub_strlen(field) + term); - -- grub_stpcpy (buffer + grub_strlen(buffer), field); -- } -+ if (!buffer) -+ return NULL; -+ -+ tmp = buffer + grub_strlen(buffer); -+ tmp = grub_stpcpy (tmp, field); -+ -+ if (is_var) -+ tmp = grub_stpcpy (tmp, " "); - - return buffer; - } -@@ -642,6 +645,8 @@ static char *expand_val(char *value) - buffer = field_append(is_var, buffer, start, end); - is_var = false; - start = value; -+ if (*start == ' ') -+ start++; - } - } - --- -1.8.3.1 - diff --git a/0185-ieee1275-ofdisk-retry-on-open-failure.patch b/0185-ieee1275-ofdisk-retry-on-open-failure.patch new file mode 100644 index 0000000000000000000000000000000000000000..275d14f45411b4273c85451f947e6b5855fc38d9 --- /dev/null +++ b/0185-ieee1275-ofdisk-retry-on-open-failure.patch @@ -0,0 +1,103 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Diego Domingos +Date: Wed, 10 Mar 2021 14:17:52 -0500 +Subject: [PATCH] ieee1275/ofdisk: retry on open failure + +This patch aims to make grub more robust when booting from SAN/Multipath disks. + +If a path is failing intermittently so grub will retry the OPEN and READ the +disk (grub_ieee1275_open and grub_ieee1275_read) until the total amount of times +specified in MAX_RETRIES. + +Signed-off-by: Diego Domingos +--- + grub-core/disk/ieee1275/ofdisk.c | 25 ++++++++++++++++++++----- + include/grub/ieee1275/ofdisk.h | 8 ++++++++ + 2 files changed, 28 insertions(+), 5 deletions(-) + +diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c +index ea7f78ac7d8..55346849d35 100644 +--- a/grub-core/disk/ieee1275/ofdisk.c ++++ b/grub-core/disk/ieee1275/ofdisk.c +@@ -225,7 +225,9 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) + char *buf, *bufptr; + unsigned i; + +- if (grub_ieee1275_open (alias->path, &ihandle)) ++ ++ RETRY_IEEE1275_OFDISK_OPEN(alias->path, &ihandle) ++ if (! ihandle) + return; + + /* This method doesn't need memory allocation for the table. Open +@@ -305,7 +307,9 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) + return; + } + +- if (grub_ieee1275_open (alias->path, &ihandle)) ++ RETRY_IEEE1275_OFDISK_OPEN(alias->path, &ihandle); ++ ++ if (! ihandle) + { + grub_free (buf); + grub_free (table); +@@ -495,7 +499,7 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) + last_ihandle = 0; + last_devpath = NULL; + +- grub_ieee1275_open (op->open_path, &last_ihandle); ++ RETRY_IEEE1275_OFDISK_OPEN(op->open_path, &last_ihandle); + if (! last_ihandle) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); + last_devpath = op->open_path; +@@ -571,7 +575,7 @@ grub_ofdisk_prepare (grub_disk_t disk, grub_disk_addr_t sector) + last_ihandle = 0; + last_devpath = NULL; + +- grub_ieee1275_open (disk->data, &last_ihandle); ++ RETRY_IEEE1275_OFDISK_OPEN(disk->data, &last_ihandle); + if (! last_ihandle) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); + last_devpath = disk->data; +@@ -598,12 +602,23 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector, + return err; + grub_ieee1275_read (last_ihandle, buf, size << disk->log_sector_size, + &actual); +- if (actual != (grub_ssize_t) (size << disk->log_sector_size)) ++ int i = 0; ++ while(actual != (grub_ssize_t) (size << disk->log_sector_size)){ ++ if (i>MAX_RETRIES){ + return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx " + "from `%s'"), + (unsigned long long) sector, + disk->name); ++ } ++ last_devpath = NULL; ++ err = grub_ofdisk_prepare (disk, sector); ++ if (err) ++ return err; + ++ grub_ieee1275_read (last_ihandle, buf, size << disk->log_sector_size, ++ &actual); ++ i++; ++ } + return 0; + } + +diff --git a/include/grub/ieee1275/ofdisk.h b/include/grub/ieee1275/ofdisk.h +index 2f69e3f191d..7d2d5409305 100644 +--- a/include/grub/ieee1275/ofdisk.h ++++ b/include/grub/ieee1275/ofdisk.h +@@ -22,4 +22,12 @@ + extern void grub_ofdisk_init (void); + extern void grub_ofdisk_fini (void); + ++#define MAX_RETRIES 20 ++ ++ ++#define RETRY_IEEE1275_OFDISK_OPEN(device, last_ihandle) unsigned retry_i=0;for(retry_i=0; retry_i < MAX_RETRIES; retry_i++){ \ ++ if(!grub_ieee1275_open(device, last_ihandle)) \ ++ break; \ ++ grub_dprintf("ofdisk","Opening disk %s failed. Retrying...\n",device); } ++ + #endif /* ! GRUB_INIT_HEADER */ diff --git a/0186-Allow-chainloading-EFI-apps-from-loop-mounts.patch b/0186-Allow-chainloading-EFI-apps-from-loop-mounts.patch new file mode 100644 index 0000000000000000000000000000000000000000..66e61a7ec3d4d09b69934b7795aee7ad64f57a61 --- /dev/null +++ b/0186-Allow-chainloading-EFI-apps-from-loop-mounts.patch @@ -0,0 +1,138 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Dimitri John Ledkov +Date: Fri, 11 Jun 2021 13:51:20 +0200 +Subject: [PATCH] Allow chainloading EFI apps from loop mounts. + +Signed-off-by: Dimitri John Ledkov +Signed-off-by: Robbie Harwood +--- + grub-core/disk/loopback.c | 9 +-------- + grub-core/loader/efi/chainloader.c | 23 +++++++++++++++++++++++ + include/grub/loopback.h | 30 ++++++++++++++++++++++++++++++ + 3 files changed, 54 insertions(+), 8 deletions(-) + create mode 100644 include/grub/loopback.h + +diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c +index 41bebd14fe3..99f47924ec2 100644 +--- a/grub-core/disk/loopback.c ++++ b/grub-core/disk/loopback.c +@@ -21,20 +21,13 @@ + #include + #include + #include ++#include + #include + #include + #include + + GRUB_MOD_LICENSE ("GPLv3+"); + +-struct grub_loopback +-{ +- char *devname; +- grub_file_t file; +- struct grub_loopback *next; +- unsigned long id; +-}; +- + static struct grub_loopback *loopback_list; + static unsigned long last_id = 0; + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index d41e8ea14a8..3af6b122926 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -901,6 +902,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + grub_efi_status_t status; + grub_efi_boot_services_t *b; + grub_device_t dev = 0; ++ grub_device_t orig_dev = 0; + grub_efi_device_path_t *dp = 0; + char *filename; + void *boot_image = 0; +@@ -958,6 +960,15 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + if (! dev) + goto fail; + ++ /* if device is loopback, use underlying dev */ ++ if (dev->disk->dev->id == GRUB_DISK_DEVICE_LOOPBACK_ID) ++ { ++ struct grub_loopback *d; ++ orig_dev = dev; ++ d = dev->disk->data; ++ dev = d->file->device; ++ } ++ + if (dev->disk) + dev_handle = grub_efidisk_get_device_handle (dev->disk); + else if (dev->net && dev->net->server) +@@ -1065,6 +1076,12 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + } + #endif + ++ if (orig_dev) ++ { ++ dev = orig_dev; ++ orig_dev = 0; ++ } ++ + rc = grub_linuxefi_secure_validate((void *)(unsigned long)address, fsize); + grub_dprintf ("chain", "linuxefi_secure_validate: %d\n", rc); + if (rc > 0) +@@ -1087,6 +1104,12 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + // -1 fall-through to fail + + fail: ++ if (orig_dev) ++ { ++ dev = orig_dev; ++ orig_dev = 0; ++ } ++ + if (dev) + grub_device_close (dev); + +diff --git a/include/grub/loopback.h b/include/grub/loopback.h +new file mode 100644 +index 00000000000..3b9a9e32e80 +--- /dev/null ++++ b/include/grub/loopback.h +@@ -0,0 +1,30 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2019 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#ifndef GRUB_LOOPBACK_HEADER ++#define GRUB_LOOPBACK_HEADER 1 ++ ++struct grub_loopback ++{ ++ char *devname; ++ grub_file_t file; ++ struct grub_loopback *next; ++ unsigned long id; ++}; ++ ++#endif /* ! GRUB_LOOPBACK_HEADER */ diff --git a/0186-blscfg-Add-support-for-sorting-the-plus-higher-than-.patch b/0186-blscfg-Add-support-for-sorting-the-plus-higher-than-.patch deleted file mode 100644 index 03b100c5cdd5d44fe1285ae070a7275827174b8c..0000000000000000000000000000000000000000 --- a/0186-blscfg-Add-support-for-sorting-the-plus-higher-than-.patch +++ /dev/null @@ -1,62 +0,0 @@ -From c8a79b3f43d083a70688067f095edea1a3dffb7b Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Mon, 4 Nov 2019 17:33:30 +0100 -Subject: [PATCH 186/220] blscfg: Add support for sorting the plus ('+') higher - than base version - -Handle plus separator. Concept is the same as tilde, except that if one of -the strings ends (base version), the other is considered as higher version. - -A plus character is used for example by the Linux kernel build system to -denote that is the base version plus some changes on top of it. - -Currently for example rpmvercmp("5.3.0", "5.3.0+") will return 0 even when -the two versions are not the same. - -Resolves: rhbz#1767395 - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/commands/blscfg.c | 19 +++++++++++++++++-- - 1 file changed, 17 insertions(+), 2 deletions(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index d78cff7..83b33c1 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -163,8 +163,8 @@ static int vercmp(const char * a, const char * b) - - /* loop through each version segment of str1 and str2 and compare them */ - while (*one || *two) { -- while (*one && !grub_isalnum(*one) && *one != '~') one++; -- while (*two && !grub_isalnum(*two) && *two != '~') two++; -+ while (*one && !grub_isalnum(*one) && *one != '~' && *one != '+') one++; -+ while (*two && !grub_isalnum(*two) && *two != '~' && *two != '+') two++; - - /* handle the tilde separator, it sorts before everything else */ - if (*one == '~' || *two == '~') { -@@ -175,6 +175,21 @@ static int vercmp(const char * a, const char * b) - continue; - } - -+ /* -+ * Handle plus separator. Concept is the same as tilde, -+ * except that if one of the strings ends (base version), -+ * the other is considered as higher version. -+ */ -+ if (*one == '+' || *two == '+') { -+ if (!*one) return -1; -+ if (!*two) return 1; -+ if (*one != '+') goto_return (1); -+ if (*two != '+') goto_return (-1); -+ one++; -+ two++; -+ continue; -+ } -+ - /* If we ran to the end of either, we are finished with the loop */ - if (!(*one && *two)) break; - --- -1.8.3.1 - diff --git a/0187-Fix-savedefault-with-blscfg.patch b/0187-Fix-savedefault-with-blscfg.patch deleted file mode 100644 index ef0d8e68a6103178af7c673331e9b9d29f5d791d..0000000000000000000000000000000000000000 --- a/0187-Fix-savedefault-with-blscfg.patch +++ /dev/null @@ -1,53 +0,0 @@ -From 51ba69910056d9720c114ed67d13da766c21a609 Mon Sep 17 00:00:00 2001 -From: Fritz Elfert -Date: Mon, 13 Jan 2020 19:29:58 +0100 -Subject: [PATCH 187/220] Fix savedefault with blscfg - -The GRUB_SAVEDEFAULT option was ignored on a BLS configuration. Fix it by -making the menu entries populated from the BLS files to call savedefault -if a save_default environment variable has been set to "true". - -This variable is set by grub2-mkconfig to the value in GRUB_SAVEDEFAULT. ---- - grub-core/commands/blscfg.c | 5 ++++- - util/grub.d/10_linux.in | 4 ++++ - 2 files changed, 8 insertions(+), 1 deletion(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 83b33c1..069db72 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -889,11 +889,14 @@ static void create_entry (struct bls_entry *entry) - - grub_dprintf ("blscfg2", "devicetree %s for id:\"%s\"\n", dt, id); - -- src = grub_xasprintf ("load_video\n" -+ const char *sdval = grub_env_get("save_default"); -+ bool savedefault = ((NULL != sdval) && (grub_strcmp(sdval, "true") == 0)); -+ src = grub_xasprintf ("%sload_video\n" - "set gfxpayload=keep\n" - "insmod gzio\n" - "linux %s%s%s%s\n" - "%s%s", -+ savedefault ? "savedefault\n" : "", - GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "", - initrd ? initrd : "", dt ? dt : ""); - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 21a6915..b70dca2 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -152,6 +152,10 @@ EOF - if [ -n "${GRUB_DEFAULT_DTB}" ]; then - ${grub_editenv} - set devicetree="${GRUB_DEFAULT_DTB}" - fi -+ -+ if [ -n "${GRUB_SAVEDEFAULT}" ]; then -+ ${grub_editenv} - set save_default="${GRUB_SAVEDEFAULT}" -+ fi - fi - - exit 0 --- -1.8.3.1 - diff --git a/0187-efinet-Add-DHCP-proxy-support.patch b/0187-efinet-Add-DHCP-proxy-support.patch new file mode 100644 index 0000000000000000000000000000000000000000..dcaac6fb39cc5c82e7a1beff8be45c80a4a599a9 --- /dev/null +++ b/0187-efinet-Add-DHCP-proxy-support.patch @@ -0,0 +1,53 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Ian Page Hands +Date: Tue, 8 Jun 2021 13:48:56 -0400 +Subject: [PATCH] efinet: Add DHCP proxy support + +If a proxyDHCP configuration is used, the server name, server IP and boot +file values should be taken from the DHCP proxy offer instead of the DHCP +server ack packet. Currently that case is not handled, add support for it. + +Signed-off-by: Ian Page Hands +Signed-off-by: Robbie Harwood +--- + grub-core/net/drivers/efi/efinet.c | 25 +++++++++++++++++++++++-- + 1 file changed, 23 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index e11d759f19a..1a24f38a21a 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -850,10 +850,31 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + else + { + grub_dprintf ("efinet", "using ipv4 and dhcp\n"); ++ ++ struct grub_net_bootp_packet *dhcp_ack = &pxe_mode->dhcp_ack; ++ ++ if (pxe_mode->proxy_offer_received) ++ { ++ grub_dprintf ("efinet", "proxy offer receive"); ++ struct grub_net_bootp_packet *proxy_offer = &pxe_mode->proxy_offer; ++ ++ if (proxy_offer && dhcp_ack->boot_file[0] == '\0') ++ { ++ grub_dprintf ("efinet", "setting values from proxy offer"); ++ /* Here we got a proxy offer and the dhcp_ack has a nil boot_file ++ * Copy the proxy DHCP offer details into the bootp_packet we are ++ * sending forward as they are the deatils we need. ++ */ ++ *dhcp_ack->server_name = *proxy_offer->server_name; ++ *dhcp_ack->boot_file = *proxy_offer->boot_file; ++ dhcp_ack->server_ip = proxy_offer->server_ip; ++ } ++ } ++ + grub_net_configure_by_dhcp_ack (card->name, card, 0, + (struct grub_net_bootp_packet *) +- packet_buf, +- packet_bufsz, ++ &pxe_mode->dhcp_ack, ++ sizeof (pxe_mode->dhcp_ack), + 1, device, path); + grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path); + } diff --git a/0188-Also-define-GRUB_EFI_MAX_ALLOCATION_ADDRESS-for-RISC.patch b/0188-Also-define-GRUB_EFI_MAX_ALLOCATION_ADDRESS-for-RISC.patch deleted file mode 100644 index 5d109f038934532e0b4281734f589427c8750eb1..0000000000000000000000000000000000000000 --- a/0188-Also-define-GRUB_EFI_MAX_ALLOCATION_ADDRESS-for-RISC.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 2fbd48422e294322dbae05bf90d39c1e92c7846c Mon Sep 17 00:00:00 2001 -From: David Abdurachmanov -Date: Thu, 16 Jan 2020 13:10:10 +0100 -Subject: [PATCH 188/220] Also define GRUB_EFI_MAX_ALLOCATION_ADDRESS for - RISC-V - -The commit "Try to pick better locations for kernel and initrd" missed to -define this macro for the RISC-V (riscv64) architecture, so add it there. - -Signed-off-by: David Abdurachmanov ---- - include/grub/riscv64/efi/memory.h | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/include/grub/riscv64/efi/memory.h b/include/grub/riscv64/efi/memory.h -index c6cb324..acb61dc 100644 ---- a/include/grub/riscv64/efi/memory.h -+++ b/include/grub/riscv64/efi/memory.h -@@ -2,5 +2,6 @@ - #include - - #define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL -+#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS - - #endif /* ! GRUB_MEMORY_CPU_HEADER */ --- -1.8.3.1 - diff --git a/0188-fs-ext2-Ignore-checksum-seed-incompat-feature.patch b/0188-fs-ext2-Ignore-checksum-seed-incompat-feature.patch new file mode 100644 index 0000000000000000000000000000000000000000..b4a5fd4ddfd9c0cec1c37c7ca8dfdb59ce380fa4 --- /dev/null +++ b/0188-fs-ext2-Ignore-checksum-seed-incompat-feature.patch @@ -0,0 +1,54 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Fri, 11 Jun 2021 00:01:29 +0200 +Subject: [PATCH] fs/ext2: Ignore checksum seed incompat feature + +This incompat feature is used to denote that the filesystem stored its +metadata checksum seed in the superblock. This is used to allow tune2fs +to change the UUID on a mounted metadata_csum filesystem without having +to rewrite all the disk metadata. + +But GRUB doesn't use the metadata checksum in anyway, so can just ignore +this feature if is enabled. This is consistent with GRUB filesystem code +in general which just does a best effort to access the filesystem's data. + +It may be removed from the ignored list in the future if supports to do +metadata checksumming verification is added to the read-only FS driver. + +Suggested-by: Eric Sandeen +Suggested-by: Lukas Czerner +Signed-off-by: Javier Martinez Canillas +--- + grub-core/fs/ext2.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c +index e7dd78e6635..731d346f886 100644 +--- a/grub-core/fs/ext2.c ++++ b/grub-core/fs/ext2.c +@@ -103,6 +103,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); + #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 + #define EXT4_FEATURE_INCOMPAT_MMP 0x0100 + #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 ++#define EXT4_FEATURE_INCOMPAT_CSUM_SEED 0x2000 + #define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000 + + /* The set of back-incompatible features this driver DOES support. Add (OR) +@@ -123,9 +124,16 @@ GRUB_MOD_LICENSE ("GPLv3+"); + * mmp: Not really back-incompatible - was added as such to + * avoid multiple read-write mounts. Safe to ignore for this + * RO driver. ++ * checksum seed: Not really back-incompatible - was added to allow tools ++ * such as tune2fs to change the UUID on a mounted metadata ++ * checksummed filesystem. Safe to ignore for now since the ++ * driver doesn't support checksum verification. But it must ++ * be removed from this list if that support is added later. ++ * + */ + #define EXT2_DRIVER_IGNORED_INCOMPAT ( EXT3_FEATURE_INCOMPAT_RECOVER \ +- | EXT4_FEATURE_INCOMPAT_MMP) ++ | EXT4_FEATURE_INCOMPAT_MMP \ ++ | EXT4_FEATURE_INCOMPAT_CSUM_SEED) + + + #define EXT3_JOURNAL_MAGIC_NUMBER 0xc03b3998U diff --git a/0189-Don-t-update-the-cmdline-when-generating-legacy-menu.patch b/0189-Don-t-update-the-cmdline-when-generating-legacy-menu.patch new file mode 100644 index 0000000000000000000000000000000000000000..2e13f399aa675fcc8d2c3bff461978cb625830bc --- /dev/null +++ b/0189-Don-t-update-the-cmdline-when-generating-legacy-menu.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 17 Jun 2021 14:31:42 +0200 +Subject: [PATCH] Don't update the cmdline when generating legacy menuentry + commands + +On OPAL ppc64le machines with an old petitboot version that doesn't have +support to parse BLS snippets, the grub2-mkconfig script is executed to +generate menuentry commands from the BLS snippets. + +In this case, the script is executed with the --no-grubenv-update option +that indicates that no side effects should happen when running the script. + +But the options field in the BLS snippets are updated regardless, only do +the update if --no-grubenv-update was not used. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub.d/10_linux.in | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 6bceabf3dc9..b95a9a8d7ca 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -261,7 +261,9 @@ if [ -z "\${kernelopts}" ]; then + fi + EOF + +- update_bls_cmdline ++ if [ "x${GRUB_GRUBENV_UPDATE}" = "xyes" ]; then ++ update_bls_cmdline ++ fi + + if [ "x${BLS_POPULATE_MENU}" = "xtrue" ]; then + populate_menu diff --git a/0189-chainloader-Define-machine-types-for-RISC-V.patch b/0189-chainloader-Define-machine-types-for-RISC-V.patch deleted file mode 100644 index 676c44fb2d285f706bca0ba264170dbc2f6a152e..0000000000000000000000000000000000000000 --- a/0189-chainloader-Define-machine-types-for-RISC-V.patch +++ /dev/null @@ -1,34 +0,0 @@ -From a41c6f6cd8ad540c6503610b2c438072ebde9117 Mon Sep 17 00:00:00 2001 -From: David Abdurachmanov -Date: Sat, 9 Nov 2019 18:06:32 +0000 -Subject: [PATCH 189/220] chainloader: Define machine types for RISC-V - -The commit "Add secureboot support on efi chainloader" didn't add machine -types for RISC-V, so this patch adds them. - -Note, that grub-core/loader/riscv/linux.c is skipped because Linux is not -supported yet. This patch might need a new revision once that's the case. - -Signed-off-by: David Abdurachmanov ---- - grub-core/loader/efi/chainloader.c | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index f4ddbed..2c529f7 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -316,6 +316,10 @@ static const grub_uint16_t machine_type __attribute__((__unused__)) = - GRUB_PE32_MACHINE_I386; - #elif defined(__ia64__) - GRUB_PE32_MACHINE_IA64; -+#elif defined(__riscv) && (__riscv_xlen == 32) -+ GRUB_PE32_MACHINE_RISCV32; -+#elif defined(__riscv) && (__riscv_xlen == 64) -+ GRUB_PE32_MACHINE_RISCV64; - #else - #error this architecture is not supported by grub2 - #endif --- -1.8.3.1 - diff --git a/0190-Suppress-gettext-error-message.patch b/0190-Suppress-gettext-error-message.patch new file mode 100644 index 0000000000000000000000000000000000000000..c42dd0d53118d24b9b4cea22f13e6b65584ea4ac --- /dev/null +++ b/0190-Suppress-gettext-error-message.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Paulo Flabiano Smorigo +Date: Tue, 29 Jun 2021 13:17:42 +0200 +Subject: [PATCH] Suppress gettext error message + +Colin Watson's patch from comment #11 on the upstream bug: +https://savannah.gnu.org/bugs/?35880#comment11 + +Resolves: rhbz#1592124 + +Signed-off-by: Paulo Flabiano Smorigo +--- + grub-core/gettext/gettext.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c +index 4d02e62c109..7ec81ca0b48 100644 +--- a/grub-core/gettext/gettext.c ++++ b/grub-core/gettext/gettext.c +@@ -424,6 +424,13 @@ grub_gettext_init_ext (struct grub_gettext_context *ctx, + grub_free (lang); + } + ++ /* If no translations are available, fall back to untranslated text. */ ++ if (err == GRUB_ERR_FILE_NOT_FOUND) ++ { ++ grub_errno = GRUB_ERR_NONE; ++ return 0; ++ } ++ + if (locale[0] == 'e' && locale[1] == 'n' + && (locale[2] == '\0' || locale[2] == '_')) + grub_errno = err = GRUB_ERR_NONE; diff --git a/0191-RISC-V-Add-__clzdi2-symbol.patch b/0191-RISC-V-Add-__clzdi2-symbol.patch deleted file mode 100644 index 0ddf275924f8b3499eb36df83ebdfde6452ded81..0000000000000000000000000000000000000000 --- a/0191-RISC-V-Add-__clzdi2-symbol.patch +++ /dev/null @@ -1,46 +0,0 @@ -From 679f2a9866b6cc770734e58fffa3e0a54ed7aded Mon Sep 17 00:00:00 2001 -From: Andreas Schwab -Date: Thu, 19 Sep 2019 09:39:04 +0200 -Subject: [PATCH 191/220] RISC-V: Add __clzdi2 symbol - -This is needed for the zstd module build for riscv64-emu. - -Signed-off-by: Andreas Schwab -Reviewed-by: Daniel Kiper ---- - configure.ac | 2 +- - include/grub/compiler-rt-emu.h | 5 +++++ - 2 files changed, 6 insertions(+), 1 deletion(-) - -diff --git a/configure.ac b/configure.ac -index 5076d63..eff160b 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -1444,7 +1444,7 @@ fi - - # Check for libgcc symbols - if test x"$platform" = xemu; then --AC_CHECK_FUNCS(__udivsi3 __umodsi3 __divsi3 __modsi3 __divdi3 __moddi3 __udivdi3 __umoddi3 __ctzdi2 __ctzsi2 __aeabi_uidiv __aeabi_uidivmod __aeabi_idiv __aeabi_idivmod __aeabi_ulcmp __muldi3 __aeabi_lmul __aeabi_memcpy __aeabi_memcpy4 __aeabi_memcpy8 __aeabi_memclr __aeabi_memclr4 __aeabi_memclr8 __aeabi_memset __aeabi_lasr __aeabi_llsl __aeabi_llsr _restgpr_14_x __ucmpdi2 __ashldi3 __ashrdi3 __lshrdi3 __bswapsi2 __bswapdi2 __bzero __register_frame_info __deregister_frame_info ___chkstk_ms __chkstk_ms) -+AC_CHECK_FUNCS(__udivsi3 __umodsi3 __divsi3 __modsi3 __divdi3 __moddi3 __udivdi3 __umoddi3 __ctzdi2 __ctzsi2 __clzdi2 __aeabi_uidiv __aeabi_uidivmod __aeabi_idiv __aeabi_idivmod __aeabi_ulcmp __muldi3 __aeabi_lmul __aeabi_memcpy __aeabi_memcpy4 __aeabi_memcpy8 __aeabi_memclr __aeabi_memclr4 __aeabi_memclr8 __aeabi_memset __aeabi_lasr __aeabi_llsl __aeabi_llsr _restgpr_14_x __ucmpdi2 __ashldi3 __ashrdi3 __lshrdi3 __bswapsi2 __bswapdi2 __bzero __register_frame_info __deregister_frame_info ___chkstk_ms __chkstk_ms) - fi - - if test "x$TARGET_APPLE_LINKER" = x1 ; then -diff --git a/include/grub/compiler-rt-emu.h b/include/grub/compiler-rt-emu.h -index b21425d..fde620a 100644 ---- a/include/grub/compiler-rt-emu.h -+++ b/include/grub/compiler-rt-emu.h -@@ -74,6 +74,11 @@ unsigned - EXPORT_FUNC (__ctzsi2) (grub_uint32_t x); - #endif - -+#ifdef HAVE___CLZDI2 -+int -+EXPORT_FUNC (__clzdi2) (grub_uint64_t x); -+#endif -+ - #ifdef HAVE___AEABI_UIDIV - grub_uint32_t - EXPORT_FUNC (__aeabi_uidiv) (grub_uint32_t a, grub_uint32_t b); --- -1.8.3.1 - diff --git a/0191-grub-set-password-Always-use-boot-grub2-user.cfg-as-.patch b/0191-grub-set-password-Always-use-boot-grub2-user.cfg-as-.patch new file mode 100644 index 0000000000000000000000000000000000000000..7ecea22d697e8ec24ecde0c96d5bb4977a8163d4 --- /dev/null +++ b/0191-grub-set-password-Always-use-boot-grub2-user.cfg-as-.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 5 Jul 2021 18:24:22 +0200 +Subject: [PATCH] grub-set-password: Always use /boot/grub2/user.cfg as + password default + +The GRUB configuration file is always placed in /boot/grub2/ now, even for +EFI. But the tool is still creating the user.cfg in the ESP and not there. + +Resolves: rhbz#1955294 + +Signed-off-by: Javier Martinez Canillas +--- + util/grub-set-password.in | 9 +-------- + 1 file changed, 1 insertion(+), 8 deletions(-) + +diff --git a/util/grub-set-password.in b/util/grub-set-password.in +index c0b5ebbfdc5..d8005e5a142 100644 +--- a/util/grub-set-password.in ++++ b/util/grub-set-password.in +@@ -1,11 +1,6 @@ + #!/bin/sh -e + +-EFIDIR=$(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/' -e 's/\"//g') +-if [ -d /sys/firmware/efi/efivars/ ]; then +- grubdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/" | sed 's,//*,/,g'` +-else +- grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'` +-fi ++grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'` + + PACKAGE_VERSION="@PACKAGE_VERSION@" + PACKAGE_NAME="@PACKAGE_NAME@" +@@ -116,8 +111,6 @@ if [ -z "${MYPASS}" ]; then + exit 1 + fi + +-# on the ESP, these will fail to set the permissions, but it's okay because +-# the directory is protected. + install -m 0600 /dev/null "${OUTPUT_PATH}/user.cfg" 2>/dev/null || : + chmod 0600 "${OUTPUT_PATH}/user.cfg" 2>/dev/null || : + echo "GRUB2_PASSWORD=${MYPASS}" > "${OUTPUT_PATH}/user.cfg" diff --git a/0192-grub-install-Define-default-platform-for-RISC-V.patch b/0192-grub-install-Define-default-platform-for-RISC-V.patch deleted file mode 100644 index ec8684e6ad5fd4a72e2ef40075a79bdefc0a6ed5..0000000000000000000000000000000000000000 --- a/0192-grub-install-Define-default-platform-for-RISC-V.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 06417565c4c66b670f72e5b0cc7ae9e7e147aaad Mon Sep 17 00:00:00 2001 -From: Andreas Schwab -Date: Thu, 15 Aug 2019 16:55:13 +0200 -Subject: [PATCH 192/220] grub-install: Define default platform for RISC-V - -Signed-off-by: Andreas Schwab -Reviewed-by: Daniel Kiper -Reviewed-by: Alexander Graf ---- - util/grub-install.c | 8 ++++++++ - 1 file changed, 8 insertions(+) - -diff --git a/util/grub-install.c b/util/grub-install.c -index 37fcdac..8b6a037 100644 ---- a/util/grub-install.c -+++ b/util/grub-install.c -@@ -324,6 +324,14 @@ get_default_platform (void) - return "arm64-efi"; - #elif defined (__amd64__) || defined (__x86_64__) || defined (__i386__) - return grub_install_get_default_x86_platform (); -+#elif defined (__riscv) -+#if __riscv_xlen == 32 -+ return "riscv32-efi"; -+#elif __riscv_xlen == 64 -+ return "riscv64-efi"; -+#else -+ return NULL; -+#endif - #else - return NULL; - #endif --- -1.8.3.1 - diff --git a/0192-templates-Check-for-EFI-at-runtime-instead-of-config.patch b/0192-templates-Check-for-EFI-at-runtime-instead-of-config.patch new file mode 100644 index 0000000000000000000000000000000000000000..e36afa113d9eb7dc5615400dcf67facb14f93152 --- /dev/null +++ b/0192-templates-Check-for-EFI-at-runtime-instead-of-config.patch @@ -0,0 +1,63 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 6 Jul 2021 00:38:40 +0200 +Subject: [PATCH] templates: Check for EFI at runtime instead of config + generation time + +The 30_uefi-firmware template checks if an OsIndicationsSupported UEFI var +exists and EFI_OS_INDICATIONS_BOOT_TO_FW_UI bit is set, to decide whether +a "fwsetup" menu entry would be added or not to the GRUB menu. + +But this has the problem that it will only work if the configuration file +was created on an UEFI machine that supports booting to a firmware UI. + +This for example doesn't support creating GRUB config files when executing +on systems that support both UEFI and legacy BIOS booting. Since creating +the config file from legacy BIOS wouldn't allow to access the firmware UI. + +To prevent this, make the template to unconditionally create the grub.cfg +snippet but check at runtime if was booted through UEFI to decide if this +entry should be added. That way it won't be added when booting with BIOS. + +There's no need to check if EFI_OS_INDICATIONS_BOOT_TO_FW_UI bit is set, +since that's already done by the "fwsetup" command when is executed. + +Resolves: rhbz#1823864 + +Signed-off-by: Javier Martinez Canillas +--- + util/grub.d/30_uefi-firmware.in | 21 ++++++++------------- + 1 file changed, 8 insertions(+), 13 deletions(-) + +diff --git a/util/grub.d/30_uefi-firmware.in b/util/grub.d/30_uefi-firmware.in +index d344d3883d7..b6041b55e2a 100644 +--- a/util/grub.d/30_uefi-firmware.in ++++ b/util/grub.d/30_uefi-firmware.in +@@ -26,19 +26,14 @@ export TEXTDOMAINDIR="@localedir@" + + . "$pkgdatadir/grub-mkconfig_lib" + +-EFI_VARS_DIR=/sys/firmware/efi/efivars +-EFI_GLOBAL_VARIABLE=8be4df61-93ca-11d2-aa0d-00e098032b8c +-OS_INDICATIONS="$EFI_VARS_DIR/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE" ++LABEL="UEFI Firmware Settings" + +-if [ -e "$OS_INDICATIONS" ] && \ +- [ "$(( $(printf 0x%x \'"$(cat $OS_INDICATIONS | cut -b5)"\') & 1 ))" = 1 ]; then +- LABEL="UEFI Firmware Settings" ++gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2 + +- gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2 +- +- cat << EOF +-menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' { +- fwsetup +-} +-EOF ++cat << EOF ++if [ "\$grub_platform" = "efi" ]; then ++ menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' { ++ fwsetup ++ } + fi ++EOF diff --git a/0193-blscfg-Always-use-the-root-variable-to-search-for-BL.patch b/0193-blscfg-Always-use-the-root-variable-to-search-for-BL.patch deleted file mode 100644 index 612fc3bd051197a67003122560a4c44eba4a4d32..0000000000000000000000000000000000000000 --- a/0193-blscfg-Always-use-the-root-variable-to-search-for-BL.patch +++ /dev/null @@ -1,50 +0,0 @@ -From 2dba8190a3e18837d37b316e82890b60993b18e5 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 14 Jan 2020 17:41:29 +0100 -Subject: [PATCH 193/220] blscfg: Always use the root variable to search for - BLS snippets - -The boot and root variables are set by grub2-mkconfig to tell GRUB what -are the devices and partitions used as the EFI System Partition (ESP) -and to store the /boot directory (or used as the /boot mount point). - -But the boot variable is not needed anymore, this was added because the -blscfg module used to search for the BLS snippets in the ESP, but was -later changed to always search for the BLS files in /boot even for EFI. - -When doing that change, the logic was made backwards and so the boot -variable is wrongly used for legacy BIOS. This only works because this -is set to the same value as the root variable. - -So the correct thing to do is to always use the root variable to search -the BLS snippets, since that is set to the partition that stores them. - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/commands/blscfg.c | 6 ++---- - 1 file changed, 2 insertions(+), 4 deletions(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 069db72..24e35a4 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -1018,14 +1018,12 @@ bls_load_entries (const char *path) - if (!devid) { - #ifdef GRUB_MACHINE_EMU - devid = "host"; --#elif defined(GRUB_MACHINE_EFI) -- devid = grub_env_get ("root"); - #else -- devid = grub_env_get ("boot"); -+ devid = grub_env_get ("root"); - #endif - if (!devid) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, -- N_("variable `%s' isn't set"), "boot"); -+ N_("variable `%s' isn't set"), "root"); - } - - grub_dprintf ("blscfg", "opening %s\n", devid); --- -1.8.3.1 - diff --git a/0193-efi-Print-an-error-if-boot-to-firmware-setup-is-not-.patch b/0193-efi-Print-an-error-if-boot-to-firmware-setup-is-not-.patch new file mode 100644 index 0000000000000000000000000000000000000000..65b4aec54b51585670ec186dbd795214baad484f --- /dev/null +++ b/0193-efi-Print-an-error-if-boot-to-firmware-setup-is-not-.patch @@ -0,0 +1,92 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 6 Jul 2021 01:10:18 +0200 +Subject: [PATCH] efi: Print an error if boot to firmware setup is not + supported + +The "fwsetup" command is only registered if the firmware supports booting +to the firmware setup UI. But it could be possible that the GRUB config +already contains a "fwsetup" entry, because it was generated in a machine +that has support for this feature. + +To prevent users getting a "can't find command `fwsetup`" error if it is +not supported by the firmware, let's just always register the command but +print a more accurate message if the firmware doesn't support this option. + +Resolves: rhbz#1823864 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/efi/efifwsetup.c | 43 ++++++++++++++++++++----------------- + 1 file changed, 23 insertions(+), 20 deletions(-) + +diff --git a/grub-core/commands/efi/efifwsetup.c b/grub-core/commands/efi/efifwsetup.c +index eaca0328388..328c45e82e0 100644 +--- a/grub-core/commands/efi/efifwsetup.c ++++ b/grub-core/commands/efi/efifwsetup.c +@@ -27,6 +27,25 @@ + + GRUB_MOD_LICENSE ("GPLv3+"); + ++static grub_efi_boolean_t ++efifwsetup_is_supported (void) ++{ ++ grub_efi_uint64_t *os_indications_supported = NULL; ++ grub_size_t oi_size = 0; ++ grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID; ++ ++ grub_efi_get_variable ("OsIndicationsSupported", &global, &oi_size, ++ (void **) &os_indications_supported); ++ ++ if (!os_indications_supported) ++ return 0; ++ ++ if (*os_indications_supported & GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI) ++ return 1; ++ ++ return 0; ++} ++ + static grub_err_t + grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), +@@ -38,6 +57,10 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)), + grub_size_t oi_size; + grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID; + ++ if (!efifwsetup_is_supported ()) ++ return grub_error (GRUB_ERR_INVALID_COMMAND, ++ N_("Reboot to firmware setup is not supported")); ++ + grub_efi_get_variable ("OsIndications", &global, &oi_size, + (void **) &old_os_indications); + +@@ -56,28 +79,8 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)), + + static grub_command_t cmd = NULL; + +-static grub_efi_boolean_t +-efifwsetup_is_supported (void) +-{ +- grub_efi_uint64_t *os_indications_supported = NULL; +- grub_size_t oi_size = 0; +- grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID; +- +- grub_efi_get_variable ("OsIndicationsSupported", &global, &oi_size, +- (void **) &os_indications_supported); +- +- if (!os_indications_supported) +- return 0; +- +- if (*os_indications_supported & GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI) +- return 1; +- +- return 0; +-} +- + GRUB_MOD_INIT (efifwsetup) + { +- if (efifwsetup_is_supported ()) + cmd = grub_register_command ("fwsetup", grub_cmd_fwsetup, NULL, + N_("Reboot into firmware setup menu.")); + diff --git a/backport-arm64-Fix-EFI-loader-kernel-image-allocation.patch b/0194-arm64-Fix-EFI-loader-kernel-image-allocation.patch similarity index 73% rename from backport-arm64-Fix-EFI-loader-kernel-image-allocation.patch rename to 0194-arm64-Fix-EFI-loader-kernel-image-allocation.patch index c4b26c024bd637fbad38060deb5971026da161d7..0472a42f3511e081b54059d895b09d35ea6666f8 100644 --- a/backport-arm64-Fix-EFI-loader-kernel-image-allocation.patch +++ b/0194-arm64-Fix-EFI-loader-kernel-image-allocation.patch @@ -1,6 +1,7 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Benjamin Herrenschmidt Date: Mon, 2 Aug 2021 23:10:01 +1000 -Subject: [PATCH 1/2] arm64: Fix EFI loader kernel image allocation +Subject: [PATCH] arm64: Fix EFI loader kernel image allocation We are currently allocating just enough memory for the file size, which means that the kernel BSS is in limbo (and not even zeroed). @@ -13,15 +14,20 @@ actual size it needs, including BSS, and make sure we clear it, and honors the specified alignment for the image. Signed-off-by: Benjamin Herrenschmidt +[pjones: arm: check for the PE magic for the compiled arch] +Signed-off-by: Peter Jones +Signed-off-by: Robbie Harwood --- - grub-core/loader/arm64/linux.c | 102 ++++++++++++++++++++++----------- - 1 file changed, 67 insertions(+), 35 deletions(-) + grub-core/loader/arm64/linux.c | 100 +++++++++++++++++++++++++++-------------- + include/grub/arm/linux.h | 1 + + include/grub/arm64/linux.h | 1 + + 3 files changed, 68 insertions(+), 34 deletions(-) diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c -index a18c487..a803aa9 100644 +index 47f8cf0d84b..f18d90bd749 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c -@@ -40,6 +40,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); +@@ -41,6 +41,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); static grub_dl_t my_mod; static int loaded; @@ -30,7 +36,7 @@ index a18c487..a803aa9 100644 static void *kernel_addr; static grub_uint64_t kernel_size; static grub_uint32_t handover_offset; -@@ -223,9 +225,8 @@ grub_linux_unload (void) +@@ -204,9 +206,8 @@ grub_linux_unload (void) GRUB_EFI_BYTES_TO_PAGES (initrd_end - initrd_start)); initrd_start = initrd_end = 0; grub_free (linux_args); @@ -42,7 +48,7 @@ index a18c487..a803aa9 100644 grub_fdt_unload (); return GRUB_ERR_NONE; } -@@ -330,14 +331,35 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), +@@ -311,14 +312,35 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), return grub_errno; } @@ -56,7 +62,7 @@ index a18c487..a803aa9 100644 + + pe = (void *)((unsigned long)kernel + lh->hdr_offset); + -+ if (pe->opt.magic != GRUB_PE32_PE64_MAGIC) ++ if (pe->opt.magic != GRUB_PE32_PEXX_MAGIC) + return grub_error(GRUB_ERR_BAD_OS, "Invalid PE optional header magic"); + + *total_size = pe->opt.image_size; @@ -80,11 +86,10 @@ index a18c487..a803aa9 100644 int rc; grub_dl_ref (my_mod); -@@ -351,41 +373,25 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); +@@ -333,40 +355,24 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (!file) goto fail; -- + - kernel_size = grub_file_size (file); - - if (grub_file_read (file, &lh, sizeof (lh)) < (long) sizeof (lh)) @@ -100,7 +105,6 @@ index a18c487..a803aa9 100644 - grub_dprintf ("linux", "kernel numpages: %lld\n", - (long long) GRUB_EFI_BYTES_TO_PAGES (kernel_size)); - if (!kernel_addr) -+ + filelen = grub_file_size (file); + kernel = grub_malloc(filelen); + if (!kernel) @@ -124,14 +128,14 @@ index a18c487..a803aa9 100644 - grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); - - if (grub_efi_secure_boot ()) + if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) { - rc = grub_linuxefi_secure_validate (kernel_addr, kernel_size); + rc = grub_linuxefi_secure_validate (kernel, filelen); if (rc <= 0) { grub_error (GRUB_ERR_INVALID_COMMAND, -@@ -394,8 +400,32 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -375,8 +381,32 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), } } @@ -166,7 +170,7 @@ index a18c487..a803aa9 100644 cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE); linux_args = grub_malloc (cmdline_size); -@@ -419,6 +449,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -400,6 +430,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), } fail: @@ -176,7 +180,7 @@ index a18c487..a803aa9 100644 if (file) grub_file_close (file); -@@ -431,9 +464,8 @@ fail: +@@ -412,9 +445,8 @@ fail: if (linux_args && !loaded) grub_free (linux_args); @@ -188,5 +192,27 @@ index a18c487..a803aa9 100644 return grub_errno; } --- -2.23.0 +diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h +index b582f67f661..966a5074f53 100644 +--- a/include/grub/arm/linux.h ++++ b/include/grub/arm/linux.h +@@ -44,6 +44,7 @@ struct grub_arm_linux_pe_header + + #if defined(__arm__) + # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE ++# define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE32_MAGIC + # define linux_arch_kernel_header linux_arm_kernel_header + # define grub_armxx_linux_pe_header grub_arm_linux_pe_header + #endif +diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h +index ea030312df3..422bf2bf24b 100644 +--- a/include/grub/arm64/linux.h ++++ b/include/grub/arm64/linux.h +@@ -48,6 +48,7 @@ struct grub_arm64_linux_pe_header + + #if defined(__aarch64__) + # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE ++# define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE64_MAGIC + # define linux_arch_kernel_header linux_arm64_kernel_header + # define grub_armxx_linux_pe_header grub_arm64_linux_pe_header + #endif diff --git a/0195-normal-main-Discover-the-device-to-read-the-config-f.patch b/0195-normal-main-Discover-the-device-to-read-the-config-f.patch new file mode 100644 index 0000000000000000000000000000000000000000..800903884efbc16d89521bf248817a21f631b1ca --- /dev/null +++ b/0195-normal-main-Discover-the-device-to-read-the-config-f.patch @@ -0,0 +1,123 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 30 Aug 2021 12:31:18 +0200 +Subject: [PATCH] normal/main: Discover the device to read the config from as a + fallback + +The GRUB core.img is generated locally, when this is done the grub2-probe +tool figures out the device and partition that needs to be read to parse +the GRUB configuration file. + +But in some cases the core.img can't be generated on the host and instead +has to be done at package build time. For example, if needs to get signed +with a key that's only available on the package building infrastructure. + +If that's the case, the prefix variable won't have a device and partition +but only a directory path. So there's no way for GRUB to know from which +device has to read the configuration file. + +To allow GRUB to continue working on that scenario, fallback to iterating +over all the available devices, if reading the config failed when using +the prefix and fw_path variables. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/normal/main.c | 58 +++++++++++++++++++++++++++++++++++++++++++------ + 1 file changed, 51 insertions(+), 7 deletions(-) + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 4ebdbd228d4..b72fe3d653c 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -337,18 +337,13 @@ grub_enter_normal_mode (const char *config) + } + + static grub_err_t +-grub_try_normal (const char *variable) ++grub_try_normal_prefix (const char *prefix) + { + char *config; +- const char *prefix; + grub_err_t err = GRUB_ERR_FILE_NOT_FOUND; + const char *net_search_cfg; + int disable_net_search = 0; + +- prefix = grub_env_get (variable); +- if (!prefix) +- return GRUB_ERR_FILE_NOT_FOUND; +- + net_search_cfg = grub_env_get ("feature_net_search_cfg"); + if (net_search_cfg && net_search_cfg[0] == 'n') + disable_net_search = 1; +@@ -362,7 +357,7 @@ grub_try_normal (const char *variable) + config = grub_malloc (config_len); + + if (! config) +- return GRUB_ERR_FILE_NOT_FOUND; ++ return err; + + grub_snprintf (config, config_len, "%s/grub.cfg", prefix); + err = grub_net_search_config_file (config); +@@ -391,6 +386,53 @@ grub_try_normal (const char *variable) + return err; + } + ++static int ++grub_try_normal_dev (const char *name, void *data) ++{ ++ grub_err_t err; ++ const char *prefix = grub_xasprintf ("(%s)%s", name, (char *)data); ++ ++ if (!prefix) ++ return 0; ++ ++ err = grub_try_normal_prefix (prefix); ++ if (err == GRUB_ERR_NONE) ++ return 1; ++ ++ return 0; ++} ++ ++static grub_err_t ++grub_try_normal_discover (void) ++{ ++ char *prefix = grub_env_get ("prefix"); ++ grub_err_t err = GRUB_ERR_FILE_NOT_FOUND; ++ ++ if (!prefix) ++ return err; ++ ++ if (grub_device_iterate (grub_try_normal_dev, (void *)prefix)) ++ return GRUB_ERR_NONE; ++ ++ return err; ++} ++ ++static grub_err_t ++grub_try_normal (const char *variable) ++{ ++ grub_err_t err = GRUB_ERR_FILE_NOT_FOUND; ++ const char *prefix; ++ ++ if (!variable) ++ return err; ++ ++ prefix = grub_env_get (variable); ++ if (!prefix) ++ return err; ++ ++ return grub_try_normal_prefix (prefix); ++} ++ + /* Enter normal mode from rescue mode. */ + static grub_err_t + grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), +@@ -405,6 +447,8 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), + err = grub_try_normal ("fw_path"); + if (err == GRUB_ERR_FILE_NOT_FOUND) + err = grub_try_normal ("prefix"); ++ if (err == GRUB_ERR_FILE_NOT_FOUND) ++ err = grub_try_normal_discover (); + if (err == GRUB_ERR_FILE_NOT_FOUND) + grub_enter_normal_mode (0); + } diff --git a/0196-powerpc-adjust-setting-of-prefix-for-signed-binary-c.patch b/0196-powerpc-adjust-setting-of-prefix-for-signed-binary-c.patch new file mode 100644 index 0000000000000000000000000000000000000000..7f3161e29b03ee56071298ef2d346b73181f4699 --- /dev/null +++ b/0196-powerpc-adjust-setting-of-prefix-for-signed-binary-c.patch @@ -0,0 +1,88 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Mon, 19 Jul 2021 14:35:55 +1000 +Subject: [PATCH] powerpc: adjust setting of prefix for signed binary case + +On RHEL-signed powerpc grub, we sign a grub with -p /grub2 and expect +that there's a boot partition. + +Unfortunately grub_set_prefix_and_root tries to convert this to +($fwdevice)/grub2. This ends up being (ieee1275/disk)/grub2 and that +falls apart pretty quickly - there's no file-system on ieee1275/disk, +and it makes the search routine try things like +(ieee1275/disk,msdos2)(ieee1275/disk)/grub2 which also doesn't work. + +Detect if we would be about to create (ieee1275/disk)/path and don't: +preserve a prefix of /path instead and hope the search later finds us. + +Related: rhbz#1899864 + +Signed-off-by: Daniel Axtens +[rharwood@redhat.com: squash in fixup commit] +Signed-off-by: Robbie Harwood +--- + grub-core/kern/main.c | 49 ++++++++++++++++++++++++++++++++++++++++++++----- + 1 file changed, 44 insertions(+), 5 deletions(-) + +diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c +index b573be6650d..3fc34014726 100644 +--- a/grub-core/kern/main.c ++++ b/grub-core/kern/main.c +@@ -216,13 +216,52 @@ grub_set_prefix_and_root (void) + if (device) + { + char *prefix_set; +- +- prefix_set = grub_xasprintf ("(%s)%s", device, path ? : ""); +- if (prefix_set) ++ ++#ifdef __powerpc__ ++ /* We have to be careful here on powerpc-ieee1275 + signed grub. We ++ will have signed something with a prefix that doesn't have a device ++ because we cannot know in advance what partition we're on. ++ ++ We will have had !device earlier, so we will have set device=fwdevice ++ However, we want to make sure we do not end up setting prefix to be ++ ($fwdevice)/path, because we will then end up trying to boot or search ++ based on a prefix of (ieee1275/disk)/path, which will not work because ++ it's missing a partition. ++ ++ Also: ++ - You can end up with a device with an FS directly on it, without ++ a partition, e.g. ieee1275/cdrom. ++ ++ - powerpc-ieee1275 + grub-install sets e.g. prefix=(,gpt2)/path, ++ which will have now been extended to device=$fwdisk,partition ++ and path=/path ++ ++ - PowerVM will give us device names like ++ ieee1275//vdevice/v-scsi@3000006c/disk@8100000000000000 ++ and we don't want to try to encode some sort of truth table about ++ what sorts of paths represent disks with partition tables and those ++ without partition tables. ++ ++ So we act unless there is a comma in the device, which would indicate ++ a partition has already been specified. ++ ++ (If we only have a path, the code in normal to discover config files ++ will try both without partitions and then with any partitions so we ++ will cover both CDs and HDs.) ++ */ ++ if (grub_strchr (device, ',') == NULL) ++ grub_env_set ("prefix", path); ++ else ++#endif + { +- grub_env_set ("prefix", prefix_set); +- grub_free (prefix_set); ++ prefix_set = grub_xasprintf ("(%s)%s", device, path ? : ""); ++ if (prefix_set) ++ { ++ grub_env_set ("prefix", prefix_set); ++ grub_free (prefix_set); ++ } + } ++ + grub_env_set ("root", device); + } + diff --git a/0197-fs-xfs-Fix-unreadable-filesystem-with-v4-superblock.patch b/0197-fs-xfs-Fix-unreadable-filesystem-with-v4-superblock.patch new file mode 100644 index 0000000000000000000000000000000000000000..893d8b41ae9c07042910f48e22c628da99c8930b --- /dev/null +++ b/0197-fs-xfs-Fix-unreadable-filesystem-with-v4-superblock.patch @@ -0,0 +1,118 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Erwan Velu +Date: Wed, 25 Aug 2021 15:31:52 +0200 +Subject: [PATCH] fs/xfs: Fix unreadable filesystem with v4 superblock + +The commit 8b1e5d193 (fs/xfs: Add bigtime incompat feature support) +introduced the bigtime support by adding some features in v3 inodes. +This change extended grub_xfs_inode struct by 76 bytes but also changed +the computation of XFS_V2_INODE_SIZE and XFS_V3_INODE_SIZE. Prior this +commit, XFS_V2_INODE_SIZE was 100 bytes. After the commit it's 84 bytes +XFS_V2_INODE_SIZE becomes 16 bytes too small. + +As a result, the data structures aren't properly aligned and the GRUB +generates "attempt to read or write outside of partition" errors when +trying to read the XFS filesystem: + + GNU GRUB version 2.11 + .... + grub> set debug=efi,gpt,xfs + grub> insmod part_gpt + grub> ls (hd0,gpt1)/ + partmap/gpt.c:93: Read a valid GPT header + partmap/gpt.c:115: GPT entry 0: start=4096, length=1953125 + fs/xfs.c:931: Reading sb + fs/xfs.c:270: Validating superblock + fs/xfs.c:295: XFS v4 superblock detected + fs/xfs.c:962: Reading root ino 128 + fs/xfs.c:515: Reading inode (128) - 64, 0 + fs/xfs.c:515: Reading inode (739521961424144223) - 344365866970255880, 3840 + error: attempt to read or write outside of partition. + +This commit change the XFS_V2_INODE_SIZE computation by subtracting 76 +bytes instead of 92 bytes from the actual size of grub_xfs_inode struct. +This 76 bytes value comes from added members: + 20 grub_uint8_t unused5 + 1 grub_uint64_t flags2 + 48 grub_uint8_t unused6 + +This patch explicitly splits the v2 and v3 parts of the structure. +The unused4 is still ending of the v2 structures and the v3 starts +at unused5. Thanks to this we will avoid future corruptions of v2 +or v3 inodes. + +The XFS_V2_INODE_SIZE is returning to its expected size and the +filesystem is back to a readable state: + + GNU GRUB version 2.11 + .... + grub> set debug=efi,gpt,xfs + grub> insmod part_gpt + grub> ls (hd0,gpt1)/ + partmap/gpt.c:93: Read a valid GPT header + partmap/gpt.c:115: GPT entry 0: start=4096, length=1953125 + fs/xfs.c:931: Reading sb + fs/xfs.c:270: Validating superblock + fs/xfs.c:295: XFS v4 superblock detected + fs/xfs.c:962: Reading root ino 128 + fs/xfs.c:515: Reading inode (128) - 64, 0 + fs/xfs.c:515: Reading inode (128) - 64, 0 + fs/xfs.c:931: Reading sb + fs/xfs.c:270: Validating superblock + fs/xfs.c:295: XFS v4 superblock detected + fs/xfs.c:962: Reading root ino 128 + fs/xfs.c:515: Reading inode (128) - 64, 0 + fs/xfs.c:515: Reading inode (128) - 64, 0 + fs/xfs.c:515: Reading inode (128) - 64, 0 + fs/xfs.c:515: Reading inode (131) - 64, 768 + efi/ fs/xfs.c:515: Reading inode (3145856) - 1464904, 0 + grub2/ fs/xfs.c:515: Reading inode (132) - 64, 1024 + grub/ fs/xfs.c:515: Reading inode (139) - 64, 2816 + grub> + +Fixes: 8b1e5d193 (fs/xfs: Add bigtime incompat feature support) + +Signed-off-by: Erwan Velu +Tested-by: Carlos Maiolino +Reviewed-by: Daniel Kiper +(cherry picked from commit a4b495520e4dc41a896a8b916a64eda9970c50ea) +--- + grub-core/fs/xfs.c | 14 ++++++++++---- + 1 file changed, 10 insertions(+), 4 deletions(-) + +diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c +index 0f524c3a8a6..e3816d1ec4a 100644 +--- a/grub-core/fs/xfs.c ++++ b/grub-core/fs/xfs.c +@@ -192,6 +192,11 @@ struct grub_xfs_time_legacy + grub_uint32_t nanosec; + } GRUB_PACKED; + ++/* ++ * The struct grub_xfs_inode layout was taken from the ++ * struct xfs_dinode_core which is described here: ++ * https://mirrors.edge.kernel.org/pub/linux/utils/fs/xfs/docs/xfs_filesystem_structure.pdf ++ */ + struct grub_xfs_inode + { + grub_uint8_t magic[2]; +@@ -208,14 +213,15 @@ struct grub_xfs_inode + grub_uint32_t nextents; + grub_uint16_t unused3; + grub_uint8_t fork_offset; +- grub_uint8_t unused4[37]; ++ grub_uint8_t unused4[17]; /* Last member of inode v2. */ ++ grub_uint8_t unused5[20]; /* First member of inode v3. */ + grub_uint64_t flags2; +- grub_uint8_t unused5[48]; ++ grub_uint8_t unused6[48]; /* Last member of inode v3. */ + } GRUB_PACKED; + + #define XFS_V3_INODE_SIZE sizeof(struct grub_xfs_inode) +-/* Size of struct grub_xfs_inode until fork_offset (included). */ +-#define XFS_V2_INODE_SIZE (XFS_V3_INODE_SIZE - 92) ++/* Size of struct grub_xfs_inode v2, up to unused4 member included. */ ++#define XFS_V2_INODE_SIZE (XFS_V3_INODE_SIZE - 76) + + struct grub_xfs_dirblock_tail + { diff --git a/0198-Print-module-name-on-license-check-failure.patch b/0198-Print-module-name-on-license-check-failure.patch new file mode 100644 index 0000000000000000000000000000000000000000..c4b9a134421e5169874b9aa25e036ed8fef6dab8 --- /dev/null +++ b/0198-Print-module-name-on-license-check-failure.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robbie Harwood +Date: Tue, 12 Oct 2021 12:34:23 -0400 +Subject: [PATCH] Print module name on license check failure + +At the very least, this will make it easier to track down the problem +module - or, if something else has gone wrong, provide more information +for debugging. + +Signed-off-by: Robbie Harwood +--- + grub-core/kern/dl.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index 9557254035e..f3044945742 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -528,14 +528,16 @@ grub_dl_find_section_index (Elf_Ehdr *e, const char *name) + Be sure to understand your license obligations. + */ + static grub_err_t +-grub_dl_check_license (Elf_Ehdr *e) ++grub_dl_check_license (grub_dl_t mod, Elf_Ehdr *e) + { + Elf_Shdr *s = grub_dl_find_section (e, ".module_license"); + if (s && (grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv3") == 0 + || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv3+") == 0 + || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv2+") == 0)) + return GRUB_ERR_NONE; +- return grub_error (GRUB_ERR_BAD_MODULE, "incompatible license"); ++ return grub_error (GRUB_ERR_BAD_MODULE, ++ "incompatible license in module %s: %s", mod->name, ++ (char *) e + s->sh_offset); + } + + static grub_err_t +@@ -743,8 +745,8 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size) + constitutes linking) and GRUB core being licensed under GPLv3+. + Be sure to understand your license obligations. + */ +- if (grub_dl_check_license (e) +- || grub_dl_resolve_name (mod, e) ++ if (grub_dl_resolve_name (mod, e) ++ || grub_dl_check_license (mod, e) + || grub_dl_resolve_dependencies (mod, e) + || grub_dl_load_segments (mod, e) + || grub_dl_resolve_symbols (mod, e) diff --git a/0199-blscfg-return-NULL-instead-of-a-zero-length-array-in.patch b/0199-blscfg-return-NULL-instead-of-a-zero-length-array-in.patch deleted file mode 100644 index c27f78940a42c51e92068281e05c8ce854e16f5b..0000000000000000000000000000000000000000 --- a/0199-blscfg-return-NULL-instead-of-a-zero-length-array-in.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 2b8388901cc52d875baa490a97dd314ef51ed0d9 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Mon, 16 Mar 2020 13:51:45 +0100 -Subject: [PATCH 199/220] 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 24e35a4..9263a5c 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; - --- -1.8.3.1 - diff --git a/0199-powerpc-ieee1275-load-grub-at-4MB-not-2MB.patch b/0199-powerpc-ieee1275-load-grub-at-4MB-not-2MB.patch new file mode 100644 index 0000000000000000000000000000000000000000..a80727e0bb16e2a24f1b006fb3d10300207996a3 --- /dev/null +++ b/0199-powerpc-ieee1275-load-grub-at-4MB-not-2MB.patch @@ -0,0 +1,106 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Fri, 22 Oct 2021 09:53:15 +1100 +Subject: [PATCH] powerpc-ieee1275: load grub at 4MB, not 2MB + +This was first reported under PFW but reproduces under SLOF. + + - The core.elf was 2126152 = 0x207148 bytes in size with the following + program headers (per readelf): + +Entry point 0x200000 +There are 4 program headers, starting at offset 52 + +Program Headers: + Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align + LOAD 0x000160 0x00200000 0x00200000 0x21f98 0x2971c RWE 0x8 + GNU_STACK 0x0220f8 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4 + LOAD 0x0220f8 0x00232000 0x00232000 0x1e4e50 0x1e4e50 RWE 0x4 + NOTE 0x206f48 0x00000000 0x00000000 0x00200 0x00000 R 0x4 + + - SLOF places the ELF file at 0x4000 (after the reserved space for + interrupt handlers etc.) upwards. The image was 2126152 = 0x207148 + bytes in size, so it runs from 0x4000 - 0x20b148. We'll call 0x4000 the + load address. + +0x0 0x4000 0x20b148 + |----------|--------------| + | reserved | ELF contents | + + - SLOF then copies the first LOAD program header (for .text). That runs + for 0x21f98 bytes. It runs from + (load addr + 0x160) to (load addr + 0x160 + 0x21f98) + = 0x4160 to 0x260f8 + and we copy it to 0x200000 to 0x221f98. This overwrites the end of the + image: + +0x0 0x4000 0x200000 0x221f98 + |----------|------------|---------------| + | reserved | ELF cont.. | .text section | + + - SLOF zeros the bss up to PhysAddr + MemSize = 0x22971c + +0x0 0x4000 0x200000 0x221f98 0x22971c + |----------|------------|---------------|--------| + | reserved | ELF cont.. | .text section | bss 0s | + + - SLOF then goes to fulfil the next LOAD header (for mods), which is + for 0x1e4e50 bytes. We copy from + (load addr + 0x220f8) to (load addr + 0x220f8 + 0x1e4e50) + = 0x260f8 to 0x20af48 + and we copy it to 0x232000 to 0x416e50: + +0x0 0x4000 0x200000 0x221f98 0x22971c + |----------|------------|---------------|--------| + | reserved | ELF cont.. | .text section | bss 0s | + |-------------| + | copied area | + 0x260f8 0x20af48 + + This goes poorly: + +0x0 0x4000 0x200000 0x221f98 0x22971c 0x232000 0x40bf08 0x416e50 + |----------|------------|---------------|--------|-----|-----------|-------------| + | reserved | ELF cont.. | .text section | bss 0s | pad | some mods | .text start | + +This matches the observations on the running system - 0x40bf08 was where +the contents of memory no longer matched the contents of the ELF file. + +This was reported as a license verification failure on SLOF as the +last module's .module_license section fell past where the corruption +began. + +Signed-off-by: Daniel Axtens +[rharwood@redhat.com: trim very detailed commit message] +Signed-off-by: Robbie Harwood +--- + grub-core/Makefile.core.def | 2 +- + include/grub/offsets.h | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 3f3459b2c70..6b00eb55575 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -89,7 +89,7 @@ kernel = { + i386_xen_pvh_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x100000'; + + mips_loongson_ldflags = '-Wl,-Ttext,0x80200000'; +- powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000'; ++ powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x400000'; + sparc64_ieee1275_ldflags = '-Wl,-Ttext,0x4400'; + mips_arc_ldflags = '-Wl,-Ttext,$(TARGET_LINK_ADDR)'; + mips_qemu_mips_ldflags = '-Wl,-Ttext,0x80200000'; +diff --git a/include/grub/offsets.h b/include/grub/offsets.h +index 871e1cd4c38..69211aa798b 100644 +--- a/include/grub/offsets.h ++++ b/include/grub/offsets.h +@@ -63,7 +63,7 @@ + #define GRUB_KERNEL_SPARC64_IEEE1275_LINK_ADDR 0x4400 + + #define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ALIGN 4 +-#define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ADDR 0x200000 ++#define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ADDR 0x400000 + + #define GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR 0x80200000 + diff --git a/backport-CVE-2021-3981-restore-umask-for-the-grub.patch b/0200-grub-mkconfig-restore-umask-for-grub.cfg.patch similarity index 33% rename from backport-CVE-2021-3981-restore-umask-for-the-grub.patch rename to 0200-grub-mkconfig-restore-umask-for-grub.cfg.patch index e2a6414ef05b736844b80d0917c4435f694a2778..7c7bee0e60f5eb8d1f55dccd2d0052aa7f672663 100644 --- a/backport-CVE-2021-3981-restore-umask-for-the-grub.patch +++ b/0200-grub-mkconfig-restore-umask-for-grub.cfg.patch @@ -1,41 +1,40 @@ -From 0adec29674561034771c13e446069b41ef41e4d4 Mon Sep 17 00:00:00 2001 -From: Michael Chang +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang via Grub-devel Date: Fri, 3 Dec 2021 16:13:28 +0800 -Subject: grub-mkconfig: Restore umask for the grub.cfg +Subject: [PATCH] grub-mkconfig: restore umask for grub.cfg -The commit ab2e53c8a (grub-mkconfig: Honor a symlink when generating -configuration by grub-mkconfig) has inadvertently discarded umask for -creating grub.cfg in the process of running grub-mkconfig. The resulting -wrong permission (0644) would allow unprivileged users to read GRUB -configuration file content. This presents a low confidentiality risk -as grub.cfg may contain non-secured plain-text passwords. +Since commit: -This patch restores the missing umask and sets the creation file mode + ab2e53c8a grub-mkconfig: Honor a symlink when generating configuration +by grub-mkconfig + +has inadvertently discarded umask for creating grub.cfg in the process +of grub-mkconfig. The resulting wrong permission (0644) would allow +unprivileged users to read grub's configuration file content. This +presents a low confidentiality risk as grub.cfg may contain non-secured +plain-text passwords. + +This patch restores the missing umask and set the file mode of creation to 0600 preventing unprivileged access. Fixes: CVE-2021-3981 Signed-off-by: Michael Chang -Reviewed-by: Daniel Kiper --- - util/grub-mkconfig.in | 3 +++ - 1 file changed, 3 insertions(+) + util/grub-mkconfig.in | 2 ++ + 1 file changed, 2 insertions(+) diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index c3ea761..62335d0 100644 +index f55339a3f64..520a672cd2c 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in -@@ -301,7 +301,10 @@ and /etc/grub.d/* files or please file a bug report with +@@ -311,7 +311,9 @@ and /etc/grub.d/* files or please file a bug report with exit 1 else # none of the children aborted with error, install the new grub.cfg -+ oldumask=$(umask) -+ umask 077 ++ oldumask=$(umask); umask 077 cat ${grub_cfg}.new > ${grub_cfg} + umask $oldumask rm -f ${grub_cfg}.new fi fi --- -cgit v1.1 - diff --git a/0200-grub-switch-to-blscfg-Update-grub2-binary-in-ESP-for.patch b/0200-grub-switch-to-blscfg-Update-grub2-binary-in-ESP-for.patch deleted file mode 100644 index b06d6c93e6c1f32b7ce2ebcbef627995072876f8..0000000000000000000000000000000000000000 --- a/0200-grub-switch-to-blscfg-Update-grub2-binary-in-ESP-for.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 8695bfa3538b24635c77242669cb35a70603e599 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Thu, 26 Mar 2020 15:08:30 +0100 -Subject: [PATCH 200/220] grub-switch-to-blscfg: Update grub2 binary in ESP for - OSTree systems - -The grub2 EFI binary in the ESP isn't updated as a part of an OSTree update -transaction. So let's make the script to update this and also create a file -to indicate that the installed version has support for the blscfg module. - -Related: rhbz#1751272 - -Signed-off-by: Javier Martinez Canillas ---- - util/grub-switch-to-blscfg.in | 9 +++++++++ - 1 file changed, 9 insertions(+) - -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index 49b3985..a05a8d9 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -266,6 +266,15 @@ copy_bls() { - fi - } - -+# The grub2 EFI binary is not copied to the ESP as a part of an ostree -+# transaction. Make sure a grub2 version with BLS support is installed. -+if test -f /run/ostree-booted && test -d /sys/firmware/efi/efivars/; then -+ grub_binary="$(find /usr/lib/ostree-boot/efi/EFI/${EFIDIR}/ -name grub*.efi)" -+ cp ${grub_binary} ${grubdir} || exit 1 -+ # Create a hidden file to indicate that grub2 now has BLS support. -+ touch /boot/grub2/.grub2-blscfg-supported -+fi -+ - GENERATE=0 - if grep '^GRUB_ENABLE_BLSCFG=.*' "${etcdefaultgrub}" \ - | grep -vq '^GRUB_ENABLE_BLSCFG="*true"*\s*$' ; then --- -1.8.3.1 - diff --git a/0201-fs-btrfs-Use-full-btrfs-bootloader-area.patch b/0201-fs-btrfs-Use-full-btrfs-bootloader-area.patch new file mode 100644 index 0000000000000000000000000000000000000000..ecfc58cd684f5430edd68e7f3523da02fcbebcd9 --- /dev/null +++ b/0201-fs-btrfs-Use-full-btrfs-bootloader-area.patch @@ -0,0 +1,160 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Mon, 13 Dec 2021 14:25:49 +0800 +Subject: [PATCH] fs/btrfs: Use full btrfs bootloader area + +Up to now GRUB can only embed to the first 64 KiB before primary +superblock of btrfs, effectively limiting the GRUB core size. That +could consequently pose restrictions to feature enablement like +advanced zstd compression. + +This patch attempts to utilize full unused area reserved by btrfs for +the bootloader outlined in the document [1]: + + The first 1MiB on each device is unused with the exception of primary + superblock that is on the offset 64KiB and spans 4KiB. + +Apart from that, adjacent sectors to superblock and first block group +are not used for embedding in case of overflow and logged access to +adjacent sectors could be useful for tracing it up. + +This patch has been tested to provide out of the box support for btrfs +zstd compression with which GRUB has been installed to the partition. + +[1] https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs(5)#BOOTLOADER_SUPPORT + +Signed-off-by: Michael Chang +Reviewed-by: Daniel Kiper +(cherry picked from commit b0f06a81c6f31b6fa20be67a96b6683bba8210c9) +--- + grub-core/fs/btrfs.c | 90 ++++++++++++++++++++++++++++++++++++++++++++-------- + include/grub/disk.h | 2 ++ + 2 files changed, 79 insertions(+), 13 deletions(-) + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 4cc86e9b79e..07c0ff874b8 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -2476,6 +2476,33 @@ grub_btrfs_label (grub_device_t device, char **label) + } + + #ifdef GRUB_UTIL ++ ++struct embed_region { ++ unsigned int start; ++ unsigned int secs; ++}; ++ ++/* ++ * https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs(5)#BOOTLOADER_SUPPORT ++ * The first 1 MiB on each device is unused with the exception of primary ++ * superblock that is on the offset 64 KiB and spans 4 KiB. ++ */ ++ ++static const struct { ++ struct embed_region available; ++ struct embed_region used[6]; ++} btrfs_head = { ++ .available = {0, GRUB_DISK_KiB_TO_SECTORS (1024)}, /* The first 1 MiB. */ ++ .used = { ++ {0, 1}, /* boot.S. */ ++ {GRUB_DISK_KiB_TO_SECTORS (64) - 1, 1}, /* Overflow guard. */ ++ {GRUB_DISK_KiB_TO_SECTORS (64), GRUB_DISK_KiB_TO_SECTORS (4)}, /* 4 KiB superblock. */ ++ {GRUB_DISK_KiB_TO_SECTORS (68), 1}, /* Overflow guard. */ ++ {GRUB_DISK_KiB_TO_SECTORS (1024) - 1, 1}, /* Overflow guard. */ ++ {0, 0} /* Array terminator. */ ++ } ++}; ++ + static grub_err_t + grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), + unsigned int *nsectors, +@@ -2483,25 +2510,62 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), + grub_embed_type_t embed_type, + grub_disk_addr_t **sectors) + { +- unsigned i; ++ unsigned int i, j, n = 0; ++ const struct embed_region *u; ++ grub_disk_addr_t *map; + + if (embed_type != GRUB_EMBED_PCBIOS) + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "BtrFS currently supports only PC-BIOS embedding"); + +- if (64 * 2 - 1 < *nsectors) +- return grub_error (GRUB_ERR_OUT_OF_RANGE, +- N_("your core.img is unusually large. " +- "It won't fit in the embedding area")); +- +- *nsectors = 64 * 2 - 1; +- if (*nsectors > max_nsectors) +- *nsectors = max_nsectors; +- *sectors = grub_calloc (*nsectors, sizeof (**sectors)); +- if (!*sectors) ++ map = grub_calloc (btrfs_head.available.secs, sizeof (*map)); ++ if (map == NULL) + return grub_errno; +- for (i = 0; i < *nsectors; i++) +- (*sectors)[i] = i + 1; ++ ++ /* ++ * Populating the map array so that it can be used to index if a disk ++ * address is available to embed: ++ * - 0: available, ++ * - 1: unavailable. ++ */ ++ for (u = btrfs_head.used; u->secs; ++u) ++ { ++ unsigned int end = u->start + u->secs; ++ ++ if (end > btrfs_head.available.secs) ++ end = btrfs_head.available.secs; ++ for (i = u->start; i < end; ++i) ++ map[i] = 1; ++ } ++ ++ /* Adding up n until it matches total size of available embedding area. */ ++ for (i = 0; i < btrfs_head.available.secs; ++i) ++ if (map[i] == 0) ++ n++; ++ ++ if (n < *nsectors) ++ { ++ grub_free (map); ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, ++ N_("your core.img is unusually large. " ++ "It won't fit in the embedding area")); ++ } ++ ++ if (n > max_nsectors) ++ n = max_nsectors; ++ ++ /* ++ * Populating the array so that it can used to index disk block address for ++ * an image file's offset to be embedded on disk (the unit is in sectors): ++ * - i: The disk block address relative to btrfs_head.available.start, ++ * - j: The offset in image file. ++ */ ++ for (i = 0, j = 0; i < btrfs_head.available.secs && j < n; ++i) ++ if (map[i] == 0) ++ map[j++] = btrfs_head.available.start + i; ++ ++ *nsectors = n; ++ *sectors = map; + + return GRUB_ERR_NONE; + } +diff --git a/include/grub/disk.h b/include/grub/disk.h +index f95aca929a6..06210a70492 100644 +--- a/include/grub/disk.h ++++ b/include/grub/disk.h +@@ -182,6 +182,8 @@ typedef struct grub_disk_memberlist *grub_disk_memberlist_t; + /* Return value of grub_disk_native_sectors() in case disk size is unknown. */ + #define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL + ++#define GRUB_DISK_KiB_TO_SECTORS(x) ((x) << (10 - GRUB_DISK_SECTOR_BITS)) ++ + /* Convert sector number from one sector size to another. */ + static inline grub_disk_addr_t + grub_convert_sector (grub_disk_addr_t sector, diff --git a/0201-grub-switch-to-blscfg-Only-mark-GRUB-as-BLS-supporte.patch b/0201-grub-switch-to-blscfg-Only-mark-GRUB-as-BLS-supporte.patch deleted file mode 100644 index 920606a995e9f349881db7de742c256319328a16..0000000000000000000000000000000000000000 --- a/0201-grub-switch-to-blscfg-Only-mark-GRUB-as-BLS-supporte.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 96e237b59b621bcfe6f5fa888fe583def382d415 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Thu, 2 Apr 2020 11:07:24 +0200 -Subject: [PATCH 201/220] grub-switch-to-blscfg: Only mark GRUB as BLS - supported if blsdir isn't set - -If the user set the blsdir environemnt variable to a path that is not the -default where ostree writes the BLS snippets, the blscfg module won't be -able to parse them and can lead to not having any menu entries on boot. - -So to minimize the risk of things going wrong when dropping the 15_ostree -script used by ostree to create the menu entries, only mark the bootloader -as BLS supported if the blsdir variable has not been set. - -Signed-off-by: Javier Martinez Canillas ---- - util/grub-switch-to-blscfg.in | 7 +++++-- - 1 file changed, 5 insertions(+), 2 deletions(-) - -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index a05a8d9..4bbed8e 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -267,8 +267,11 @@ copy_bls() { - } - - # The grub2 EFI binary is not copied to the ESP as a part of an ostree --# transaction. Make sure a grub2 version with BLS support is installed. --if test -f /run/ostree-booted && test -d /sys/firmware/efi/efivars/; then -+# transaction. Make sure a grub2 version with BLS support is installed -+# but only do this if the blsdir is not set, to make sure that the BLS -+# parsing module will search for the BLS snippets in the default path. -+if test -f /run/ostree-booted && test -d /sys/firmware/efi/efivars && \ -+ ! ${grub_editenv} - list | grep -q blsdir; then - grub_binary="$(find /usr/lib/ostree-boot/efi/EFI/${EFIDIR}/ -name grub*.efi)" - cp ${grub_binary} ${grubdir} || exit 1 - # Create a hidden file to indicate that grub2 now has BLS support. --- -1.8.3.1 - diff --git a/0202-10_linux.in-Merge-logic-from-10_linux_bls-and-drop-t.patch b/0202-10_linux.in-Merge-logic-from-10_linux_bls-and-drop-t.patch deleted file mode 100644 index 576503bc0583dd9ef45ed5e148b79ec2750ab837..0000000000000000000000000000000000000000 --- a/0202-10_linux.in-Merge-logic-from-10_linux_bls-and-drop-t.patch +++ /dev/null @@ -1,665 +0,0 @@ -From 25d1ed30a9330c8b3d84fdc3e0812ef5d1db5238 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 31 Mar 2020 12:35:42 +0200 -Subject: [PATCH 202/220] 10_linux.in: Merge logic from 10_linux_bls and drop - that script - -There's a 10_linux_bls snippet that's used in ppc64le machines to generate -a set of menuentry commands by parsing BLS configs in /boot/loader/entries. - -This was made because on PowerNV ppc64le machines that boot using the OPAL -firmware, there could be an old version of the Petitboot bootloader that -doesn't have support to parse BLS snippets. - -But there is no need to have a separate GRUB script for that and the logic -could just be part of the usual 10_linux snippet. - -Also the BLS files could be used directly if the bootloader has support to -parse them, which is the case for GRUB that's used in ppc64le OF or if the -Petitboot used in ppc64le OPAL machines is version 1.8.0 or newer. - -So only generate the menuentry commands from the BLS snippets in the case -of OPAL machines with an old Petitboot version. - -Signed-off-by: Javier Martinez Canillas ---- - Makefile.util.def | 7 - - util/grub.d/10_linux.in | 97 ++++++++- - util/grub.d/10_linux_bls.in | 470 -------------------------------------------- - 3 files changed, 96 insertions(+), 478 deletions(-) - delete mode 100644 util/grub.d/10_linux_bls.in - -diff --git a/Makefile.util.def b/Makefile.util.def -index 1fa92ca..f3a6996 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -518,13 +518,6 @@ script = { - }; - - script = { -- name = '10_linux_bls'; -- common = util/grub.d/10_linux_bls.in; -- installdir = grubconf; -- condition = COND_HOST_LINUX; --}; -- --script = { - name = '10_reset_boot_success'; - common = util/grub.d/10_reset_boot_success.in; - installdir = grubconf; -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index b70dca2..c72cc32 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -84,18 +84,86 @@ esac - - populate_header_warn() - { -+if [ "x${BLS_POPULATE_MENU}" = "xtrue" ]; then -+ bls_parser="10_linux script" -+else -+ bls_parser="blscfg command" -+fi - cat <&2 -+ -+ files=($(for bls in ${blsdir}/*.conf ; do -+ if ! [[ -e "${bls}" ]] ; then -+ continue -+ fi -+ bls="${bls%.conf}" -+ bls="${bls##*/}" -+ echo "${bls}" -+ done | ${kernel_sort} | tac)) || : -+ -+ for bls in "${files[@]}" ; do -+ read_config "${blsdir}/${bls}.conf" -+ -+ menu="${menu}menuentry '${title}' ${grub_arg} --id=${bls} {\n" -+ menu="${menu}\t linux ${linux} ${options}\n" -+ if [ -n "${initrd}" ] ; then -+ menu="${menu}\t initrd ${boot_prefix}${initrd}\n" -+ fi -+ menu="${menu}}\n\n" -+ done -+ # The printf command seems to be more reliable across shells for special character (\n, \t) evaluation -+ printf "$menu" -+} -+ - if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then - if [ x$dirname = x/ ]; then - if [ -z "${prepare_root_cache}" ]; then -@@ -115,6 +183,26 @@ if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then - prepare_grub_to_access_device_with_variable boot ${boot_device} - fi - -+ arch="$(uname -m)" -+ if [ "x${arch}" = "xppc64le" ] && [ -d /sys/firmware/opal ]; then -+ -+ petitboot_path="/sys/firmware/devicetree/base/ibm,firmware-versions/petitboot" -+ -+ if test -e ${petitboot_path}; then -+ read -a petitboot_version < ${petitboot_path} -+ petitboot_version="$(echo ${petitboot_version//v})" -+ major_version="$(echo ${petitboot_version} | cut -d . -f1)" -+ minor_version="$(echo ${petitboot_version} | cut -d . -f2)" -+ -+ if test -z ${petitboot_version} || test ${major_version} -lt 1 || \ -+ test ${major_version} -eq 1 -a ${minor_version} -lt 8; then -+ BLS_POPULATE_MENU="true" -+ fi -+ else -+ BLS_POPULATE_MENU="true" -+ fi -+ fi -+ - populate_header_warn - - cat << EOF -@@ -129,10 +217,17 @@ if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then - if [ -z "\${kernelopts}" ]; then - set kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" - fi -+EOF -+ -+ if [ "x${BLS_POPULATE_MENU}" = "xtrue" ]; then -+ populate_menu -+ else -+ cat << EOF - - insmod blscfg - blscfg - EOF -+ fi - - if [ "x${GRUB_GRUBENV_UPDATE}" = "xyes" ]; then - blsdir="/boot/loader/entries" -diff --git a/util/grub.d/10_linux_bls.in b/util/grub.d/10_linux_bls.in -deleted file mode 100644 -index 68fbedf..0000000 ---- a/util/grub.d/10_linux_bls.in -+++ /dev/null -@@ -1,470 +0,0 @@ --#! /bin/sh --set -e -- --# grub-mkconfig helper script. --# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. --# --# GRUB is free software: you can redistribute it and/or modify --# it under the terms of the GNU General Public License as published by --# the Free Software Foundation, either version 3 of the License, or --# (at your option) any later version. --# --# GRUB is distributed in the hope that it will be useful, --# but WITHOUT ANY WARRANTY; without even the implied warranty of --# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --# GNU General Public License for more details. --# --# You should have received a copy of the GNU General Public License --# along with GRUB. If not, see . -- --prefix="@prefix@" --exec_prefix="@exec_prefix@" --datarootdir="@datarootdir@" -- --. "$pkgdatadir/grub-mkconfig_lib" -- --export TEXTDOMAIN=@PACKAGE@ --export TEXTDOMAINDIR="@localedir@" -- --CLASS="--class gnu-linux --class gnu --class os --unrestricted" -- --if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then -- OS="$(eval $(grep PRETTY_NAME /etc/os-release) ; echo ${PRETTY_NAME})" -- CLASS="--class $(eval $(grep '^ID_LIKE=\|^ID=' /etc/os-release) ; [ -n "${ID_LIKE}" ] && echo ${ID_LIKE} || echo ${ID}) ${CLASS}" --else -- OS="${GRUB_DISTRIBUTOR}" -- CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" --fi -- --# loop-AES arranges things so that /dev/loop/X can be our root device, but --# the initrds that Linux uses don't like that. --case ${GRUB_DEVICE} in -- /dev/loop/*|/dev/loop[0-9]) -- GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"` -- ;; --esac -- --# Default to disabling partition uuid support to maintian compatibility with --# older kernels. --GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true} -- --# btrfs may reside on multiple devices. We cannot pass them as value of root= parameter --# and mounting btrfs requires user space scanning, so force UUID in this case. --if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \ -- || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ -- && [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \ -- || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ -- && ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \ -- || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then -- LINUX_ROOT_DEVICE=${GRUB_DEVICE} --elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \ -- || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then -- LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID} --else -- LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} --fi -- --case x"$GRUB_FS" in -- xbtrfs) -- if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then -- GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}" -- else -- rootsubvol="`make_system_path_relative_to_its_root /`" -- rootsubvol="${rootsubvol#/}" -- if [ "x${rootsubvol}" != x ]; then -- GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" -- fi -- fi;; -- xzfs) -- rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` -- bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`" -- LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}" -- ;; --esac -- --mktitle () --{ -- local title_type -- local version -- local OS_NAME -- local OS_VERS -- -- title_type=$1 && shift -- version=$1 && shift -- -- OS_NAME="$(eval $(grep ^NAME= /etc/os-release) ; echo ${NAME})" -- OS_VERS="$(eval $(grep ^VERSION= /etc/os-release) ; echo ${VERSION})" -- -- case $title_type in -- recovery) -- title=$(printf '%s (%s) %s (recovery mode)' \ -- "${OS_NAME}" "${version}" "${OS_VERS}") -- ;; -- *) -- title=$(printf '%s (%s) %s' \ -- "${OS_NAME}" "${version}" "${OS_VERS}") -- ;; -- esac -- echo -n ${title} --} -- --title_correction_code= -- --populate_header_warn() --{ --cat <&2 -- -- files=($(for bls in ${blsdir}/*.conf ; do -- if ! [[ -e "${bls}" ]] ; then -- continue -- fi -- bls="${bls%.conf}" -- bls="${bls##*/}" -- echo "${bls}" -- done | ${kernel_sort} | tac)) || : -- -- for bls in "${files[@]}" ; do -- read_config "${blsdir}/${bls}.conf" -- -- menu="${menu}menuentry '${title}' ${grub_arg} --id=${bls} {\n" -- menu="${menu}\t linux ${linux} ${options}\n" -- if [ -n "${initrd}" ] ; then -- menu="${menu}\t initrd ${boot_prefix}${initrd}\n" -- fi -- menu="${menu}}\n\n" -- done -- # The printf command seems to be more reliable across shells for special character (\n, \t) evaluation -- printf "$menu" --} -- --linux_entry () --{ -- os="$1" -- version="$2" -- type="$3" -- isdebug="$4" -- args="$5" -- -- if [ -z "$boot_device_id" ]; then -- boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" -- fi -- -- if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then -- if [ x$dirname = x/ ]; then -- if [ -z "${prepare_root_cache}" ]; then -- prepare_grub_to_access_device ${GRUB_DEVICE} -- fi -- else -- if [ -z "${prepare_boot_cache}" ]; then -- prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} -- fi -- fi -- -- if [ -d /sys/firmware/efi ]; then -- bootefi_device="`${grub_probe} --target=device /boot/efi/`" -- prepare_grub_to_access_device_with_variable boot ${bootefi_device} -- else -- boot_device="`${grub_probe} --target=device /boot/`" -- prepare_grub_to_access_device_with_variable boot ${boot_device} -- fi -- -- populate_header_warn -- populate_menu -- -- if [ "x${GRUB_GRUBENV_UPDATE}" = "xyes" ]; then -- blsdir="/boot/loader/entries" -- [ -d "${blsdir}" ] && GRUB_BLS_FS="$(${grub_probe} --target=fs ${blsdir})" -- if [ "x${GRUB_BLS_FS}" = "xbtrfs" ] || [ "x${GRUB_BLS_FS}" = "xzfs" ]; then -- blsdir=$(make_system_path_relative_to_its_root "${blsdir}") -- if [ "x${blsdir}" != "x/loader/entries" ] && [ "x${blsdir}" != "x/boot/loader/entries" ]; then -- ${grub_editenv} - set blsdir="${blsdir}" -- fi -- fi -- -- ${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}" -- if [ -n "${GRUB_EARLY_INITRD_LINUX_CUSTOM}" ]; then -- ${grub_editenv} - set early_initrd="${GRUB_EARLY_INITRD_LINUX_CUSTOM}" -- fi -- fi -- -- exit 0 -- fi -- -- if [ x$type != xsimple ] ; then -- title=$(mktitle "$type" "$version") -- if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then -- replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')" -- quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)" -- title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;" -- fi -- if [ x$isdebug = xdebug ]; then -- title="$title${GRUB_LINUX_DEBUG_TITLE_POSTFIX}" -- fi -- echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/" -- else -- echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/" -- fi -- if [ x$type != xrecovery ] ; then -- save_default_entry | grub_add_tab -- fi -- -- # Use ELILO's generic "efifb" when it's known to be available. -- # FIXME: We need an interface to select vesafb in case efifb can't be used. -- if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then -- echo " load_video" | sed "s/^/$submenu_indentation/" -- if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \ -- && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then -- echo " set gfxpayload=keep" | sed "s/^/$submenu_indentation/" -- fi -- else -- if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then -- echo " load_video" | sed "s/^/$submenu_indentation/" -- fi -- echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/" -- fi -- -- echo " insmod gzio" | sed "s/^/$submenu_indentation/" -- -- if [ x$dirname = x/ ]; then -- if [ -z "${prepare_root_cache}" ]; then -- prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)" -- fi -- printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/" -- else -- if [ -z "${prepare_boot_cache}" ]; then -- prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)" -- fi -- printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" -- fi -- sed "s/^/$submenu_indentation/" << EOF -- linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} --EOF -- if test -n "${initrd}" ; then -- initrd_path= -- for i in ${initrd}; do -- initrd_path="${initrd_path} ${rel_dirname}/${i}" -- done -- sed "s/^/$submenu_indentation/" << EOF -- initrd $(echo $initrd_path) --EOF -- fi -- if test -n "${fdt}" ; then -- sed "s/^/$submenu_indentation/" << EOF -- devicetree ${rel_dirname}/${fdt} --EOF -- fi -- sed "s/^/$submenu_indentation/" << EOF --} --EOF --} -- --machine=`uname -m` --case "x$machine" in -- xi?86 | xx86_64) -- list= -- for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do -- if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi -- done ;; -- *) -- list= -- for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do -- if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi -- done ;; --esac -- --if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then -- for i in /boot/ostree/*/vmlinuz-* ; do -- if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi -- done --fi -- --case "$machine" in -- i?86) GENKERNEL_ARCH="x86" ;; -- mips|mips64) GENKERNEL_ARCH="mips" ;; -- mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;; -- arm*) GENKERNEL_ARCH="arm" ;; -- *) GENKERNEL_ARCH="$machine" ;; --esac -- --prepare_boot_cache= --prepare_root_cache= --boot_device_id= --title_correction_code= -- --# Extra indentation to add to menu entries in a submenu. We're not in a submenu --# yet, so it's empty. In a submenu it will be equal to '\t' (one tab). --submenu_indentation="" -- --is_top_level=true --while [ "x$list" != "x" ] ; do -- linux=`version_find_latest $list` -- if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then -- gettext_printf "Found linux image: %s\n" "$linux" >&2 -- fi -- -- basename=`basename $linux` -- dirname=`dirname $linux` -- rel_dirname=`make_system_path_relative_to_its_root $dirname` -- version=`echo $basename | sed -e "s,^[^0-9]*-,,g"` -- alt_version=`echo $version | sed -e "s,\.old$,,g"` -- linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" -- -- initrd_early= -- for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \ -- ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do -- if test -e "${dirname}/${i}" ; then -- initrd_early="${initrd_early} ${i}" -- fi -- done -- -- initrd_real= -- for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \ -- "initrd-${version}" "initramfs-${version}.img" \ -- "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ -- "initrd-${alt_version}" "initramfs-${alt_version}.img" \ -- "initramfs-genkernel-${version}" \ -- "initramfs-genkernel-${alt_version}" \ -- "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \ -- "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do -- if test -e "${dirname}/${i}" ; then -- initrd_real="${i}" -- break -- fi -- done -- -- initrd= -- if test -n "${initrd_early}" || test -n "${initrd_real}"; then -- initrd="${initrd_early} ${initrd_real}" -- -- initrd_display= -- for i in ${initrd}; do -- initrd_display="${initrd_display} ${dirname}/${i}" -- done -- if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then -- gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 -- fi -- fi -- -- fdt= -- for i in "dtb-${version}" "dtb-${alt_version}"; do -- if test -f "${dirname}/${i}/${GRUB_DEFAULT_DTB}" ; then -- fdt="${i}/${GRUB_DEFAULT_DTB}" -- break -- fi -- done -- -- config= -- for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do -- if test -e "${i}" ; then -- config="${i}" -- break -- fi -- done -- -- initramfs= -- if test -n "${config}" ; then -- initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"` -- fi -- -- if test -z "${initramfs}" && test -z "${initrd_real}" ; then -- # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's -- # no initrd or builtin initramfs, it can't work here. -- if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \ -- || [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then -- -- linux_root_device_thisversion=${GRUB_DEVICE} -- else -- linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID} -- fi -- fi -- -- if [ "x${GRUB_DISABLE_SUBMENU}" = "xyes" ] || [ "x${GRUB_DISABLE_SUBMENU}" = "xy" ]; then -- GRUB_DISABLE_SUBMENU="true" -- fi -- -- if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then -- linux_entry "${OS}" "${version}" simple standard \ -- "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" -- if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then -- linux_entry "${OS}" "${version}" simple debug \ -- "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}" -- fi -- -- submenu_indentation="$grub_tab" -- -- if [ -z "$boot_device_id" ]; then -- boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" -- fi -- # TRANSLATORS: %s is replaced with an OS name -- echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {" -- is_top_level=false -- fi -- -- linux_entry "${OS}" "${version}" advanced standard \ -- "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" -- if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then -- linux_entry "${OS}" "${version}" advanced debug \ -- "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}" -- fi -- -- if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then -- linux_entry "${OS}" "${version}" recovery standard \ -- "single ${GRUB_CMDLINE_LINUX}" -- fi -- -- list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '` --done -- --# If at least one kernel was found, then we need to --# add a closing '}' for the submenu command. --if [ x"$is_top_level" != xtrue ]; then -- echo '}' --fi -- --echo "$title_correction_code" --- -1.8.3.1 - diff --git a/0203-grub-switch-to-blscfg-Use-install-to-copy-GRUB-binar.patch b/0203-grub-switch-to-blscfg-Use-install-to-copy-GRUB-binar.patch deleted file mode 100644 index 217876caedd33ad950a293fde63c44ca65b0034b..0000000000000000000000000000000000000000 --- a/0203-grub-switch-to-blscfg-Use-install-to-copy-GRUB-binar.patch +++ /dev/null @@ -1,49 +0,0 @@ -From 06b00bced8807fe8c16f2abdfad956f59e053ca8 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Thu, 16 Apr 2020 18:53:03 +0200 -Subject: [PATCH 203/220] grub-switch-to-blscfg: Use install to copy GRUB - binary, modules and config - -By default the cp command truncates the destination before copying from the -source, so if interrupted it can lead to a file that's half written. - -This behavior can be modified using the --remove-destination option, but is -usually a better choice to use the install tool for this. So let's do that. - -Signed-off-by: Javier Martinez Canillas ---- - util/grub-switch-to-blscfg.in | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index 4bbed8e..3333a62 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -273,7 +273,7 @@ copy_bls() { - if test -f /run/ostree-booted && test -d /sys/firmware/efi/efivars && \ - ! ${grub_editenv} - list | grep -q blsdir; then - grub_binary="$(find /usr/lib/ostree-boot/efi/EFI/${EFIDIR}/ -name grub*.efi)" -- cp ${grub_binary} ${grubdir} || exit 1 -+ install -m 700 ${grub_binary} ${grubdir} || exit 1 - # Create a hidden file to indicate that grub2 now has BLS support. - touch /boot/grub2/.grub2-blscfg-supported - fi -@@ -307,13 +307,13 @@ if [ "${GENERATE}" -eq 1 ] ; then - - if [ -n "${mod_dir}" ]; then - for mod in blscfg increment; do -- cp ${prefix}/lib/grub/${mod_dir}/${mod}.mod ${grubdir}/$mod_dir/ || exit 1 -+ install -m 700 ${prefix}/lib/grub/${mod_dir}/${mod}.mod ${grubdir}/$mod_dir/ || exit 1 - done - fi - - cp -af "${GRUB_CONFIG_FILE}" "${GRUB_CONFIG_FILE}${backupsuffix}" - if ! grub2-mkconfig -o "${GRUB_CONFIG_FILE}" ; then -- cp -af "${GRUB_CONFIG_FILE}${backupsuffix}" "${GRUB_CONFIG_FILE}" -+ install -m 700 "${GRUB_CONFIG_FILE}${backupsuffix}" "${GRUB_CONFIG_FILE}" - sed -i"${backupsuffix}" \ - -e 's,^GRUB_ENABLE_BLSCFG=.*,GRUB_ENABLE_BLSCFG=false,' \ - "${etcdefaultgrub}" --- -1.8.3.1 - diff --git a/0204-10_linux.in-Enable-BLS-configuration-if-new-kernel-p.patch b/0204-10_linux.in-Enable-BLS-configuration-if-new-kernel-p.patch deleted file mode 100644 index a7af8ac375f4eba2270c34a3e7acd4749608117a..0000000000000000000000000000000000000000 --- a/0204-10_linux.in-Enable-BLS-configuration-if-new-kernel-p.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 4522b79934cf8777fbd4bdc437497ed22f77a9f0 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Thu, 16 Apr 2020 18:53:05 +0200 -Subject: [PATCH 204/220] 10_linux.in: Enable BLS configuration if - new-kernel-pkg isn't present - -Currently if the the GRUB_ENABLE_BLSCFG option in /etc/default/grub hasn't -been set, the 10_linux script will generate a GRUB configuration that does -not include the blscfg command to populate the menu entries from BLS files. - -But on kernel install the /usr/lib/kernel/install.d/20-grub.install script -will only add menuentry commands to the GRUB config file if the old grubby -tool and new-kernel-pkg script are installed. - -So a configuration with the GRUB_ENABLE_BLSCFG option will lead to a setup -where new kernel entries are not added. Make a BLS config the default if -that option wasn't set and the new-kernel-pkg script is not present. - -Signed-off-by: Javier Martinez Canillas ---- - util/grub.d/10_linux.in | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index c72cc32..847646b 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -164,6 +164,11 @@ populate_menu() - printf "$menu" - } - -+# Make BLS the default if GRUB_ENABLE_BLSCFG was not set and grubby is not installed. -+if [ -z "${GRUB_ENABLE_BLSCFG}" ] && [ -z "$(which new-kernel-pkg 2> /dev/null)" ]; then -+ GRUB_ENABLE_BLSCFG="true" -+fi -+ - if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then - if [ x$dirname = x/ ]; then - if [ -z "${prepare_root_cache}" ]; then --- -1.8.3.1 - diff --git a/0206-blscfg-Lookup-default_kernelopts-variable-as-fallbac.patch b/0206-blscfg-Lookup-default_kernelopts-variable-as-fallbac.patch deleted file mode 100644 index caeb3f8fb5c173b407a82d84c44f5bed52de26e9..0000000000000000000000000000000000000000 --- a/0206-blscfg-Lookup-default_kernelopts-variable-as-fallbac.patch +++ /dev/null @@ -1,43 +0,0 @@ -From 79e6846f6f4a4c097d88e83c9544b96334a6ea9e Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Wed, 29 Apr 2020 20:08:27 +0200 -Subject: [PATCH 206/220] blscfg: Lookup default_kernelopts variable as - fallback for options - -The 10_linux script sets a variable that contains the kernel command line -parameters. This is done so the entries will still have a kernel cmdline -defined even if the grubenv can't be read. - -But older versions of the script used to set a default_kernelopts variable -while newer versions just sets the kernelopts, which is what's defined in -the BLS snippets. - -The blscfg module needs to keep looking for the default_kernelops since it -may be that a user doesn't have a grubenv file and has an older grub.cfg -that sets this variable instead of kernelopts. - -Related: rhbz#1765297 - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/commands/blscfg.c | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 9263a5c..4ec6504 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -759,6 +759,10 @@ static void create_entry (struct bls_entry *entry) - - title = bls_get_val (entry, "title", NULL); - options = expand_val (bls_get_val (entry, "options", NULL)); -+ -+ if (!options) -+ options = expand_val (grub_env_get("default_kernelopts")); -+ - initrds = bls_make_list (entry, "initrd", NULL); - - devicetree = expand_val (bls_get_val (entry, "devicetree", NULL)); --- -1.8.3.1 - diff --git a/0207-10_linux.in-fix-early-exit-due-error-when-reading-pe.patch b/0207-10_linux.in-fix-early-exit-due-error-when-reading-pe.patch deleted file mode 100644 index bebd24038857c94dcf07a5c2f2366197c615b9a0..0000000000000000000000000000000000000000 --- a/0207-10_linux.in-fix-early-exit-due-error-when-reading-pe.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 35181b2c411954a96e3ed9a0ebc6ce470d037595 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Thu, 30 Apr 2020 15:45:31 +0200 -Subject: [PATCH 207/220] 10_linux.in: fix early exit due error when reading - petitboot version - -The script uses bash's read built-in command to get the petitboot version -version, but this command has a non-zero exit status if the EOF is found. - -Since the /sys/firmware/devicetree/base/ibm,firmware-versions/petitboot -string ends with a NUL character, use the empty string as read delimiter -to prevent the command to read to the end-of-file and exit with an error. - -Resolves: rhbz#1827397 - -Signed-off-by: Javier Martinez Canillas ---- - util/grub.d/10_linux.in | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 847646b..09adfce 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -194,7 +194,7 @@ if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then - petitboot_path="/sys/firmware/devicetree/base/ibm,firmware-versions/petitboot" - - if test -e ${petitboot_path}; then -- read -a petitboot_version < ${petitboot_path} -+ read -r -d '' petitboot_version < ${petitboot_path} - petitboot_version="$(echo ${petitboot_version//v})" - major_version="$(echo ${petitboot_version} | cut -d . -f1)" - minor_version="$(echo ${petitboot_version} | cut -d . -f2)" --- -1.8.3.1 - diff --git a/0208-envblk-Fix-buffer-overrun-when-attempting-to-shrink-.patch b/0208-envblk-Fix-buffer-overrun-when-attempting-to-shrink-.patch deleted file mode 100644 index 586cc71695b2017789d96e71cc6c01151ebb8b78..0000000000000000000000000000000000000000 --- a/0208-envblk-Fix-buffer-overrun-when-attempting-to-shrink-.patch +++ /dev/null @@ -1,63 +0,0 @@ -From aecc9de8fc2345cb582d0587fc89d01891ae2650 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 12 May 2020 01:00:51 +0200 -Subject: [PATCH 208/220] envblk: Fix buffer overrun when attempting to shrink - a variable value -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -If an existing variable is set with a value whose length is smaller than -the current value, a memory corruption can happen due copying padding '#' -characters outside of the environment block buffer. - -This is caused by a wrong calculation of the previous free space position -after moving backward the characters that followed the old variable value. - -That position is calculated to fill the remaining of the buffer with the -padding '#' characters. But since isn't calculated correctly, it can lead -to copies outside of the buffer. - -The issue can be reproduced by creating a variable with a large value and -then try to set a new value that is much smaller: - -$ grub2-editenv --version -grub2-editenv (GRUB) 2.04 - -$ grub2-editenv env create - -$ grub2-editenv env set a="$(for i in {1..500}; do var="b$var"; done; echo $var)" - -$ wc -c env -1024 grubenv - -$ grub2-editenv env set a="$(for i in {1..50}; do var="b$var"; done; echo $var)" -malloc(): corrupted top size -Aborted (core dumped) - -$ wc -c env -0 grubenv - -Reported-by: Renaud Métrich -Signed-off-by: Javier Martinez Canillas -Patch-cc: Daniel Kiper ---- - grub-core/lib/envblk.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/lib/envblk.c b/grub-core/lib/envblk.c -index f89d86d..874506d 100644 ---- a/grub-core/lib/envblk.c -+++ b/grub-core/lib/envblk.c -@@ -143,7 +143,7 @@ grub_envblk_set (grub_envblk_t envblk, const char *name, const char *value) - /* Move the following characters backward, and fill the new - space with harmless characters. */ - grub_memmove (p + vl, p + len, pend - (p + len)); -- grub_memset (space + len - vl, '#', len - vl); -+ grub_memset (space - (len - vl), '#', len - vl); - } - else - /* Move the following characters forward. */ --- -1.8.3.1 - diff --git a/0209-10_linux.in-Store-cmdline-in-BLS-snippets-instead-of.patch b/0209-10_linux.in-Store-cmdline-in-BLS-snippets-instead-of.patch deleted file mode 100644 index 6c3fc7970d0e193d4cf6c399fb567d24eed7daeb..0000000000000000000000000000000000000000 --- a/0209-10_linux.in-Store-cmdline-in-BLS-snippets-instead-of.patch +++ /dev/null @@ -1,163 +0,0 @@ -From 9140d0e92dc51839ff77634d4b030bf4f88f248a Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Wed, 13 May 2020 19:40:10 +0200 -Subject: [PATCH 209/220] 10_linux.in: Store cmdline in BLS snippets instead of - using a variable - -The kernel cmdline was stored as a kernelopts variable in the grubenv file -and the BLS snippets used that. But this turned out to be fragile since the -grubenv file could be removed or get corrupted easily. - -To prevent the entries to not have a cmdline if the grubenv can't be read, -a fallback variable was set in the GRUB config file. But this still caused -issues since the config needs to be re-generated to change the parameters. - -Instead, let's store the cmdline in the BLS snippets. This will make the -configuration more robust, since it will work even without the grubenv -file and the BLS entries will contain all the information needed to boot. - -Signed-off-by: Javier Martinez Canillas ---- - util/grub-switch-to-blscfg.in | 30 ++++++++++-------------------- - util/grub.d/10_linux.in | 41 +++++++++++++++++++++++++++++++---------- - 2 files changed, 41 insertions(+), 30 deletions(-) - -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index 3333a62..cb22912 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -190,7 +190,7 @@ fi - mkbls() { - local kernelver=$1 && shift - local datetime=$1 && shift -- local bootprefix=$1 && shift -+ local kernelopts=$1 && shift - - local debugname="" - local debugid="" -@@ -209,10 +209,9 @@ mkbls() { - cat <"${bls_target}" -- fi -+ mkbls "${kernelver}" \ -+ "$(date -u +%Y%m%d%H%M%S -d "$(stat -c '%y' "${kernel_dir}")")" \ -+ "${bootprefix}" "${cmdline}" >"${bls_target}" - - if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then - bls_debug="$(echo ${bls_target} | sed -e "s/${kernelver}/${kernelver}~debug/")" - cp -aT "${bls_target}" "${bls_debug}" - title="$(grep '^title[ \t]' "${bls_debug}" | sed -e 's/^title[ \t]*//')" -- blsid="$(grep '^id[ \t]' "${bls_debug}" | sed -e "s/\.${ARCH}/-debug.${arch}/")" -+ options="$(echo "${cmdline} ${GRUB_CMDLINE_LINUX_DEBUG}" | sed -e 's/\//\\\//g')" - sed -i -e "s/^title.*/title ${title}${GRUB_LINUX_DEBUG_TITLE_POSTFIX}/" "${bls_debug}" -- sed -i -e "s/^id.*/${blsid}/" "${bls_debug}" -- sed -i -e "s/^options.*/options \$kernelopts ${GRUB_CMDLINE_LINUX_DEBUG}/" "${bls_debug}" -+ sed -i -e "s/^options.*/options ${options}/" "${bls_debug}" - fi - done - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 09adfce..80299ec 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -134,23 +134,43 @@ read_config() - done < ${config_file} - } - --populate_menu() -+blsdir="/boot/loader/entries" -+ -+get_sorted_bls() - { -- blsdir="/boot/loader/entries" -- local -a files - local IFS=$'\n' -- gettext_printf "Generating boot entries from BLS files...\n" >&2 - -- files=($(for bls in ${blsdir}/*.conf ; do -- if ! [[ -e "${bls}" ]] ; then -- continue -- fi -+ files=($(for bls in ${blsdir}/*.conf; do - bls="${bls%.conf}" - bls="${bls##*/}" - echo "${bls}" - done | ${kernel_sort} | tac)) || : - -- for bls in "${files[@]}" ; do -+ echo "${files[@]}" -+} -+ -+update_bls_cmdline() -+{ -+ local cmdline="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" -+ local -a files=($(get_sorted_bls)) -+ -+ for bls in "${files[@]}"; do -+ local options="${cmdline}" -+ if [ -z "${bls##*debug*}" ]; then -+ options="${options} ${GRUB_CMDLINE_LINUX_DEBUG}" -+ fi -+ options="$(echo "${options}" | sed -e 's/\//\\\//g')" -+ sed -i -e "s/^options.*/options ${options}/" "${blsdir}/${bls}.conf" -+ done -+} -+ -+populate_menu() -+{ -+ local -a files=($(get_sorted_bls)) -+ -+ gettext_printf "Generating boot entries from BLS files...\n" >&2 -+ -+ for bls in "${files[@]}"; do - read_config "${blsdir}/${bls}.conf" - - menu="${menu}menuentry '${title}' ${grub_arg} --id=${bls} {\n" -@@ -224,6 +244,8 @@ if [ -z "\${kernelopts}" ]; then - fi - EOF - -+ update_bls_cmdline -+ - if [ "x${BLS_POPULATE_MENU}" = "xtrue" ]; then - populate_menu - else -@@ -244,7 +266,6 @@ EOF - fi - fi - -- ${grub_editenv} - set kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" - if [ -n "${GRUB_EARLY_INITRD_LINUX_CUSTOM}" ]; then - ${grub_editenv} - set early_initrd="${GRUB_EARLY_INITRD_LINUX_CUSTOM}" - fi --- -1.8.3.1 - diff --git a/0210-10_linux.in-restore-existence-check-in-get_sorted_bl.patch b/0210-10_linux.in-restore-existence-check-in-get_sorted_bl.patch deleted file mode 100644 index ae262249170542c3f74b7fa85fac032575eedee9..0000000000000000000000000000000000000000 --- a/0210-10_linux.in-restore-existence-check-in-get_sorted_bl.patch +++ /dev/null @@ -1,36 +0,0 @@ -From e635565f71e4a2ee106b6d8ef71e989452af90f8 Mon Sep 17 00:00:00 2001 -From: Adam Williamson -Date: Thu, 14 May 2020 17:52:53 -0700 -Subject: [PATCH 210/220] 10_linux.in: restore existence check in - `get_sorted_bls` - -This is necessary to handle `/boot/loader/entries` not existing -at all (or possibly existing but being empty - not sure about -that case). Without this check, this function gets pretty wacky -and winds up returning the contents of the current working -directory, which of course causes whatever called it to break. - -Resolves: rhbz#1836020 - -Signed-off-by: Adam Williamson ---- - util/grub.d/10_linux.in | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 80299ec..519e2d9 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -141,6 +141,9 @@ get_sorted_bls() - local IFS=$'\n' - - files=($(for bls in ${blsdir}/*.conf; do -+ if ! [[ -e "${bls}" ]] ; then -+ continue -+ fi - bls="${bls%.conf}" - bls="${bls##*/}" - echo "${bls}" --- -1.8.3.1 - diff --git a/0212-tpm-Enable-module-for-all-EFI-platforms.patch b/0212-tpm-Enable-module-for-all-EFI-platforms.patch deleted file mode 100644 index db25a35c85b9bbbe6370f504920ddd3f98327c63..0000000000000000000000000000000000000000 --- a/0212-tpm-Enable-module-for-all-EFI-platforms.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 605c3bd42fbec1fa1c09e35bb93c6c577110b870 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Mon, 18 May 2020 12:56:27 +0200 -Subject: [PATCH 212/220] tpm: Enable module for all EFI platforms - -The tpm module is only enabled for x86_64, but there's nothing specific to -that architecture in the code and could be enabled for all EFI platforms. - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/Makefile.core.def | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 6619946..b283c50 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -2512,7 +2512,7 @@ module = { - name = tpm; - common = commands/tpm.c; - efi = commands/efi/tpm.c; -- enable = x86_64_efi; -+ enable = efi; - }; - - module = { --- -1.8.3.1 - diff --git a/0213-10_linux.in-Don-t-update-BLS-files-that-aren-t-manag.patch b/0213-10_linux.in-Don-t-update-BLS-files-that-aren-t-manag.patch deleted file mode 100644 index 3df6cb46db844becfbac0cece1fcf22cbe781505..0000000000000000000000000000000000000000 --- a/0213-10_linux.in-Don-t-update-BLS-files-that-aren-t-manag.patch +++ /dev/null @@ -1,59 +0,0 @@ -From b72f41efc2b25d77e8530d0ed412acc03d6911d3 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Wed, 20 May 2020 12:23:27 +0200 -Subject: [PATCH 213/220] 10_linux.in: Don't update BLS files that aren't - managed by GRUB scripts - -The script is updating all BLS files present in the /boot/loader/entries -directory, but it should only update the BLS that belong to the machine. - -Otherwise if a user is sharing the same boot partition between different -operating systems, the grub2-mkconfig tool will wrongly update BLS files -that were created by a different OS. - -There are also cases where the BLS snippets are not managed by the GRUB -scripts at all, for example in OSTree based systems. So it's also wrong -to update the BLS snippets created by OSTree. - -Resolves: rhbz#1837783 - -Signed-off-by: Javier Martinez Canillas ---- - util/grub.d/10_linux.in | 13 +++++++++++-- - 1 file changed, 11 insertions(+), 2 deletions(-) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 519e2d9..e61b6c9 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -138,16 +138,25 @@ blsdir="/boot/loader/entries" - - get_sorted_bls() - { -+ if ! [ -d "${blsdir}" ] || ! [ -e /etc/machine-id ]; then -+ return -+ fi -+ -+ read machine_id < /etc/machine-id -+ if [ -z "${machine_id}" ]; then -+ return -+ fi -+ - local IFS=$'\n' - -- files=($(for bls in ${blsdir}/*.conf; do -+ files=($(for bls in ${blsdir}/${machine_id}-*.conf; do - if ! [[ -e "${bls}" ]] ; then - continue - fi - bls="${bls%.conf}" - bls="${bls##*/}" - echo "${bls}" -- done | ${kernel_sort} | tac)) || : -+ done | ${kernel_sort} 2>/dev/null | tac)) || : - - echo "${files[@]}" - } --- -1.8.3.1 - diff --git a/0216-fix-build-with-rpm-4.16.patch b/0216-fix-build-with-rpm-4.16.patch deleted file mode 100644 index 4fe21917a072ecb3e54eddce4ae523ea203ffac9..0000000000000000000000000000000000000000 --- a/0216-fix-build-with-rpm-4.16.patch +++ /dev/null @@ -1,33 +0,0 @@ -From 975515d9a2ccab6ca78f9d2dd9e916e444f568ae Mon Sep 17 00:00:00 2001 -From: Thierry Vignaud -Date: Mon, 8 Jun 2020 06:50:21 +0200 -Subject: [PATCH 216/220] fix build with rpm-4.16 - -Signed-off-by: Thierry Vignaud ---- - configure.ac | 9 +++++++++ - 1 file changed, 9 insertions(+) - -diff --git a/configure.ac b/configure.ac -index eff160b..5d33161 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -1887,6 +1887,15 @@ if test x"$rpm_sort_excuse" = x ; then - [Define to 1 if you have the rpm library.]) - fi - -+if test x"$LIBRPM" = x ; then -+ # Check for rpm library. -+ AC_CHECK_LIB([rpmio], [rpmvercmp], [], -+ [rpm_sort_excuse="rpmio missing rpmvercmp"]) -+ LIBRPM="-lrpmio"; -+ AC_DEFINE([HAVE_RPMIO], [1], -+ [Define to 1 if you have the rpm library.]) -+fi -+ - AC_SUBST([LIBRPM]) - - LIBGEOM= --- -1.8.3.1 - diff --git a/0217-Only-mark-GRUB-as-BLS-supported-in-OSTree-systems-wi.patch b/0217-Only-mark-GRUB-as-BLS-supported-in-OSTree-systems-wi.patch deleted file mode 100644 index c27df449b956e822819dc7b32ac00aab2dd13221..0000000000000000000000000000000000000000 --- a/0217-Only-mark-GRUB-as-BLS-supported-in-OSTree-systems-wi.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 077d33c5035a51c50fa256330bbc82cde106855e Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Thu, 18 Jun 2020 11:19:00 +0200 -Subject: [PATCH 217/220] Only mark GRUB as BLS supported in OSTree systems - with a boot partition - -The script grub2-switch-to-blscfg updates the grub2 EFI binary in OSTree -systems and marks that has BLS support, to indicate that's not necessary -to add menuentry commands since the BLS snippets can be used to populate -the GRUB boot menu. - -But OSTree doesn't support installations that don't have a boot partition, -the BLS snippets assume that there will be one so this has to be checked -and only mark the bootloader as supporting BLS in OSTree installations -that have /boot as a mountpoint. - -Signed-off-by: Javier Martinez Canillas ---- - util/grub-switch-to-blscfg.in | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index cb22912..a851424 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -261,7 +261,8 @@ copy_bls() { - # but only do this if the blsdir is not set, to make sure that the BLS - # parsing module will search for the BLS snippets in the default path. - if test -f /run/ostree-booted && test -d /sys/firmware/efi/efivars && \ -- ! ${grub_editenv} - list | grep -q blsdir; then -+ ! ${grub_editenv} - list | grep -q blsdir && \ -+ mountpoint -q /boot; then - grub_binary="$(find /usr/lib/ostree-boot/efi/EFI/${EFIDIR}/ -name grub*.efi)" - install -m 700 ${grub_binary} ${grubdir} || exit 1 - # Create a hidden file to indicate that grub2 now has BLS support. --- -1.8.3.1 - diff --git a/0218-support-TPM2.0-in-grub2-both-legacy-and-efi.patch b/0218-support-TPM2.0-in-grub2-both-legacy-and-efi.patch deleted file mode 100644 index d5fbdf7a85dfb186154f2b89a89733f141dddade..0000000000000000000000000000000000000000 --- a/0218-support-TPM2.0-in-grub2-both-legacy-and-efi.patch +++ /dev/null @@ -1,27 +0,0 @@ -From ca6d4093a87c9aa6059ad4e396a50ff485cc0066 Mon Sep 17 00:00:00 2001 -From: linyanly -Date: Fri, 3 Nov 2017 15:53:29 +0800 -Subject: [PATCH 218/220] backport 'support TPM2.0 in grub2, both legacy and - efi' - ---- - grub-core/kern/emu/mm.c | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/grub-core/kern/emu/mm.c b/grub-core/kern/emu/mm.c -index f262e95..43b31fa 100644 ---- a/grub-core/kern/emu/mm.c -+++ b/grub-core/kern/emu/mm.c -@@ -50,7 +50,8 @@ grub_zalloc (grub_size_t size) - void - grub_free (void *ptr) - { -- free (ptr); -+ if (ptr) -+ free (ptr); - } - - void * --- -1.8.3.1 - diff --git a/0219-Workaround-for-EFI-Bug-Plan3.patch b/0219-Workaround-for-EFI-Bug-Plan3.patch deleted file mode 100644 index a1cd9bd1d3a2cb363f83db2480f4b5cde302a35a..0000000000000000000000000000000000000000 --- a/0219-Workaround-for-EFI-Bug-Plan3.patch +++ /dev/null @@ -1,160 +0,0 @@ -From 55f6c378c70e139d28f1d8b60bb0197946659fb1 Mon Sep 17 00:00:00 2001 -From: Zhao Lei -Date: Mon, 25 Feb 2019 18:04:10 +0800 -Subject: [PATCH 219/220] Workaround for EFI Bug (Plan3) - -Signed-off-by: Zhao Lei ---- - grub-core/disk/efi/efidisk.c | 108 ++++++++++++++++++++++++++++++++++++++++++- - 1 file changed, 107 insertions(+), 1 deletion(-) - -diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c -index 54c227b..abb98aa 100644 ---- a/grub-core/disk/efi/efidisk.c -+++ b/grub-core/disk/efi/efidisk.c -@@ -27,12 +27,19 @@ - #include - #include - -+typedef enum { -+ GRUB_EFI_BIOS_OVERFLOW_INIT, -+ GRUB_EFI_BIOS_OVERFLOW_EXIST, -+ GRUB_EFI_BIOS_OVERFLOW_NOEXIST -+} grub_efi_bios_overflow_t; -+ - struct grub_efidisk_data - { - grub_efi_handle_t handle; - grub_efi_device_path_t *device_path; - grub_efi_device_path_t *last_device_path; - grub_efi_block_io_t *block_io; -+ grub_efi_bios_overflow_t bios_overflow; - struct grub_efidisk_data *next; - }; - -@@ -107,6 +114,7 @@ make_devices (void) - d->device_path = dp; - d->last_device_path = ldp; - d->block_io = bio; -+ d->bios_overflow = GRUB_EFI_BIOS_OVERFLOW_INIT; - d->next = devices; - devices = d; - } -@@ -540,8 +548,9 @@ grub_efidisk_close (struct grub_disk *disk __attribute__ ((unused))) - grub_dprintf ("efidisk", "closing %s\n", disk->name); - } - -+ - static grub_efi_status_t --grub_efidisk_readwrite (struct grub_disk *disk, grub_disk_addr_t sector, -+__grub_efidisk_readwrite (struct grub_disk *disk, grub_disk_addr_t sector, - grub_size_t size, char *buf, int wr) - { - struct grub_efidisk_data *d; -@@ -584,6 +593,103 @@ grub_efidisk_readwrite (struct grub_disk *disk, grub_disk_addr_t sector, - return status; - } - -+static void grub_efidisk_set_overflow(struct grub_disk *disk) -+{ -+ struct grub_efidisk_data *d = disk->data; -+ -+ char *buf; -+ int read_len; -+ int buf_len; -+ -+ static char magic_list[] = {0x55, 0xaa}; -+ unsigned int magic_index; -+ -+ if (d->bios_overflow != GRUB_EFI_BIOS_OVERFLOW_INIT) -+ return; -+ -+ if (d->block_io->media->removable_media) { -+ d->bios_overflow = GRUB_EFI_BIOS_OVERFLOW_NOEXIST; -+ return; -+ } -+ -+ read_len = (1 << disk->log_sector_size); -+ -+ /* read_len + 9 is enough, we use more */ -+ buf_len = (read_len + 8) * 2; -+ -+ buf = grub_malloc(buf_len); -+ if (!buf) { -+ grub_printf("grub_efidisk_set_overflow: malloc failed, ignore operation %s\n", disk->name); -+ d->bios_overflow = GRUB_EFI_BIOS_OVERFLOW_EXIST; -+ return; -+ } -+ -+ for (magic_index = 0; magic_index < sizeof(magic_list)/sizeof(magic_list[0]); magic_index++) { -+ int buf_index; -+ -+ grub_memset(buf + read_len, magic_list[magic_index], buf_len - read_len); -+ -+ /* -+ * If disk can not read, we can not determine overflow state now, -+ * just leave GRUB_EFI_BIOS_OVERFLOW_INIT state and re-check on -+ * next operation of this disk. -+ */ -+ if (GRUB_EFI_SUCCESS != __grub_efidisk_readwrite(disk, 0, 1, buf, 0)) { -+ d->bios_overflow = GRUB_EFI_BIOS_OVERFLOW_INIT; -+ goto out; -+ } -+ -+ for (buf_index = read_len; buf_index < buf_len; buf_index++) { -+ if (buf[buf_index] != magic_list[magic_index]) { -+ d->bios_overflow = GRUB_EFI_BIOS_OVERFLOW_EXIST; -+ goto out; -+ } -+ } -+ } -+ -+ d->bios_overflow = GRUB_EFI_BIOS_OVERFLOW_NOEXIST; -+ -+out: -+ grub_free(buf); -+ return; -+} -+ -+static int grub_efidisk_check_overflow(struct grub_disk *disk) -+{ -+ struct grub_efidisk_data *d = disk->data; -+ int ret; -+ -+ grub_efidisk_set_overflow(disk); -+ -+ switch (d->bios_overflow) { -+ case GRUB_EFI_BIOS_OVERFLOW_INIT: -+ ret = 0; -+ break; -+ case GRUB_EFI_BIOS_OVERFLOW_NOEXIST: -+ ret = 0; -+ break; -+ case GRUB_EFI_BIOS_OVERFLOW_EXIST: -+ ret = 1; -+ break; -+ default: -+ grub_printf("grub_efidisk_check_overflow: internal error in bios_overflow value(%d), ignore operation %s\n", d->bios_overflow, disk->name); -+ ret = 1; -+ break; -+ } -+ -+ return ret; -+} -+ -+static grub_efi_status_t -+grub_efidisk_readwrite (struct grub_disk *disk, grub_disk_addr_t sector, -+ grub_size_t size, char *buf, int wr) -+{ -+ if (grub_efidisk_check_overflow(disk)) -+ return GRUB_ERR_UNKNOWN_DEVICE; -+ -+ return __grub_efidisk_readwrite(disk, sector, size, buf, wr); -+} -+ - static grub_err_t - grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector, - grub_size_t size, char *buf) --- -1.8.3.1 - diff --git a/0220-bugfix-remove-excess-qutos.patch b/0220-bugfix-remove-excess-qutos.patch deleted file mode 100644 index f1a1e42b85fb929b568d9ef10d4cab5aa0c111fe..0000000000000000000000000000000000000000 --- a/0220-bugfix-remove-excess-qutos.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 2332d14570ed41a15c36ff264b9790d832106607 Mon Sep 17 00:00:00 2001 -From: fengtao -Date: Tue, 10 Sep 2019 21:43:31 +0800 -Subject: [PATCH 220/220] fix grub2-setpassword errors for openEuler - ---- - util/grub-set-password.in | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/util/grub-set-password.in b/util/grub-set-password.in -index c0b5ebb..487fbb1 100644 ---- a/util/grub-set-password.in -+++ b/util/grub-set-password.in -@@ -1,6 +1,6 @@ - #!/bin/sh -e - --EFIDIR=$(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/' -e 's/\"//g') -+EFIDIR=$(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/' -e 's/\"//g' | tr -d '"') - if [ -d /sys/firmware/efi/efivars/ ]; then - grubdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/" | sed 's,//*,/,g'` - else --- -1.8.3.1 - diff --git a/0221-yylex-Make-lexer-fatal-errors-actually-be-fatal.patch b/0221-yylex-Make-lexer-fatal-errors-actually-be-fatal.patch deleted file mode 100644 index ca9fbe1686ef15eb0748766c68f3d9ebe67c8701..0000000000000000000000000000000000000000 --- a/0221-yylex-Make-lexer-fatal-errors-actually-be-fatal.patch +++ /dev/null @@ -1,69 +0,0 @@ -From a4d3fbdff1e3ca8f87642af2ac8752c30c617a3e Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 15 Apr 2020 15:45:02 -0400 -Subject: [PATCH 01/27] yylex: Make lexer fatal errors actually be fatal - -When presented with a command that can't be tokenized to anything -smaller than YYLMAX characters, the parser calls YY_FATAL_ERROR(errmsg), -expecting that will stop further processing, as such: - - #define YY_DO_BEFORE_ACTION \ - yyg->yytext_ptr = yy_bp; \ - yyleng = (int) (yy_cp - yy_bp); \ - yyg->yy_hold_char = *yy_cp; \ - *yy_cp = '\0'; \ - if ( yyleng >= YYLMAX ) \ - YY_FATAL_ERROR( "token too large, exceeds YYLMAX" ); \ - yy_flex_strncpy( yytext, yyg->yytext_ptr, yyleng + 1 , yyscanner); \ - yyg->yy_c_buf_p = yy_cp; - -The code flex generates expects that YY_FATAL_ERROR() will either return -for it or do some form of longjmp(), or handle the error in some way at -least, and so the strncpy() call isn't in an "else" clause, and thus if -YY_FATAL_ERROR() is *not* actually fatal, it does the call with the -questionable limit, and predictable results ensue. - -Unfortunately, our implementation of YY_FATAL_ERROR() is: - - #define YY_FATAL_ERROR(msg) \ - do { \ - grub_printf (_("fatal error: %s\n"), _(msg)); \ - } while (0) - -The same pattern exists in yyless(), and similar problems exist in users -of YY_INPUT(), several places in the main parsing loop, -yy_get_next_buffer(), yy_load_buffer_state(), yyensure_buffer_stack, -yy_scan_buffer(), etc. - -All of these callers expect YY_FATAL_ERROR() to actually be fatal, and -the things they do if it returns after calling it are wildly unsafe. - -Fixes: CVE-2020-10713 - -Signed-off-by: Peter Jones -Reviewed-by: Daniel Kiper ---- - grub-core/script/yylex.l | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/script/yylex.l b/grub-core/script/yylex.l -index 7b44c37..b7203c8 100644 ---- a/grub-core/script/yylex.l -+++ b/grub-core/script/yylex.l -@@ -37,11 +37,11 @@ - - /* - * As we don't have access to yyscanner, we cannot do much except to -- * print the fatal error. -+ * print the fatal error and exit. - */ - #define YY_FATAL_ERROR(msg) \ - do { \ -- grub_printf (_("fatal error: %s\n"), _(msg)); \ -+ grub_fatal (_("fatal error: %s\n"), _(msg));\ - } while (0) - - #define COPY(str, hint) \ --- -2.23.0 - diff --git a/0222-safemath-Add-some-arithmetic-primitives-that-check-f.patch b/0222-safemath-Add-some-arithmetic-primitives-that-check-f.patch deleted file mode 100644 index 0cb63df816d1f61bb893d8452822143dd287471b..0000000000000000000000000000000000000000 --- a/0222-safemath-Add-some-arithmetic-primitives-that-check-f.patch +++ /dev/null @@ -1,89 +0,0 @@ -From 68708c4503018d61dbcce7ac11cbb511d6425f4d Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 15 Jun 2020 10:58:42 -0400 -Subject: [PATCH 02/27] safemath: Add some arithmetic primitives that check for - overflow - -This adds a new header, include/grub/safemath.h, that includes easy to -use wrappers for __builtin_{add,sub,mul}_overflow() declared like: - - bool OP(a, b, res) - -where OP is grub_add, grub_sub or grub_mul. OP() returns true in the -case where the operation would overflow and res is not modified. -Otherwise, false is returned and the operation is executed. - -These arithmetic primitives require newer compiler versions. So, bump -these requirements in the INSTALL file too. - -Signed-off-by: Peter Jones -Reviewed-by: Daniel Kiper ---- - include/grub/compiler.h | 8 ++++++++ - include/grub/safemath.h | 37 +++++++++++++++++++++++++++++++++++++ - 2 files changed, 45 insertions(+) - create mode 100644 include/grub/safemath.h - -diff --git a/include/grub/compiler.h b/include/grub/compiler.h -index 9859ff4..61c0cb3 100644 ---- a/include/grub/compiler.h -+++ b/include/grub/compiler.h -@@ -50,4 +50,12 @@ - - #define UNUSED __attribute__((__unused__)) - -+#if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__) -+# define CLANG_PREREQ(maj,min) \ -+ ((__clang_major__ > (maj)) || \ -+ (__clang_major__ == (maj) && __clang_minor__ >= (min))) -+#else -+# define CLANG_PREREQ(maj,min) 0 -+#endif -+ - #endif /* ! GRUB_COMPILER_HEADER */ -diff --git a/include/grub/safemath.h b/include/grub/safemath.h -new file mode 100644 -index 0000000..c17b89b ---- /dev/null -+++ b/include/grub/safemath.h -@@ -0,0 +1,37 @@ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2020 Free Software Foundation, Inc. -+ * -+ * GRUB is free software: you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation, either version 3 of the License, or -+ * (at your option) any later version. -+ * -+ * GRUB is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with GRUB. If not, see . -+ * -+ * Arithmetic operations that protect against overflow. -+ */ -+ -+#ifndef GRUB_SAFEMATH_H -+#define GRUB_SAFEMATH_H 1 -+ -+#include -+ -+/* These appear in gcc 5.1 and clang 3.8. */ -+#if GNUC_PREREQ(5, 1) || CLANG_PREREQ(3, 8) -+ -+#define grub_add(a, b, res) __builtin_add_overflow(a, b, res) -+#define grub_sub(a, b, res) __builtin_sub_overflow(a, b, res) -+#define grub_mul(a, b, res) __builtin_mul_overflow(a, b, res) -+ -+#else -+#error gcc 5.1 or newer or clang 3.8 or newer is required -+#endif -+ -+#endif /* GRUB_SAFEMATH_H */ --- -2.23.0 - diff --git a/0223-calloc-Make-sure-we-always-have-an-overflow-checking.patch b/0223-calloc-Make-sure-we-always-have-an-overflow-checking.patch deleted file mode 100644 index bdfeb09db4bec5d98ff252bcb746d0dd945e90c8..0000000000000000000000000000000000000000 --- a/0223-calloc-Make-sure-we-always-have-an-overflow-checking.patch +++ /dev/null @@ -1,242 +0,0 @@ -From 64e26162ebfe68317c143ca5ec996c892019f8f8 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 15 Jun 2020 12:15:29 -0400 -Subject: [PATCH 03/27] calloc: Make sure we always have an overflow-checking - calloc() available - -This tries to make sure that everywhere in this source tree, we always have -an appropriate version of calloc() (i.e. grub_calloc(), xcalloc(), etc.) -available, and that they all safely check for overflow and return NULL when -it would occur. - -Signed-off-by: Peter Jones -Reviewed-by: Daniel Kiper ---- - grub-core/kern/emu/misc.c | 12 +++++++++ - grub-core/kern/emu/mm.c | 10 ++++++++ - grub-core/kern/mm.c | 40 ++++++++++++++++++++++++++++++ - grub-core/lib/libgcrypt_wrap/mem.c | 11 ++++++-- - grub-core/lib/posix_wrap/stdlib.h | 8 +++++- - include/grub/emu/misc.h | 1 + - include/grub/mm.h | 6 +++++ - 7 files changed, 85 insertions(+), 3 deletions(-) - -diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c -index 7a8d9e6..f08a1bb 100644 ---- a/grub-core/kern/emu/misc.c -+++ b/grub-core/kern/emu/misc.c -@@ -86,6 +86,18 @@ grub_util_error (const char *fmt, ...) - grub_exit (1); - } - -+void * -+xcalloc (grub_size_t nmemb, grub_size_t size) -+{ -+ void *p; -+ -+ p = calloc (nmemb, size); -+ if (!p) -+ grub_util_error ("%s", _("out of memory")); -+ -+ return p; -+} -+ - void * - xmalloc (grub_size_t size) - { -diff --git a/grub-core/kern/emu/mm.c b/grub-core/kern/emu/mm.c -index 43b31fa..4d1046a 100644 ---- a/grub-core/kern/emu/mm.c -+++ b/grub-core/kern/emu/mm.c -@@ -25,6 +25,16 @@ - #include - #include - -+void * -+grub_calloc (grub_size_t nmemb, grub_size_t size) -+{ -+ void *ret; -+ ret = calloc (nmemb, size); -+ if (!ret) -+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); -+ return ret; -+} -+ - void * - grub_malloc (grub_size_t size) - { -diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c -index 002cbfa..80d0720 100644 ---- a/grub-core/kern/mm.c -+++ b/grub-core/kern/mm.c -@@ -67,8 +67,10 @@ - #include - #include - #include -+#include - - #ifdef MM_DEBUG -+# undef grub_calloc - # undef grub_malloc - # undef grub_zalloc - # undef grub_realloc -@@ -375,6 +377,30 @@ grub_memalign (grub_size_t align, grub_size_t size) - return 0; - } - -+/* -+ * Allocate NMEMB instances of SIZE bytes and return the pointer, or error on -+ * integer overflow. -+ */ -+void * -+grub_calloc (grub_size_t nmemb, grub_size_t size) -+{ -+ void *ret; -+ grub_size_t sz = 0; -+ -+ if (grub_mul (nmemb, size, &sz)) -+ { -+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); -+ return NULL; -+ } -+ -+ ret = grub_memalign (0, sz); -+ if (!ret) -+ return NULL; -+ -+ grub_memset (ret, 0, sz); -+ return ret; -+} -+ - /* Allocate SIZE bytes and return the pointer. */ - void * - grub_malloc (grub_size_t size) -@@ -561,6 +587,20 @@ grub_mm_dump (unsigned lineno) - grub_printf ("\n"); - } - -+void * -+grub_debug_calloc (const char *file, int line, grub_size_t nmemb, grub_size_t size) -+{ -+ void *ptr; -+ -+ if (grub_mm_debug) -+ grub_printf ("%s:%d: calloc (0x%" PRIxGRUB_SIZE ", 0x%" PRIxGRUB_SIZE ") = ", -+ file, line, size); -+ ptr = grub_calloc (nmemb, size); -+ if (grub_mm_debug) -+ grub_printf ("%p\n", ptr); -+ return ptr; -+} -+ - void * - grub_debug_malloc (const char *file, int line, grub_size_t size) - { -diff --git a/grub-core/lib/libgcrypt_wrap/mem.c b/grub-core/lib/libgcrypt_wrap/mem.c -index beeb661..74c6eaf 100644 ---- a/grub-core/lib/libgcrypt_wrap/mem.c -+++ b/grub-core/lib/libgcrypt_wrap/mem.c -@@ -4,6 +4,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -36,7 +37,10 @@ void * - gcry_xcalloc (size_t n, size_t m) - { - void *ret; -- ret = grub_zalloc (n * m); -+ size_t sz; -+ if (grub_mul (n, m, &sz)) -+ grub_fatal ("gcry_xcalloc would overflow"); -+ ret = grub_zalloc (sz); - if (!ret) - grub_fatal ("gcry_xcalloc failed"); - return ret; -@@ -56,7 +60,10 @@ void * - gcry_xcalloc_secure (size_t n, size_t m) - { - void *ret; -- ret = grub_zalloc (n * m); -+ size_t sz; -+ if (grub_mul (n, m, &sz)) -+ grub_fatal ("gcry_xcalloc would overflow"); -+ ret = grub_zalloc (sz); - if (!ret) - grub_fatal ("gcry_xcalloc failed"); - return ret; -diff --git a/grub-core/lib/posix_wrap/stdlib.h b/grub-core/lib/posix_wrap/stdlib.h -index 3b46f47..7a8d385 100644 ---- a/grub-core/lib/posix_wrap/stdlib.h -+++ b/grub-core/lib/posix_wrap/stdlib.h -@@ -21,6 +21,7 @@ - - #include - #include -+#include - - static inline void - free (void *ptr) -@@ -37,7 +38,12 @@ malloc (grub_size_t size) - static inline void * - calloc (grub_size_t size, grub_size_t nelem) - { -- return grub_zalloc (size * nelem); -+ grub_size_t sz; -+ -+ if (grub_mul (size, nelem, &sz)) -+ return NULL; -+ -+ return grub_zalloc (sz); - } - - static inline void * -diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h -index 5ef4f79..0105695 100644 ---- a/include/grub/emu/misc.h -+++ b/include/grub/emu/misc.h -@@ -47,6 +47,7 @@ grub_util_device_is_mapped (const char *dev); - #define GRUB_HOST_PRIuLONG_LONG "llu" - #define GRUB_HOST_PRIxLONG_LONG "llx" - -+void * EXPORT_FUNC(xcalloc) (grub_size_t nmemb, grub_size_t size) WARN_UNUSED_RESULT; - void * EXPORT_FUNC(xmalloc) (grub_size_t size) WARN_UNUSED_RESULT; - void * EXPORT_FUNC(xrealloc) (void *ptr, grub_size_t size) WARN_UNUSED_RESULT; - char * EXPORT_FUNC(xstrdup) (const char *str) WARN_UNUSED_RESULT; -diff --git a/include/grub/mm.h b/include/grub/mm.h -index 28e2e53..9c38dd3 100644 ---- a/include/grub/mm.h -+++ b/include/grub/mm.h -@@ -29,6 +29,7 @@ - #endif - - void grub_mm_init_region (void *addr, grub_size_t size); -+void *EXPORT_FUNC(grub_calloc) (grub_size_t nmemb, grub_size_t size); - void *EXPORT_FUNC(grub_malloc) (grub_size_t size); - void *EXPORT_FUNC(grub_zalloc) (grub_size_t size); - void EXPORT_FUNC(grub_free) (void *ptr); -@@ -48,6 +49,9 @@ extern int EXPORT_VAR(grub_mm_debug); - void grub_mm_dump_free (void); - void grub_mm_dump (unsigned lineno); - -+#define grub_calloc(nmemb, size) \ -+ grub_debug_calloc (GRUB_FILE, __LINE__, nmemb, size) -+ - #define grub_malloc(size) \ - grub_debug_malloc (GRUB_FILE, __LINE__, size) - -@@ -63,6 +67,8 @@ void grub_mm_dump (unsigned lineno); - #define grub_free(ptr) \ - grub_debug_free (GRUB_FILE, __LINE__, ptr) - -+void *EXPORT_FUNC(grub_debug_calloc) (const char *file, int line, -+ grub_size_t nmemb, grub_size_t size); - void *EXPORT_FUNC(grub_debug_malloc) (const char *file, int line, - grub_size_t size); - void *EXPORT_FUNC(grub_debug_zalloc) (const char *file, int line, --- -2.23.0 - diff --git a/0224-calloc-Use-calloc-at-most-places.patch b/0224-calloc-Use-calloc-at-most-places.patch deleted file mode 100644 index d806057826c2673b280743f8ffe9eae856fb9382..0000000000000000000000000000000000000000 --- a/0224-calloc-Use-calloc-at-most-places.patch +++ /dev/null @@ -1,1836 +0,0 @@ -From f725fa7cb2ece547c5af01eeeecfe8d95802ed41 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 15 Jun 2020 12:26:01 -0400 -Subject: [PATCH 04/27] calloc: Use calloc() at most places - -This modifies most of the places we do some form of: - - X = malloc(Y * Z); - -to use calloc(Y, Z) instead. - -Among other issues, this fixes: - - allocation of integer overflow in grub_png_decode_image_header() - reported by Chris Coulson, - - allocation of integer overflow in luks_recover_key() - reported by Chris Coulson, - - allocation of integer overflow in grub_lvm_detect() - reported by Chris Coulson. - -Fixes: CVE-2020-14308 - -Signed-off-by: Peter Jones -Reviewed-by: Daniel Kiper ---- - grub-core/bus/usb/usbhub.c | 8 ++++---- - grub-core/commands/efi/lsefisystab.c | 3 ++- - grub-core/commands/legacycfg.c | 6 +++--- - grub-core/commands/menuentry.c | 2 +- - grub-core/commands/nativedisk.c | 2 +- - grub-core/commands/parttool.c | 12 +++++++++--- - grub-core/commands/regexp.c | 2 +- - grub-core/commands/search_wrap.c | 2 +- - grub-core/disk/diskfilter.c | 4 ++-- - grub-core/disk/ieee1275/ofdisk.c | 2 +- - grub-core/disk/ldm.c | 14 +++++++------- - grub-core/disk/luks.c | 2 +- - grub-core/disk/lvm.c | 8 ++++---- - grub-core/disk/xen/xendisk.c | 2 +- - grub-core/efiemu/loadcore.c | 2 +- - grub-core/efiemu/mm.c | 6 +++--- - grub-core/font/font.c | 3 +-- - grub-core/fs/affs.c | 6 +++--- - grub-core/fs/btrfs.c | 6 +++--- - grub-core/fs/hfs.c | 2 +- - grub-core/fs/hfsplus.c | 6 +++--- - grub-core/fs/iso9660.c | 2 +- - grub-core/fs/ntfs.c | 4 ++-- - grub-core/fs/sfs.c | 2 +- - grub-core/fs/tar.c | 2 +- - grub-core/fs/udf.c | 4 ++-- - grub-core/fs/zfs/zfs.c | 4 ++-- - grub-core/gfxmenu/gui_string_util.c | 2 +- - grub-core/gfxmenu/widget-box.c | 4 ++-- - grub-core/io/gzio.c | 2 +- - grub-core/kern/efi/efi.c | 6 +++--- - grub-core/kern/emu/hostdisk.c | 2 +- - grub-core/kern/fs.c | 2 +- - grub-core/kern/misc.c | 2 +- - grub-core/kern/parser.c | 2 +- - grub-core/kern/uboot/uboot.c | 2 +- - grub-core/lib/libgcrypt/cipher/ac.c | 8 ++++---- - grub-core/lib/libgcrypt/cipher/primegen.c | 4 ++-- - grub-core/lib/libgcrypt/cipher/pubkey.c | 4 ++-- - grub-core/lib/priority_queue.c | 2 +- - grub-core/lib/reed_solomon.c | 7 +++---- - grub-core/lib/relocator.c | 10 +++++----- - grub-core/lib/zstd/fse_decompress.c | 2 +- - grub-core/loader/arm/linux.c | 2 +- - grub-core/loader/efi/chainloader.c | 2 +- - grub-core/loader/i386/bsdXX.c | 2 +- - grub-core/loader/i386/xnu.c | 4 ++-- - grub-core/loader/macho.c | 2 +- - grub-core/loader/multiboot_elfxx.c | 2 +- - grub-core/loader/xnu.c | 2 +- - grub-core/mmap/mmap.c | 4 ++-- - grub-core/net/bootp.c | 2 +- - grub-core/net/dns.c | 10 +++++----- - grub-core/net/net.c | 4 ++-- - grub-core/normal/charset.c | 10 +++++----- - grub-core/normal/cmdline.c | 14 +++++++------- - grub-core/normal/menu_entry.c | 14 +++++++------- - grub-core/normal/menu_text.c | 4 ++-- - grub-core/normal/term.c | 4 ++-- - grub-core/osdep/linux/getroot.c | 6 +++--- - grub-core/osdep/unix/config.c | 2 +- - grub-core/osdep/windows/getroot.c | 2 +- - grub-core/osdep/windows/hostdisk.c | 4 ++-- - grub-core/osdep/windows/init.c | 2 +- - grub-core/osdep/windows/platform.c | 4 ++-- - grub-core/osdep/windows/relpath.c | 2 +- - grub-core/partmap/gpt.c | 2 +- - grub-core/partmap/msdos.c | 2 +- - grub-core/script/execute.c | 2 +- - grub-core/tests/fake_input.c | 2 +- - grub-core/tests/video_checksum.c | 6 +++--- - grub-core/video/capture.c | 2 +- - grub-core/video/emu/sdl.c | 2 +- - grub-core/video/i386/pc/vga.c | 2 +- - grub-core/video/readers/png.c | 2 +- - include/grub/unicode.h | 4 ++-- - util/getroot.c | 2 +- - util/grub-file.c | 2 +- - util/grub-fstest.c | 4 ++-- - util/grub-install-common.c | 2 +- - util/grub-install.c | 4 ++-- - util/grub-mkimagexx.c | 6 ++---- - util/grub-mkrescue.c | 4 ++-- - util/grub-mkstandalone.c | 2 +- - util/grub-pe2elf.c | 12 +++++------- - util/grub-probe.c | 4 ++-- - 86 files changed, 176 insertions(+), 175 deletions(-) - -diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c -index 34a7ff1..a06cce3 100644 ---- a/grub-core/bus/usb/usbhub.c -+++ b/grub-core/bus/usb/usbhub.c -@@ -149,8 +149,8 @@ grub_usb_add_hub (grub_usb_device_t dev) - grub_usb_set_configuration (dev, 1); - - dev->nports = hubdesc.portcnt; -- dev->children = grub_zalloc (hubdesc.portcnt * sizeof (dev->children[0])); -- dev->ports = grub_zalloc (dev->nports * sizeof (dev->ports[0])); -+ dev->children = grub_calloc (hubdesc.portcnt, sizeof (dev->children[0])); -+ dev->ports = grub_calloc (dev->nports, sizeof (dev->ports[0])); - if (!dev->children || !dev->ports) - { - grub_free (dev->children); -@@ -268,8 +268,8 @@ grub_usb_controller_dev_register_iter (grub_usb_controller_t controller, void *d - - /* Query the number of ports the root Hub has. */ - hub->nports = controller->dev->hubports (controller); -- hub->devices = grub_zalloc (sizeof (hub->devices[0]) * hub->nports); -- hub->ports = grub_zalloc (sizeof (hub->ports[0]) * hub->nports); -+ hub->devices = grub_calloc (hub->nports, sizeof (hub->devices[0])); -+ hub->ports = grub_calloc (hub->nports, sizeof (hub->ports[0])); - if (!hub->devices || !hub->ports) - { - grub_free (hub->devices); -diff --git a/grub-core/commands/efi/lsefisystab.c b/grub-core/commands/efi/lsefisystab.c -index df10302..cd81507 100644 ---- a/grub-core/commands/efi/lsefisystab.c -+++ b/grub-core/commands/efi/lsefisystab.c -@@ -71,7 +71,8 @@ grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)), - grub_printf ("Vendor: "); - - for (vendor_utf16 = st->firmware_vendor; *vendor_utf16; vendor_utf16++); -- vendor = grub_malloc (4 * (vendor_utf16 - st->firmware_vendor) + 1); -+ /* Allocate extra 3 bytes to simplify math. */ -+ vendor = grub_calloc (4, vendor_utf16 - st->firmware_vendor + 1); - if (!vendor) - return grub_errno; - *grub_utf16_to_utf8 ((grub_uint8_t *) vendor, st->firmware_vendor, -diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c -index 891eac5..da5143d 100644 ---- a/grub-core/commands/legacycfg.c -+++ b/grub-core/commands/legacycfg.c -@@ -315,7 +315,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), - if (argc < 2) - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - -- cutargs = grub_malloc (sizeof (cutargs[0]) * (argc - 1)); -+ cutargs = grub_calloc (argc - 1, sizeof (cutargs[0])); - if (!cutargs) - return grub_errno; - cutargc = argc - 1; -@@ -437,7 +437,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), - { - char rbuf[3] = "-r"; - bsdargc = cutargc + 2; -- bsdargs = grub_malloc (sizeof (bsdargs[0]) * bsdargc); -+ bsdargs = grub_calloc (bsdargc, sizeof (bsdargs[0])); - if (!bsdargs) - { - err = grub_errno; -@@ -560,7 +560,7 @@ grub_cmd_legacy_initrdnounzip (struct grub_command *mycmd __attribute__ ((unused - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"), - "module"); - -- newargs = grub_malloc ((argc + 1) * sizeof (newargs[0])); -+ newargs = grub_calloc (argc + 1, sizeof (newargs[0])); - if (!newargs) - return grub_errno; - grub_memcpy (newargs + 1, args, argc * sizeof (newargs[0])); -diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c -index 29736f5..84edfc0 100644 ---- a/grub-core/commands/menuentry.c -+++ b/grub-core/commands/menuentry.c -@@ -157,7 +157,7 @@ grub_normal_add_menu_entry (int argc, const char **args, - grub_dprintf ("menu", "menu_id:\"%s\"\n", menu_id); - - /* Save argc, args to pass as parameters to block arg later. */ -- menu_args = grub_malloc (sizeof (char*) * (argc + 1)); -+ menu_args = grub_calloc (argc + 1, sizeof (char *)); - if (! menu_args) - goto fail; - -diff --git a/grub-core/commands/nativedisk.c b/grub-core/commands/nativedisk.c -index 699447d..7c8f97f 100644 ---- a/grub-core/commands/nativedisk.c -+++ b/grub-core/commands/nativedisk.c -@@ -195,7 +195,7 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)), - else - path_prefix = prefix; - -- mods = grub_malloc (argc * sizeof (mods[0])); -+ mods = grub_calloc (argc, sizeof (mods[0])); - if (!mods) - return grub_errno; - -diff --git a/grub-core/commands/parttool.c b/grub-core/commands/parttool.c -index 22b46b1..051e313 100644 ---- a/grub-core/commands/parttool.c -+++ b/grub-core/commands/parttool.c -@@ -59,7 +59,13 @@ grub_parttool_register(const char *part_name, - for (nargs = 0; args[nargs].name != 0; nargs++); - cur->nargs = nargs; - cur->args = (struct grub_parttool_argdesc *) -- grub_malloc ((nargs + 1) * sizeof (struct grub_parttool_argdesc)); -+ grub_calloc (nargs + 1, sizeof (struct grub_parttool_argdesc)); -+ if (!cur->args) -+ { -+ grub_free (cur); -+ curhandle--; -+ return -1; -+ } - grub_memcpy (cur->args, args, - (nargs + 1) * sizeof (struct grub_parttool_argdesc)); - -@@ -257,7 +263,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), - return err; - } - -- parsed = (int *) grub_zalloc (argc * sizeof (int)); -+ parsed = (int *) grub_calloc (argc, sizeof (int)); - - for (i = 1; i < argc; i++) - if (! parsed[i]) -@@ -290,7 +296,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), - } - ptool = cur; - pargs = (struct grub_parttool_args *) -- grub_zalloc (ptool->nargs * sizeof (struct grub_parttool_args)); -+ grub_calloc (ptool->nargs, sizeof (struct grub_parttool_args)); - for (j = i; j < argc; j++) - if (! parsed[j]) - { -diff --git a/grub-core/commands/regexp.c b/grub-core/commands/regexp.c -index 7c5c72f..612003f 100644 ---- a/grub-core/commands/regexp.c -+++ b/grub-core/commands/regexp.c -@@ -116,7 +116,7 @@ grub_cmd_regexp (grub_extcmd_context_t ctxt, int argc, char **args) - if (ret) - goto fail; - -- matches = grub_zalloc (sizeof (*matches) * (regex.re_nsub + 1)); -+ matches = grub_calloc (regex.re_nsub + 1, sizeof (*matches)); - if (! matches) - goto fail; - -diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c -index d7fd26b..47fc8eb 100644 ---- a/grub-core/commands/search_wrap.c -+++ b/grub-core/commands/search_wrap.c -@@ -122,7 +122,7 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args) - for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++) - nhints++; - -- hints = grub_malloc (sizeof (hints[0]) * nhints); -+ hints = grub_calloc (nhints, sizeof (hints[0])); - if (!hints) - return grub_errno; - j = 0; -diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c -index 3f264be..88784dc 100644 ---- a/grub-core/disk/diskfilter.c -+++ b/grub-core/disk/diskfilter.c -@@ -1137,7 +1137,7 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, - array->lvs->segments->node_count = nmemb; - array->lvs->segments->raid_member_size = disk_size; - array->lvs->segments->nodes -- = grub_zalloc (nmemb * sizeof (array->lvs->segments->nodes[0])); -+ = grub_calloc (nmemb, sizeof (array->lvs->segments->nodes[0])); - array->lvs->segments->stripe_size = stripe_size; - for (i = 0; i < nmemb; i++) - { -@@ -1230,7 +1230,7 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id, - grub_partition_t p; - for (p = disk->partition; p; p = p->parent) - s++; -- pv->partmaps = xmalloc (s * sizeof (pv->partmaps[0])); -+ pv->partmaps = xcalloc (s, sizeof (pv->partmaps[0])); - s = 0; - for (p = disk->partition; p; p = p->parent) - pv->partmaps[s++] = xstrdup (p->partmap->name); -diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c -index f73257e..03674cb 100644 ---- a/grub-core/disk/ieee1275/ofdisk.c -+++ b/grub-core/disk/ieee1275/ofdisk.c -@@ -297,7 +297,7 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) - /* Power machines documentation specify 672 as maximum SAS disks in - one system. Using a slightly larger value to be safe. */ - table_size = 768; -- table = grub_malloc (table_size * sizeof (grub_uint64_t)); -+ table = grub_calloc (table_size, sizeof (grub_uint64_t)); - - if (!table) - { -diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c -index 2a22d2d..e632370 100644 ---- a/grub-core/disk/ldm.c -+++ b/grub-core/disk/ldm.c -@@ -323,8 +323,8 @@ make_vg (grub_disk_t disk, - lv->segments->type = GRUB_DISKFILTER_MIRROR; - lv->segments->node_count = 0; - lv->segments->node_alloc = 8; -- lv->segments->nodes = grub_zalloc (sizeof (*lv->segments->nodes) -- * lv->segments->node_alloc); -+ lv->segments->nodes = grub_calloc (lv->segments->node_alloc, -+ sizeof (*lv->segments->nodes)); - if (!lv->segments->nodes) - goto fail2; - ptr = vblk[i].dynamic; -@@ -543,8 +543,8 @@ make_vg (grub_disk_t disk, - { - comp->segment_alloc = 8; - comp->segment_count = 0; -- comp->segments = grub_malloc (sizeof (*comp->segments) -- * comp->segment_alloc); -+ comp->segments = grub_calloc (comp->segment_alloc, -+ sizeof (*comp->segments)); - if (!comp->segments) - goto fail2; - } -@@ -590,8 +590,8 @@ make_vg (grub_disk_t disk, - } - comp->segments->node_count = read_int (ptr + 1, *ptr); - comp->segments->node_alloc = comp->segments->node_count; -- comp->segments->nodes = grub_zalloc (sizeof (*comp->segments->nodes) -- * comp->segments->node_alloc); -+ comp->segments->nodes = grub_calloc (comp->segments->node_alloc, -+ sizeof (*comp->segments->nodes)); - if (!lv->segments->nodes) - goto fail2; - } -@@ -1017,7 +1017,7 @@ grub_util_ldm_embed (struct grub_disk *disk, unsigned int *nsectors, - *nsectors = lv->size; - if (*nsectors > max_nsectors) - *nsectors = max_nsectors; -- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); -+ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); - if (!*sectors) - return grub_errno; - for (i = 0; i < *nsectors; i++) -diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c -index 86c50c6..18b3a8b 100644 ---- a/grub-core/disk/luks.c -+++ b/grub-core/disk/luks.c -@@ -336,7 +336,7 @@ luks_recover_key (grub_disk_t source, - && grub_be_to_cpu32 (header.keyblock[i].stripes) > max_stripes) - max_stripes = grub_be_to_cpu32 (header.keyblock[i].stripes); - -- split_key = grub_malloc (keysize * max_stripes); -+ split_key = grub_calloc (keysize, max_stripes); - if (!split_key) - return grub_errno; - -diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c -index 0cbd0dd..8e76d1a 100644 ---- a/grub-core/disk/lvm.c -+++ b/grub-core/disk/lvm.c -@@ -174,7 +174,7 @@ grub_lvm_detect (grub_disk_t disk, - first one. */ - - /* Allocate buffer space for the circular worst-case scenario. */ -- metadatabuf = grub_malloc (2 * mda_size); -+ metadatabuf = grub_calloc (2, mda_size); - if (! metadatabuf) - goto fail; - -@@ -427,7 +427,7 @@ grub_lvm_detect (grub_disk_t disk, - #endif - goto lvs_fail; - } -- lv->segments = grub_zalloc (sizeof (*seg) * lv->segment_count); -+ lv->segments = grub_calloc (lv->segment_count, sizeof (*seg)); - seg = lv->segments; - - for (i = 0; i < lv->segment_count; i++) -@@ -484,8 +484,8 @@ grub_lvm_detect (grub_disk_t disk, - if (seg->node_count != 1) - seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); - -- seg->nodes = grub_zalloc (sizeof (*stripe) -- * seg->node_count); -+ seg->nodes = grub_calloc (seg->node_count, -+ sizeof (*stripe)); - stripe = seg->nodes; - - p = grub_strstr (p, "stripes = ["); -diff --git a/grub-core/disk/xen/xendisk.c b/grub-core/disk/xen/xendisk.c -index 48476cb..d6612ee 100644 ---- a/grub-core/disk/xen/xendisk.c -+++ b/grub-core/disk/xen/xendisk.c -@@ -426,7 +426,7 @@ grub_xendisk_init (void) - if (!ctr) - return; - -- virtdisks = grub_malloc (ctr * sizeof (virtdisks[0])); -+ virtdisks = grub_calloc (ctr, sizeof (virtdisks[0])); - if (!virtdisks) - return; - if (grub_xenstore_dir ("device/vbd", fill, &ctr)) -diff --git a/grub-core/efiemu/loadcore.c b/grub-core/efiemu/loadcore.c -index 44085ef..2b92462 100644 ---- a/grub-core/efiemu/loadcore.c -+++ b/grub-core/efiemu/loadcore.c -@@ -201,7 +201,7 @@ grub_efiemu_count_symbols (const Elf_Ehdr *e) - - grub_efiemu_nelfsyms = (unsigned) s->sh_size / (unsigned) s->sh_entsize; - grub_efiemu_elfsyms = (struct grub_efiemu_elf_sym *) -- grub_malloc (sizeof (struct grub_efiemu_elf_sym) * grub_efiemu_nelfsyms); -+ grub_calloc (grub_efiemu_nelfsyms, sizeof (struct grub_efiemu_elf_sym)); - - /* Relocators */ - for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); -diff --git a/grub-core/efiemu/mm.c b/grub-core/efiemu/mm.c -index 52a032f..9b8e0d0 100644 ---- a/grub-core/efiemu/mm.c -+++ b/grub-core/efiemu/mm.c -@@ -554,11 +554,11 @@ grub_efiemu_mmap_sort_and_uniq (void) - /* Initialize variables*/ - grub_memset (present, 0, sizeof (int) * GRUB_EFI_MAX_MEMORY_TYPE); - scanline_events = (struct grub_efiemu_mmap_scan *) -- grub_malloc (sizeof (struct grub_efiemu_mmap_scan) * 2 * mmap_num); -+ grub_calloc (mmap_num, sizeof (struct grub_efiemu_mmap_scan) * 2); - - /* Number of chunks can't increase more than by factor of 2 */ - result = (grub_efi_memory_descriptor_t *) -- grub_malloc (sizeof (grub_efi_memory_descriptor_t) * 2 * mmap_num); -+ grub_calloc (mmap_num, sizeof (grub_efi_memory_descriptor_t) * 2); - if (!result || !scanline_events) - { - grub_free (result); -@@ -660,7 +660,7 @@ grub_efiemu_mm_do_alloc (void) - - /* Preallocate mmap */ - efiemu_mmap = (grub_efi_memory_descriptor_t *) -- grub_malloc (mmap_reserved_size * sizeof (grub_efi_memory_descriptor_t)); -+ grub_calloc (mmap_reserved_size, sizeof (grub_efi_memory_descriptor_t)); - if (!efiemu_mmap) - { - grub_efiemu_unload (); -diff --git a/grub-core/font/font.c b/grub-core/font/font.c -index 85a2925..8e118b3 100644 ---- a/grub-core/font/font.c -+++ b/grub-core/font/font.c -@@ -293,8 +293,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct - font->num_chars = sect_length / FONT_CHAR_INDEX_ENTRY_SIZE; - - /* Allocate the character index array. */ -- font->char_index = grub_malloc (font->num_chars -- * sizeof (struct char_index_entry)); -+ font->char_index = grub_calloc (font->num_chars, sizeof (struct char_index_entry)); - if (!font->char_index) - return 1; - font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t)); -diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c -index 6b6a2bc..220b371 100644 ---- a/grub-core/fs/affs.c -+++ b/grub-core/fs/affs.c -@@ -301,7 +301,7 @@ grub_affs_read_symlink (grub_fshelp_node_t node) - return 0; - } - latin1[symlink_size] = 0; -- utf8 = grub_malloc (symlink_size * GRUB_MAX_UTF8_PER_LATIN1 + 1); -+ utf8 = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, symlink_size); - if (!utf8) - { - grub_free (latin1); -@@ -422,7 +422,7 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir, - return 1; - } - -- hashtable = grub_zalloc (data->htsize * sizeof (*hashtable)); -+ hashtable = grub_calloc (data->htsize, sizeof (*hashtable)); - if (!hashtable) - return 1; - -@@ -628,7 +628,7 @@ grub_affs_label (grub_device_t device, char **label) - len = file.namelen; - if (len > sizeof (file.name)) - len = sizeof (file.name); -- *label = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); -+ *label = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, len); - if (*label) - *grub_latin1_to_utf8 ((grub_uint8_t *) *label, file.name, len) = '\0'; - } -diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index 9cd7f4b..ba080fd 100644 ---- a/grub-core/fs/btrfs.c -+++ b/grub-core/fs/btrfs.c -@@ -442,7 +442,7 @@ lower_bound (struct grub_btrfs_data *data, - { - desc->allocated = 16; - desc->depth = 0; -- desc->data = grub_malloc (sizeof (desc->data[0]) * desc->allocated); -+ desc->data = grub_calloc (desc->allocated, sizeof (desc->data[0])); - if (!desc->data) - return grub_errno; - } -@@ -781,7 +781,7 @@ raid56_read_retry (struct grub_btrfs_data *data, - grub_err_t ret = GRUB_ERR_OUT_OF_MEMORY; - grub_uint64_t i, failed_devices; - -- buffers = grub_zalloc (sizeof(*buffers) * nstripes); -+ buffers = grub_calloc (nstripes, sizeof (*buffers)); - if (!buffers) - goto cleanup; - -@@ -2477,7 +2477,7 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), - *nsectors = 64 * 2 - 1; - if (*nsectors > max_nsectors) - *nsectors = max_nsectors; -- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); -+ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); - if (!*sectors) - return grub_errno; - for (i = 0; i < *nsectors; i++) -diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c -index ac0a409..3fe842b 100644 ---- a/grub-core/fs/hfs.c -+++ b/grub-core/fs/hfs.c -@@ -1360,7 +1360,7 @@ grub_hfs_label (grub_device_t device, char **label) - grub_size_t len = data->sblock.volname[0]; - if (len > sizeof (data->sblock.volname) - 1) - len = sizeof (data->sblock.volname) - 1; -- *label = grub_malloc (len * MAX_UTF8_PER_MAC_ROMAN + 1); -+ *label = grub_calloc (MAX_UTF8_PER_MAC_ROMAN + 1, len); - if (*label) - macroman_to_utf8 (*label, data->sblock.volname + 1, - len + 1, 0); -diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c -index 54786bb..dae43be 100644 ---- a/grub-core/fs/hfsplus.c -+++ b/grub-core/fs/hfsplus.c -@@ -720,7 +720,7 @@ list_nodes (void *record, void *hook_arg) - if (! filename) - return 0; - -- keyname = grub_malloc (grub_be_to_cpu16 (catkey->namelen) * sizeof (*keyname)); -+ keyname = grub_calloc (grub_be_to_cpu16 (catkey->namelen), sizeof (*keyname)); - if (!keyname) - { - grub_free (filename); -@@ -1007,7 +1007,7 @@ grub_hfsplus_label (grub_device_t device, char **label) - grub_hfsplus_btree_recptr (&data->catalog_tree, node, ptr); - - label_len = grub_be_to_cpu16 (catkey->namelen); -- label_name = grub_malloc (label_len * sizeof (*label_name)); -+ label_name = grub_calloc (label_len, sizeof (*label_name)); - if (!label_name) - { - grub_free (node); -@@ -1029,7 +1029,7 @@ grub_hfsplus_label (grub_device_t device, char **label) - } - } - -- *label = grub_malloc (label_len * GRUB_MAX_UTF8_PER_UTF16 + 1); -+ *label = grub_calloc (label_len, GRUB_MAX_UTF8_PER_UTF16 + 1); - if (! *label) - { - grub_free (label_name); -diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c -index 49c0c63..4f1b52a 100644 ---- a/grub-core/fs/iso9660.c -+++ b/grub-core/fs/iso9660.c -@@ -331,7 +331,7 @@ grub_iso9660_convert_string (grub_uint8_t *us, int len) - int i; - grub_uint16_t t[MAX_NAMELEN / 2 + 1]; - -- p = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1); -+ p = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1); - if (! p) - return NULL; - -diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c -index fc4e1f6..2f34f76 100644 ---- a/grub-core/fs/ntfs.c -+++ b/grub-core/fs/ntfs.c -@@ -556,8 +556,8 @@ get_utf8 (grub_uint8_t *in, grub_size_t len) - grub_uint16_t *tmp; - grub_size_t i; - -- buf = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1); -- tmp = grub_malloc (len * sizeof (tmp[0])); -+ buf = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1); -+ tmp = grub_calloc (len, sizeof (tmp[0])); - if (!buf || !tmp) - { - grub_free (buf); -diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c -index 50c1fe7..90f7fb3 100644 ---- a/grub-core/fs/sfs.c -+++ b/grub-core/fs/sfs.c -@@ -266,7 +266,7 @@ grub_sfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) - node->next_extent = node->block; - node->cache_size = 0; - -- node->cache = grub_malloc (sizeof (node->cache[0]) * cache_size); -+ node->cache = grub_calloc (cache_size, sizeof (node->cache[0])); - if (!node->cache) - { - grub_errno = 0; -diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c -index 7d63e0c..c551ed6 100644 ---- a/grub-core/fs/tar.c -+++ b/grub-core/fs/tar.c -@@ -120,7 +120,7 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, - if (data->linkname_alloc < linksize + 1) - { - char *n; -- n = grub_malloc (2 * (linksize + 1)); -+ n = grub_calloc (2, linksize + 1); - if (!n) - return grub_errno; - grub_free (data->linkname); -diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c -index dc8b6e2..a837616 100644 ---- a/grub-core/fs/udf.c -+++ b/grub-core/fs/udf.c -@@ -873,7 +873,7 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) - { - unsigned i; - utf16len = sz - 1; -- utf16 = grub_malloc (utf16len * sizeof (utf16[0])); -+ utf16 = grub_calloc (utf16len, sizeof (utf16[0])); - if (!utf16) - return NULL; - for (i = 0; i < utf16len; i++) -@@ -883,7 +883,7 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) - { - unsigned i; - utf16len = (sz - 1) / 2; -- utf16 = grub_malloc (utf16len * sizeof (utf16[0])); -+ utf16 = grub_calloc (utf16len, sizeof (utf16[0])); - if (!utf16) - return NULL; - for (i = 0; i < utf16len; i++) -diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c -index 2f72e42..381dde5 100644 ---- a/grub-core/fs/zfs/zfs.c -+++ b/grub-core/fs/zfs/zfs.c -@@ -3325,7 +3325,7 @@ dnode_get_fullpath (const char *fullpath, struct subvolume *subvol, - } - subvol->nkeys = 0; - zap_iterate (&keychain_dn, 8, count_zap_keys, &ctx, data); -- subvol->keyring = grub_zalloc (subvol->nkeys * sizeof (subvol->keyring[0])); -+ subvol->keyring = grub_calloc (subvol->nkeys, sizeof (subvol->keyring[0])); - if (!subvol->keyring) - { - grub_free (fsname); -@@ -4336,7 +4336,7 @@ grub_zfs_embed (grub_device_t device __attribute__ ((unused)), - *nsectors = (VDEV_BOOT_SIZE >> GRUB_DISK_SECTOR_BITS); - if (*nsectors > max_nsectors) - *nsectors = max_nsectors; -- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); -+ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); - if (!*sectors) - return grub_errno; - for (i = 0; i < *nsectors; i++) -diff --git a/grub-core/gfxmenu/gui_string_util.c b/grub-core/gfxmenu/gui_string_util.c -index a9a415e..ba1e1ea 100644 ---- a/grub-core/gfxmenu/gui_string_util.c -+++ b/grub-core/gfxmenu/gui_string_util.c -@@ -55,7 +55,7 @@ canonicalize_path (const char *path) - if (*p == '/') - components++; - -- char **path_array = grub_malloc (components * sizeof (*path_array)); -+ char **path_array = grub_calloc (components, sizeof (*path_array)); - if (! path_array) - return 0; - -diff --git a/grub-core/gfxmenu/widget-box.c b/grub-core/gfxmenu/widget-box.c -index b606028..470597d 100644 ---- a/grub-core/gfxmenu/widget-box.c -+++ b/grub-core/gfxmenu/widget-box.c -@@ -303,10 +303,10 @@ grub_gfxmenu_create_box (const char *pixmaps_prefix, - box->content_height = 0; - box->raw_pixmaps = - (struct grub_video_bitmap **) -- grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); -+ grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *)); - box->scaled_pixmaps = - (struct grub_video_bitmap **) -- grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); -+ grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *)); - - /* Initialize all pixmap pointers to NULL so that proper destruction can - be performed if an error is encountered partway through construction. */ -diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c -index 6208a97..43d98a7 100644 ---- a/grub-core/io/gzio.c -+++ b/grub-core/io/gzio.c -@@ -554,7 +554,7 @@ huft_build (unsigned *b, /* code lengths in bits (all assumed <= BMAX) */ - z = 1 << j; /* table entries for j-bit table */ - - /* allocate and link in new table */ -- q = (struct huft *) grub_zalloc ((z + 1) * sizeof (struct huft)); -+ q = (struct huft *) grub_calloc (z + 1, sizeof (struct huft)); - if (! q) - { - if (h) -diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index 279394d..ab133fe 100644 ---- a/grub-core/kern/efi/efi.c -+++ b/grub-core/kern/efi/efi.c -@@ -207,7 +207,7 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, - - len = grub_strlen (var); - len16 = len * GRUB_MAX_UTF16_PER_UTF8; -- var16 = grub_malloc ((len16 + 1) * sizeof (var16[0])); -+ var16 = grub_calloc (len16 + 1, sizeof (var16[0])); - if (!var16) - return grub_errno; - len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); -@@ -245,7 +245,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, - - len = grub_strlen (var); - len16 = len * GRUB_MAX_UTF16_PER_UTF8; -- var16 = grub_malloc ((len16 + 1) * sizeof (var16[0])); -+ var16 = grub_calloc (len16 + 1, sizeof (var16[0])); - if (!var16) - return NULL; - len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); -@@ -401,7 +401,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) - while (len > 0 && fp->path_name[len - 1] == 0) - len--; - -- dup_name = grub_malloc (len * sizeof (*dup_name)); -+ dup_name = grub_calloc (len, sizeof (*dup_name)); - if (!dup_name) - { - grub_free (name); -diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c -index e9ec680..d975265 100644 ---- a/grub-core/kern/emu/hostdisk.c -+++ b/grub-core/kern/emu/hostdisk.c -@@ -615,7 +615,7 @@ static char * - grub_util_path_concat_real (size_t n, int ext, va_list ap) - { - size_t totlen = 0; -- char **l = xmalloc ((n + ext) * sizeof (l[0])); -+ char **l = xcalloc (n + ext, sizeof (l[0])); - char *r, *p, *pi; - size_t i; - int first = 1; -diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c -index 88d3936..fb30da9 100644 ---- a/grub-core/kern/fs.c -+++ b/grub-core/kern/fs.c -@@ -151,7 +151,7 @@ grub_fs_blocklist_open (grub_file_t file, const char *name) - while (p); - - /* Allocate a block list. */ -- blocks = grub_zalloc (sizeof (struct grub_fs_block) * (num + 1)); -+ blocks = grub_calloc (num + 1, sizeof (struct grub_fs_block)); - if (! blocks) - return 0; - -diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 87afb43..dc5e10b 100644 ---- a/grub-core/kern/misc.c -+++ b/grub-core/kern/misc.c -@@ -750,7 +750,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args, - args->ptr = args->prealloc; - else - { -- args->ptr = grub_malloc (args->count * sizeof (args->ptr[0])); -+ args->ptr = grub_calloc (args->count, sizeof (args->ptr[0])); - if (!args->ptr) - { - grub_errno = GRUB_ERR_NONE; -diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c -index 78175aa..619db31 100644 ---- a/grub-core/kern/parser.c -+++ b/grub-core/kern/parser.c -@@ -213,7 +213,7 @@ grub_parser_split_cmdline (const char *cmdline, - return grub_errno; - grub_memcpy (args, buffer, bp - buffer); - -- *argv = grub_malloc (sizeof (char *) * (*argc + 1)); -+ *argv = grub_calloc (*argc + 1, sizeof (char *)); - if (!*argv) - { - grub_free (args); -diff --git a/grub-core/kern/uboot/uboot.c b/grub-core/kern/uboot/uboot.c -index be4816f..aac8f9a 100644 ---- a/grub-core/kern/uboot/uboot.c -+++ b/grub-core/kern/uboot/uboot.c -@@ -133,7 +133,7 @@ grub_uboot_dev_enum (void) - return num_devices; - - max_devices = 2; -- enum_devices = grub_malloc (sizeof(struct device_info) * max_devices); -+ enum_devices = grub_calloc (max_devices, sizeof(struct device_info)); - if (!enum_devices) - return 0; - -diff --git a/grub-core/lib/libgcrypt/cipher/ac.c b/grub-core/lib/libgcrypt/cipher/ac.c -index f5e946a..63f6fcd 100644 ---- a/grub-core/lib/libgcrypt/cipher/ac.c -+++ b/grub-core/lib/libgcrypt/cipher/ac.c -@@ -185,7 +185,7 @@ ac_data_mpi_copy (gcry_ac_mpi_t *data_mpis, unsigned int data_mpis_n, - gcry_mpi_t mpi; - char *label; - -- data_mpis_new = gcry_malloc (sizeof (*data_mpis_new) * data_mpis_n); -+ data_mpis_new = gcry_calloc (data_mpis_n, sizeof (*data_mpis_new)); - if (! data_mpis_new) - { - err = gcry_error_from_errno (errno); -@@ -572,7 +572,7 @@ _gcry_ac_data_to_sexp (gcry_ac_data_t data, gcry_sexp_t *sexp, - } - - /* Add MPI list. */ -- arg_list = gcry_malloc (sizeof (*arg_list) * (data_n + 1)); -+ arg_list = gcry_calloc (data_n + 1, sizeof (*arg_list)); - if (! arg_list) - { - err = gcry_error_from_errno (errno); -@@ -1283,7 +1283,7 @@ ac_data_construct (const char *identifier, int include_flags, - /* We build a list of arguments to pass to - gcry_sexp_build_array(). */ - data_length = _gcry_ac_data_length (data); -- arg_list = gcry_malloc (sizeof (*arg_list) * (data_length * 2)); -+ arg_list = gcry_calloc (data_length, sizeof (*arg_list) * 2); - if (! arg_list) - { - err = gcry_error_from_errno (errno); -@@ -1593,7 +1593,7 @@ _gcry_ac_key_pair_generate (gcry_ac_handle_t handle, unsigned int nbits, - arg_list_n += 2; - - /* Allocate list. */ -- arg_list = gcry_malloc (sizeof (*arg_list) * arg_list_n); -+ arg_list = gcry_calloc (arg_list_n, sizeof (*arg_list)); - if (! arg_list) - { - err = gcry_error_from_errno (errno); -diff --git a/grub-core/lib/libgcrypt/cipher/primegen.c b/grub-core/lib/libgcrypt/cipher/primegen.c -index 2788e34..b12e79b 100644 ---- a/grub-core/lib/libgcrypt/cipher/primegen.c -+++ b/grub-core/lib/libgcrypt/cipher/primegen.c -@@ -383,7 +383,7 @@ prime_generate_internal (int need_q_factor, - } - - /* Allocate an array to track pool usage. */ -- pool_in_use = gcry_malloc (n * sizeof *pool_in_use); -+ pool_in_use = gcry_calloc (n, sizeof *pool_in_use); - if (!pool_in_use) - { - err = gpg_err_code_from_errno (errno); -@@ -765,7 +765,7 @@ gen_prime (unsigned int nbits, int secret, int randomlevel, - if (nbits < 16) - log_fatal ("can't generate a prime with less than %d bits\n", 16); - -- mods = gcry_xmalloc( no_of_small_prime_numbers * sizeof *mods ); -+ mods = gcry_xcalloc( no_of_small_prime_numbers, sizeof *mods); - /* Make nbits fit into gcry_mpi_t implementation. */ - val_2 = mpi_alloc_set_ui( 2 ); - val_3 = mpi_alloc_set_ui( 3); -diff --git a/grub-core/lib/libgcrypt/cipher/pubkey.c b/grub-core/lib/libgcrypt/cipher/pubkey.c -index 9109821..ca087ad 100644 ---- a/grub-core/lib/libgcrypt/cipher/pubkey.c -+++ b/grub-core/lib/libgcrypt/cipher/pubkey.c -@@ -2941,7 +2941,7 @@ gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey) - * array to a format string, so we have to do it this way :-(. */ - /* FIXME: There is now such a format specifier, so we can - change the code to be more clear. */ -- arg_list = malloc (nelem * sizeof *arg_list); -+ arg_list = calloc (nelem, sizeof *arg_list); - if (!arg_list) - { - rc = gpg_err_code_from_syserror (); -@@ -3233,7 +3233,7 @@ gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey) - } - strcpy (p, "))"); - -- arg_list = malloc (nelem * sizeof *arg_list); -+ arg_list = calloc (nelem, sizeof *arg_list); - if (!arg_list) - { - rc = gpg_err_code_from_syserror (); -diff --git a/grub-core/lib/priority_queue.c b/grub-core/lib/priority_queue.c -index 659be0b..7d5e7c0 100644 ---- a/grub-core/lib/priority_queue.c -+++ b/grub-core/lib/priority_queue.c -@@ -92,7 +92,7 @@ grub_priority_queue_new (grub_size_t elsize, - { - struct grub_priority_queue *ret; - void *els; -- els = grub_malloc (elsize * 8); -+ els = grub_calloc (8, elsize); - if (!els) - return 0; - ret = (struct grub_priority_queue *) grub_malloc (sizeof (*ret)); -diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c -index 19c2008..79037c0 100644 ---- a/grub-core/lib/reed_solomon.c -+++ b/grub-core/lib/reed_solomon.c -@@ -20,6 +20,7 @@ - #include - #include - #include -+#define xcalloc calloc - #define xmalloc malloc - #define grub_memset memset - #define grub_memcpy memcpy -@@ -158,11 +159,9 @@ rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) - gf_single_t *rs_polynomial; - unsigned int i, j; - gf_single_t *m; -- m = xmalloc ((s + rs) * sizeof (gf_single_t)); -+ m = xcalloc (s + rs, sizeof (gf_single_t)); - grub_memcpy (m, data, s * sizeof (gf_single_t)); -- grub_memset (m + s, 0, rs * sizeof (gf_single_t)); -- rs_polynomial = xmalloc ((rs + 1) * sizeof (gf_single_t)); -- grub_memset (rs_polynomial, 0, (rs + 1) * sizeof (gf_single_t)); -+ rs_polynomial = xcalloc (rs + 1, sizeof (gf_single_t)); - rs_polynomial[rs] = 1; - /* Multiply with X - a^r */ - for (j = 0; j < rs; j++) -diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c -index ea3ebc7..5847aac 100644 ---- a/grub-core/lib/relocator.c -+++ b/grub-core/lib/relocator.c -@@ -495,9 +495,9 @@ malloc_in_range (struct grub_relocator *rel, - } - #endif - -- eventt = grub_malloc (maxevents * sizeof (events[0])); -+ eventt = grub_calloc (maxevents, sizeof (events[0])); - counter = grub_malloc ((DIGITSORT_MASK + 2) * sizeof (counter[0])); -- events = grub_malloc (maxevents * sizeof (events[0])); -+ events = grub_calloc (maxevents, sizeof (events[0])); - if (!events || !eventt || !counter) - { - grub_dprintf ("relocator", "events or counter allocation failed %d\n", -@@ -963,7 +963,7 @@ malloc_in_range (struct grub_relocator *rel, - #endif - unsigned cural = 0; - int oom = 0; -- res->subchunks = grub_malloc (sizeof (res->subchunks[0]) * nallocs); -+ res->subchunks = grub_calloc (nallocs, sizeof (res->subchunks[0])); - if (!res->subchunks) - oom = 1; - res->nsubchunks = nallocs; -@@ -1562,8 +1562,8 @@ grub_relocator_prepare_relocs (struct grub_relocator *rel, grub_addr_t addr, - count[(chunk->src & 0xff) + 1]++; - } - } -- from = grub_malloc (nchunks * sizeof (sorted[0])); -- to = grub_malloc (nchunks * sizeof (sorted[0])); -+ from = grub_calloc (nchunks, sizeof (sorted[0])); -+ to = grub_calloc (nchunks, sizeof (sorted[0])); - if (!from || !to) - { - grub_free (from); -diff --git a/grub-core/lib/zstd/fse_decompress.c b/grub-core/lib/zstd/fse_decompress.c -index 72bbead..2227b84 100644 ---- a/grub-core/lib/zstd/fse_decompress.c -+++ b/grub-core/lib/zstd/fse_decompress.c -@@ -82,7 +82,7 @@ - FSE_DTable* FSE_createDTable (unsigned tableLog) - { - if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX; -- return (FSE_DTable*)malloc( FSE_DTABLE_SIZE_U32(tableLog) * sizeof (U32) ); -+ return (FSE_DTable*)calloc( FSE_DTABLE_SIZE_U32(tableLog), sizeof (U32) ); - } - - void FSE_freeDTable (FSE_DTable* dt) -diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c -index 5168491..d70c174 100644 ---- a/grub-core/loader/arm/linux.c -+++ b/grub-core/loader/arm/linux.c -@@ -78,7 +78,7 @@ linux_prepare_atag (void *target_atag) - - /* some place for cmdline, initrd and terminator. */ - tmp_size = get_atag_size (atag_orig) + 20 + (arg_size) / 4; -- tmp_atag = grub_malloc (tmp_size * sizeof (grub_uint32_t)); -+ tmp_atag = grub_calloc (tmp_size, sizeof (grub_uint32_t)); - if (!tmp_atag) - return grub_errno; - -diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index 2c529f7..7365051 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -125,7 +125,7 @@ copy_file_path (grub_efi_file_path_device_path_t *fp, - fp->header.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE; - fp->header.subtype = GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE; - -- path_name = grub_malloc (len * GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); -+ path_name = grub_calloc (len, GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); - if (!path_name) - return; - -diff --git a/grub-core/loader/i386/bsdXX.c b/grub-core/loader/i386/bsdXX.c -index af6741d..a8d8bf7 100644 ---- a/grub-core/loader/i386/bsdXX.c -+++ b/grub-core/loader/i386/bsdXX.c -@@ -48,7 +48,7 @@ read_headers (grub_file_t file, const char *filename, Elf_Ehdr *e, char **shdr) - if (e->e_ident[EI_CLASS] != SUFFIX (ELFCLASS)) - return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic")); - -- *shdr = grub_malloc ((grub_uint32_t) e->e_shnum * e->e_shentsize); -+ *shdr = grub_calloc (e->e_shnum, e->e_shentsize); - if (! *shdr) - return grub_errno; - -diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c -index e64ed08..b7d176b 100644 ---- a/grub-core/loader/i386/xnu.c -+++ b/grub-core/loader/i386/xnu.c -@@ -295,7 +295,7 @@ grub_xnu_devprop_add_property_utf8 (struct grub_xnu_devprop_device_descriptor *d - return grub_errno; - - len = grub_strlen (name); -- utf16 = grub_malloc (sizeof (grub_uint16_t) * len); -+ utf16 = grub_calloc (len, sizeof (grub_uint16_t)); - if (!utf16) - { - grub_free (utf8); -@@ -331,7 +331,7 @@ grub_xnu_devprop_add_property_utf16 (struct grub_xnu_devprop_device_descriptor * - grub_uint16_t *utf16; - grub_err_t err; - -- utf16 = grub_malloc (sizeof (grub_uint16_t) * namelen); -+ utf16 = grub_calloc (namelen, sizeof (grub_uint16_t)); - if (!utf16) - return grub_errno; - grub_memcpy (utf16, name, sizeof (grub_uint16_t) * namelen); -diff --git a/grub-core/loader/macho.c b/grub-core/loader/macho.c -index 085f9c6..05710c4 100644 ---- a/grub-core/loader/macho.c -+++ b/grub-core/loader/macho.c -@@ -97,7 +97,7 @@ grub_macho_file (grub_file_t file, const char *filename, int is_64bit) - if (grub_file_seek (macho->file, sizeof (struct grub_macho_fat_header)) - == (grub_off_t) -1) - goto fail; -- archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs); -+ archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch)); - if (!archs) - goto fail; - if (grub_file_read (macho->file, archs, -diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c -index 70cd1db..cc68536 100644 ---- a/grub-core/loader/multiboot_elfxx.c -+++ b/grub-core/loader/multiboot_elfxx.c -@@ -217,7 +217,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) - { - grub_uint8_t *shdr, *shdrptr; - -- shdr = grub_malloc ((grub_uint32_t) ehdr->e_shnum * ehdr->e_shentsize); -+ shdr = grub_calloc (ehdr->e_shnum, ehdr->e_shentsize); - if (!shdr) - return grub_errno; - -diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c -index e0f47e7..2f0ebd0 100644 ---- a/grub-core/loader/xnu.c -+++ b/grub-core/loader/xnu.c -@@ -801,7 +801,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)), - if (grub_be_to_cpu32 (head.magic) == GRUB_MACHO_FAT_MAGIC) - { - narchs = grub_be_to_cpu32 (head.nfat_arch); -- archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs); -+ archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch)); - if (! archs) - { - grub_file_close (file); -diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c -index b569cb2..64684c2 100644 ---- a/grub-core/mmap/mmap.c -+++ b/grub-core/mmap/mmap.c -@@ -143,9 +143,9 @@ grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data) - - /* Initialize variables. */ - ctx.scanline_events = (struct grub_mmap_scan *) -- grub_malloc (sizeof (struct grub_mmap_scan) * 2 * mmap_num); -+ grub_calloc (mmap_num, sizeof (struct grub_mmap_scan) * 2); - -- present = grub_zalloc (sizeof (present[0]) * current_priority); -+ present = grub_calloc (current_priority, sizeof (present[0])); - - if (! ctx.scanline_events || !present) - { -diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index 2e46842..5a5ebbf 100644 ---- a/grub-core/net/bootp.c -+++ b/grub-core/net/bootp.c -@@ -1629,7 +1629,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), - if (ncards == 0) - return grub_error (GRUB_ERR_NET_NO_CARD, N_("no network card found")); - -- ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); -+ ifaces = grub_calloc (ncards, sizeof (ifaces[0])); - if (!ifaces) - return grub_errno; - -diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c -index 5d9afe0..e332d5e 100644 ---- a/grub-core/net/dns.c -+++ b/grub-core/net/dns.c -@@ -285,8 +285,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), - ptr++; - ptr += 4; - } -- *data->addresses = grub_malloc (sizeof ((*data->addresses)[0]) -- * grub_be_to_cpu16 (head->ancount)); -+ *data->addresses = grub_calloc (grub_be_to_cpu16 (head->ancount), -+ sizeof ((*data->addresses)[0])); - if (!*data->addresses) - { - grub_errno = GRUB_ERR_NONE; -@@ -406,8 +406,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), - dns_cache[h].addresses = 0; - dns_cache[h].name = grub_strdup (data->oname); - dns_cache[h].naddresses = *data->naddresses; -- dns_cache[h].addresses = grub_malloc (*data->naddresses -- * sizeof (dns_cache[h].addresses[0])); -+ dns_cache[h].addresses = grub_calloc (*data->naddresses, -+ sizeof (dns_cache[h].addresses[0])); - dns_cache[h].limit_time = grub_get_time_ms () + 1000 * ttl_all; - if (!dns_cache[h].addresses || !dns_cache[h].name) - { -@@ -479,7 +479,7 @@ grub_net_dns_lookup (const char *name, - } - } - -- sockets = grub_malloc (sizeof (sockets[0]) * n_servers); -+ sockets = grub_calloc (n_servers, sizeof (sockets[0])); - if (!sockets) - return grub_errno; - -diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index 15073dd..ad024c9 100644 ---- a/grub-core/net/net.c -+++ b/grub-core/net/net.c -@@ -338,8 +338,8 @@ grub_cmd_ipv6_autoconf (struct grub_command *cmd __attribute__ ((unused)), - ncards++; - } - -- ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); -- slaacs = grub_zalloc (ncards * sizeof (slaacs[0])); -+ ifaces = grub_calloc (ncards, sizeof (ifaces[0])); -+ slaacs = grub_calloc (ncards, sizeof (slaacs[0])); - if (!ifaces || !slaacs) - { - grub_free (ifaces); -diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c -index b0ab47d..d57fb72 100644 ---- a/grub-core/normal/charset.c -+++ b/grub-core/normal/charset.c -@@ -203,7 +203,7 @@ grub_utf8_to_ucs4_alloc (const char *msg, grub_uint32_t **unicode_msg, - { - grub_size_t msg_len = grub_strlen (msg); - -- *unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); -+ *unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); - - if (!*unicode_msg) - return -1; -@@ -488,7 +488,7 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen, - } - else - { -- n = grub_malloc (sizeof (n[0]) * (out->ncomb + 1)); -+ n = grub_calloc (out->ncomb + 1, sizeof (n[0])); - if (!n) - { - grub_errno = GRUB_ERR_NONE; -@@ -842,7 +842,7 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t *logical, - } \ - } - -- visual = grub_malloc (sizeof (visual[0]) * logical_len); -+ visual = grub_calloc (logical_len, sizeof (visual[0])); - if (!visual) - return -1; - -@@ -1165,8 +1165,8 @@ grub_bidi_logical_to_visual (const grub_uint32_t *logical, - { - const grub_uint32_t *line_start = logical, *ptr; - struct grub_unicode_glyph *visual_ptr; -- *visual_out = visual_ptr = grub_malloc (3 * sizeof (visual_ptr[0]) -- * (logical_len + 2)); -+ *visual_out = visual_ptr = grub_calloc (logical_len + 2, -+ 3 * sizeof (visual_ptr[0])); - if (!visual_ptr) - return -1; - for (ptr = logical; ptr <= logical + logical_len; ptr++) -diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c -index c037d50..c57242e 100644 ---- a/grub-core/normal/cmdline.c -+++ b/grub-core/normal/cmdline.c -@@ -41,7 +41,7 @@ grub_err_t - grub_set_history (int newsize) - { - grub_uint32_t **old_hist_lines = hist_lines; -- hist_lines = grub_malloc (sizeof (grub_uint32_t *) * newsize); -+ hist_lines = grub_calloc (newsize, sizeof (grub_uint32_t *)); - - /* Copy the old lines into the new buffer. */ - if (old_hist_lines) -@@ -114,7 +114,7 @@ static void - grub_history_set (int pos, grub_uint32_t *s, grub_size_t len) - { - grub_free (hist_lines[pos]); -- hist_lines[pos] = grub_malloc ((len + 1) * sizeof (grub_uint32_t)); -+ hist_lines[pos] = grub_calloc (len + 1, sizeof (grub_uint32_t)); - if (!hist_lines[pos]) - { - grub_print_error (); -@@ -349,7 +349,7 @@ grub_cmdline_get (const char *prompt_translated) - char *ret; - unsigned nterms; - -- buf = grub_malloc (max_len * sizeof (grub_uint32_t)); -+ buf = grub_calloc (max_len, sizeof (grub_uint32_t)); - if (!buf) - return 0; - -@@ -377,7 +377,7 @@ grub_cmdline_get (const char *prompt_translated) - FOR_ACTIVE_TERM_OUTPUTS(cur) - nterms++; - -- cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms); -+ cl_terms = grub_calloc (nterms, sizeof (cl_terms[0])); - if (!cl_terms) - { - grub_free (buf); -@@ -385,7 +385,7 @@ grub_cmdline_get (const char *prompt_translated) - } - cl_term_cur = cl_terms; - -- unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); -+ unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); - if (!unicode_msg) - { - grub_free (buf); -@@ -495,7 +495,7 @@ grub_cmdline_get (const char *prompt_translated) - grub_uint32_t *insert; - - insertlen = grub_strlen (insertu8); -- insert = grub_malloc ((insertlen + 1) * sizeof (grub_uint32_t)); -+ insert = grub_calloc (insertlen + 1, sizeof (grub_uint32_t)); - if (!insert) - { - grub_free (insertu8); -@@ -602,7 +602,7 @@ grub_cmdline_get (const char *prompt_translated) - - grub_free (kill_buf); - -- kill_buf = grub_malloc ((n + 1) * sizeof(grub_uint32_t)); -+ kill_buf = grub_calloc (n + 1, sizeof (grub_uint32_t)); - if (grub_errno) - { - grub_print_error (); -diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c -index 5785f67..f31487c 100644 ---- a/grub-core/normal/menu_entry.c -+++ b/grub-core/normal/menu_entry.c -@@ -95,8 +95,8 @@ init_line (struct screen *screen, struct line *linep) - { - linep->len = 0; - linep->max_len = 80; -- linep->buf = grub_malloc ((linep->max_len + 1) * sizeof (linep->buf[0])); -- linep->pos = grub_zalloc (screen->nterms * sizeof (linep->pos[0])); -+ linep->buf = grub_calloc (linep->max_len + 1, sizeof (linep->buf[0])); -+ linep->pos = grub_calloc (screen->nterms, sizeof (linep->pos[0])); - if (! linep->buf || !linep->pos) - { - grub_free (linep->buf); -@@ -287,7 +287,7 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen, - pos = linep->pos + (term_screen - screen->terms); - - if (!*pos) -- *pos = grub_zalloc ((linep->len + 1) * sizeof (**pos)); -+ *pos = grub_calloc (linep->len + 1, sizeof (**pos)); - - if (i == region_start || linep == screen->lines + screen->line - || (i > region_start && mode == ALL_LINES)) -@@ -471,7 +471,7 @@ insert_string (struct screen *screen, const char *s, int update) - - /* Insert the string. */ - current_linep = screen->lines + screen->line; -- unicode_msg = grub_malloc ((p - s) * sizeof (grub_uint32_t)); -+ unicode_msg = grub_calloc (p - s, sizeof (grub_uint32_t)); - - if (!unicode_msg) - return 0; -@@ -1023,7 +1023,7 @@ complete (struct screen *screen, int continuous, int update) - if (completion_buffer.buf) - { - buflen = grub_strlen (completion_buffer.buf); -- ucs4 = grub_malloc (sizeof (grub_uint32_t) * (buflen + 1)); -+ ucs4 = grub_calloc (buflen + 1, sizeof (grub_uint32_t)); - - if (!ucs4) - { -@@ -1265,7 +1265,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) - for (i = 0; i < (unsigned) screen->num_lines; i++) - { - grub_free (screen->lines[i].pos); -- screen->lines[i].pos = grub_zalloc (screen->nterms * sizeof (screen->lines[i].pos[0])); -+ screen->lines[i].pos = grub_calloc (screen->nterms, sizeof (screen->lines[i].pos[0])); - if (! screen->lines[i].pos) - { - grub_print_error (); -@@ -1275,7 +1275,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) - } - } - -- screen->terms = grub_zalloc (screen->nterms * sizeof (screen->terms[0])); -+ screen->terms = grub_calloc (screen->nterms, sizeof (screen->terms[0])); - if (!screen->terms) - { - grub_print_error (); -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index 7681f7d..ca13562 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -78,7 +78,7 @@ grub_print_message_indented_real (const char *msg, int margin_left, - grub_size_t msg_len = grub_strlen (msg) + 2; - int ret = 0; - -- unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); -+ unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); - - if (!unicode_msg) - return 0; -@@ -167,7 +167,7 @@ print_entry (int y, int highlight, grub_menu_entry_t entry, - - title = entry ? entry->title : ""; - title_len = grub_strlen (title); -- unicode_title = grub_malloc (title_len * sizeof (*unicode_title)); -+ unicode_title = grub_calloc (title_len, sizeof (*unicode_title)); - if (! unicode_title) - /* XXX How to show this error? */ - return; -diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c -index a1e5c5a..cc8c173 100644 ---- a/grub-core/normal/term.c -+++ b/grub-core/normal/term.c -@@ -264,7 +264,7 @@ grub_term_save_pos (void) - FOR_ACTIVE_TERM_OUTPUTS(cur) - cnt++; - -- ret = grub_malloc (cnt * sizeof (ret[0])); -+ ret = grub_calloc (cnt, sizeof (ret[0])); - if (!ret) - return NULL; - -@@ -1013,7 +1013,7 @@ grub_xnputs (const char *str, grub_size_t msg_len) - - grub_error_push (); - -- unicode_str = grub_malloc (msg_len * sizeof (grub_uint32_t)); -+ unicode_str = grub_calloc (msg_len, sizeof (grub_uint32_t)); - - grub_error_pop (); - -diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c -index 36429a7..f0c503f 100644 ---- a/grub-core/osdep/linux/getroot.c -+++ b/grub-core/osdep/linux/getroot.c -@@ -176,7 +176,7 @@ grub_util_raid_getmembers (const char *name, int bootable) - if (ret != 0) - grub_util_error (_("ioctl GET_ARRAY_INFO error: %s"), strerror (errno)); - -- devicelist = xmalloc ((info.nr_disks + 1) * sizeof (char *)); -+ devicelist = xcalloc (info.nr_disks + 1, sizeof (char *)); - - for (i = 0, j = 0; j < info.nr_disks; i++) - { -@@ -249,7 +249,7 @@ grub_find_root_devices_from_btrfs (const char *dir) - return NULL; - } - -- ret = xmalloc ((fsi.num_devices + 1) * sizeof (ret[0])); -+ ret = xcalloc (fsi.num_devices + 1, sizeof (ret[0])); - - for (i = 1; i <= fsi.max_id && j < fsi.num_devices; i++) - { -@@ -508,7 +508,7 @@ grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) - if (relroot) - *relroot = NULL; - -- entries = xmalloc (entry_max * sizeof (*entries)); -+ entries = xcalloc (entry_max, sizeof (*entries)); - - again: - fp = grub_util_fopen ("/proc/self/mountinfo", "r"); -diff --git a/grub-core/osdep/unix/config.c b/grub-core/osdep/unix/config.c -index b637c58..46a8815 100644 ---- a/grub-core/osdep/unix/config.c -+++ b/grub-core/osdep/unix/config.c -@@ -102,7 +102,7 @@ grub_util_load_config (struct grub_util_config *cfg) - argv[0] = "sh"; - argv[1] = "-c"; - -- script = xmalloc (4 * strlen (cfgfile) + 300); -+ script = xcalloc (4, strlen (cfgfile) + 300); - - ptr = script; - memcpy (ptr, ". '", 3); -diff --git a/grub-core/osdep/windows/getroot.c b/grub-core/osdep/windows/getroot.c -index 661d954..eada663 100644 ---- a/grub-core/osdep/windows/getroot.c -+++ b/grub-core/osdep/windows/getroot.c -@@ -59,7 +59,7 @@ grub_get_mount_point (const TCHAR *path) - - for (ptr = path; *ptr; ptr++); - allocsize = (ptr - path + 10) * 2; -- out = xmalloc (allocsize * sizeof (out[0])); -+ out = xcalloc (allocsize, sizeof (out[0])); - - /* When pointing to EFI system partition GetVolumePathName fails - for ESP root and returns abberant information for everything -diff --git a/grub-core/osdep/windows/hostdisk.c b/grub-core/osdep/windows/hostdisk.c -index 87a106c..29cf427 100644 ---- a/grub-core/osdep/windows/hostdisk.c -+++ b/grub-core/osdep/windows/hostdisk.c -@@ -111,7 +111,7 @@ grub_util_get_windows_path_real (const char *path) - - while (1) - { -- fpa = xmalloc (alloc * sizeof (fpa[0])); -+ fpa = xcalloc (alloc, sizeof (fpa[0])); - - len = GetFullPathName (tpath, alloc, fpa, NULL); - if (len >= alloc) -@@ -405,7 +405,7 @@ grub_util_fd_opendir (const char *name) - for (l = 0; name_windows[l]; l++); - for (l--; l >= 0 && (name_windows[l] == '\\' || name_windows[l] == '/'); l--); - l++; -- pattern = xmalloc ((l + 3) * sizeof (pattern[0])); -+ pattern = xcalloc (l + 3, sizeof (pattern[0])); - memcpy (pattern, name_windows, l * sizeof (pattern[0])); - pattern[l] = '\\'; - pattern[l + 1] = '*'; -diff --git a/grub-core/osdep/windows/init.c b/grub-core/osdep/windows/init.c -index e8ffd62..6297de6 100644 ---- a/grub-core/osdep/windows/init.c -+++ b/grub-core/osdep/windows/init.c -@@ -161,7 +161,7 @@ grub_util_host_init (int *argc __attribute__ ((unused)), - LPWSTR *targv; - - targv = CommandLineToArgvW (tcmdline, argc); -- *argv = xmalloc ((*argc + 1) * sizeof (argv[0])); -+ *argv = xcalloc (*argc + 1, sizeof (argv[0])); - - for (i = 0; i < *argc; i++) - (*argv)[i] = grub_util_tchar_to_utf8 (targv[i]); -diff --git a/grub-core/osdep/windows/platform.c b/grub-core/osdep/windows/platform.c -index 7eb53fe..1ef86bf 100644 ---- a/grub-core/osdep/windows/platform.c -+++ b/grub-core/osdep/windows/platform.c -@@ -225,8 +225,8 @@ grub_install_register_efi (grub_device_t efidir_grub_dev, - grub_util_error ("%s", _("no EFI routines are available when running in BIOS mode")); - - distrib8_len = grub_strlen (efi_distributor); -- distributor16 = xmalloc ((distrib8_len + 1) * GRUB_MAX_UTF16_PER_UTF8 -- * sizeof (grub_uint16_t)); -+ distributor16 = xcalloc (distrib8_len + 1, -+ GRUB_MAX_UTF16_PER_UTF8 * sizeof (grub_uint16_t)); - distrib16_len = grub_utf8_to_utf16 (distributor16, distrib8_len * GRUB_MAX_UTF16_PER_UTF8, - (const grub_uint8_t *) efi_distributor, - distrib8_len, 0); -diff --git a/grub-core/osdep/windows/relpath.c b/grub-core/osdep/windows/relpath.c -index cb08617..478e8ef 100644 ---- a/grub-core/osdep/windows/relpath.c -+++ b/grub-core/osdep/windows/relpath.c -@@ -72,7 +72,7 @@ grub_make_system_path_relative_to_its_root (const char *path) - if (dirwindows[0] && dirwindows[1] == ':') - offset = 2; - } -- ret = xmalloc (sizeof (ret[0]) * (flen - offset + 2)); -+ ret = xcalloc (flen - offset + 2, sizeof (ret[0])); - if (dirwindows[offset] != '\\' - && dirwindows[offset] != '/' - && dirwindows[offset]) -diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c -index 103f679..72a2e37 100644 ---- a/grub-core/partmap/gpt.c -+++ b/grub-core/partmap/gpt.c -@@ -199,7 +199,7 @@ gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, - *nsectors = ctx.len; - if (*nsectors > max_nsectors) - *nsectors = max_nsectors; -- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); -+ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); - if (!*sectors) - return grub_errno; - for (i = 0; i < *nsectors; i++) -diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c -index 7b8e450..ee3f249 100644 ---- a/grub-core/partmap/msdos.c -+++ b/grub-core/partmap/msdos.c -@@ -337,7 +337,7 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, - avail_nsectors = *nsectors; - if (*nsectors > max_nsectors) - *nsectors = max_nsectors; -- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); -+ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); - if (!*sectors) - return grub_errno; - for (i = 0; i < *nsectors; i++) -diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c -index c6d2c36..b55e171 100644 ---- a/grub-core/script/execute.c -+++ b/grub-core/script/execute.c -@@ -587,7 +587,7 @@ gettext_append (struct grub_script_argv *result, const char *orig_str) - for (iptr = orig_str; *iptr; iptr++) - if (*iptr == '$') - dollar_cnt++; -- ctx.allowed_strings = grub_malloc (sizeof (ctx.allowed_strings[0]) * dollar_cnt); -+ ctx.allowed_strings = grub_calloc (dollar_cnt, sizeof (ctx.allowed_strings[0])); - - if (parse_string (orig_str, gettext_save_allow, &ctx, 0)) - goto fail; -diff --git a/grub-core/tests/fake_input.c b/grub-core/tests/fake_input.c -index 2d60852..b5eb516 100644 ---- a/grub-core/tests/fake_input.c -+++ b/grub-core/tests/fake_input.c -@@ -49,7 +49,7 @@ grub_terminal_input_fake_sequence (int *seq_in, int nseq_in) - saved = grub_term_inputs; - if (seq) - grub_free (seq); -- seq = grub_malloc (nseq_in * sizeof (seq[0])); -+ seq = grub_calloc (nseq_in, sizeof (seq[0])); - if (!seq) - return; - -diff --git a/grub-core/tests/video_checksum.c b/grub-core/tests/video_checksum.c -index 74d5b65..44d0810 100644 ---- a/grub-core/tests/video_checksum.c -+++ b/grub-core/tests/video_checksum.c -@@ -336,7 +336,7 @@ grub_video_capture_write_bmp (const char *fname, - { - case 4: - { -- grub_uint8_t *buffer = xmalloc (mode_info->width * 3); -+ grub_uint8_t *buffer = xcalloc (3, mode_info->width); - grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1); - grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1); - grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1); -@@ -367,7 +367,7 @@ grub_video_capture_write_bmp (const char *fname, - } - case 3: - { -- grub_uint8_t *buffer = xmalloc (mode_info->width * 3); -+ grub_uint8_t *buffer = xcalloc (3, mode_info->width); - grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1); - grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1); - grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1); -@@ -407,7 +407,7 @@ grub_video_capture_write_bmp (const char *fname, - } - case 2: - { -- grub_uint8_t *buffer = xmalloc (mode_info->width * 3); -+ grub_uint8_t *buffer = xcalloc (3, mode_info->width); - grub_uint16_t rmask = ((1 << mode_info->red_mask_size) - 1); - grub_uint16_t gmask = ((1 << mode_info->green_mask_size) - 1); - grub_uint16_t bmask = ((1 << mode_info->blue_mask_size) - 1); -diff --git a/grub-core/video/capture.c b/grub-core/video/capture.c -index 4f83c74..4d3195e 100644 ---- a/grub-core/video/capture.c -+++ b/grub-core/video/capture.c -@@ -89,7 +89,7 @@ grub_video_capture_start (const struct grub_video_mode_info *mode_info, - framebuffer.mode_info = *mode_info; - framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info); - -- framebuffer.ptr = grub_malloc (framebuffer.mode_info.height * framebuffer.mode_info.pitch); -+ framebuffer.ptr = grub_calloc (framebuffer.mode_info.height, framebuffer.mode_info.pitch); - if (!framebuffer.ptr) - return grub_errno; - -diff --git a/grub-core/video/emu/sdl.c b/grub-core/video/emu/sdl.c -index a2f639f..0ebab6f 100644 ---- a/grub-core/video/emu/sdl.c -+++ b/grub-core/video/emu/sdl.c -@@ -172,7 +172,7 @@ grub_video_sdl_set_palette (unsigned int start, unsigned int count, - if (start + count > mode_info.number_of_colors) - count = mode_info.number_of_colors - start; - -- tmp = grub_malloc (count * sizeof (tmp[0])); -+ tmp = grub_calloc (count, sizeof (tmp[0])); - for (i = 0; i < count; i++) - { - tmp[i].r = palette_data[i].r; -diff --git a/grub-core/video/i386/pc/vga.c b/grub-core/video/i386/pc/vga.c -index 01f4711..b2f776c 100644 ---- a/grub-core/video/i386/pc/vga.c -+++ b/grub-core/video/i386/pc/vga.c -@@ -127,7 +127,7 @@ grub_video_vga_setup (unsigned int width, unsigned int height, - - vga_height = height ? : 480; - -- framebuffer.temporary_buffer = grub_malloc (vga_height * VGA_WIDTH); -+ framebuffer.temporary_buffer = grub_calloc (vga_height, VGA_WIDTH); - framebuffer.front_page = 0; - framebuffer.back_page = 0; - if (!framebuffer.temporary_buffer) -diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c -index 777e713..61bd645 100644 ---- a/grub-core/video/readers/png.c -+++ b/grub-core/video/readers/png.c -@@ -309,7 +309,7 @@ grub_png_decode_image_header (struct grub_png_data *data) - if (data->is_16bit || data->is_gray || data->is_palette) - #endif - { -- data->image_data = grub_malloc (data->image_height * data->row_bytes); -+ data->image_data = grub_calloc (data->image_height, data->row_bytes); - if (grub_errno) - return grub_errno; - -diff --git a/include/grub/unicode.h b/include/grub/unicode.h -index a0403e9..4de986a 100644 ---- a/include/grub/unicode.h -+++ b/include/grub/unicode.h -@@ -293,7 +293,7 @@ grub_unicode_glyph_dup (const struct grub_unicode_glyph *in) - grub_memcpy (out, in, sizeof (*in)); - if (in->ncomb > ARRAY_SIZE (out->combining_inline)) - { -- out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0])); -+ out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0])); - if (!out->combining_ptr) - { - grub_free (out); -@@ -315,7 +315,7 @@ grub_unicode_set_glyph (struct grub_unicode_glyph *out, - grub_memcpy (out, in, sizeof (*in)); - if (in->ncomb > ARRAY_SIZE (out->combining_inline)) - { -- out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0])); -+ out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0])); - if (!out->combining_ptr) - return; - grub_memcpy (out->combining_ptr, in->combining_ptr, -diff --git a/util/getroot.c b/util/getroot.c -index fa3460d..6feb2a4 100644 ---- a/util/getroot.c -+++ b/util/getroot.c -@@ -219,7 +219,7 @@ make_device_name (const char *drive) - char *ret, *ptr; - const char *iptr; - -- ret = xmalloc (strlen (drive) * 2); -+ ret = xcalloc (2, strlen (drive)); - ptr = ret; - for (iptr = drive; *iptr; iptr++) - { -diff --git a/util/grub-file.c b/util/grub-file.c -index 50c18b6..b2e7dd6 100644 ---- a/util/grub-file.c -+++ b/util/grub-file.c -@@ -54,7 +54,7 @@ main (int argc, char *argv[]) - - grub_util_host_init (&argc, &argv); - -- argv2 = xmalloc (argc * sizeof (argv2[0])); -+ argv2 = xcalloc (argc, sizeof (argv2[0])); - - if (argc == 2 && strcmp (argv[1], "--version") == 0) - { -diff --git a/util/grub-fstest.c b/util/grub-fstest.c -index 39bad1f..bfcef85 100644 ---- a/util/grub-fstest.c -+++ b/util/grub-fstest.c -@@ -650,7 +650,7 @@ argp_parser (int key, char *arg, struct argp_state *state) - if (args_count < num_disks) - { - if (args_count == 0) -- images = xmalloc (num_disks * sizeof (images[0])); -+ images = xcalloc (num_disks, sizeof (images[0])); - images[args_count] = grub_canonicalize_file_name (arg); - args_count++; - return 0; -@@ -734,7 +734,7 @@ main (int argc, char *argv[]) - - grub_util_host_init (&argc, &argv); - -- args = xmalloc (argc * sizeof (args[0])); -+ args = xcalloc (argc, sizeof (args[0])); - - argp_parse (&argp, argc, argv, 0, 0, 0); - -diff --git a/util/grub-install-common.c b/util/grub-install-common.c -index ca0ac61..0295d40 100644 ---- a/util/grub-install-common.c -+++ b/util/grub-install-common.c -@@ -286,7 +286,7 @@ handle_install_list (struct install_list *il, const char *val, - il->n_entries++; - } - il->n_alloc = il->n_entries + 1; -- il->entries = xmalloc (il->n_alloc * sizeof (il->entries[0])); -+ il->entries = xcalloc (il->n_alloc, sizeof (il->entries[0])); - ptr = val; - for (ce = il->entries; ; ce++) - { -diff --git a/util/grub-install.c b/util/grub-install.c -index 8b6a037..dddb757 100644 ---- a/util/grub-install.c -+++ b/util/grub-install.c -@@ -634,7 +634,7 @@ device_map_check_duplicates (const char *dev_map) - if (! fp) - return; - -- d = xmalloc (alloced * sizeof (d[0])); -+ d = xcalloc (alloced, sizeof (d[0])); - - while (fgets (buf, sizeof (buf), fp)) - { -@@ -1263,7 +1263,7 @@ main (int argc, char *argv[]) - ndev++; - } - -- grub_drives = xmalloc (sizeof (grub_drives[0]) * (ndev + 1)); -+ grub_drives = xcalloc (ndev + 1, sizeof (grub_drives[0])); - - for (curdev = grub_devices, curdrive = grub_drives; *curdev; curdev++, - curdrive++) -diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c -index d16ec63..52bc9c8 100644 ---- a/util/grub-mkimagexx.c -+++ b/util/grub-mkimagexx.c -@@ -2294,10 +2294,8 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path, - + grub_host_to_target16 (e->e_shstrndx) * smd.section_entsize); - smd.strtab = (char *) e + grub_host_to_target_addr (s->sh_offset); - -- smd.addrs = xmalloc (sizeof (*smd.addrs) * smd.num_sections); -- memset (smd.addrs, 0, sizeof (*smd.addrs) * smd.num_sections); -- smd.vaddrs = xmalloc (sizeof (*smd.vaddrs) * smd.num_sections); -- memset (smd.vaddrs, 0, sizeof (*smd.vaddrs) * smd.num_sections); -+ smd.addrs = xcalloc (smd.num_sections, sizeof (*smd.addrs)); -+ smd.vaddrs = xcalloc (smd.num_sections, sizeof (*smd.vaddrs)); - - SUFFIX (locate_sections) (e, kernel_path, &smd, layout, image_target); - -diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c -index ce2cbc4..5183102 100644 ---- a/util/grub-mkrescue.c -+++ b/util/grub-mkrescue.c -@@ -441,8 +441,8 @@ main (int argc, char *argv[]) - xorriso = xstrdup ("xorriso"); - label_font = grub_util_path_concat (2, pkgdatadir, "unicode.pf2"); - -- argp_argv = xmalloc (sizeof (argp_argv[0]) * argc); -- xorriso_tail_argv = xmalloc (sizeof (argp_argv[0]) * argc); -+ argp_argv = xcalloc (argc, sizeof (argp_argv[0])); -+ xorriso_tail_argv = xcalloc (argc, sizeof (argp_argv[0])); - - xorriso_tail_argc = 0; - /* Program name */ -diff --git a/util/grub-mkstandalone.c b/util/grub-mkstandalone.c -index 4907d44..edf3097 100644 ---- a/util/grub-mkstandalone.c -+++ b/util/grub-mkstandalone.c -@@ -296,7 +296,7 @@ main (int argc, char *argv[]) - grub_util_host_init (&argc, &argv); - grub_util_disable_fd_syncs (); - -- files = xmalloc ((argc + 1) * sizeof (files[0])); -+ files = xcalloc (argc + 1, sizeof (files[0])); - - argp_parse (&argp, argc, argv, 0, 0, 0); - -diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c -index 0d4084a..1133129 100644 ---- a/util/grub-pe2elf.c -+++ b/util/grub-pe2elf.c -@@ -100,9 +100,9 @@ write_section_data (FILE* fp, const char *name, char *image, - char *pe_strtab = (image + pe_chdr->symtab_offset - + pe_chdr->num_symbols * sizeof (struct grub_pe32_symbol)); - -- section_map = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (int)); -+ section_map = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (int)); - section_map[0] = 0; -- shdr = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (shdr[0])); -+ shdr = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (shdr[0])); - idx = 1; - idx_reloc = pe_chdr->num_sections + 1; - -@@ -233,7 +233,7 @@ write_reloc_section (FILE* fp, const char *name, char *image, - - pe_sec = pe_shdr + shdr[i].sh_link; - pe_rel = (struct grub_pe32_reloc *) (image + pe_sec->relocations_offset); -- rel = (elf_reloc_t *) xmalloc (pe_sec->num_relocations * sizeof (elf_reloc_t)); -+ rel = (elf_reloc_t *) xcalloc (pe_sec->num_relocations, sizeof (elf_reloc_t)); - num_rels = 0; - modified = 0; - -@@ -365,12 +365,10 @@ write_symbol_table (FILE* fp, const char *name, char *image, - pe_symtab = (struct grub_pe32_symbol *) (image + pe_chdr->symtab_offset); - pe_strtab = (char *) (pe_symtab + pe_chdr->num_symbols); - -- symtab = (Elf_Sym *) xmalloc ((pe_chdr->num_symbols + 1) * -- sizeof (Elf_Sym)); -- memset (symtab, 0, (pe_chdr->num_symbols + 1) * sizeof (Elf_Sym)); -+ symtab = (Elf_Sym *) xcalloc (pe_chdr->num_symbols + 1, sizeof (Elf_Sym)); - num_syms = 1; - -- symtab_map = (int *) xmalloc (pe_chdr->num_symbols * sizeof (int)); -+ symtab_map = (int *) xcalloc (pe_chdr->num_symbols, sizeof (int)); - - for (i = 0; i < (int) pe_chdr->num_symbols; - i += pe_symtab->num_aux + 1, pe_symtab += pe_symtab->num_aux + 1) -diff --git a/util/grub-probe.c b/util/grub-probe.c -index 7481e48..cf4291c 100644 ---- a/util/grub-probe.c -+++ b/util/grub-probe.c -@@ -361,8 +361,8 @@ probe (const char *path, char **device_names, char delim) - grub_util_pull_device (*curdev); - ndev++; - } -- -- drives_names = xmalloc (sizeof (drives_names[0]) * (ndev + 1)); -+ -+ drives_names = xcalloc (ndev + 1, sizeof (drives_names[0])); - - for (curdev = device_names, curdrive = drives_names; *curdev; curdev++, - curdrive++) --- -2.23.0 - diff --git a/0225-malloc-Use-overflow-checking-primitives-where-we-do-.patch b/0225-malloc-Use-overflow-checking-primitives-where-we-do-.patch deleted file mode 100644 index 3f6f47f3eba87ff7b8fd6cbc331a3ed1658869de..0000000000000000000000000000000000000000 --- a/0225-malloc-Use-overflow-checking-primitives-where-we-do-.patch +++ /dev/null @@ -1,1322 +0,0 @@ -From 3f05d693d1274965ffbe4ba99080dc2c570944c6 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 15 Jun 2020 12:28:27 -0400 -Subject: [PATCH 05/27] malloc: Use overflow checking primitives where we do - complex allocations - -This attempts to fix the places where we do the following where -arithmetic_expr may include unvalidated data: - - X = grub_malloc(arithmetic_expr); - -It accomplishes this by doing the arithmetic ahead of time using grub_add(), -grub_sub(), grub_mul() and testing for overflow before proceeding. - -Among other issues, this fixes: - - allocation of integer overflow in grub_video_bitmap_create() - reported by Chris Coulson, - - allocation of integer overflow in grub_png_decode_image_header() - reported by Chris Coulson, - - allocation of integer overflow in grub_squash_read_symlink() - reported by Chris Coulson, - - allocation of integer overflow in grub_ext2_read_symlink() - reported by Chris Coulson, - - allocation of integer overflow in read_section_as_string() - reported by Chris Coulson. - -Fixes: CVE-2020-14309, CVE-2020-14310, CVE-2020-14311 - -Signed-off-by: Peter Jones -Reviewed-by: Daniel Kiper ---- - grub-core/commands/legacycfg.c | 29 +++++++++++++++---- - grub-core/commands/wildcard.c | 36 ++++++++++++++++++++---- - grub-core/disk/ldm.c | 32 +++++++++++++++------ - grub-core/font/font.c | 7 ++++- - grub-core/fs/btrfs.c | 28 +++++++++++++------ - grub-core/fs/ext2.c | 10 ++++++- - grub-core/fs/iso9660.c | 51 ++++++++++++++++++++++++---------- - grub-core/fs/sfs.c | 27 ++++++++++++++---- - grub-core/fs/squash4.c | 45 ++++++++++++++++++++++-------- - grub-core/fs/udf.c | 41 +++++++++++++++++---------- - grub-core/fs/xfs.c | 11 +++++--- - grub-core/fs/zfs/zfs.c | 22 ++++++++++----- - grub-core/fs/zfs/zfscrypt.c | 7 ++++- - grub-core/lib/arg.c | 20 +++++++++++-- - grub-core/loader/i386/bsd.c | 8 +++++- - grub-core/net/dns.c | 9 +++++- - grub-core/normal/charset.c | 10 +++++-- - grub-core/normal/cmdline.c | 14 ++++++++-- - grub-core/normal/menu_entry.c | 13 +++++++-- - grub-core/script/argv.c | 16 +++++++++-- - grub-core/script/lexer.c | 21 ++++++++++++-- - grub-core/video/bitmap.c | 25 +++++++++++------ - grub-core/video/readers/png.c | 13 +++++++-- - 23 files changed, 382 insertions(+), 113 deletions(-) - -diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c -index da5143d..782761c 100644 ---- a/grub-core/commands/legacycfg.c -+++ b/grub-core/commands/legacycfg.c -@@ -32,6 +32,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -104,13 +105,22 @@ legacy_file (const char *filename) - if (newsuffix) - { - char *t; -- -+ grub_size_t sz; -+ -+ if (grub_add (grub_strlen (suffix), grub_strlen (newsuffix), &sz) || -+ grub_add (sz, 1, &sz)) -+ { -+ grub_errno = GRUB_ERR_OUT_OF_RANGE; -+ goto fail_0; -+ } -+ - t = suffix; -- suffix = grub_realloc (suffix, grub_strlen (suffix) -- + grub_strlen (newsuffix) + 1); -+ suffix = grub_realloc (suffix, sz); - if (!suffix) - { - grub_free (t); -+ -+ fail_0: - grub_free (entrysrc); - grub_free (parsed); - grub_free (newsuffix); -@@ -154,13 +164,22 @@ legacy_file (const char *filename) - else - { - char *t; -+ grub_size_t sz; -+ -+ if (grub_add (grub_strlen (entrysrc), grub_strlen (parsed), &sz) || -+ grub_add (sz, 1, &sz)) -+ { -+ grub_errno = GRUB_ERR_OUT_OF_RANGE; -+ goto fail_1; -+ } - - t = entrysrc; -- entrysrc = grub_realloc (entrysrc, grub_strlen (entrysrc) -- + grub_strlen (parsed) + 1); -+ entrysrc = grub_realloc (entrysrc, sz); - if (!entrysrc) - { - grub_free (t); -+ -+ fail_1: - grub_free (parsed); - grub_free (suffix); - return grub_errno; -diff --git a/grub-core/commands/wildcard.c b/grub-core/commands/wildcard.c -index 560d437..8f67a4b 100644 ---- a/grub-core/commands/wildcard.c -+++ b/grub-core/commands/wildcard.c -@@ -23,6 +23,7 @@ - #include - #include - #include -+#include - - #include - -@@ -48,6 +49,7 @@ merge (char **dest, char **ps) - int i; - int j; - char **p; -+ grub_size_t sz; - - if (! dest) - return ps; -@@ -60,7 +62,12 @@ merge (char **dest, char **ps) - for (j = 0; ps[j]; j++) - ; - -- p = grub_realloc (dest, sizeof (char*) * (i + j + 1)); -+ if (grub_add (i, j, &sz) || -+ grub_add (sz, 1, &sz) || -+ grub_mul (sz, sizeof (char *), &sz)) -+ return dest; -+ -+ p = grub_realloc (dest, sz); - if (! p) - { - grub_free (dest); -@@ -115,8 +122,15 @@ make_regex (const char *start, const char *end, regex_t *regexp) - char ch; - int i = 0; - unsigned len = end - start; -- char *buffer = grub_malloc (len * 2 + 2 + 1); /* worst case size. */ -+ char *buffer; -+ grub_size_t sz; - -+ /* Worst case size is (len * 2 + 2 + 1). */ -+ if (grub_mul (len, 2, &sz) || -+ grub_add (sz, 3, &sz)) -+ return 1; -+ -+ buffer = grub_malloc (sz); - if (! buffer) - return 1; - -@@ -226,6 +240,7 @@ match_devices_iter (const char *name, void *data) - struct match_devices_ctx *ctx = data; - char **t; - char *buffer; -+ grub_size_t sz; - - /* skip partitions if asked to. */ - if (ctx->noparts && grub_strchr (name, ',')) -@@ -239,11 +254,16 @@ match_devices_iter (const char *name, void *data) - if (regexec (ctx->regexp, buffer, 0, 0, 0)) - { - grub_dprintf ("expand", "not matched\n"); -+ fail: - grub_free (buffer); - return 0; - } - -- t = grub_realloc (ctx->devs, sizeof (char*) * (ctx->ndev + 2)); -+ if (grub_add (ctx->ndev, 2, &sz) || -+ grub_mul (sz, sizeof (char *), &sz)) -+ goto fail; -+ -+ t = grub_realloc (ctx->devs, sz); - if (! t) - { - grub_free (buffer); -@@ -300,6 +320,7 @@ match_files_iter (const char *name, - struct match_files_ctx *ctx = data; - char **t; - char *buffer; -+ grub_size_t sz; - - /* skip . and .. names */ - if (grub_strcmp(".", name) == 0 || grub_strcmp("..", name) == 0) -@@ -315,9 +336,14 @@ match_files_iter (const char *name, - if (! buffer) - return 1; - -- t = grub_realloc (ctx->files, sizeof (char*) * (ctx->nfile + 2)); -- if (! t) -+ if (grub_add (ctx->nfile, 2, &sz) || -+ grub_mul (sz, sizeof (char *), &sz)) -+ goto fail; -+ -+ t = grub_realloc (ctx->files, sz); -+ if (!t) - { -+ fail: - grub_free (buffer); - return 1; - } -diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c -index e632370..58f8a53 100644 ---- a/grub-core/disk/ldm.c -+++ b/grub-core/disk/ldm.c -@@ -25,6 +25,7 @@ - #include - #include - #include -+#include - - #ifdef GRUB_UTIL - #include -@@ -289,6 +290,7 @@ make_vg (grub_disk_t disk, - struct grub_ldm_vblk vblk[GRUB_DISK_SECTOR_SIZE - / sizeof (struct grub_ldm_vblk)]; - unsigned i; -+ grub_size_t sz; - err = grub_disk_read (disk, cursec, 0, - sizeof(vblk), &vblk); - if (err) -@@ -350,7 +352,13 @@ make_vg (grub_disk_t disk, - grub_free (lv); - goto fail2; - } -- lv->name = grub_malloc (*ptr + 1); -+ if (grub_add (*ptr, 1, &sz)) -+ { -+ grub_free (lv->internal_id); -+ grub_free (lv); -+ goto fail2; -+ } -+ lv->name = grub_malloc (sz); - if (!lv->name) - { - grub_free (lv->internal_id); -@@ -599,10 +607,13 @@ make_vg (grub_disk_t disk, - if (lv->segments->node_alloc == lv->segments->node_count) - { - void *t; -- lv->segments->node_alloc *= 2; -- t = grub_realloc (lv->segments->nodes, -- sizeof (*lv->segments->nodes) -- * lv->segments->node_alloc); -+ grub_size_t sz; -+ -+ if (grub_mul (lv->segments->node_alloc, 2, &lv->segments->node_alloc) || -+ grub_mul (lv->segments->node_alloc, sizeof (*lv->segments->nodes), &sz)) -+ goto fail2; -+ -+ t = grub_realloc (lv->segments->nodes, sz); - if (!t) - goto fail2; - lv->segments->nodes = t; -@@ -723,10 +734,13 @@ make_vg (grub_disk_t disk, - if (comp->segment_alloc == comp->segment_count) - { - void *t; -- comp->segment_alloc *= 2; -- t = grub_realloc (comp->segments, -- comp->segment_alloc -- * sizeof (*comp->segments)); -+ grub_size_t sz; -+ -+ if (grub_mul (comp->segment_alloc, 2, &comp->segment_alloc) || -+ grub_mul (comp->segment_alloc, sizeof (*comp->segments), &sz)) -+ goto fail2; -+ -+ t = grub_realloc (comp->segments, sz); - if (!t) - goto fail2; - comp->segments = t; -diff --git a/grub-core/font/font.c b/grub-core/font/font.c -index 8e118b3..5edb477 100644 ---- a/grub-core/font/font.c -+++ b/grub-core/font/font.c -@@ -30,6 +30,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -360,9 +361,13 @@ static char * - read_section_as_string (struct font_file_section *section) - { - char *str; -+ grub_size_t sz; - grub_ssize_t ret; - -- str = grub_malloc (section->length + 1); -+ if (grub_add (section->length, 1, &sz)) -+ return NULL; -+ -+ str = grub_malloc (sz); - if (!str) - return 0; - -diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index ba080fd..0d8c666 100644 ---- a/grub-core/fs/btrfs.c -+++ b/grub-core/fs/btrfs.c -@@ -44,6 +44,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -358,9 +359,13 @@ save_ref (struct grub_btrfs_leaf_descriptor *desc, - if (desc->allocated < desc->depth) - { - void *newdata; -- desc->allocated *= 2; -- newdata = grub_realloc (desc->data, sizeof (desc->data[0]) -- * desc->allocated); -+ grub_size_t sz; -+ -+ if (grub_mul (desc->allocated, 2, &desc->allocated) || -+ grub_mul (desc->allocated, sizeof (desc->data[0]), &sz)) -+ return GRUB_ERR_OUT_OF_RANGE; -+ -+ newdata = grub_realloc (desc->data, sz); - if (!newdata) - return grub_errno; - desc->data = newdata; -@@ -651,16 +656,21 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t id) - if (data->n_devices_attached > data->n_devices_allocated) - { - void *tmp; -- data->n_devices_allocated = 2 * data->n_devices_attached + 1; -- data->devices_attached -- = grub_realloc (tmp = data->devices_attached, -- data->n_devices_allocated -- * sizeof (data->devices_attached[0])); -+ grub_size_t sz; -+ -+ if (grub_mul (data->n_devices_attached, 2, &data->n_devices_allocated) || -+ grub_add (data->n_devices_allocated, 1, &data->n_devices_allocated) || -+ grub_mul (data->n_devices_allocated, sizeof (data->devices_attached[0]), &sz)) -+ goto fail; -+ -+ data->devices_attached = grub_realloc (tmp = data->devices_attached, sz); - if (!data->devices_attached) - { -+ data->devices_attached = tmp; -+ -+ fail: - if (ctx.dev_found) - grub_device_close (ctx.dev_found); -- data->devices_attached = tmp; - return NULL; - } - } -diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c -index 9b38980..ac33bcd 100644 ---- a/grub-core/fs/ext2.c -+++ b/grub-core/fs/ext2.c -@@ -46,6 +46,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -703,6 +704,7 @@ grub_ext2_read_symlink (grub_fshelp_node_t node) - { - char *symlink; - struct grub_fshelp_node *diro = node; -+ grub_size_t sz; - - if (! diro->inode_read) - { -@@ -717,7 +719,13 @@ grub_ext2_read_symlink (grub_fshelp_node_t node) - } - } - -- symlink = grub_malloc (grub_le_to_cpu32 (diro->inode.size) + 1); -+ if (grub_add (grub_le_to_cpu32 (diro->inode.size), 1, &sz)) -+ { -+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); -+ return NULL; -+ } -+ -+ symlink = grub_malloc (sz); - if (! symlink) - return 0; - -diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c -index 4f1b52a..7ba5b30 100644 ---- a/grub-core/fs/iso9660.c -+++ b/grub-core/fs/iso9660.c -@@ -28,6 +28,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -531,8 +532,13 @@ add_part (struct iterate_dir_ctx *ctx, - int len2) - { - int size = ctx->symlink ? grub_strlen (ctx->symlink) : 0; -+ grub_size_t sz; - -- ctx->symlink = grub_realloc (ctx->symlink, size + len2 + 1); -+ if (grub_add (size, len2, &sz) || -+ grub_add (sz, 1, &sz)) -+ return; -+ -+ ctx->symlink = grub_realloc (ctx->symlink, sz); - if (! ctx->symlink) - return; - -@@ -560,17 +566,24 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry, - { - grub_size_t off = 0, csize = 1; - char *old; -+ grub_size_t sz; -+ - csize = entry->len - 5; - old = ctx->filename; - if (ctx->filename_alloc) - { - off = grub_strlen (ctx->filename); -- ctx->filename = grub_realloc (ctx->filename, csize + off + 1); -+ if (grub_add (csize, off, &sz) || -+ grub_add (sz, 1, &sz)) -+ return GRUB_ERR_OUT_OF_RANGE; -+ ctx->filename = grub_realloc (ctx->filename, sz); - } - else - { - off = 0; -- ctx->filename = grub_zalloc (csize + 1); -+ if (grub_add (csize, 1, &sz)) -+ return GRUB_ERR_OUT_OF_RANGE; -+ ctx->filename = grub_zalloc (sz); - } - if (!ctx->filename) - { -@@ -776,14 +789,18 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, - if (node->have_dirents >= node->alloc_dirents) - { - struct grub_fshelp_node *new_node; -- node->alloc_dirents *= 2; -- new_node = grub_realloc (node, -- sizeof (struct grub_fshelp_node) -- + ((node->alloc_dirents -- - ARRAY_SIZE (node->dirents)) -- * sizeof (node->dirents[0]))); -+ grub_size_t sz; -+ -+ if (grub_mul (node->alloc_dirents, 2, &node->alloc_dirents) || -+ grub_sub (node->alloc_dirents, ARRAY_SIZE (node->dirents), &sz) || -+ grub_mul (sz, sizeof (node->dirents[0]), &sz) || -+ grub_add (sz, sizeof (struct grub_fshelp_node), &sz)) -+ goto fail_0; -+ -+ new_node = grub_realloc (node, sz); - if (!new_node) - { -+ fail_0: - if (ctx.filename_alloc) - grub_free (ctx.filename); - grub_free (node); -@@ -799,14 +816,18 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, - * sizeof (node->dirents[0]) < grub_strlen (ctx.symlink) + 1) - { - struct grub_fshelp_node *new_node; -- new_node = grub_realloc (node, -- sizeof (struct grub_fshelp_node) -- + ((node->alloc_dirents -- - ARRAY_SIZE (node->dirents)) -- * sizeof (node->dirents[0])) -- + grub_strlen (ctx.symlink) + 1); -+ grub_size_t sz; -+ -+ if (grub_sub (node->alloc_dirents, ARRAY_SIZE (node->dirents), &sz) || -+ grub_mul (sz, sizeof (node->dirents[0]), &sz) || -+ grub_add (sz, sizeof (struct grub_fshelp_node) + 1, &sz) || -+ grub_add (sz, grub_strlen (ctx.symlink), &sz)) -+ goto fail_1; -+ -+ new_node = grub_realloc (node, sz); - if (!new_node) - { -+ fail_1: - if (ctx.filename_alloc) - grub_free (ctx.filename); - grub_free (node); -diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c -index 90f7fb3..de2b107 100644 ---- a/grub-core/fs/sfs.c -+++ b/grub-core/fs/sfs.c -@@ -26,6 +26,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -307,10 +308,15 @@ grub_sfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) - if (node->cache && node->cache_size >= node->cache_allocated) - { - struct cache_entry *e = node->cache; -- e = grub_realloc (node->cache,node->cache_allocated * 2 -- * sizeof (e[0])); -+ grub_size_t sz; -+ -+ if (grub_mul (node->cache_allocated, 2 * sizeof (e[0]), &sz)) -+ goto fail; -+ -+ e = grub_realloc (node->cache, sz); - if (!e) - { -+ fail: - grub_errno = 0; - grub_free (node->cache); - node->cache = 0; -@@ -477,10 +483,16 @@ grub_sfs_create_node (struct grub_fshelp_node **node, - grub_size_t len = grub_strlen (name); - grub_uint8_t *name_u8; - int ret; -+ grub_size_t sz; -+ -+ if (grub_mul (len, GRUB_MAX_UTF8_PER_LATIN1, &sz) || -+ grub_add (sz, 1, &sz)) -+ return 1; -+ - *node = grub_malloc (sizeof (**node)); - if (!*node) - return 1; -- name_u8 = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); -+ name_u8 = grub_malloc (sz); - if (!name_u8) - { - grub_free (*node); -@@ -724,8 +736,13 @@ grub_sfs_label (grub_device_t device, char **label) - data = grub_sfs_mount (disk); - if (data) - { -- grub_size_t len = grub_strlen (data->label); -- *label = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); -+ grub_size_t sz, len = grub_strlen (data->label); -+ -+ if (grub_mul (len, GRUB_MAX_UTF8_PER_LATIN1, &sz) || -+ grub_add (sz, 1, &sz)) -+ return GRUB_ERR_OUT_OF_RANGE; -+ -+ *label = grub_malloc (sz); - if (*label) - *grub_latin1_to_utf8 ((grub_uint8_t *) *label, - (const grub_uint8_t *) data->label, -diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c -index 95d5c1e..7851238 100644 ---- a/grub-core/fs/squash4.c -+++ b/grub-core/fs/squash4.c -@@ -26,6 +26,7 @@ - #include - #include - #include -+#include - #include - - #include "xz.h" -@@ -459,7 +460,17 @@ grub_squash_read_symlink (grub_fshelp_node_t node) - { - char *ret; - grub_err_t err; -- ret = grub_malloc (grub_le_to_cpu32 (node->ino.symlink.namelen) + 1); -+ grub_size_t sz; -+ -+ if (grub_add (grub_le_to_cpu32 (node->ino.symlink.namelen), 1, &sz)) -+ { -+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); -+ return NULL; -+ } -+ -+ ret = grub_malloc (sz); -+ if (!ret) -+ return NULL; - - err = read_chunk (node->data, ret, - grub_le_to_cpu32 (node->ino.symlink.namelen), -@@ -506,11 +517,16 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, - - { - grub_fshelp_node_t node; -- node = grub_malloc (sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); -+ grub_size_t sz; -+ -+ if (grub_mul (dir->stsize, sizeof (dir->stack[0]), &sz) || -+ grub_add (sz, sizeof (*node), &sz)) -+ return 0; -+ -+ node = grub_malloc (sz); - if (!node) - return 0; -- grub_memcpy (node, dir, -- sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); -+ grub_memcpy (node, dir, sz); - if (hook (".", GRUB_FSHELP_DIR, node, hook_data)) - return 1; - -@@ -518,12 +534,15 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, - { - grub_err_t err; - -- node = grub_malloc (sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); -+ if (grub_mul (dir->stsize, sizeof (dir->stack[0]), &sz) || -+ grub_add (sz, sizeof (*node), &sz)) -+ return 0; -+ -+ node = grub_malloc (sz); - if (!node) - return 0; - -- grub_memcpy (node, dir, -- sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); -+ grub_memcpy (node, dir, sz); - - node->stsize--; - err = read_chunk (dir->data, &node->ino, sizeof (node->ino), -@@ -557,6 +576,7 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, - enum grub_fshelp_filetype filetype = GRUB_FSHELP_REG; - struct grub_squash_dirent di; - struct grub_squash_inode ino; -+ grub_size_t sz; - - err = read_chunk (dir->data, &di, sizeof (di), - grub_le_to_cpu64 (dir->data->sb.diroffset) -@@ -589,13 +609,16 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, - if (grub_le_to_cpu16 (di.type) == SQUASH_TYPE_SYMLINK) - filetype = GRUB_FSHELP_SYMLINK; - -- node = grub_malloc (sizeof (*node) -- + (dir->stsize + 1) * sizeof (dir->stack[0])); -+ if (grub_add (dir->stsize, 1, &sz) || -+ grub_mul (sz, sizeof (dir->stack[0]), &sz) || -+ grub_add (sz, sizeof (*node), &sz)) -+ return 0; -+ -+ node = grub_malloc (sz); - if (! node) - return 0; - -- grub_memcpy (node, dir, -- sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); -+ grub_memcpy (node, dir, sz - sizeof(dir->stack[0])); - - node->ino = ino; - node->stack[node->stsize].ino_chunk = grub_le_to_cpu32 (dh.ino_chunk); -diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c -index a837616..21ac7f4 100644 ---- a/grub-core/fs/udf.c -+++ b/grub-core/fs/udf.c -@@ -28,6 +28,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -890,9 +891,19 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) - utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2]; - } - if (!outbuf) -- outbuf = grub_malloc (utf16len * GRUB_MAX_UTF8_PER_UTF16 + 1); -+ { -+ grub_size_t size; -+ -+ if (grub_mul (utf16len, GRUB_MAX_UTF8_PER_UTF16, &size) || -+ grub_add (size, 1, &size)) -+ goto fail; -+ -+ outbuf = grub_malloc (size); -+ } - if (outbuf) - *grub_utf16_to_utf8 ((grub_uint8_t *) outbuf, utf16, utf16len) = '\0'; -+ -+ fail: - grub_free (utf16); - return outbuf; - } -@@ -1005,7 +1016,7 @@ grub_udf_read_symlink (grub_fshelp_node_t node) - grub_size_t sz = U64 (node->block.fe.file_size); - grub_uint8_t *raw; - const grub_uint8_t *ptr; -- char *out, *optr; -+ char *out = NULL, *optr; - - if (sz < 4) - return NULL; -@@ -1013,14 +1024,16 @@ grub_udf_read_symlink (grub_fshelp_node_t node) - if (!raw) - return NULL; - if (grub_udf_read_file (node, NULL, NULL, 0, sz, (char *) raw) < 0) -- { -- grub_free (raw); -- return NULL; -- } -+ goto fail_1; - -- out = grub_malloc (sz * 2 + 1); -+ if (grub_mul (sz, 2, &sz) || -+ grub_add (sz, 1, &sz)) -+ goto fail_0; -+ -+ out = grub_malloc (sz); - if (!out) - { -+ fail_0: - grub_free (raw); - return NULL; - } -@@ -1031,17 +1044,17 @@ grub_udf_read_symlink (grub_fshelp_node_t node) - { - grub_size_t s; - if ((grub_size_t) (ptr - raw + 4) > sz) -- goto fail; -+ goto fail_1; - if (!(ptr[2] == 0 && ptr[3] == 0)) -- goto fail; -+ goto fail_1; - s = 4 + ptr[1]; - if ((grub_size_t) (ptr - raw + s) > sz) -- goto fail; -+ goto fail_1; - switch (*ptr) - { - case 1: - if (ptr[1]) -- goto fail; -+ goto fail_1; - /* Fallthrough. */ - case 2: - /* in 4 bytes. out: 1 byte. */ -@@ -1066,11 +1079,11 @@ grub_udf_read_symlink (grub_fshelp_node_t node) - if (optr != out) - *optr++ = '/'; - if (!read_string (ptr + 4, s - 4, optr)) -- goto fail; -+ goto fail_1; - optr += grub_strlen (optr); - break; - default: -- goto fail; -+ goto fail_1; - } - ptr += s; - } -@@ -1078,7 +1091,7 @@ grub_udf_read_symlink (grub_fshelp_node_t node) - grub_free (raw); - return out; - -- fail: -+ fail_1: - grub_free (raw); - grub_free (out); - grub_error (GRUB_ERR_BAD_FS, "invalid symlink"); -diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c -index 96ffecb..ea65902 100644 ---- a/grub-core/fs/xfs.c -+++ b/grub-core/fs/xfs.c -@@ -25,6 +25,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -899,6 +900,7 @@ static struct grub_xfs_data * - grub_xfs_mount (grub_disk_t disk) - { - struct grub_xfs_data *data = 0; -+ grub_size_t sz; - - data = grub_zalloc (sizeof (struct grub_xfs_data)); - if (!data) -@@ -913,10 +915,11 @@ grub_xfs_mount (grub_disk_t disk) - if (!grub_xfs_sb_valid(data)) - goto fail; - -- data = grub_realloc (data, -- sizeof (struct grub_xfs_data) -- - sizeof (struct grub_xfs_inode) -- + grub_xfs_inode_size(data) + 1); -+ if (grub_add (grub_xfs_inode_size (data), -+ sizeof (struct grub_xfs_data) - sizeof (struct grub_xfs_inode) + 1, &sz)) -+ goto fail; -+ -+ data = grub_realloc (data, sz); - - if (! data) - goto fail; -diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c -index 381dde5..36d0373 100644 ---- a/grub-core/fs/zfs/zfs.c -+++ b/grub-core/fs/zfs/zfs.c -@@ -55,6 +55,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -773,11 +774,14 @@ fill_vdev_info (struct grub_zfs_data *data, - if (data->n_devices_attached > data->n_devices_allocated) - { - void *tmp; -- data->n_devices_allocated = 2 * data->n_devices_attached + 1; -- data->devices_attached -- = grub_realloc (tmp = data->devices_attached, -- data->n_devices_allocated -- * sizeof (data->devices_attached[0])); -+ grub_size_t sz; -+ -+ if (grub_mul (data->n_devices_attached, 2, &data->n_devices_allocated) || -+ grub_add (data->n_devices_allocated, 1, &data->n_devices_allocated) || -+ grub_mul (data->n_devices_allocated, sizeof (data->devices_attached[0]), &sz)) -+ return GRUB_ERR_OUT_OF_RANGE; -+ -+ data->devices_attached = grub_realloc (tmp = data->devices_attached, sz); - if (!data->devices_attached) - { - data->devices_attached = tmp; -@@ -3468,14 +3472,18 @@ grub_zfs_nvlist_lookup_nvlist (const char *nvlist, const char *name) - { - char *nvpair; - char *ret; -- grub_size_t size; -+ grub_size_t size, sz; - int found; - - found = nvlist_find_value (nvlist, name, DATA_TYPE_NVLIST, &nvpair, - &size, 0); - if (!found) - return 0; -- ret = grub_zalloc (size + 3 * sizeof (grub_uint32_t)); -+ -+ if (grub_add (size, 3 * sizeof (grub_uint32_t), &sz)) -+ return 0; -+ -+ ret = grub_zalloc (sz); - if (!ret) - return 0; - grub_memcpy (ret, nvlist, sizeof (grub_uint32_t)); -diff --git a/grub-core/fs/zfs/zfscrypt.c b/grub-core/fs/zfs/zfscrypt.c -index 1402e0b..de3b015 100644 ---- a/grub-core/fs/zfs/zfscrypt.c -+++ b/grub-core/fs/zfs/zfscrypt.c -@@ -22,6 +22,7 @@ - #include - #include - #include -+#include - #include - #include - #include -@@ -82,9 +83,13 @@ grub_zfs_add_key (grub_uint8_t *key_in, - int passphrase) - { - struct grub_zfs_wrap_key *key; -+ grub_size_t sz; -+ - if (!passphrase && keylen > 32) - keylen = 32; -- key = grub_malloc (sizeof (*key) + keylen); -+ if (grub_add (sizeof (*key), keylen, &sz)) -+ return GRUB_ERR_OUT_OF_RANGE; -+ key = grub_malloc (sz); - if (!key) - return grub_errno; - key->is_passphrase = passphrase; -diff --git a/grub-core/lib/arg.c b/grub-core/lib/arg.c -index ccc1850..8439a00 100644 ---- a/grub-core/lib/arg.c -+++ b/grub-core/lib/arg.c -@@ -23,6 +23,7 @@ - #include - #include - #include -+#include - - /* Built-in parser for default options. */ - static const struct grub_arg_option help_options[] = -@@ -216,7 +217,13 @@ static inline grub_err_t - add_arg (char ***argl, int *num, char *s) - { - char **p = *argl; -- *argl = grub_realloc (*argl, (++(*num) + 1) * sizeof (char *)); -+ grub_size_t sz; -+ -+ if (grub_add (++(*num), 1, &sz) || -+ grub_mul (sz, sizeof (char *), &sz)) -+ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); -+ -+ *argl = grub_realloc (*argl, sz); - if (! *argl) - { - grub_free (p); -@@ -431,6 +438,7 @@ grub_arg_list_alloc(grub_extcmd_t extcmd, int argc, - grub_size_t argcnt; - struct grub_arg_list *list; - const struct grub_arg_option *options; -+ grub_size_t sz0, sz1; - - options = extcmd->options; - if (! options) -@@ -443,7 +451,15 @@ grub_arg_list_alloc(grub_extcmd_t extcmd, int argc, - argcnt += ((grub_size_t) argc + 1) / 2 + 1; /* max possible for any option */ - } - -- list = grub_zalloc (sizeof (*list) * i + sizeof (char*) * argcnt); -+ if (grub_mul (sizeof (*list), i, &sz0) || -+ grub_mul (sizeof (char *), argcnt, &sz1) || -+ grub_add (sz0, sz1, &sz0)) -+ { -+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); -+ return 0; -+ } -+ -+ list = grub_zalloc (sz0); - if (! list) - return 0; - -diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c -index 50cca30..ff98fb7 100644 ---- a/grub-core/loader/i386/bsd.c -+++ b/grub-core/loader/i386/bsd.c -@@ -35,6 +35,7 @@ - #include - #include - #include -+#include - #include - #ifdef GRUB_MACHINE_PCBIOS - #include -@@ -1013,11 +1014,16 @@ grub_netbsd_add_modules (void) - struct grub_netbsd_btinfo_modules *mods; - unsigned i; - grub_err_t err; -+ grub_size_t sz; - - for (mod = netbsd_mods; mod; mod = mod->next) - modcnt++; - -- mods = grub_malloc (sizeof (*mods) + sizeof (mods->mods[0]) * modcnt); -+ if (grub_mul (modcnt, sizeof (mods->mods[0]), &sz) || -+ grub_add (sz, sizeof (*mods), &sz)) -+ return GRUB_ERR_OUT_OF_RANGE; -+ -+ mods = grub_malloc (sz); - if (!mods) - return grub_errno; - -diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c -index e332d5e..906ec7d 100644 ---- a/grub-core/net/dns.c -+++ b/grub-core/net/dns.c -@@ -22,6 +22,7 @@ - #include - #include - #include -+#include - - struct dns_cache_element - { -@@ -51,9 +52,15 @@ grub_net_add_dns_server (const struct grub_net_network_level_address *s) - { - int na = dns_servers_alloc * 2; - struct grub_net_network_level_address *ns; -+ grub_size_t sz; -+ - if (na < 8) - na = 8; -- ns = grub_realloc (dns_servers, na * sizeof (ns[0])); -+ -+ if (grub_mul (na, sizeof (ns[0]), &sz)) -+ return GRUB_ERR_OUT_OF_RANGE; -+ -+ ns = grub_realloc (dns_servers, sz); - if (!ns) - return grub_errno; - dns_servers_alloc = na; -diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c -index d57fb72..4dfcc31 100644 ---- a/grub-core/normal/charset.c -+++ b/grub-core/normal/charset.c -@@ -48,6 +48,7 @@ - #include - #include - #include -+#include - - #if HAVE_FONT_SOURCE - #include "widthspec.h" -@@ -464,6 +465,7 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen, - { - struct grub_unicode_combining *n; - unsigned j; -+ grub_size_t sz; - - if (!haveout) - continue; -@@ -477,10 +479,14 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen, - n = out->combining_inline; - else if (out->ncomb > (int) ARRAY_SIZE (out->combining_inline)) - { -- n = grub_realloc (out->combining_ptr, -- sizeof (n[0]) * (out->ncomb + 1)); -+ if (grub_add (out->ncomb, 1, &sz) || -+ grub_mul (sz, sizeof (n[0]), &sz)) -+ goto fail; -+ -+ n = grub_realloc (out->combining_ptr, sz); - if (!n) - { -+ fail: - grub_errno = GRUB_ERR_NONE; - continue; - } -diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c -index c57242e..de03fe6 100644 ---- a/grub-core/normal/cmdline.c -+++ b/grub-core/normal/cmdline.c -@@ -28,6 +28,7 @@ - #include - #include - #include -+#include - - static grub_uint32_t *kill_buf; - -@@ -307,12 +308,21 @@ cl_insert (struct cmdline_term *cl_terms, unsigned nterms, - if (len + (*llen) >= (*max_len)) - { - grub_uint32_t *nbuf; -- (*max_len) *= 2; -- nbuf = grub_realloc ((*buf), sizeof (grub_uint32_t) * (*max_len)); -+ grub_size_t sz; -+ -+ if (grub_mul (*max_len, 2, max_len) || -+ grub_mul (*max_len, sizeof (grub_uint32_t), &sz)) -+ { -+ grub_errno = GRUB_ERR_OUT_OF_RANGE; -+ goto fail; -+ } -+ -+ nbuf = grub_realloc ((*buf), sz); - if (nbuf) - (*buf) = nbuf; - else - { -+ fail: - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - (*max_len) /= 2; -diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c -index f31487c..de64a36 100644 ---- a/grub-core/normal/menu_entry.c -+++ b/grub-core/normal/menu_entry.c -@@ -27,6 +27,7 @@ - #include - #include - #include -+#include - - enum update_mode - { -@@ -113,10 +114,18 @@ ensure_space (struct line *linep, int extra) - { - if (linep->max_len < linep->len + extra) - { -- linep->max_len = 2 * (linep->len + extra); -- linep->buf = grub_realloc (linep->buf, (linep->max_len + 1) * sizeof (linep->buf[0])); -+ grub_size_t sz0, sz1; -+ -+ if (grub_add (linep->len, extra, &sz0) || -+ grub_mul (sz0, 2, &sz0) || -+ grub_add (sz0, 1, &sz1) || -+ grub_mul (sz1, sizeof (linep->buf[0]), &sz1)) -+ return 0; -+ -+ linep->buf = grub_realloc (linep->buf, sz1); - if (! linep->buf) - return 0; -+ linep->max_len = sz0; - } - - return 1; -diff --git a/grub-core/script/argv.c b/grub-core/script/argv.c -index 217ec5d..5751fdd 100644 ---- a/grub-core/script/argv.c -+++ b/grub-core/script/argv.c -@@ -20,6 +20,7 @@ - #include - #include - #include -+#include - - /* Return nearest power of two that is >= v. */ - static unsigned -@@ -81,11 +82,16 @@ int - grub_script_argv_next (struct grub_script_argv *argv) - { - char **p = argv->args; -+ grub_size_t sz; - - if (argv->args && argv->argc && argv->args[argv->argc - 1] == 0) - return 0; - -- p = grub_realloc (p, round_up_exp ((argv->argc + 2) * sizeof (char *))); -+ if (grub_add (argv->argc, 2, &sz) || -+ grub_mul (sz, sizeof (char *), &sz)) -+ return 1; -+ -+ p = grub_realloc (p, round_up_exp (sz)); - if (! p) - return 1; - -@@ -105,13 +111,19 @@ grub_script_argv_append (struct grub_script_argv *argv, const char *s, - { - grub_size_t a; - char *p = argv->args[argv->argc - 1]; -+ grub_size_t sz; - - if (! s) - return 0; - - a = p ? grub_strlen (p) : 0; - -- p = grub_realloc (p, round_up_exp ((a + slen + 1) * sizeof (char))); -+ if (grub_add (a, slen, &sz) || -+ grub_add (sz, 1, &sz) || -+ grub_mul (sz, sizeof (char), &sz)) -+ return 1; -+ -+ p = grub_realloc (p, round_up_exp (sz)); - if (! p) - return 1; - -diff --git a/grub-core/script/lexer.c b/grub-core/script/lexer.c -index c6bd317..5fb0cbd 100644 ---- a/grub-core/script/lexer.c -+++ b/grub-core/script/lexer.c -@@ -24,6 +24,7 @@ - #include - #include - #include -+#include - - #define yytext_ptr char * - #include "grub_script.tab.h" -@@ -110,10 +111,14 @@ grub_script_lexer_record (struct grub_parser_param *parser, char *str) - old = lexer->recording; - if (lexer->recordlen < len) - lexer->recordlen = len; -- lexer->recordlen *= 2; -+ -+ if (grub_mul (lexer->recordlen, 2, &lexer->recordlen)) -+ goto fail; -+ - lexer->recording = grub_realloc (lexer->recording, lexer->recordlen); - if (!lexer->recording) - { -+ fail: - grub_free (old); - lexer->recordpos = 0; - lexer->recordlen = 0; -@@ -130,7 +135,7 @@ int - grub_script_lexer_yywrap (struct grub_parser_param *parserstate, - const char *input) - { -- grub_size_t len = 0; -+ grub_size_t len = 0, sz; - char *p = 0; - char *line = 0; - YY_BUFFER_STATE buffer; -@@ -168,12 +173,22 @@ grub_script_lexer_yywrap (struct grub_parser_param *parserstate, - } - else if (len && line[len - 1] != '\n') - { -- p = grub_realloc (line, len + 2); -+ if (grub_add (len, 2, &sz)) -+ { -+ grub_free (line); -+ grub_script_yyerror (parserstate, N_("overflow is detected")); -+ return 1; -+ } -+ -+ p = grub_realloc (line, sz); - if (p) - { - p[len++] = '\n'; - p[len] = '\0'; - } -+ else -+ grub_free (line); -+ - line = p; - } - -diff --git a/grub-core/video/bitmap.c b/grub-core/video/bitmap.c -index b2e0315..6256e20 100644 ---- a/grub-core/video/bitmap.c -+++ b/grub-core/video/bitmap.c -@@ -23,6 +23,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -58,7 +59,7 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap, - enum grub_video_blit_format blit_format) - { - struct grub_video_mode_info *mode_info; -- unsigned int size; -+ grub_size_t size; - - if (!bitmap) - return grub_error (GRUB_ERR_BUG, "invalid argument"); -@@ -137,19 +138,25 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap, - - mode_info->pitch = width * mode_info->bytes_per_pixel; - -- /* Calculate size needed for the data. */ -- size = (width * mode_info->bytes_per_pixel) * height; -+ /* Calculate size needed for the data. */ -+ if (grub_mul (width, mode_info->bytes_per_pixel, &size) || -+ grub_mul (size, height, &size)) -+ { -+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); -+ goto fail; -+ } - - (*bitmap)->data = grub_zalloc (size); - if (! (*bitmap)->data) -- { -- grub_free (*bitmap); -- *bitmap = 0; -- -- return grub_errno; -- } -+ goto fail; - - return GRUB_ERR_NONE; -+ -+ fail: -+ grub_free (*bitmap); -+ *bitmap = NULL; -+ -+ return grub_errno; - } - - /* Frees all resources allocated by bitmap. */ -diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c -index 61bd645..0157ff7 100644 ---- a/grub-core/video/readers/png.c -+++ b/grub-core/video/readers/png.c -@@ -23,6 +23,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -301,9 +302,17 @@ grub_png_decode_image_header (struct grub_png_data *data) - data->bpp <<= 1; - - data->color_bits = color_bits; -- data->row_bytes = data->image_width * data->bpp; -+ -+ if (grub_mul (data->image_width, data->bpp, &data->row_bytes)) -+ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); -+ - if (data->color_bits <= 4) -- data->row_bytes = (data->image_width * data->color_bits + 7) / 8; -+ { -+ if (grub_mul (data->image_width, data->color_bits + 7, &data->row_bytes)) -+ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); -+ -+ data->row_bytes >>= 3; -+ } - - #ifndef GRUB_CPU_WORDS_BIGENDIAN - if (data->is_16bit || data->is_gray || data->is_palette) --- -2.23.0 - diff --git a/0226-iso9660-Don-t-leak-memory-on-realloc-failures.patch b/0226-iso9660-Don-t-leak-memory-on-realloc-failures.patch deleted file mode 100644 index 93dc15ec5b8404bf8be158c11828b59fbab58ef8..0000000000000000000000000000000000000000 --- a/0226-iso9660-Don-t-leak-memory-on-realloc-failures.patch +++ /dev/null @@ -1,68 +0,0 @@ -From f14380cfa955a2fb502ba148d045f68ac1250f2d Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Sat, 4 Jul 2020 12:25:09 -0400 -Subject: [PATCH 06/27] iso9660: Don't leak memory on realloc() failures - -Signed-off-by: Peter Jones -Reviewed-by: Daniel Kiper ---- - grub-core/fs/iso9660.c | 24 ++++++++++++++++++++---- - 1 file changed, 20 insertions(+), 4 deletions(-) - -diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c -index 7ba5b30..5ec4433 100644 ---- a/grub-core/fs/iso9660.c -+++ b/grub-core/fs/iso9660.c -@@ -533,14 +533,20 @@ add_part (struct iterate_dir_ctx *ctx, - { - int size = ctx->symlink ? grub_strlen (ctx->symlink) : 0; - grub_size_t sz; -+ char *new; - - if (grub_add (size, len2, &sz) || - grub_add (sz, 1, &sz)) - return; - -- ctx->symlink = grub_realloc (ctx->symlink, sz); -- if (! ctx->symlink) -- return; -+ new = grub_realloc (ctx->symlink, sz); -+ if (!new) -+ { -+ grub_free (ctx->symlink); -+ ctx->symlink = NULL; -+ return; -+ } -+ ctx->symlink = new; - - grub_memcpy (ctx->symlink + size, part, len2); - ctx->symlink[size + len2] = 0; -@@ -634,7 +640,12 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry, - is the length. Both are part of the `Component - Record'. */ - if (ctx->symlink && !ctx->was_continue) -- add_part (ctx, "/", 1); -+ { -+ add_part (ctx, "/", 1); -+ if (grub_errno) -+ return grub_errno; -+ } -+ - add_part (ctx, (char *) &entry->data[pos + 2], - entry->data[pos + 1]); - ctx->was_continue = (entry->data[pos] & 1); -@@ -653,6 +664,11 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry, - add_part (ctx, "/", 1); - break; - } -+ -+ /* Check if grub_realloc() failed in add_part(). */ -+ if (grub_errno) -+ return grub_errno; -+ - /* In pos + 1 the length of the `Component Record' is - stored. */ - pos += entry->data[pos + 1] + 2; --- -2.23.0 - diff --git a/0227-font-Do-not-load-more-than-one-NAME-section.patch b/0227-font-Do-not-load-more-than-one-NAME-section.patch deleted file mode 100644 index c80d43b5baf9b570d95c64c39dfc848c6bea57c3..0000000000000000000000000000000000000000 --- a/0227-font-Do-not-load-more-than-one-NAME-section.patch +++ /dev/null @@ -1,37 +0,0 @@ -From 7c1e10c986d1c4b50146f03f58c1aece2aa0bdbe Mon Sep 17 00:00:00 2001 -From: Daniel Kiper -Date: Tue, 7 Jul 2020 15:36:26 +0200 -Subject: [PATCH 07/27] font: Do not load more than one NAME section - -The GRUB font file can have one NAME section only. Though if somebody -crafts a broken font file with many NAME sections and loads it then the -GRUB leaks memory. So, prevent against that by loading first NAME -section and failing in controlled way on following one. - -Reported-by: Chris Coulson -Signed-off-by: Daniel Kiper -Reviewed-by: Jan Setje-Eilers ---- - grub-core/font/font.c | 6 ++++++ - 1 file changed, 6 insertions(+) - -diff --git a/grub-core/font/font.c b/grub-core/font/font.c -index 5edb477..d09bb38 100644 ---- a/grub-core/font/font.c -+++ b/grub-core/font/font.c -@@ -532,6 +532,12 @@ grub_font_load (const char *filename) - if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FONT_NAME, - sizeof (FONT_FORMAT_SECTION_NAMES_FONT_NAME) - 1) == 0) - { -+ if (font->name != NULL) -+ { -+ grub_error (GRUB_ERR_BAD_FONT, "invalid font file: too many NAME sections"); -+ goto fail; -+ } -+ - font->name = read_section_as_string (§ion); - if (!font->name) - goto fail; --- -2.23.0 - diff --git a/0228-gfxmenu-Fix-double-free-in-load_image.patch b/0228-gfxmenu-Fix-double-free-in-load_image.patch deleted file mode 100644 index 7170aca842ca83645f551938f76ecdd2aecd3a50..0000000000000000000000000000000000000000 --- a/0228-gfxmenu-Fix-double-free-in-load_image.patch +++ /dev/null @@ -1,35 +0,0 @@ -From a2e9386cbca0aeb951badd992a1fc3634c348877 Mon Sep 17 00:00:00 2001 -From: Alexey Makhalov -Date: Wed, 8 Jul 2020 20:41:56 +0000 -Subject: [PATCH 08/27] gfxmenu: Fix double free in load_image() - -self->bitmap should be zeroed after free. Otherwise, there is a chance -to double free (USE_AFTER_FREE) it later in rescale_image(). - -Fixes: CID 292472 - -Signed-off-by: Alexey Makhalov -Reviewed-by: Daniel Kiper ---- - grub-core/gfxmenu/gui_image.c | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/grub-core/gfxmenu/gui_image.c b/grub-core/gfxmenu/gui_image.c -index 29784ed..6b2e976 100644 ---- a/grub-core/gfxmenu/gui_image.c -+++ b/grub-core/gfxmenu/gui_image.c -@@ -195,7 +195,10 @@ load_image (grub_gui_image_t self, const char *path) - return grub_errno; - - if (self->bitmap && (self->bitmap != self->raw_bitmap)) -- grub_video_bitmap_destroy (self->bitmap); -+ { -+ grub_video_bitmap_destroy (self->bitmap); -+ self->bitmap = 0; -+ } - if (self->raw_bitmap) - grub_video_bitmap_destroy (self->raw_bitmap); - --- -2.23.0 - diff --git a/0229-xnu-Fix-double-free-in-grub_xnu_devprop_add_property.patch b/0229-xnu-Fix-double-free-in-grub_xnu_devprop_add_property.patch deleted file mode 100644 index 6a80f6e326883645c90e78f60b437a0beb9cc1af..0000000000000000000000000000000000000000 --- a/0229-xnu-Fix-double-free-in-grub_xnu_devprop_add_property.patch +++ /dev/null @@ -1,54 +0,0 @@ -From d7bdee0e38c93b4c49281f5ca79d416bab6eb3ce Mon Sep 17 00:00:00 2001 -From: Alexey Makhalov -Date: Wed, 8 Jul 2020 21:30:43 +0000 -Subject: [PATCH 09/27] xnu: Fix double free in grub_xnu_devprop_add_property() - -grub_xnu_devprop_add_property() should not free utf8 and utf16 as it get -allocated and freed in the caller. - -Minor improvement: do prop fields initialization after memory allocations. - -Fixes: CID 292442, CID 292457, CID 292460, CID 292466 - -Signed-off-by: Alexey Makhalov -Reviewed-by: Daniel Kiper ---- - grub-core/loader/i386/xnu.c | 17 ++++++++--------- - 1 file changed, 8 insertions(+), 9 deletions(-) - -diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c -index b7d176b..e9e1192 100644 ---- a/grub-core/loader/i386/xnu.c -+++ b/grub-core/loader/i386/xnu.c -@@ -262,20 +262,19 @@ grub_xnu_devprop_add_property (struct grub_xnu_devprop_device_descriptor *dev, - if (!prop) - return grub_errno; - -- prop->name = utf8; -- prop->name16 = utf16; -- prop->name16len = utf16len; -- -- prop->length = datalen; -- prop->data = grub_malloc (prop->length); -+ prop->data = grub_malloc (datalen); - if (!prop->data) - { -- grub_free (prop->name); -- grub_free (prop->name16); - grub_free (prop); - return grub_errno; - } -- grub_memcpy (prop->data, data, prop->length); -+ grub_memcpy (prop->data, data, datalen); -+ -+ prop->name = utf8; -+ prop->name16 = utf16; -+ prop->name16len = utf16len; -+ prop->length = datalen; -+ - grub_list_push (GRUB_AS_LIST_P (&dev->properties), - GRUB_AS_LIST (prop)); - return GRUB_ERR_NONE; --- -2.23.0 - diff --git a/0230-lzma-Make-sure-we-don-t-dereference-past-array.patch b/0230-lzma-Make-sure-we-don-t-dereference-past-array.patch deleted file mode 100644 index 74f4f2a366b6ab1e93d656a76e255d99ff56a32a..0000000000000000000000000000000000000000 --- a/0230-lzma-Make-sure-we-don-t-dereference-past-array.patch +++ /dev/null @@ -1,51 +0,0 @@ -From a2fd8fe73250d5a6ebe7e1b9dc31df6ecbcdfc8f Mon Sep 17 00:00:00 2001 -From: Konrad Rzeszutek Wilk -Date: Thu, 9 Jul 2020 03:05:23 +0000 -Subject: [PATCH 10/27] lzma: Make sure we don't dereference past array - -The two dimensional array p->posSlotEncoder[4][64] is being dereferenced -using the GetLenToPosState() macro which checks if len is less than 5, -and if so subtracts 2 from it. If len = 0, that is 0 - 2 = 4294967294. -Obviously we don't want to dereference that far out so we check if the -position found is greater or equal kNumLenToPosStates (4) and bail out. - -N.B.: Upstream LZMA 18.05 and later has this function completely rewritten -without any history. - -Fixes: CID 51526 - -Signed-off-by: Konrad Rzeszutek Wilk -Reviewed-by: Daniel Kiper ---- - grub-core/lib/LzmaEnc.c | 10 ++++++++-- - 1 file changed, 8 insertions(+), 2 deletions(-) - -diff --git a/grub-core/lib/LzmaEnc.c b/grub-core/lib/LzmaEnc.c -index f2ec04a..753e56a 100644 ---- a/grub-core/lib/LzmaEnc.c -+++ b/grub-core/lib/LzmaEnc.c -@@ -1877,13 +1877,19 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize - } - else - { -- UInt32 posSlot; -+ UInt32 posSlot, lenToPosState; - RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0); - p->state = kMatchNextStates[p->state]; - LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices); - pos -= LZMA_NUM_REPS; - GetPosSlot(pos, posSlot); -- RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot); -+ lenToPosState = GetLenToPosState(len); -+ if (lenToPosState >= kNumLenToPosStates) -+ { -+ p->result = SZ_ERROR_DATA; -+ return CheckErrors(p); -+ } -+ RcTree_Encode(&p->rc, p->posSlotEncoder[lenToPosState], kNumPosSlotBits, posSlot); - - if (posSlot >= kStartPosModelIndex) - { --- -2.23.0 - diff --git a/0231-term-Fix-overflow-on-user-inputs.patch b/0231-term-Fix-overflow-on-user-inputs.patch deleted file mode 100644 index 90def3496da9021c8a2354827c1cf7c5991563af..0000000000000000000000000000000000000000 --- a/0231-term-Fix-overflow-on-user-inputs.patch +++ /dev/null @@ -1,65 +0,0 @@ -From 8054c31c62c4caf5a8767c0e4c8ce09219b8ec6e Mon Sep 17 00:00:00 2001 -From: Konrad Rzeszutek Wilk -Date: Tue, 7 Jul 2020 15:12:25 -0400 -Subject: [PATCH 11/27] term: Fix overflow on user inputs - -This requires a very weird input from the serial interface but can cause -an overflow in input_buf (keys) overwriting the next variable (npending) -with the user choice: - -(pahole output) - -struct grub_terminfo_input_state { - int input_buf[6]; /* 0 24 */ - int npending; /* 24 4 */ <- CORRUPT - ...snip... - -The magic string requires causing this is "ESC,O,],0,1,2,q" and we overflow -npending with "q" (aka increase npending to 161). The simplest fix is to -just to disallow overwrites input_buf, which exactly what this patch does. - -Fixes: CID 292449 - -Signed-off-by: Konrad Rzeszutek Wilk -Reviewed-by: Daniel Kiper ---- - grub-core/term/terminfo.c | 9 ++++++--- - 1 file changed, 6 insertions(+), 3 deletions(-) - -diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c -index 537a5c0..44d0b3b 100644 ---- a/grub-core/term/terminfo.c -+++ b/grub-core/term/terminfo.c -@@ -398,7 +398,7 @@ grub_terminfo_getwh (struct grub_term_output *term) - } - - static void --grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, -+grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, int max_len, - int (*readkey) (struct grub_term_input *term)) - { - int c; -@@ -414,6 +414,9 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, - if (c == -1) \ - return; \ - \ -+ if (*len >= max_len) \ -+ return; \ -+ \ - keys[*len] = c; \ - (*len)++; \ - } -@@ -602,8 +605,8 @@ grub_terminfo_getkey (struct grub_term_input *termi) - return ret; - } - -- grub_terminfo_readkey (termi, data->input_buf, -- &data->npending, data->readkey); -+ grub_terminfo_readkey (termi, data->input_buf, &data->npending, -+ GRUB_TERMINFO_READKEY_MAX_LEN, data->readkey); - - #if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275) - if (data->npending == 1 && data->input_buf[0] == GRUB_TERM_ESC --- -2.23.0 - diff --git a/0232-udf-Fix-memory-leak.patch b/0232-udf-Fix-memory-leak.patch deleted file mode 100644 index 2a743697aa3b1a3c8c8cfc0e051bd0c086a2dd57..0000000000000000000000000000000000000000 --- a/0232-udf-Fix-memory-leak.patch +++ /dev/null @@ -1,55 +0,0 @@ -From ba6a43c85d73196ed00ba662a4d310c310540864 Mon Sep 17 00:00:00 2001 -From: Konrad Rzeszutek Wilk -Date: Tue, 7 Jul 2020 22:02:31 -0400 -Subject: [PATCH 12/27] udf: Fix memory leak - -Fixes: CID 73796 - -Signed-off-by: Konrad Rzeszutek Wilk -Reviewed-by: Daniel Kiper -Reviewed-by: Jan Setje-Eilers ---- - grub-core/fs/udf.c | 17 +++++++++++++---- - 1 file changed, 13 insertions(+), 4 deletions(-) - -diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c -index 21ac7f4..2ac5c1d 100644 ---- a/grub-core/fs/udf.c -+++ b/grub-core/fs/udf.c -@@ -965,8 +965,10 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, - return 0; - - if (grub_udf_read_icb (dir->data, &dirent.icb, child)) -- return 0; -- -+ { -+ grub_free (child); -+ return 0; -+ } - if (dirent.characteristics & GRUB_UDF_FID_CHAR_PARENT) - { - /* This is the parent directory. */ -@@ -988,11 +990,18 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, - dirent.file_ident_length, - (char *) raw)) - != dirent.file_ident_length) -- return 0; -+ { -+ grub_free (child); -+ return 0; -+ } - - filename = read_string (raw, dirent.file_ident_length, 0); - if (!filename) -- grub_print_error (); -+ { -+ /* As the hook won't get called. */ -+ grub_free (child); -+ grub_print_error (); -+ } - - if (filename && hook (filename, type, child, hook_data)) - { --- -2.23.0 - diff --git a/0233-multiboot2-Fix-memory-leak-if-grub_create_loader_cmd.patch b/0233-multiboot2-Fix-memory-leak-if-grub_create_loader_cmd.patch deleted file mode 100644 index c53f98100aefe8413ef15fcab8bcaad4bd62254d..0000000000000000000000000000000000000000 --- a/0233-multiboot2-Fix-memory-leak-if-grub_create_loader_cmd.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 1eebc205991aeb48f5d88acaac3833ad527b1fb1 Mon Sep 17 00:00:00 2001 -From: Konrad Rzeszutek Wilk -Date: Fri, 26 Jun 2020 10:51:43 -0400 -Subject: [PATCH 13/27] multiboot2: Fix memory leak if - grub_create_loader_cmdline() fails - -Fixes: CID 292468 - -Signed-off-by: Konrad Rzeszutek Wilk -Reviewed-by: Daniel Kiper ---- - grub-core/loader/multiboot_mbi2.c | 6 +++++- - 1 file changed, 5 insertions(+), 1 deletion(-) - -diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c -index 53da786..0efc660 100644 ---- a/grub-core/loader/multiboot_mbi2.c -+++ b/grub-core/loader/multiboot_mbi2.c -@@ -1070,7 +1070,11 @@ grub_multiboot2_add_module (grub_addr_t start, grub_size_t size, - err = grub_create_loader_cmdline (argc, argv, newmod->cmdline, - newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE); - if (err) -- return err; -+ { -+ grub_free (newmod->cmdline); -+ grub_free (newmod); -+ return err; -+ } - - if (modules_last) - modules_last->next = newmod; --- -2.23.0 - diff --git a/0234-tftp-Do-not-use-priority-queue.patch b/0234-tftp-Do-not-use-priority-queue.patch deleted file mode 100644 index da00b103323458a705f8fda2c7a248f8acd69b4f..0000000000000000000000000000000000000000 --- a/0234-tftp-Do-not-use-priority-queue.patch +++ /dev/null @@ -1,284 +0,0 @@ -From 781b3e5efc35c17cbce95393aafd63a5b429f9e6 Mon Sep 17 00:00:00 2001 -From: Alexey Makhalov -Date: Thu, 9 Jul 2020 08:10:40 +0000 -Subject: [PATCH 14/27] tftp: Do not use priority queue - -There is not need to reassemble the order of blocks. Per RFC 1350, -server must wait for the ACK, before sending next block. Data packets -can be served immediately without putting them to priority queue. - -Logic to handle incoming packet is this: - - if packet block id equal to expected block id, then - process the packet, - - if packet block id is less than expected - this is retransmit - of old packet, then ACK it and drop the packet, - - if packet block id is more than expected - that shouldn't - happen, just drop the packet. - -It makes the tftp receive path code simpler, smaller and faster. -As a benefit, this change fixes CID# 73624 and CID# 96690, caused -by following while loop: - - while (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) == 0) - -where tftph pointer is not moving from one iteration to another, causing -to serve same packet again. Luckily, double serving didn't happen due to -data->block++ during the first iteration. - -Fixes: CID 73624, CID 96690 - -Signed-off-by: Alexey Makhalov -Reviewed-by: Daniel Kiper ---- ---- - grub-core/net/tftp.c | 168 ++++++++++++++----------------------------- - 1 file changed, 53 insertions(+), 115 deletions(-) - -diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c -index e267af3..c2df3d7 100644 ---- a/grub-core/net/tftp.c -+++ b/grub-core/net/tftp.c -@@ -25,7 +25,6 @@ - #include - #include - #include --#include - #include - - GRUB_MOD_LICENSE ("GPLv3+"); -@@ -106,31 +105,8 @@ typedef struct tftp_data - int have_oack; - struct grub_error_saved save_err; - grub_net_udp_socket_t sock; -- grub_priority_queue_t pq; - } *tftp_data_t; - --static int --cmp_block (grub_uint16_t a, grub_uint16_t b) --{ -- grub_int16_t i = (grub_int16_t) (a - b); -- if (i > 0) -- return +1; -- if (i < 0) -- return -1; -- return 0; --} -- --static int --cmp (const void *a__, const void *b__) --{ -- struct grub_net_buff *a_ = *(struct grub_net_buff **) a__; -- struct grub_net_buff *b_ = *(struct grub_net_buff **) b__; -- struct tftphdr *a = (struct tftphdr *) a_->data; -- struct tftphdr *b = (struct tftphdr *) b_->data; -- /* We want the first elements to be on top. */ -- return -cmp_block (grub_be_to_cpu16 (a->u.data.block), grub_be_to_cpu16 (b->u.data.block)); --} -- - static grub_err_t - ack (tftp_data_t data, grub_uint64_t block) - { -@@ -207,73 +183,60 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)), - return GRUB_ERR_NONE; - } - -- err = grub_priority_queue_push (data->pq, &nb); -- if (err) -- return err; -- -- { -- struct grub_net_buff **nb_top_p, *nb_top; -- while (1) -- { -- nb_top_p = grub_priority_queue_top (data->pq); -- if (!nb_top_p) -- return GRUB_ERR_NONE; -- nb_top = *nb_top_p; -- tftph = (struct tftphdr *) nb_top->data; -- if (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) >= 0) -- break; -- ack (data, grub_be_to_cpu16 (tftph->u.data.block)); -- grub_netbuff_free (nb_top); -- grub_priority_queue_pop (data->pq); -- } -- while (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) == 0) -- { -- unsigned size; -- -- grub_priority_queue_pop (data->pq); -- -- if (file->device->net->packs.count < 50) -+ /* Ack old/retransmitted block. */ -+ if (grub_be_to_cpu16 (tftph->u.data.block) < data->block + 1) -+ ack (data, grub_be_to_cpu16 (tftph->u.data.block)); -+ /* Ignore unexpected block. */ -+ else if (grub_be_to_cpu16 (tftph->u.data.block) > data->block + 1) -+ grub_dprintf ("tftp", "TFTP unexpected block # %d\n", tftph->u.data.block); -+ else -+ { -+ unsigned size; -+ -+ if (file->device->net->packs.count < 50) -+ { - err = ack (data, data->block + 1); -- else -- { -- file->device->net->stall = 1; -- err = 0; -- } -- if (err) -- return err; -- -- err = grub_netbuff_pull (nb_top, sizeof (tftph->opcode) + -- sizeof (tftph->u.data.block)); -- if (err) -- return err; -- size = nb_top->tail - nb_top->data; -- -- data->block++; -- if (size < data->block_size) -- { -- if (data->ack_sent < data->block) -- ack (data, data->block); -- file->device->net->eof = 1; -- file->device->net->stall = 1; -- grub_net_udp_close (data->sock); -- data->sock = NULL; -- } -- /* Prevent garbage in broken cards. Is it still necessary -- given that IP implementation has been fixed? -- */ -- if (size > data->block_size) -- { -- err = grub_netbuff_unput (nb_top, size - data->block_size); -- if (err) -- return err; -- } -- /* If there is data, puts packet in socket list. */ -- if ((nb_top->tail - nb_top->data) > 0) -- grub_net_put_packet (&file->device->net->packs, nb_top); -- else -- grub_netbuff_free (nb_top); -- } -- } -+ if (err) -+ return err; -+ } -+ else -+ file->device->net->stall = 1; -+ -+ err = grub_netbuff_pull (nb, sizeof (tftph->opcode) + -+ sizeof (tftph->u.data.block)); -+ if (err) -+ return err; -+ size = nb->tail - nb->data; -+ -+ data->block++; -+ if (size < data->block_size) -+ { -+ if (data->ack_sent < data->block) -+ ack (data, data->block); -+ file->device->net->eof = 1; -+ file->device->net->stall = 1; -+ grub_net_udp_close (data->sock); -+ data->sock = NULL; -+ } -+ /* -+ * Prevent garbage in broken cards. Is it still necessary -+ * given that IP implementation has been fixed? -+ */ -+ if (size > data->block_size) -+ { -+ err = grub_netbuff_unput (nb, size - data->block_size); -+ if (err) -+ return err; -+ } -+ /* If there is data, puts packet in socket list. */ -+ if ((nb->tail - nb->data) > 0) -+ { -+ grub_net_put_packet (&file->device->net->packs, nb); -+ /* Do not free nb. */ -+ return GRUB_ERR_NONE; -+ } -+ } -+ grub_netbuff_free (nb); - return GRUB_ERR_NONE; - case TFTP_ERROR: - data->have_oack = 1; -@@ -287,19 +250,6 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)), - } - } - --static void --destroy_pq (tftp_data_t data) --{ -- struct grub_net_buff **nb_p; -- while ((nb_p = grub_priority_queue_top (data->pq))) -- { -- grub_netbuff_free (*nb_p); -- grub_priority_queue_pop (data->pq); -- } -- -- grub_priority_queue_destroy (data->pq); --} -- - /* Create a normalized copy of the filename. - Compress any string of consecutive forward slashes to a single forward - slash. */ -@@ -395,13 +345,6 @@ tftp_open (struct grub_file *file, const char *filename) - file->not_easily_seekable = 1; - file->data = data; - -- data->pq = grub_priority_queue_new (sizeof (struct grub_net_buff *), cmp); -- if (!data->pq) -- { -- grub_free (data); -- return grub_errno; -- } -- - grub_dprintf("tftp", "resolving address for %s\n", file->device->net->server); - err = grub_net_resolve_address (file->device->net->server, &addr); - if (err) -@@ -410,7 +353,6 @@ tftp_open (struct grub_file *file, const char *filename) - grub_dprintf ("tftp", "file_size is %llu, block_size is %llu\n", - (unsigned long long)data->file_size, - (unsigned long long)data->block_size); -- destroy_pq (data); - grub_free (data); - return err; - } -@@ -422,7 +364,6 @@ tftp_open (struct grub_file *file, const char *filename) - if (!data->sock) - { - grub_dprintf("tftp", "connection failed\n"); -- destroy_pq (data); - grub_free (data); - return grub_errno; - } -@@ -436,7 +377,6 @@ tftp_open (struct grub_file *file, const char *filename) - if (err) - { - grub_net_udp_close (data->sock); -- destroy_pq (data); - grub_free (data); - return err; - } -@@ -453,7 +393,6 @@ tftp_open (struct grub_file *file, const char *filename) - if (grub_errno) - { - grub_net_udp_close (data->sock); -- destroy_pq (data); - grub_free (data); - return grub_errno; - } -@@ -496,7 +435,6 @@ tftp_close (struct grub_file *file) - grub_print_error (); - grub_net_udp_close (data->sock); - } -- destroy_pq (data); - grub_free (data); - return GRUB_ERR_NONE; - } --- -2.23.0 - diff --git a/0235-relocator-Protect-grub_relocator_alloc_chunk_addr-in.patch b/0235-relocator-Protect-grub_relocator_alloc_chunk_addr-in.patch deleted file mode 100644 index a1a42cfe951c5e2b5e3f3d38606c3995e58b0e95..0000000000000000000000000000000000000000 --- a/0235-relocator-Protect-grub_relocator_alloc_chunk_addr-in.patch +++ /dev/null @@ -1,149 +0,0 @@ -From caea56d1f8fa1ae298936f8d75b220e7f12b73d3 Mon Sep 17 00:00:00 2001 -From: Alexey Makhalov -Date: Wed, 15 Jul 2020 06:42:37 +0000 -Subject: [PATCH 15/27] relocator: Protect grub_relocator_alloc_chunk_addr() - input args against integer underflow/overflow - -Use arithmetic macros from safemath.h to accomplish it. In this commit, -I didn't want to be too paranoid to check every possible math equation -for overflow/underflow. Only obvious places (with non zero chance of -overflow/underflow) were refactored. - -Signed-off-by: Alexey Makhalov -Reviewed-by: Daniel Kiper ---- - grub-core/loader/i386/linux.c | 9 +++++++-- - grub-core/loader/i386/pc/linux.c | 9 +++++++-- - grub-core/loader/i386/xen.c | 12 ++++++++++-- - grub-core/loader/xnu.c | 11 +++++++---- - 4 files changed, 31 insertions(+), 10 deletions(-) - -diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c -index 201e659..90f2315 100644 ---- a/grub-core/loader/i386/linux.c -+++ b/grub-core/loader/i386/linux.c -@@ -37,6 +37,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -548,9 +549,13 @@ grub_linux_boot (void) - - { - grub_relocator_chunk_t ch; -+ grub_size_t sz; -+ -+ if (grub_add (ctx.real_size, efi_mmap_size, &sz)) -+ return GRUB_ERR_OUT_OF_RANGE; -+ - err = grub_relocator_alloc_chunk_addr (relocator, &ch, -- ctx.real_mode_target, -- (ctx.real_size + efi_mmap_size)); -+ ctx.real_mode_target, sz); - if (err) - return err; - real_mode_mem = get_virtual_current_address (ch); -diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c -index 0bf0e13..33d1196 100644 ---- a/grub-core/loader/i386/pc/linux.c -+++ b/grub-core/loader/i386/pc/linux.c -@@ -36,6 +36,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -231,8 +232,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - setup_sects = GRUB_LINUX_DEFAULT_SETUP_SECTS; - - real_size = setup_sects << GRUB_DISK_SECTOR_BITS; -- grub_linux16_prot_size = grub_file_size (file) -- - real_size - GRUB_DISK_SECTOR_SIZE; -+ if (grub_sub (grub_file_size (file), real_size, &grub_linux16_prot_size) || -+ grub_sub (grub_linux16_prot_size, GRUB_DISK_SECTOR_SIZE, &grub_linux16_prot_size)) -+ { -+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); -+ goto fail; -+ } - - if (! grub_linux_is_bzimage - && GRUB_LINUX_ZIMAGE_ADDR + grub_linux16_prot_size -diff --git a/grub-core/loader/i386/xen.c b/grub-core/loader/i386/xen.c -index 8f662c8..cd24874 100644 ---- a/grub-core/loader/i386/xen.c -+++ b/grub-core/loader/i386/xen.c -@@ -41,6 +41,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -636,6 +637,7 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)), - grub_relocator_chunk_t ch; - grub_addr_t kern_start; - grub_addr_t kern_end; -+ grub_size_t sz; - - if (argc == 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); -@@ -703,8 +705,14 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)), - - xen_state.max_addr = ALIGN_UP (kern_end, PAGE_SIZE); - -- err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, kern_start, -- kern_end - kern_start); -+ -+ if (grub_sub (kern_end, kern_start, &sz)) -+ { -+ err = GRUB_ERR_OUT_OF_RANGE; -+ goto fail; -+ } -+ -+ err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, kern_start, sz); - if (err) - goto fail; - kern_chunk_src = get_virtual_current_address (ch); -diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c -index 2f0ebd0..3fd6539 100644 ---- a/grub-core/loader/xnu.c -+++ b/grub-core/loader/xnu.c -@@ -35,6 +35,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -60,15 +61,17 @@ grub_xnu_heap_malloc (int size, void **src, grub_addr_t *target) - { - grub_err_t err; - grub_relocator_chunk_t ch; -+ grub_addr_t tgt; -+ -+ if (grub_add (grub_xnu_heap_target_start, grub_xnu_heap_size, &tgt)) -+ return GRUB_ERR_OUT_OF_RANGE; - -- err = grub_relocator_alloc_chunk_addr (grub_xnu_relocator, &ch, -- grub_xnu_heap_target_start -- + grub_xnu_heap_size, size); -+ err = grub_relocator_alloc_chunk_addr (grub_xnu_relocator, &ch, tgt, size); - if (err) - return err; - - *src = get_virtual_current_address (ch); -- *target = grub_xnu_heap_target_start + grub_xnu_heap_size; -+ *target = tgt; - grub_xnu_heap_size += size; - grub_dprintf ("xnu", "val=%p\n", *src); - return GRUB_ERR_NONE; --- -2.23.0 - diff --git a/0236-multiboot2-Set-min-address-for-mbi-allocation-to-0x1.patch b/0236-multiboot2-Set-min-address-for-mbi-allocation-to-0x1.patch deleted file mode 100644 index ba498f86c99fb8e258295b0fd70dcc998baadbee..0000000000000000000000000000000000000000 --- a/0236-multiboot2-Set-min-address-for-mbi-allocation-to-0x1.patch +++ /dev/null @@ -1,49 +0,0 @@ -From 0f3f5b7c13fa9b677a64cf11f20eca0f850a2b20 Mon Sep 17 00:00:00 2001 -From: Lukasz Hawrylko -Date: Mon, 16 Dec 2019 11:15:55 +0100 -Subject: [PATCH] multiboot2: Set min address for mbi allocation to 0x1000 - -Subject: [PATCH 16/27] multiboot2: Set min address for mbi allocation to - 0x1000 - -In some cases GRUB2 allocates multiboot2 structure at 0 address, that is -a confusing behavior. Consumers of that structure can have internal NULL-checks -that will throw an error when get a pointer to data allocated at address 0. -To prevent that, define min address for mbi allocation on x86 and x86_64 -platforms. - -Signed-off-by: Lukasz Hawrylko -Reviewed-by: Daniel Kiper ---- - grub-core/loader/multiboot_mbi2.c | 8 +++++++- - 1 file changed, 7 insertions(+), 1 deletion(-) - -diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c -index 0efc660..e88c9f4 100644 ---- a/grub-core/loader/multiboot_mbi2.c -+++ b/grub-core/loader/multiboot_mbi2.c -@@ -48,6 +48,12 @@ - #define HAS_VGA_TEXT 0 - #endif - -+#if defined (__i386__) || defined (__x86_64__) -+#define MBI_MIN_ADDR 0x1000 -+#else -+#define MBI_MIN_ADDR 0 -+#endif -+ - struct module - { - struct module *next; -@@ -708,7 +714,7 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) - COMPILE_TIME_ASSERT (MULTIBOOT_TAG_ALIGN % sizeof (grub_properly_aligned_t) == 0); - - err = grub_relocator_alloc_chunk_align (grub_multiboot2_relocator, &ch, -- 0, 0xffffffff - bufsize, -+ MBI_MIN_ADDR, 0xffffffff - bufsize, - bufsize, MULTIBOOT_TAG_ALIGN, - GRUB_RELOCATOR_PREFERENCE_NONE, 1); - if (err) --- -2.23.0 - diff --git a/0237-relocator-Protect-grub_relocator_alloc_chunk_align-m.patch b/0237-relocator-Protect-grub_relocator_alloc_chunk_align-m.patch deleted file mode 100644 index 21065756b1f8c7a1bb7bae9fababd526946ede3d..0000000000000000000000000000000000000000 --- a/0237-relocator-Protect-grub_relocator_alloc_chunk_align-m.patch +++ /dev/null @@ -1,334 +0,0 @@ -From 61ff5602fe8f2a3446346795daebe4ec3b82c20f Mon Sep 17 00:00:00 2001 -From: Alexey Makhalov -Date: Wed, 8 Jul 2020 01:44:38 +0000 -Subject: [PATCH 17/27] relocator: Protect grub_relocator_alloc_chunk_align() - max_addr against integer underflow - -This commit introduces integer underflow mitigation in max_addr calculation -in grub_relocator_alloc_chunk_align() invocation. - -It consists of 2 fixes: - 1. Introduced grub_relocator_alloc_chunk_align_safe() wrapper function to perform - sanity check for min/max and size values, and to make safe invocation of - grub_relocator_alloc_chunk_align() with validated max_addr value. Replace all - invocations such as grub_relocator_alloc_chunk_align(..., min_addr, max_addr - size, size, ...) - by grub_relocator_alloc_chunk_align_safe(..., min_addr, max_addr, size, ...). - 2. Introduced UP_TO_TOP32(s) macro for the cases where max_addr is 32-bit top - address (0xffffffff - size + 1) or similar. ---- - grub-core/lib/i386/relocator.c | 28 ++++++++++---------------- - grub-core/lib/mips/relocator.c | 6 ++---- - grub-core/lib/powerpc/relocator.c | 6 ++---- - grub-core/lib/x86_64/efi/relocator.c | 7 +++---- - grub-core/loader/i386/linux.c | 5 ++--- - grub-core/loader/i386/multiboot_mbi.c | 7 +++---- - grub-core/loader/i386/pc/linux.c | 6 ++---- - grub-core/loader/mips/linux.c | 9 +++------ - grub-core/loader/multiboot.c | 2 +- - grub-core/loader/multiboot_elfxx.c | 10 ++++----- - grub-core/loader/multiboot_mbi2.c | 10 ++++----- - grub-core/loader/xnu_resume.c | 2 +- - include/grub/relocator.h | 29 +++++++++++++++++++++++++++ - 13 files changed, 69 insertions(+), 58 deletions(-) - -diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c -index 71dd4f0..34cbe83 100644 ---- a/grub-core/lib/i386/relocator.c -+++ b/grub-core/lib/i386/relocator.c -@@ -83,11 +83,10 @@ grub_relocator32_boot (struct grub_relocator *rel, - /* Specific memory range due to Global Descriptor Table for use by payload - that we will store in returned chunk. The address range and preference - are based on "THE LINUX/x86 BOOT PROTOCOL" specification. */ -- err = grub_relocator_alloc_chunk_align (rel, &ch, 0x1000, -- 0x9a000 - RELOCATOR_SIZEOF (32), -- RELOCATOR_SIZEOF (32), 16, -- GRUB_RELOCATOR_PREFERENCE_LOW, -- avoid_efi_bootservices); -+ err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0x1000, 0x9a000, -+ RELOCATOR_SIZEOF (32), 16, -+ GRUB_RELOCATOR_PREFERENCE_LOW, -+ avoid_efi_bootservices); - if (err) - return err; - -@@ -125,13 +124,10 @@ grub_relocator16_boot (struct grub_relocator *rel, - grub_relocator_chunk_t ch; - - /* Put it higher than the byte it checks for A20 check. */ -- err = grub_relocator_alloc_chunk_align (rel, &ch, 0x8010, -- 0xa0000 - RELOCATOR_SIZEOF (16) -- - GRUB_RELOCATOR16_STACK_SIZE, -- RELOCATOR_SIZEOF (16) -- + GRUB_RELOCATOR16_STACK_SIZE, 16, -- GRUB_RELOCATOR_PREFERENCE_NONE, -- 0); -+ err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0x8010, 0xa0000, -+ RELOCATOR_SIZEOF (16) + -+ GRUB_RELOCATOR16_STACK_SIZE, 16, -+ GRUB_RELOCATOR_PREFERENCE_NONE, 0); - if (err) - return err; - -@@ -183,11 +179,9 @@ grub_relocator64_boot (struct grub_relocator *rel, - void *relst; - grub_relocator_chunk_t ch; - -- err = grub_relocator_alloc_chunk_align (rel, &ch, min_addr, -- max_addr - RELOCATOR_SIZEOF (64), -- RELOCATOR_SIZEOF (64), 16, -- GRUB_RELOCATOR_PREFERENCE_NONE, -- 0); -+ err = grub_relocator_alloc_chunk_align_safe (rel, &ch, min_addr, max_addr, -+ RELOCATOR_SIZEOF (64), 16, -+ GRUB_RELOCATOR_PREFERENCE_NONE, 0); - if (err) - return err; - -diff --git a/grub-core/lib/mips/relocator.c b/grub-core/lib/mips/relocator.c -index 9d5f49c..743b213 100644 ---- a/grub-core/lib/mips/relocator.c -+++ b/grub-core/lib/mips/relocator.c -@@ -120,10 +120,8 @@ grub_relocator32_boot (struct grub_relocator *rel, - unsigned i; - grub_addr_t vtarget; - -- err = grub_relocator_alloc_chunk_align (rel, &ch, 0, -- (0xffffffff - stateset_size) -- + 1, stateset_size, -- sizeof (grub_uint32_t), -+ err = grub_relocator_alloc_chunk_align (rel, &ch, 0, UP_TO_TOP32 (stateset_size), -+ stateset_size, sizeof (grub_uint32_t), - GRUB_RELOCATOR_PREFERENCE_NONE, 0); - if (err) - return err; -diff --git a/grub-core/lib/powerpc/relocator.c b/grub-core/lib/powerpc/relocator.c -index bdf2b11..8ffb8b6 100644 ---- a/grub-core/lib/powerpc/relocator.c -+++ b/grub-core/lib/powerpc/relocator.c -@@ -115,10 +115,8 @@ grub_relocator32_boot (struct grub_relocator *rel, - unsigned i; - grub_relocator_chunk_t ch; - -- err = grub_relocator_alloc_chunk_align (rel, &ch, 0, -- (0xffffffff - stateset_size) -- + 1, stateset_size, -- sizeof (grub_uint32_t), -+ err = grub_relocator_alloc_chunk_align (rel, &ch, 0, UP_TO_TOP32 (stateset_size), -+ stateset_size, sizeof (grub_uint32_t), - GRUB_RELOCATOR_PREFERENCE_NONE, 0); - if (err) - return err; -diff --git a/grub-core/lib/x86_64/efi/relocator.c b/grub-core/lib/x86_64/efi/relocator.c -index 3caef7a..7d200a1 100644 ---- a/grub-core/lib/x86_64/efi/relocator.c -+++ b/grub-core/lib/x86_64/efi/relocator.c -@@ -50,10 +50,9 @@ grub_relocator64_efi_boot (struct grub_relocator *rel, - * 64-bit relocator code may live above 4 GiB quite well. - * However, I do not want ask for problems. Just in case. - */ -- err = grub_relocator_alloc_chunk_align (rel, &ch, 0, -- 0x100000000 - RELOCATOR_SIZEOF (64_efi), -- RELOCATOR_SIZEOF (64_efi), 16, -- GRUB_RELOCATOR_PREFERENCE_NONE, 1); -+ err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0, 0x100000000, -+ RELOCATOR_SIZEOF (64_efi), 16, -+ GRUB_RELOCATOR_PREFERENCE_NONE, 1); - if (err) - return err; - -diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c -index 90f2315..7d0c987 100644 ---- a/grub-core/loader/i386/linux.c -+++ b/grub-core/loader/i386/linux.c -@@ -182,9 +182,8 @@ allocate_pages (grub_size_t prot_size, grub_size_t *align, - for (; err && *align + 1 > min_align; (*align)--) - { - grub_errno = GRUB_ERR_NONE; -- err = grub_relocator_alloc_chunk_align (relocator, &ch, -- 0x1000000, -- 0xffffffff & ~prot_size, -+ err = grub_relocator_alloc_chunk_align (relocator, &ch, 0x1000000, -+ UP_TO_TOP32 (prot_size), - prot_size, 1 << *align, - GRUB_RELOCATOR_PREFERENCE_LOW, - 1); -diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c -index ad3cc29..a67d9d0 100644 ---- a/grub-core/loader/i386/multiboot_mbi.c -+++ b/grub-core/loader/i386/multiboot_mbi.c -@@ -466,10 +466,9 @@ grub_multiboot_make_mbi (grub_uint32_t *target) - - bufsize = grub_multiboot_get_mbi_size (); - -- err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, -- 0x10000, 0xa0000 - bufsize, -- bufsize, 4, -- GRUB_RELOCATOR_PREFERENCE_NONE, 0); -+ err = grub_relocator_alloc_chunk_align_safe (grub_multiboot_relocator, &ch, -+ 0x10000, 0xa0000, bufsize, 4, -+ GRUB_RELOCATOR_PREFERENCE_NONE, 0); - if (err) - return err; - ptrorig = get_virtual_current_address (ch); -diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c -index 33d1196..f1ad185 100644 ---- a/grub-core/loader/i386/pc/linux.c -+++ b/grub-core/loader/i386/pc/linux.c -@@ -463,10 +463,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), - - { - grub_relocator_chunk_t ch; -- err = grub_relocator_alloc_chunk_align (relocator, &ch, -- addr_min, addr_max - size, -- size, 0x1000, -- GRUB_RELOCATOR_PREFERENCE_HIGH, 0); -+ err = grub_relocator_alloc_chunk_align_safe (relocator, &ch, addr_min, addr_max, size, -+ 0x1000, GRUB_RELOCATOR_PREFERENCE_HIGH, 0); - if (err) - return err; - initrd_chunk = get_virtual_current_address (ch); -diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c -index 7b723bf..e4ed959 100644 ---- a/grub-core/loader/mips/linux.c -+++ b/grub-core/loader/mips/linux.c -@@ -442,12 +442,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), - { - grub_relocator_chunk_t ch; - -- err = grub_relocator_alloc_chunk_align (relocator, &ch, -- (target_addr & 0x1fffffff) -- + linux_size + 0x10000, -- (0x10000000 - size), -- size, 0x10000, -- GRUB_RELOCATOR_PREFERENCE_NONE, 0); -+ err = grub_relocator_alloc_chunk_align_safe (relocator, &ch, (target_addr & 0x1fffffff) + -+ linux_size + 0x10000, 0x10000000, size, -+ 0x10000, GRUB_RELOCATOR_PREFERENCE_NONE, 0); - - if (err) - goto fail; -diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c -index 3e6ad16..3e28690 100644 ---- a/grub-core/loader/multiboot.c -+++ b/grub-core/loader/multiboot.c -@@ -404,7 +404,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), - { - grub_relocator_chunk_t ch; - err = grub_relocator_alloc_chunk_align (GRUB_MULTIBOOT (relocator), &ch, -- lowest_addr, (0xffffffff - size) + 1, -+ lowest_addr, UP_TO_TOP32 (size), - size, MULTIBOOT_MOD_ALIGN, - GRUB_RELOCATOR_PREFERENCE_NONE, 1); - if (err) -diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c -index cc68536..f2318e0 100644 ---- a/grub-core/loader/multiboot_elfxx.c -+++ b/grub-core/loader/multiboot_elfxx.c -@@ -109,10 +109,10 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) - if (load_size > mld->max_addr || mld->min_addr > mld->max_addr - load_size) - return grub_error (GRUB_ERR_BAD_OS, "invalid min/max address and/or load size"); - -- err = grub_relocator_alloc_chunk_align (GRUB_MULTIBOOT (relocator), &ch, -- mld->min_addr, mld->max_addr - load_size, -- load_size, mld->align ? mld->align : 1, -- mld->preference, mld->avoid_efi_boot_services); -+ err = grub_relocator_alloc_chunk_align_safe (GRUB_MULTIBOOT (relocator), &ch, -+ mld->min_addr, mld->max_addr, -+ load_size, mld->align ? mld->align : 1, -+ mld->preference, mld->avoid_efi_boot_services); - - if (err) - { -@@ -256,7 +256,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) - continue; - - err = grub_relocator_alloc_chunk_align (GRUB_MULTIBOOT (relocator), &ch, 0, -- (0xffffffff - sh->sh_size) + 1, -+ UP_TO_TOP32 (sh->sh_size), - sh->sh_size, sh->sh_addralign, - GRUB_RELOCATOR_PREFERENCE_NONE, - mld->avoid_efi_boot_services); -diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c -index e88c9f4..9a943d7 100644 ---- a/grub-core/loader/multiboot_mbi2.c -+++ b/grub-core/loader/multiboot_mbi2.c -@@ -301,10 +301,10 @@ grub_multiboot2_load (grub_file_t file, const char *filename) - return grub_error (GRUB_ERR_BAD_OS, "invalid min/max address and/or load size"); - } - -- err = grub_relocator_alloc_chunk_align (grub_multiboot2_relocator, &ch, -- mld.min_addr, mld.max_addr - code_size, -- code_size, mld.align ? mld.align : 1, -- mld.preference, keep_bs); -+ err = grub_relocator_alloc_chunk_align_safe (grub_multiboot2_relocator, &ch, -+ mld.min_addr, mld.max_addr, -+ code_size, mld.align ? mld.align : 1, -+ mld.preference, keep_bs); - } - else - err = grub_relocator_alloc_chunk_addr (grub_multiboot2_relocator, -@@ -714,7 +714,7 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) - COMPILE_TIME_ASSERT (MULTIBOOT_TAG_ALIGN % sizeof (grub_properly_aligned_t) == 0); - - err = grub_relocator_alloc_chunk_align (grub_multiboot2_relocator, &ch, -- MBI_MIN_ADDR, 0xffffffff - bufsize, -+ MBI_MIN_ADDR, UP_TO_TOP32 (bufsize), - bufsize, MULTIBOOT_TAG_ALIGN, - GRUB_RELOCATOR_PREFERENCE_NONE, 1); - if (err) -diff --git a/grub-core/loader/xnu_resume.c b/grub-core/loader/xnu_resume.c -index 8089804..d648ef0 100644 ---- a/grub-core/loader/xnu_resume.c -+++ b/grub-core/loader/xnu_resume.c -@@ -129,7 +129,7 @@ grub_xnu_resume (char *imagename) - { - grub_relocator_chunk_t ch; - err = grub_relocator_alloc_chunk_align (grub_xnu_relocator, &ch, 0, -- (0xffffffff - hibhead.image_size) + 1, -+ UP_TO_TOP32 (hibhead.image_size), - hibhead.image_size, - GRUB_XNU_PAGESIZE, - GRUB_RELOCATOR_PREFERENCE_NONE, 0); -diff --git a/include/grub/relocator.h b/include/grub/relocator.h -index 24d8672..1b3bdd9 100644 ---- a/include/grub/relocator.h -+++ b/include/grub/relocator.h -@@ -49,6 +49,35 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel, - int preference, - int avoid_efi_boot_services); - -+/* -+ * Wrapper for grub_relocator_alloc_chunk_align() with purpose of -+ * protecting against integer underflow. -+ * -+ * Compare to its callee, max_addr has different meaning here. -+ * It covers entire chunk and not just start address of the chunk. -+ */ -+static inline grub_err_t -+grub_relocator_alloc_chunk_align_safe (struct grub_relocator *rel, -+ grub_relocator_chunk_t *out, -+ grub_phys_addr_t min_addr, -+ grub_phys_addr_t max_addr, -+ grub_size_t size, grub_size_t align, -+ int preference, -+ int avoid_efi_boot_services) -+{ -+ /* Sanity check and ensure following equation (max_addr - size) is safe. */ -+ if (max_addr < size || (max_addr - size) < min_addr) -+ return GRUB_ERR_OUT_OF_RANGE; -+ -+ return grub_relocator_alloc_chunk_align (rel, out, min_addr, -+ max_addr - size, -+ size, align, preference, -+ avoid_efi_boot_services); -+} -+ -+/* Top 32-bit address minus s bytes and plus 1 byte. */ -+#define UP_TO_TOP32(s) ((~(s) & 0xffffffff) + 1) -+ - #define GRUB_RELOCATOR_PREFERENCE_NONE 0 - #define GRUB_RELOCATOR_PREFERENCE_LOW 1 - #define GRUB_RELOCATOR_PREFERENCE_HIGH 2 --- -2.23.0 - diff --git a/0238-script-Remove-unused-fields-from-grub_script_functio.patch b/0238-script-Remove-unused-fields-from-grub_script_functio.patch deleted file mode 100644 index 3567b6f64594372cf8feac11731011f53928a6dd..0000000000000000000000000000000000000000 --- a/0238-script-Remove-unused-fields-from-grub_script_functio.patch +++ /dev/null @@ -1,33 +0,0 @@ -From 78dc80eec01a56866a0732bf2f808ec26ae45a59 Mon Sep 17 00:00:00 2001 -From: Chris Coulson -Date: Fri, 10 Jul 2020 11:21:14 +0100 -Subject: [PATCH 18/27] script: Remove unused fields from grub_script_function - struct - -Signed-off-by: Chris Coulson -Reviewed-by: Daniel Kiper ---- - include/grub/script_sh.h | 5 ----- - 1 file changed, 5 deletions(-) - -diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h -index 360c2be..b382bcf 100644 ---- a/include/grub/script_sh.h -+++ b/include/grub/script_sh.h -@@ -359,13 +359,8 @@ struct grub_script_function - /* The script function. */ - struct grub_script *func; - -- /* The flags. */ -- unsigned flags; -- - /* The next element. */ - struct grub_script_function *next; -- -- int references; - }; - typedef struct grub_script_function *grub_script_function_t; - --- -2.23.0 - diff --git a/0239-script-Avoid-a-use-after-free-when-redefining-a-func.patch b/0239-script-Avoid-a-use-after-free-when-redefining-a-func.patch deleted file mode 100644 index a48426ee927c4962d93f6fe7cd25febda57144a8..0000000000000000000000000000000000000000 --- a/0239-script-Avoid-a-use-after-free-when-redefining-a-func.patch +++ /dev/null @@ -1,109 +0,0 @@ -From 0b86881d32d66a0d21b71fdb148ec2accba1be6e Mon Sep 17 00:00:00 2001 -From: Chris Coulson -Date: Fri, 10 Jul 2020 14:41:45 +0100 -Subject: [PATCH 19/27] script: Avoid a use-after-free when redefining a - function during execution - -Defining a new function with the same name as a previously defined -function causes the grub_script and associated resources for the -previous function to be freed. If the previous function is currently -executing when a function with the same name is defined, this results -in use-after-frees when processing subsequent commands in the original -function. - -Instead, reject a new function definition if it has the same name as -a previously defined function, and that function is currently being -executed. Although a behavioural change, this should be backwards -compatible with existing configurations because they can't be -dependent on the current behaviour without being broken. - -Fixes: CVE-2020-15706 - -Signed-off-by: Chris Coulson -Reviewed-by: Daniel Kiper ---- - grub-core/script/execute.c | 2 ++ - grub-core/script/function.c | 16 +++++++++++++--- - grub-core/script/parser.y | 3 ++- - include/grub/script_sh.h | 2 ++ - 4 files changed, 19 insertions(+), 4 deletions(-) - -diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c -index b55e171..d2f02cc 100644 ---- a/grub-core/script/execute.c -+++ b/grub-core/script/execute.c -@@ -872,7 +872,9 @@ grub_script_function_call (grub_script_function_t func, int argc, char **args) - old_scope = scope; - scope = &new_scope; - -+ func->executing++; - ret = grub_script_execute (func->func); -+ func->executing--; - - function_return = 0; - active_loops = loops; -diff --git a/grub-core/script/function.c b/grub-core/script/function.c -index d36655e..3aad04b 100644 ---- a/grub-core/script/function.c -+++ b/grub-core/script/function.c -@@ -34,6 +34,7 @@ grub_script_function_create (struct grub_script_arg *functionname_arg, - func = (grub_script_function_t) grub_malloc (sizeof (*func)); - if (! func) - return 0; -+ func->executing = 0; - - func->name = grub_strdup (functionname_arg->str); - if (! func->name) -@@ -60,10 +61,19 @@ grub_script_function_create (struct grub_script_arg *functionname_arg, - grub_script_function_t q; - - q = *p; -- grub_script_free (q->func); -- q->func = cmd; - grub_free (func); -- func = q; -+ if (q->executing > 0) -+ { -+ grub_error (GRUB_ERR_BAD_ARGUMENT, -+ N_("attempt to redefine a function being executed")); -+ func = NULL; -+ } -+ else -+ { -+ grub_script_free (q->func); -+ q->func = cmd; -+ func = q; -+ } - } - else - { -diff --git a/grub-core/script/parser.y b/grub-core/script/parser.y -index 4f0ab83..f80b86b 100644 ---- a/grub-core/script/parser.y -+++ b/grub-core/script/parser.y -@@ -289,7 +289,8 @@ function: "function" "name" - grub_script_mem_free (state->func_mem); - else { - script->children = state->scripts; -- grub_script_function_create ($2, script); -+ if (!grub_script_function_create ($2, script)) -+ grub_script_free (script); - } - - state->scripts = $3; -diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h -index b382bcf..6c48e07 100644 ---- a/include/grub/script_sh.h -+++ b/include/grub/script_sh.h -@@ -361,6 +361,8 @@ struct grub_script_function - - /* The next element. */ - struct grub_script_function *next; -+ -+ unsigned executing; - }; - typedef struct grub_script_function *grub_script_function_t; - --- -2.23.0 - diff --git a/0240-relocator-Fix-grub_relocator_alloc_chunk_align-top-m.patch b/0240-relocator-Fix-grub_relocator_alloc_chunk_align-top-m.patch deleted file mode 100644 index 9df944f5263c2b172405d8edb63969cf34902cb5..0000000000000000000000000000000000000000 --- a/0240-relocator-Fix-grub_relocator_alloc_chunk_align-top-m.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 93ec7ea234ae82499034313df0f63c01cb382520 Mon Sep 17 00:00:00 2001 -From: Alexey Makhalov -Date: Fri, 17 Jul 2020 05:17:26 +0000 -Subject: [PATCH 20/27] relocator: Fix grub_relocator_alloc_chunk_align() top - memory allocation - -Current implementation of grub_relocator_alloc_chunk_align() -does not allow allocation of the top byte. - -Assuming input args are: - max_addr = 0xfffff000; - size = 0x1000; - -And this is valid. But following overflow protection will -unnecessarily move max_addr one byte down (to 0xffffefff): - if (max_addr > ~size) - max_addr = ~size; - -~size + 1 will fix the situation. In addition, check size -for non zero to do not zero max_addr. - -Signed-off-by: Alexey Makhalov -Reviewed-by: Daniel Kiper ---- - grub-core/lib/relocator.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c -index 5847aac..f2c1944 100644 ---- a/grub-core/lib/relocator.c -+++ b/grub-core/lib/relocator.c -@@ -1386,8 +1386,8 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel, - }; - grub_addr_t min_addr2 = 0, max_addr2; - -- if (max_addr > ~size) -- max_addr = ~size; -+ if (size && (max_addr > ~size)) -+ max_addr = ~size + 1; - - #ifdef GRUB_MACHINE_PCBIOS - if (min_addr < 0x1000) --- -2.23.0 - diff --git a/0241-hfsplus-Fix-two-more-overflows.patch b/0241-hfsplus-Fix-two-more-overflows.patch deleted file mode 100644 index 1dbbd029f534bf3c007ba5659ce381ad16dbbffd..0000000000000000000000000000000000000000 --- a/0241-hfsplus-Fix-two-more-overflows.patch +++ /dev/null @@ -1,57 +0,0 @@ -From 0c0c7f7de657dde6994c58e29133a7356f6f672f Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Sun, 19 Jul 2020 14:43:31 -0400 -Subject: [PATCH 21/27] hfsplus: Fix two more overflows - -Both node->size and node->namelen come from the supplied filesystem, -which may be user-supplied. We can't trust them for the math unless we -know they don't overflow. Making sure they go through grub_add() or -grub_calloc() first will give us that. - -Signed-off-by: Peter Jones -Reviewed-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/fs/hfsplus.c | 11 ++++++++--- - 1 file changed, 8 insertions(+), 3 deletions(-) - -diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c -index dae43be..9c4e4c8 100644 ---- a/grub-core/fs/hfsplus.c -+++ b/grub-core/fs/hfsplus.c -@@ -31,6 +31,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -475,8 +476,12 @@ grub_hfsplus_read_symlink (grub_fshelp_node_t node) - { - char *symlink; - grub_ssize_t numread; -+ grub_size_t sz = node->size; - -- symlink = grub_malloc (node->size + 1); -+ if (grub_add (sz, 1, &sz)) -+ return NULL; -+ -+ symlink = grub_malloc (sz); - if (!symlink) - return 0; - -@@ -715,8 +720,8 @@ list_nodes (void *record, void *hook_arg) - if (type == GRUB_FSHELP_UNKNOWN) - return 0; - -- filename = grub_malloc (grub_be_to_cpu16 (catkey->namelen) -- * GRUB_MAX_UTF8_PER_UTF16 + 1); -+ filename = grub_calloc (grub_be_to_cpu16 (catkey->namelen), -+ GRUB_MAX_UTF8_PER_UTF16 + 1); - if (! filename) - return 0; - --- -2.23.0 - diff --git a/0242-lvm-Fix-two-more-potential-data-dependent-alloc-over.patch b/0242-lvm-Fix-two-more-potential-data-dependent-alloc-over.patch deleted file mode 100644 index 3f3cad234181d02f06377d228d781d124128cf61..0000000000000000000000000000000000000000 --- a/0242-lvm-Fix-two-more-potential-data-dependent-alloc-over.patch +++ /dev/null @@ -1,112 +0,0 @@ -From 4a56a951ae3cc8ff25f94a291051b5246f1b828a Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Sun, 19 Jul 2020 15:48:20 -0400 -Subject: [PATCH 22/27] lvm: Fix two more potential data-dependent alloc - overflows - -It appears to be possible to make a (possibly invalid) lvm PV with -a metadata size field that overflows our type when adding it to the -address we've allocated. Even if it doesn't, it may be possible to do so -with the math using the outcome of that as an operand. Check them both. - -Signed-off-by: Peter Jones -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/disk/lvm.c | 48 ++++++++++++++++++++++++++++++++++++-------- - 1 file changed, 40 insertions(+), 8 deletions(-) - -diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c -index 8e76d1a..9f5630c 100644 ---- a/grub-core/disk/lvm.c -+++ b/grub-core/disk/lvm.c -@@ -25,6 +25,7 @@ - #include - #include - #include -+#include - - #ifdef GRUB_UTIL - #include -@@ -102,10 +103,11 @@ grub_lvm_detect (grub_disk_t disk, - { - grub_err_t err; - grub_uint64_t mda_offset, mda_size; -+ grub_size_t ptr; - char buf[GRUB_LVM_LABEL_SIZE]; - char vg_id[GRUB_LVM_ID_STRLEN+1]; - char pv_id[GRUB_LVM_ID_STRLEN+1]; -- char *metadatabuf, *vgname; -+ char *metadatabuf, *mda_end, *vgname; - const char *p, *q; - struct grub_lvm_label_header *lh = (struct grub_lvm_label_header *) buf; - struct grub_lvm_pv_header *pvh; -@@ -206,19 +208,31 @@ grub_lvm_detect (grub_disk_t disk, - grub_le_to_cpu64 (rlocn->size) - - grub_le_to_cpu64 (mdah->size)); - } -- p = q = metadatabuf + grub_le_to_cpu64 (rlocn->offset); - -- while (*q != ' ' && q < metadatabuf + mda_size) -- q++; -- -- if (q == metadatabuf + mda_size) -+ if (grub_add ((grub_size_t)metadatabuf, -+ (grub_size_t)grub_le_to_cpu64 (rlocn->offset), -+ &ptr)) - { -+ error_parsing_metadata: - #ifdef GRUB_UTIL - grub_util_info ("error parsing metadata"); - #endif - goto fail2; - } - -+ p = q = (char *)ptr; -+ -+ if (grub_add ((grub_size_t)metadatabuf, (grub_size_t)mda_size, &ptr)) -+ goto error_parsing_metadata; -+ -+ mda_end = (char *)ptr; -+ -+ while (*q != ' ' && q < mda_end) -+ q++; -+ -+ if (q == mda_end) -+ goto error_parsing_metadata; -+ - vgname_len = q - p; - vgname = grub_malloc (vgname_len + 1); - if (!vgname) -@@ -368,8 +382,26 @@ grub_lvm_detect (grub_disk_t disk, - { - const char *iptr; - char *optr; -- lv->fullname = grub_malloc (sizeof ("lvm/") - 1 + 2 * vgname_len -- + 1 + 2 * s + 1); -+ -+ /* -+ * This is kind of hard to read with our safe (but rather -+ * baroque) math primatives, but it boils down to: -+ * -+ * sz0 = vgname_len * 2 + 1 + -+ * s * 2 + 1 + -+ * sizeof ("lvm/") - 1; -+ */ -+ grub_size_t sz0 = vgname_len, sz1 = s; -+ -+ if (grub_mul (sz0, 2, &sz0) || -+ grub_add (sz0, 1, &sz0) || -+ grub_mul (sz1, 2, &sz1) || -+ grub_add (sz1, 1, &sz1) || -+ grub_add (sz0, sz1, &sz0) || -+ grub_add (sz0, sizeof ("lvm/") - 1, &sz0)) -+ goto lvs_fail; -+ -+ lv->fullname = grub_malloc (sz0); - if (!lv->fullname) - goto lvs_fail; - --- -2.23.0 - diff --git a/0243-efi-Fix-some-malformed-device-path-arithmetic-errors.patch b/0243-efi-Fix-some-malformed-device-path-arithmetic-errors.patch deleted file mode 100644 index 4453d63d0562fe0bc626dd49283f7fd0782f2792..0000000000000000000000000000000000000000 --- a/0243-efi-Fix-some-malformed-device-path-arithmetic-errors.patch +++ /dev/null @@ -1,235 +0,0 @@ -From 8088b8c61e7b45dd8d6115eac72bc718e261e6fe Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Sun, 19 Jul 2020 16:53:27 -0400 -Subject: [PATCH 23/27] efi: Fix some malformed device path arithmetic errors - -Several places we take the length of a device path and subtract 4 from -it, without ever checking that it's >= 4. There are also cases where -this kind of malformation will result in unpredictable iteration, -including treating the length from one dp node as the type in the next -node. These are all errors, no matter where the data comes from. - -This patch adds a checking macro, GRUB_EFI_DEVICE_PATH_VALID(), which -can be used in several places, and makes GRUB_EFI_NEXT_DEVICE_PATH() -return NULL and GRUB_EFI_END_ENTIRE_DEVICE_PATH() evaluate as true when -the length is too small. Additionally, it makes several places in the -code check for and return errors in these cases. - -Signed-off-by: Peter Jones -Reviewed-by: Daniel Kiper ---- - grub-core/kern/efi/efi.c | 64 +++++++++++++++++++++++++----- - grub-core/loader/efi/chainloader.c | 13 +++++- - grub-core/loader/i386/xnu.c | 9 +++-- - include/grub/efi/api.h | 14 ++++--- - 4 files changed, 79 insertions(+), 21 deletions(-) - -diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index ab133fe..d6f7bf0 100644 ---- a/grub-core/kern/efi/efi.c -+++ b/grub-core/kern/efi/efi.c -@@ -350,7 +350,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) - - dp = dp0; - -- while (1) -+ while (dp) - { - grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); - grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); -@@ -360,9 +360,15 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) - if (type == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE - && subtype == GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE) - { -- grub_efi_uint16_t len; -- len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4) -- / sizeof (grub_efi_char16_t)); -+ grub_efi_uint16_t len = GRUB_EFI_DEVICE_PATH_LENGTH (dp); -+ -+ if (len < 4) -+ { -+ grub_error (GRUB_ERR_OUT_OF_RANGE, -+ "malformed EFI Device Path node has length=%d", len); -+ return NULL; -+ } -+ len = (len - 4) / sizeof (grub_efi_char16_t); - filesize += GRUB_MAX_UTF8_PER_UTF16 * len + 2; - } - -@@ -378,7 +384,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) - if (!name) - return NULL; - -- while (1) -+ while (dp) - { - grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); - grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); -@@ -394,8 +400,15 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) - - *p++ = '/'; - -- len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4) -- / sizeof (grub_efi_char16_t)); -+ len = GRUB_EFI_DEVICE_PATH_LENGTH (dp); -+ if (len < 4) -+ { -+ grub_error (GRUB_ERR_OUT_OF_RANGE, -+ "malformed EFI Device Path node has length=%d", len); -+ return NULL; -+ } -+ -+ len = (len - 4) / sizeof (grub_efi_char16_t); - fp = (grub_efi_file_path_device_path_t *) dp; - /* According to EFI spec Path Name is NULL terminated */ - while (len > 0 && fp->path_name[len - 1] == 0) -@@ -470,7 +483,26 @@ grub_efi_duplicate_device_path (const grub_efi_device_path_t *dp) - ; - p = GRUB_EFI_NEXT_DEVICE_PATH (p)) - { -- total_size += GRUB_EFI_DEVICE_PATH_LENGTH (p); -+ grub_size_t len = GRUB_EFI_DEVICE_PATH_LENGTH (p); -+ -+ /* -+ * In the event that we find a node that's completely garbage, for -+ * example if we get to 0x7f 0x01 0x02 0x00 ... (EndInstance with a size -+ * of 2), GRUB_EFI_END_ENTIRE_DEVICE_PATH() will be true and -+ * GRUB_EFI_NEXT_DEVICE_PATH() will return NULL, so we won't continue, -+ * and neither should our consumers, but there won't be any error raised -+ * even though the device path is junk. -+ * -+ * This keeps us from passing junk down back to our caller. -+ */ -+ if (len < 4) -+ { -+ grub_error (GRUB_ERR_OUT_OF_RANGE, -+ "malformed EFI Device Path node has length=%d", len); -+ return NULL; -+ } -+ -+ total_size += len; - if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (p)) - break; - } -@@ -515,7 +547,7 @@ dump_vendor_path (const char *type, grub_efi_vendor_device_path_t *vendor) - void - grub_efi_print_device_path (grub_efi_device_path_t *dp) - { -- while (1) -+ while (GRUB_EFI_DEVICE_PATH_VALID (dp)) - { - grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); - grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); -@@ -987,7 +1019,10 @@ grub_efi_compare_device_paths (const grub_efi_device_path_t *dp1, - /* Return non-zero. */ - return 1; - -- while (1) -+ if (dp1 == dp2) -+ return 0; -+ -+ while (GRUB_EFI_DEVICE_PATH_VALID (dp1) && GRUB_EFI_DEVICE_PATH_VALID (dp2)) - { - grub_efi_uint8_t type1, type2; - grub_efi_uint8_t subtype1, subtype2; -@@ -1023,5 +1058,14 @@ grub_efi_compare_device_paths (const grub_efi_device_path_t *dp1, - dp2 = (grub_efi_device_path_t *) ((char *) dp2 + len2); - } - -+ /* -+ * There's no "right" answer here, but we probably don't want to call a valid -+ * dp and an invalid dp equal, so pick one way or the other. -+ */ -+ if (GRUB_EFI_DEVICE_PATH_VALID (dp1) && !GRUB_EFI_DEVICE_PATH_VALID (dp2)) -+ return 1; -+ else if (!GRUB_EFI_DEVICE_PATH_VALID (dp1) && GRUB_EFI_DEVICE_PATH_VALID (dp2)) -+ return -1; -+ - return 0; - } -diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index 7365051..9a99f04 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -165,9 +165,18 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) - - size = 0; - d = dp; -- while (1) -+ while (d) - { -- size += GRUB_EFI_DEVICE_PATH_LENGTH (d); -+ grub_size_t len = GRUB_EFI_DEVICE_PATH_LENGTH (d); -+ -+ if (len < 4) -+ { -+ grub_error (GRUB_ERR_OUT_OF_RANGE, -+ "malformed EFI Device Path node has length=%d", len); -+ return NULL; -+ } -+ -+ size += len; - if ((GRUB_EFI_END_ENTIRE_DEVICE_PATH (d))) - break; - d = GRUB_EFI_NEXT_DEVICE_PATH (d); -diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c -index e9e1192..a700936 100644 ---- a/grub-core/loader/i386/xnu.c -+++ b/grub-core/loader/i386/xnu.c -@@ -515,14 +515,15 @@ grub_cmd_devprop_load (grub_command_t cmd __attribute__ ((unused)), - - devhead = buf; - buf = devhead + 1; -- dpstart = buf; -+ dp = dpstart = buf; - -- do -+ while (GRUB_EFI_DEVICE_PATH_VALID (dp) && buf < bufend) - { -- dp = buf; - buf = (char *) buf + GRUB_EFI_DEVICE_PATH_LENGTH (dp); -+ if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp)) -+ break; -+ dp = buf; - } -- while (!GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp) && buf < bufend); - - dev = grub_xnu_devprop_add_device (dpstart, (char *) buf - - (char *) dpstart); -diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index dec7b06..fc8a564 100644 ---- a/include/grub/efi/api.h -+++ b/include/grub/efi/api.h -@@ -666,6 +666,7 @@ typedef struct grub_efi_device_path grub_efi_device_path_protocol_t; - #define GRUB_EFI_DEVICE_PATH_TYPE(dp) ((dp)->type & 0x7f) - #define GRUB_EFI_DEVICE_PATH_SUBTYPE(dp) ((dp)->subtype) - #define GRUB_EFI_DEVICE_PATH_LENGTH(dp) ((dp)->length) -+#define GRUB_EFI_DEVICE_PATH_VALID(dp) ((dp) != NULL && GRUB_EFI_DEVICE_PATH_LENGTH (dp) >= 4) - - /* The End of Device Path nodes. */ - #define GRUB_EFI_END_DEVICE_PATH_TYPE (0xff & 0x7f) -@@ -674,13 +675,16 @@ typedef struct grub_efi_device_path grub_efi_device_path_protocol_t; - #define GRUB_EFI_END_THIS_DEVICE_PATH_SUBTYPE 0x01 - - #define GRUB_EFI_END_ENTIRE_DEVICE_PATH(dp) \ -- (GRUB_EFI_DEVICE_PATH_TYPE (dp) == GRUB_EFI_END_DEVICE_PATH_TYPE \ -- && (GRUB_EFI_DEVICE_PATH_SUBTYPE (dp) \ -- == GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE)) -+ (!GRUB_EFI_DEVICE_PATH_VALID (dp) || \ -+ (GRUB_EFI_DEVICE_PATH_TYPE (dp) == GRUB_EFI_END_DEVICE_PATH_TYPE \ -+ && (GRUB_EFI_DEVICE_PATH_SUBTYPE (dp) \ -+ == GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE))) - - #define GRUB_EFI_NEXT_DEVICE_PATH(dp) \ -- ((grub_efi_device_path_t *) ((char *) (dp) \ -- + GRUB_EFI_DEVICE_PATH_LENGTH (dp))) -+ (GRUB_EFI_DEVICE_PATH_VALID (dp) \ -+ ? ((grub_efi_device_path_t *) \ -+ ((char *) (dp) + GRUB_EFI_DEVICE_PATH_LENGTH (dp))) \ -+ : NULL) - - /* Hardware Device Path. */ - #define GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE 1 --- -2.23.0 - diff --git a/0244-efi-chainloader-Propagate-errors-from-copy_file_path.patch b/0244-efi-chainloader-Propagate-errors-from-copy_file_path.patch deleted file mode 100644 index df0d20c3a99b86038548b2c15f2b79f03649e990..0000000000000000000000000000000000000000 --- a/0244-efi-chainloader-Propagate-errors-from-copy_file_path.patch +++ /dev/null @@ -1,74 +0,0 @@ -From 098058752e1cee7b457ff45562a81e756ab0b532 Mon Sep 17 00:00:00 2001 -From: Daniel Kiper -Date: Wed, 29 Jul 2020 13:38:31 +0200 -Subject: [PATCH 24/27] efi/chainloader: Propagate errors from copy_file_path() - -Without any error propagated to the caller, make_file_path() -would then try to advance the invalid device path node with -GRUB_EFI_NEXT_DEVICE_PATH(), which would fail, returning a NULL -pointer that would subsequently be dereferenced. Hence, propagate -errors from copy_file_path(). - -Signed-off-by: Chris Coulson -Reviewed-by: Daniel Kiper ---- - grub-core/loader/efi/chainloader.c | 19 +++++++++++++------ - 1 file changed, 13 insertions(+), 6 deletions(-) - -diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index 9a99f04..813dc0e 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -115,7 +115,7 @@ grub_chainloader_boot (void) - return grub_errno; - } - --static void -+static grub_err_t - copy_file_path (grub_efi_file_path_device_path_t *fp, - const char *str, grub_efi_uint16_t len) - { -@@ -127,7 +127,7 @@ copy_file_path (grub_efi_file_path_device_path_t *fp, - - path_name = grub_calloc (len, GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); - if (!path_name) -- return; -+ return grub_error (GRUB_ERR_OUT_OF_MEMORY, "failed to allocate path buffer"); - - size = grub_utf8_to_utf16 (path_name, len * GRUB_MAX_UTF16_PER_UTF8, - (const grub_uint8_t *) str, len, 0); -@@ -140,6 +140,7 @@ copy_file_path (grub_efi_file_path_device_path_t *fp, - fp->path_name[size++] = '\0'; - fp->header.length = size * sizeof (grub_efi_char16_t) + sizeof (*fp); - grub_free (path_name); -+ return GRUB_ERR_NONE; - } - - static grub_efi_device_path_t * -@@ -197,13 +198,19 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) - /* Fill the file path for the directory. */ - d = (grub_efi_device_path_t *) ((char *) file_path - + ((char *) d - (char *) dp)); -- copy_file_path ((grub_efi_file_path_device_path_t *) d, -- dir_start, dir_end - dir_start); -+ if (copy_file_path ((grub_efi_file_path_device_path_t *) d, -+ dir_start, dir_end - dir_start) != GRUB_ERR_NONE) -+ { -+fail: -+ grub_free(file_path); -+ return 0; -+ } - - /* Fill the file path for the file. */ - d = GRUB_EFI_NEXT_DEVICE_PATH (d); -- copy_file_path ((grub_efi_file_path_device_path_t *) d, -- dir_end + 1, grub_strlen (dir_end + 1)); -+ if (copy_file_path ((grub_efi_file_path_device_path_t *) d, -+ dir_end + 1, grub_strlen (dir_end + 1)) != GRUB_ERR_NONE) -+ goto fail; - - /* Fill the end of device path nodes. */ - d = GRUB_EFI_NEXT_DEVICE_PATH (d); --- -2.23.0 - diff --git a/0245-efi-Fix-use-after-free-in-halt-reboot-path.patch b/0245-efi-Fix-use-after-free-in-halt-reboot-path.patch deleted file mode 100644 index cfc13ab057508f41ccd361bf6b34fd049ba4d5ea..0000000000000000000000000000000000000000 --- a/0245-efi-Fix-use-after-free-in-halt-reboot-path.patch +++ /dev/null @@ -1,179 +0,0 @@ -From f7bd9986f607a924bf23b813900a8595f2815f0c Mon Sep 17 00:00:00 2001 -From: Alexey Makhalov -Date: Mon, 20 Jul 2020 23:03:05 +0000 -Subject: [PATCH 25/27] efi: Fix use-after-free in halt/reboot path - -commit 92bfc33db984 ("efi: Free malloc regions on exit") -introduced memory freeing in grub_efi_fini(), which is -used not only by exit path but by halt/reboot one as well. -As result of memory freeing, code and data regions used by -modules, such as halt, reboot, acpi (used by halt) also got -freed. After return to module code, CPU executes, filled -by UEFI firmware (tested with edk2), 0xAFAFAFAF pattern as -a code. Which leads to #UD exception later. - -grub> halt -!!!! X64 Exception Type - 06(#UD - Invalid Opcode) CPU Apic ID - 00000000 !!!! -RIP - 0000000003F4EC28, CS - 0000000000000038, RFLAGS - 0000000000200246 -RAX - 0000000000000000, RCX - 00000000061DA188, RDX - 0A74C0854DC35D41 -RBX - 0000000003E10E08, RSP - 0000000007F0F860, RBP - 0000000000000000 -RSI - 00000000064DB768, RDI - 000000000832C5C3 -R8 - 0000000000000002, R9 - 0000000000000000, R10 - 00000000061E2E52 -R11 - 0000000000000020, R12 - 0000000003EE5C1F, R13 - 00000000061E0FF4 -R14 - 0000000003E10D80, R15 - 00000000061E2F60 -DS - 0000000000000030, ES - 0000000000000030, FS - 0000000000000030 -GS - 0000000000000030, SS - 0000000000000030 -CR0 - 0000000080010033, CR2 - 0000000000000000, CR3 - 0000000007C01000 -CR4 - 0000000000000668, CR8 - 0000000000000000 -DR0 - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000 -DR3 - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400 -GDTR - 00000000079EEA98 0000000000000047, LDTR - 0000000000000000 -IDTR - 0000000007598018 0000000000000FFF, TR - 0000000000000000 -FXSAVE_STATE - 0000000007F0F4C0 - -Proposal here is to continue to free allocated memory for -exit boot services path but keep it for halt/reboot path -as it won't be much security concern here. -Introduced GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY -loader flag to be used by efi halt/reboot path. - -Signed-off-by: Alexey Makhalov -Reviewed-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/kern/arm/efi/init.c | 3 +++ - grub-core/kern/arm64/efi/init.c | 3 +++ - grub-core/kern/efi/efi.c | 3 ++- - grub-core/kern/efi/init.c | 1 - - grub-core/kern/i386/efi/init.c | 9 +++++++-- - grub-core/kern/ia64/efi/init.c | 9 +++++++-- - grub-core/kern/riscv/efi/init.c | 3 +++ - grub-core/lib/efi/halt.c | 3 ++- - include/grub/loader.h | 1 + - 9 files changed, 28 insertions(+), 7 deletions(-) - -diff --git a/grub-core/kern/arm/efi/init.c b/grub-core/kern/arm/efi/init.c -index 06df60e..40c3b46 100644 ---- a/grub-core/kern/arm/efi/init.c -+++ b/grub-core/kern/arm/efi/init.c -@@ -71,4 +71,7 @@ grub_machine_fini (int flags) - efi_call_1 (b->close_event, tmr_evt); - - grub_efi_fini (); -+ -+ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) -+ grub_efi_memory_fini (); - } -diff --git a/grub-core/kern/arm64/efi/init.c b/grub-core/kern/arm64/efi/init.c -index 6224999..5010cae 100644 ---- a/grub-core/kern/arm64/efi/init.c -+++ b/grub-core/kern/arm64/efi/init.c -@@ -57,4 +57,7 @@ grub_machine_fini (int flags) - return; - - grub_efi_fini (); -+ -+ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) -+ grub_efi_memory_fini (); - } -diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index d6f7bf0..c45c8f4 100644 ---- a/grub-core/kern/efi/efi.c -+++ b/grub-core/kern/efi/efi.c -@@ -157,7 +157,8 @@ grub_efi_get_loaded_image (grub_efi_handle_t image_handle) - void - grub_reboot (void) - { -- grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); -+ grub_machine_fini (GRUB_LOADER_FLAG_NORETURN | -+ GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY); - efi_call_4 (grub_efi_system_table->runtime_services->reset_system, - GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL); - for (;;) ; -diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c -index d1afa3a..2ffb520 100644 ---- a/grub-core/kern/efi/init.c -+++ b/grub-core/kern/efi/init.c -@@ -131,5 +131,4 @@ grub_efi_fini (void) - { - grub_efidisk_fini (); - grub_console_fini (); -- grub_efi_memory_fini (); - } -diff --git a/grub-core/kern/i386/efi/init.c b/grub-core/kern/i386/efi/init.c -index da499ab..deb2eac 100644 ---- a/grub-core/kern/i386/efi/init.c -+++ b/grub-core/kern/i386/efi/init.c -@@ -39,6 +39,11 @@ grub_machine_init (void) - void - grub_machine_fini (int flags) - { -- if (flags & GRUB_LOADER_FLAG_NORETURN) -- grub_efi_fini (); -+ if (!(flags & GRUB_LOADER_FLAG_NORETURN)) -+ return; -+ -+ grub_efi_fini (); -+ -+ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) -+ grub_efi_memory_fini (); - } -diff --git a/grub-core/kern/ia64/efi/init.c b/grub-core/kern/ia64/efi/init.c -index b5ecbd0..f196557 100644 ---- a/grub-core/kern/ia64/efi/init.c -+++ b/grub-core/kern/ia64/efi/init.c -@@ -70,6 +70,11 @@ grub_machine_init (void) - void - grub_machine_fini (int flags) - { -- if (flags & GRUB_LOADER_FLAG_NORETURN) -- grub_efi_fini (); -+ if (!(flags & GRUB_LOADER_FLAG_NORETURN)) -+ return; -+ -+ grub_efi_fini (); -+ -+ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) -+ grub_efi_memory_fini (); - } -diff --git a/grub-core/kern/riscv/efi/init.c b/grub-core/kern/riscv/efi/init.c -index 7eb1969..38795fe 100644 ---- a/grub-core/kern/riscv/efi/init.c -+++ b/grub-core/kern/riscv/efi/init.c -@@ -73,4 +73,7 @@ grub_machine_fini (int flags) - return; - - grub_efi_fini (); -+ -+ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) -+ grub_efi_memory_fini (); - } -diff --git a/grub-core/lib/efi/halt.c b/grub-core/lib/efi/halt.c -index 5859f04..29d4136 100644 ---- a/grub-core/lib/efi/halt.c -+++ b/grub-core/lib/efi/halt.c -@@ -28,7 +28,8 @@ - void - grub_halt (void) - { -- grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); -+ grub_machine_fini (GRUB_LOADER_FLAG_NORETURN | -+ GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY); - #if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__) && \ - !defined(__riscv) - grub_acpi_halt (); -diff --git a/include/grub/loader.h b/include/grub/loader.h -index 7f82a49..b208642 100644 ---- a/include/grub/loader.h -+++ b/include/grub/loader.h -@@ -33,6 +33,7 @@ enum - { - GRUB_LOADER_FLAG_NORETURN = 1, - GRUB_LOADER_FLAG_PXE_NOT_UNLOAD = 2, -+ GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY = 4, - }; - - void EXPORT_FUNC (grub_loader_set) (grub_err_t (*boot) (void), --- -2.23.0 - diff --git a/0246-loader-linux-Avoid-overflow-on-initrd-size-calculati.patch b/0246-loader-linux-Avoid-overflow-on-initrd-size-calculati.patch deleted file mode 100644 index fdfc666ed1d03c5dae85656891119e12f916f5a8..0000000000000000000000000000000000000000 --- a/0246-loader-linux-Avoid-overflow-on-initrd-size-calculati.patch +++ /dev/null @@ -1,28 +0,0 @@ -From cb79f0455946270ddaf6b098d8cd71b39f840edc Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 24 Jul 2020 13:57:27 -0400 -Subject: [PATCH 26/27] loader/linux: Avoid overflow on initrd size calculation - -Signed-off-by: Peter Jones -Reviewed-by: Daniel Kiper ---- - grub-core/loader/linux.c | 3 +-- - 1 file changed, 1 insertion(+), 2 deletions(-) - -diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c -index 471b214..4cd8c20 100644 ---- a/grub-core/loader/linux.c -+++ b/grub-core/loader/linux.c -@@ -151,8 +151,7 @@ grub_initrd_init (int argc, char *argv[], - initrd_ctx->nfiles = 0; - initrd_ctx->components = 0; - -- initrd_ctx->components = grub_zalloc (argc -- * sizeof (initrd_ctx->components[0])); -+ initrd_ctx->components = grub_calloc (argc, sizeof (initrd_ctx->components[0])); - if (!initrd_ctx->components) - return grub_errno; - --- -2.23.0 - diff --git a/0247-linux-Fix-integer-overflows-in-initrd-size-handling.patch b/0247-linux-Fix-integer-overflows-in-initrd-size-handling.patch deleted file mode 100644 index 6deb52d12205a4b0721043d1165bb540a2e803d7..0000000000000000000000000000000000000000 --- a/0247-linux-Fix-integer-overflows-in-initrd-size-handling.patch +++ /dev/null @@ -1,169 +0,0 @@ -From 4edf7dc1bf561beb36fe245348a91d3bde699f15 Mon Sep 17 00:00:00 2001 -From: Colin Watson -Date: Sat, 25 Jul 2020 12:15:37 +0100 -Subject: [PATCH 27/27] linux: Fix integer overflows in initrd size handling - -These could be triggered by a crafted filesystem with very large files. - -Fixes: CVE-2020-15707 - -Signed-off-by: Colin Watson -Reviewed-by: Jan Setje-Eilers -Reviewed-by: Daniel Kiper ---- - grub-core/loader/linux.c | 74 +++++++++++++++++++++++++++++----------- - 1 file changed, 54 insertions(+), 20 deletions(-) - -diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c -index 4cd8c20..3fe390f 100644 ---- a/grub-core/loader/linux.c -+++ b/grub-core/loader/linux.c -@@ -4,6 +4,7 @@ - #include - #include - #include -+#include - - struct newc_head - { -@@ -98,13 +99,13 @@ free_dir (struct dir *root) - grub_free (root); - } - --static grub_size_t -+static grub_err_t - insert_dir (const char *name, struct dir **root, -- grub_uint8_t *ptr) -+ grub_uint8_t *ptr, grub_size_t *size) - { - struct dir *cur, **head = root; - const char *cb, *ce = name; -- grub_size_t size = 0; -+ *size = 0; - while (1) - { - for (cb = ce; *cb == '/'; cb++); -@@ -130,14 +131,22 @@ insert_dir (const char *name, struct dir **root, - ptr = make_header (ptr, name, ce - name, - 040777, 0); - } -- size += ALIGN_UP ((ce - (char *) name) -- + sizeof (struct newc_head), 4); -+ if (grub_add (*size, -+ ALIGN_UP ((ce - (char *) name) -+ + sizeof (struct newc_head), 4), -+ size)) -+ { -+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); -+ grub_free (n->name); -+ grub_free (n); -+ return grub_errno; -+ } - *head = n; - cur = n; - } - root = &cur->next; - } -- return size; -+ return GRUB_ERR_NONE; - } - - grub_err_t -@@ -172,26 +181,33 @@ grub_initrd_init (int argc, char *argv[], - eptr = grub_strchr (ptr, ':'); - if (eptr) - { -+ grub_size_t dir_size, name_len; -+ - initrd_ctx->components[i].newc_name = grub_strndup (ptr, eptr - ptr); -- if (!initrd_ctx->components[i].newc_name) -+ if (!initrd_ctx->components[i].newc_name || -+ insert_dir (initrd_ctx->components[i].newc_name, &root, 0, -+ &dir_size)) - { - grub_initrd_close (initrd_ctx); - return grub_errno; - } -- initrd_ctx->size -- += ALIGN_UP (sizeof (struct newc_head) -- + grub_strlen (initrd_ctx->components[i].newc_name), -- 4); -- initrd_ctx->size += insert_dir (initrd_ctx->components[i].newc_name, -- &root, 0); -+ name_len = grub_strlen (initrd_ctx->components[i].newc_name); -+ if (grub_add (initrd_ctx->size, -+ ALIGN_UP (sizeof (struct newc_head) + name_len, 4), -+ &initrd_ctx->size) || -+ grub_add (initrd_ctx->size, dir_size, &initrd_ctx->size)) -+ goto overflow; - newc = 1; - fname = eptr + 1; - } - } - else if (newc) - { -- initrd_ctx->size += ALIGN_UP (sizeof (struct newc_head) -- + sizeof ("TRAILER!!!") - 1, 4); -+ if (grub_add (initrd_ctx->size, -+ ALIGN_UP (sizeof (struct newc_head) -+ + sizeof ("TRAILER!!!") - 1, 4), -+ &initrd_ctx->size)) -+ goto overflow; - free_dir (root); - root = 0; - newc = 0; -@@ -207,19 +223,29 @@ grub_initrd_init (int argc, char *argv[], - initrd_ctx->nfiles++; - initrd_ctx->components[i].size - = grub_file_size (initrd_ctx->components[i].file); -- initrd_ctx->size += initrd_ctx->components[i].size; -+ if (grub_add (initrd_ctx->size, initrd_ctx->components[i].size, -+ &initrd_ctx->size)) -+ goto overflow; - } - - if (newc) - { - initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4); -- initrd_ctx->size += ALIGN_UP (sizeof (struct newc_head) -- + sizeof ("TRAILER!!!") - 1, 4); -+ if (grub_add (initrd_ctx->size, -+ ALIGN_UP (sizeof (struct newc_head) -+ + sizeof ("TRAILER!!!") - 1, 4), -+ &initrd_ctx->size)) -+ goto overflow; - free_dir (root); - root = 0; - } - - return GRUB_ERR_NONE; -+ -+ overflow: -+ free_dir (root); -+ grub_initrd_close (initrd_ctx); -+ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); - } - - grub_size_t -@@ -260,8 +286,16 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, - - if (initrd_ctx->components[i].newc_name) - { -- ptr += insert_dir (initrd_ctx->components[i].newc_name, -- &root, ptr); -+ grub_size_t dir_size; -+ -+ if (insert_dir (initrd_ctx->components[i].newc_name, &root, ptr, -+ &dir_size)) -+ { -+ free_dir (root); -+ grub_initrd_close (initrd_ctx); -+ return grub_errno; -+ } -+ ptr += dir_size; - ptr = make_header (ptr, initrd_ctx->components[i].newc_name, - grub_strlen (initrd_ctx->components[i].newc_name), - 0100777, --- -2.23.0 - diff --git a/0249-remove-08_fallback_counting.in-apply-grubby.patch b/0249-remove-08_fallback_counting.in-apply-grubby.patch deleted file mode 100644 index 48ea19c588bfc9b1d24ab2b248d30494d9453973..0000000000000000000000000000000000000000 --- a/0249-remove-08_fallback_counting.in-apply-grubby.patch +++ /dev/null @@ -1,61 +0,0 @@ -From f09f144a2f04bd2775367a0df0a2e7900d96d6a1 Mon Sep 17 00:00:00 2001 -From: Fedora Ninjas -Date: Tue, 1 Sep 2020 16:59:53 +0800 -Subject: [PATCH] remove 08_fallback_counting.in apply grubby - ---- - Makefile.util.def | 6 ------ - util/grub.d/08_fallback_counting.in | 24 ------------------------ - 2 files changed, 30 deletions(-) - delete mode 100644 util/grub.d/08_fallback_counting.in - -diff --git a/Makefile.util.def b/Makefile.util.def -index f3a6996..3473947 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -458,12 +458,6 @@ script = { - }; - - script = { -- name = '08_fallback_counting'; -- common = util/grub.d/08_fallback_counting.in; -- installdir = grubconf; --}; -- --script = { - name = '12_menu_auto_hide'; - common = util/grub.d/12_menu_auto_hide.in; - installdir = grubconf; -diff --git a/util/grub.d/08_fallback_counting.in b/util/grub.d/08_fallback_counting.in -deleted file mode 100644 -index 2e2c3ff..0000000 ---- a/util/grub.d/08_fallback_counting.in -+++ /dev/null -@@ -1,24 +0,0 @@ --#! /bin/sh -e --# Fallback Countdown --# --# This snippet depends on 10_reset_boot_success and needs to be kept in sync. --# --# The boot_counter env var can be used to count down boot attempts after an --# OSTree upgrade and choose the rollback deployment when 0 is reached. --# Both boot_counter=X and boot_success=1 need to be set from userspace. --cat << EOF --insmod increment --# Check if boot_counter exists and boot_success=0 to activate this behaviour. --if [ -n "\${boot_counter}" -a "\${boot_success}" = "0" ]; then -- # if countdown has ended, choose to boot rollback deployment, -- # i.e. default=1 on OSTree-based systems. -- if [ "\${boot_counter}" = "0" -o "\${boot_counter}" = "-1" ]; then -- set default=1 -- set boot_counter=-1 -- # otherwise decrement boot_counter -- else -- decrement boot_counter -- fi -- save_env boot_counter --fi --EOF --- -1.8.3.1 - diff --git a/0250-tftp-roll-over-block-counter-to-prevent-timeouts-wit.patch b/0250-tftp-roll-over-block-counter-to-prevent-timeouts-wit.patch deleted file mode 100644 index 6f5a0726a25832e19d484aa23dc8cc8e9412f661..0000000000000000000000000000000000000000 --- a/0250-tftp-roll-over-block-counter-to-prevent-timeouts-wit.patch +++ /dev/null @@ -1,81 +0,0 @@ -From 54e42c1874f75cfe9129e0af0972becc5f9e71f5 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Thu, 10 Sep 2020 17:17:57 +0200 -Subject: [PATCH] tftp: Roll-over block counter to prevent data packets - timeouts - -Commit 781b3e5efc3 (tftp: Do not use priority queue) caused a regression -when fetching files over TFTP whose size is bigger than 65535 * block size. - - grub> linux /images/pxeboot/vmlinuz - grub> echo $? - 0 - grub> initrd /images/pxeboot/initrd.img - error: timeout reading '/images/pxeboot/initrd.img'. - grub> echo $? - 28 - -It is caused by the block number counter being a 16-bit field, which leads -to a maximum file size of ((1 << 16) - 1) * block size. Because GRUB sets -the block size to 1024 octets (by using the TFTP Blocksize Option from RFC -2348 [0]), the maximum file size that can be transferred is 67107840 bytes. - -The TFTP PROTOCOL (REVISION 2) RFC 1350 [1] does not mention what a client -should do when a file size is bigger than the maximum, but most TFTP hosts -support the block number counter to be rolled over. That is, acking a data -packet with a block number of 0 is taken as if the 65356th block was acked. - -It was working before because the block counter roll-over was happening due -an overflow. But that got fixed by the mentioned commit, which led to the -regression when attempting to fetch files larger than the maximum size. - -To allow TFTP file transfers of unlimited size again, re-introduce a block -counter roll-over so the data packets are acked preventing the timeouts. - -[0]: https://tools.ietf.org/html/rfc2348 -[1]: https://tools.ietf.org/html/rfc1350 - -Fixes: 781b3e5efc3 (tftp: Do not use priority queue) - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=a6838bbc6726ad624bd2b94991f690b8e9d23c69 - -Suggested-by: Peter Jones -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - grub-core/net/tftp.c | 17 ++++++++++++++--- - 1 file changed, 14 insertions(+), 3 deletions(-) - -diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c -index c2df3d7..300c5ca 100644 ---- a/grub-core/net/tftp.c -+++ b/grub-core/net/tftp.c -@@ -183,11 +183,22 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)), - return GRUB_ERR_NONE; - } - -- /* Ack old/retransmitted block. */ -- if (grub_be_to_cpu16 (tftph->u.data.block) < data->block + 1) -+ /* -+ * Ack old/retransmitted block. -+ * -+ * The block number is a 16-bit counter, thus the maximum file size that -+ * could be transfered is 65535 * block size. Most TFTP hosts support to -+ * roll-over the block counter to allow unlimited transfer file size. -+ * -+ * This behavior is not defined in the RFC 1350 [0] but is implemented by -+ * most TFTP clients and hosts. -+ * -+ * [0]: https://tools.ietf.org/html/rfc1350 -+ */ -+ if (grub_be_to_cpu16 (tftph->u.data.block) < ((grub_uint16_t) (data->block + 1))) - ack (data, grub_be_to_cpu16 (tftph->u.data.block)); - /* Ignore unexpected block. */ -- else if (grub_be_to_cpu16 (tftph->u.data.block) > data->block + 1) -+ else if (grub_be_to_cpu16 (tftph->u.data.block) > ((grub_uint16_t) (data->block + 1))) - grub_dprintf ("tftp", "TFTP unexpected block # %d\n", tftph->u.data.block); - else - { --- -2.19.1 - diff --git a/backport-0001-CVE-2020-27749.patch b/backport-0001-CVE-2020-27749.patch deleted file mode 100644 index 57f97007333899a8a2e3bf499607149918700089..0000000000000000000000000000000000000000 --- a/backport-0001-CVE-2020-27749.patch +++ /dev/null @@ -1,50 +0,0 @@ -From d06161b035dde4769199ad65aa0a587a5920012b Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Fri, 22 Jan 2021 12:32:41 +0000 -Subject: kern/parser: Fix resource leak if argc == 0 - -After processing the command-line yet arriving at the point where we are -setting argv, we are allocating memory, even if argc == 0, which makes -no sense since we never put anything into the allocated argv. - -The solution is to simply return that we've successfully processed the -arguments but that argc == 0, and also ensure that argv is NULL when -we're not allocating anything in it. - -There are only 2 callers of this function, and both are handling a zero -value in argc assuming nothing is allocated in argv. - -Fixes: CID 96680 - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/kern/parser.c | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c -index 619db31..d1cf061 100644 ---- a/grub-core/kern/parser.c -+++ b/grub-core/kern/parser.c -@@ -146,6 +146,7 @@ grub_parser_split_cmdline (const char *cmdline, - int i; - - *argc = 0; -+ *argv = NULL; - do - { - if (!rd || !*rd) -@@ -207,6 +208,10 @@ grub_parser_split_cmdline (const char *cmdline, - (*argc)++; - } - -+ /* If there are no args, then we're done. */ -+ if (!*argc) -+ return 0; -+ - /* Reserve memory for the return values. */ - args = grub_malloc (bp - buffer); - if (!args) --- -2.23.0 - diff --git a/backport-0001-CVE-2020-27779-and-CVE-2020-14372.patch b/backport-0001-CVE-2020-27779-and-CVE-2020-14372.patch deleted file mode 100644 index 2476441366c2c5606a270585d553d05fda66310b..0000000000000000000000000000000000000000 --- a/backport-0001-CVE-2020-27779-and-CVE-2020-14372.patch +++ /dev/null @@ -1,129 +0,0 @@ -From ea5950d8597278ba9066f24d7abcee403f825668 Mon Sep 17 00:00:00 2001 -From: Marco A Benatto -Date: Wed, 23 Sep 2020 11:33:33 -0400 -Subject: [PATCH 07/46] verifiers: Move verifiers API to kernel image - -Move verifiers API from a module to the kernel image, so it can be -used there as well. There are no functional changes in this patch. - -Signed-off-by: Marco A Benatto -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - grub-core/Makefile.am | 1 + - grub-core/Makefile.core.def | 6 +----- - grub-core/kern/main.c | 4 ++++ - grub-core/{commands => kern}/verifiers.c | 8 ++------ - include/grub/verify.h | 9 ++++++--- - 5 files changed, 14 insertions(+), 14 deletions(-) - rename grub-core/{commands => kern}/verifiers.c (97%) - -diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am -index 5ff3afd62..3569b7101 100644 ---- a/grub-core/Makefile.am -+++ b/grub-core/Makefile.am -@@ -91,6 +91,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/parser.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/partition.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h -+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/verify.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 072b1628c..5cb869f5b 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -140,6 +140,7 @@ kernel = { - common = kern/rescue_reader.c; - common = kern/term.c; - common = kern/backtrace.c; -+ common = kern/verifiers.c; - - x86 = kern/i386/backtrace.c; - i386_xen = kern/i386/backtrace.c; -@@ -943,11 +944,6 @@ module = { - cppflags = '-I$(srcdir)/lib/posix_wrap'; - }; - --module = { -- name = verifiers; -- common = commands/verifiers.c; --}; -- - module = { - name = shim_lock; - common = commands/efi/shim_lock.c; -diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c -index 9cad0c448..73967e2f5 100644 ---- a/grub-core/kern/main.c -+++ b/grub-core/kern/main.c -@@ -29,6 +29,7 @@ - #include - #include - #include -+#include - - #ifdef GRUB_MACHINE_PCBIOS - #include -@@ -274,6 +275,9 @@ grub_main (void) - - grub_boot_time ("After machine init."); - -+ /* Init verifiers API. */ -+ grub_verifiers_init (); -+ - grub_load_config (); - - grub_boot_time ("Before loading embedded modules."); -diff --git a/grub-core/commands/verifiers.c b/grub-core/kern/verifiers.c -similarity index 97% -rename from grub-core/commands/verifiers.c -rename to grub-core/kern/verifiers.c -index 7b9297cd3..3d19bffd1 100644 ---- a/grub-core/commands/verifiers.c -+++ b/grub-core/kern/verifiers.c -@@ -218,12 +218,8 @@ grub_verify_string (char *str, enum grub_verify_string_type type) - return GRUB_ERR_NONE; - } - --GRUB_MOD_INIT(verifiers) -+void -+grub_verifiers_init (void) - { - grub_file_filter_register (GRUB_FILE_FILTER_VERIFY, grub_verifiers_open); - } -- --GRUB_MOD_FINI(verifiers) --{ -- grub_file_filter_unregister (GRUB_FILE_FILTER_VERIFY); --} -diff --git a/include/grub/verify.h b/include/grub/verify.h -index ea0491433..cd129c398 100644 ---- a/include/grub/verify.h -+++ b/include/grub/verify.h -@@ -64,7 +64,10 @@ struct grub_file_verifier - grub_err_t (*verify_string) (char *str, enum grub_verify_string_type type); - }; - --extern struct grub_file_verifier *grub_file_verifiers; -+extern struct grub_file_verifier *EXPORT_VAR (grub_file_verifiers); -+ -+extern void -+grub_verifiers_init (void); - - static inline void - grub_verifier_register (struct grub_file_verifier *ver) -@@ -78,7 +81,7 @@ grub_verifier_unregister (struct grub_file_verifier *ver) - grub_list_remove (GRUB_AS_LIST (ver)); - } - --grub_err_t --grub_verify_string (char *str, enum grub_verify_string_type type); -+extern grub_err_t -+EXPORT_FUNC (grub_verify_string) (char *str, enum grub_verify_string_type type); - - #endif /* ! GRUB_VERIFY_HEADER */ --- -2.26.2 - diff --git a/backport-0001-mmap-Fix-memory-leak-when-iterating-over-mapped-memo.patch b/backport-0001-mmap-Fix-memory-leak-when-iterating-over-mapped-memo.patch deleted file mode 100644 index b3646bb89337df7f894e14cce3503ad04055f42e..0000000000000000000000000000000000000000 --- a/backport-0001-mmap-Fix-memory-leak-when-iterating-over-mapped-memo.patch +++ /dev/null @@ -1,40 +0,0 @@ -From e0cd3c9d4dd8e2f796e32e9cc0061e2298e18ef2 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Thu, 3 Dec 2020 14:39:45 +0000 -Subject: [PATCH] mmap: Fix memory leak when iterating over mapped memory -When returning from grub_mmap_iterate() the memory allocated to present -is not being released causing it to leak. - -Fixes: CID 96655 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=8cb2848f9699642a698af84b12ba187cab722031 - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/mmap/mmap.c | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c -index 3cae683..c8c8312 100644 ---- a/grub-core/mmap/mmap.c -+++ b/grub-core/mmap/mmap.c -@@ -270,6 +270,7 @@ grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data) - hook_data)) - { - grub_free (ctx.scanline_events); -+ grub_free (present); - return GRUB_ERR_NONE; - } - -@@ -282,6 +283,7 @@ grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data) - } - - grub_free (ctx.scanline_events); -+ grub_free (present); - return GRUB_ERR_NONE; - } - --- -2.19.1 - diff --git a/backport-0002-CVE-2020-27749.patch b/backport-0002-CVE-2020-27749.patch deleted file mode 100644 index 51b3c282b3279b8ef5c086df7c2287cbc5927e0f..0000000000000000000000000000000000000000 --- a/backport-0002-CVE-2020-27749.patch +++ /dev/null @@ -1,77 +0,0 @@ -From c6c426e5ab6ea715153b72584de6bd8c82f698ec Mon Sep 17 00:00:00 2001 -From: Chris Coulson -Date: Wed, 18 Nov 2020 00:59:24 +0000 -Subject: kern/parser: Fix a memory leak - -The getline() function supplied to grub_parser_split_cmdline() returns -a newly allocated buffer and can be called multiple times, but the -returned buffer is never freed. - -Signed-off-by: Chris Coulson -Reviewed-by: Daniel Kiper ---- - grub-core/kern/parser.c | 22 +++++++++++++++++----- - 1 file changed, 17 insertions(+), 5 deletions(-) - -diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c -index d1cf061..0163a62 100644 ---- a/grub-core/kern/parser.c -+++ b/grub-core/kern/parser.c -@@ -141,6 +141,7 @@ grub_parser_split_cmdline (const char *cmdline, - char *bp = buffer; - char *rd = (char *) cmdline; - char varname[200]; -+ char *rp = rd; - char *vp = varname; - char *args; - int i; -@@ -149,10 +150,18 @@ grub_parser_split_cmdline (const char *cmdline, - *argv = NULL; - do - { -- if (!rd || !*rd) -- { -+ if (rp == NULL || *rp == '\0') -+ { -+ if (rd != cmdline) -+ { -+ grub_free (rd); -+ rd = rp = NULL; -+ } - if (getline) -- getline (&rd, 1, getline_data); -+ { -+ getline (&rd, 1, getline_data); -+ rp = rd; -+ } - else - break; - } -@@ -160,12 +169,12 @@ grub_parser_split_cmdline (const char *cmdline, - if (!rd) - break; - -- for (; *rd; rd++) -+ for (; *rp != '\0'; rp++) - { - grub_parser_state_t newstate; - char use; - -- newstate = grub_parser_cmdline_state (state, *rd, &use); -+ newstate = grub_parser_cmdline_state (state, *rp, &use); - - /* If a variable was being processed and this character does - not describe the variable anymore, write the variable to -@@ -198,6 +207,9 @@ grub_parser_split_cmdline (const char *cmdline, - } - while (state != GRUB_PARSER_STATE_TEXT && !check_varstate (state)); - -+ if (rd != cmdline) -+ grub_free (rd); -+ - /* A special case for when the last character was part of a - variable. */ - add_var (varname, &bp, &vp, state, GRUB_PARSER_STATE_TEXT); --- -2.23.0 - diff --git a/backport-0002-CVE-2020-27779-and-CVE-2020-14372.patch b/backport-0002-CVE-2020-27779-and-CVE-2020-14372.patch deleted file mode 100644 index 3806ee1ce97e68095f86540ed22a4f7c63a7f83d..0000000000000000000000000000000000000000 --- a/backport-0002-CVE-2020-27779-and-CVE-2020-14372.patch +++ /dev/null @@ -1,430 +0,0 @@ -From 1aebb5645e749917034444b24b88825ea557cae9 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Mon, 28 Sep 2020 20:08:02 +0200 -Subject: [PATCH 09/46] kern: Add lockdown support - -When the GRUB starts on a secure boot platform, some commands can be -used to subvert the protections provided by the verification mechanism and -could lead to booting untrusted system. - -To prevent that situation, allow GRUB to be locked down. That way the code -may check if GRUB has been locked down and further restrict the commands -that are registered or what subset of their functionality could be used. - -The lockdown support adds the following components: - -* The grub_lockdown() function which can be used to lockdown GRUB if, - e.g., UEFI Secure Boot is enabled. - -* The grub_is_lockdown() function which can be used to check if the GRUB - was locked down. - -* A verifier that flags OS kernels, the GRUB modules, Device Trees and ACPI - tables as GRUB_VERIFY_FLAGS_DEFER_AUTH to defer verification to other - verifiers. These files are only successfully verified if another registered - verifier returns success. Otherwise, the whole verification process fails. - - For example, PE/COFF binaries verification can be done by the shim_lock - verifier which validates the signatures using the shim_lock protocol. - However, the verification is not deferred directly to the shim_lock verifier. - The shim_lock verifier is hooked into the verification process instead. - -* A set of grub_{command,extcmd}_lockdown functions that can be used by - code registering command handlers, to only register unsafe commands if - the GRUB has not been locked down. - -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - conf/Makefile.common | 2 + - docs/grub-dev.texi | 27 +++++++++++++ - docs/grub.texi | 8 ++++ - grub-core/Makefile.am | 5 ++- - grub-core/Makefile.core.def | 1 + - grub-core/commands/extcmd.c | 23 +++++++++++ - grub-core/kern/command.c | 24 +++++++++++ - grub-core/kern/lockdown.c | 80 +++++++++++++++++++++++++++++++++++++ - include/grub/command.h | 5 +++ - include/grub/extcmd.h | 7 ++++ - include/grub/lockdown.h | 44 ++++++++++++++++++++ - 11 files changed, 225 insertions(+), 1 deletion(-) - create mode 100644 grub-core/kern/lockdown.c - create mode 100644 include/grub/lockdown.h - -diff --git a/conf/Makefile.common b/conf/Makefile.common -index 6cd71cbb2..2a1a886f6 100644 ---- a/conf/Makefile.common -+++ b/conf/Makefile.common -@@ -84,7 +84,9 @@ CPPFLAGS_PARTTOOL_LIST = -Dgrub_parttool_register=PARTTOOL_LIST_MARKER - CPPFLAGS_TERMINAL_LIST = '-Dgrub_term_register_input(...)=INPUT_TERMINAL_LIST_MARKER(__VA_ARGS__)' - CPPFLAGS_TERMINAL_LIST += '-Dgrub_term_register_output(...)=OUTPUT_TERMINAL_LIST_MARKER(__VA_ARGS__)' - CPPFLAGS_COMMAND_LIST = '-Dgrub_register_command(...)=COMMAND_LIST_MARKER(__VA_ARGS__)' -+CPPFLAGS_COMMAND_LIST += '-Dgrub_register_command_lockdown(...)=COMMAND_LOCKDOWN_LIST_MARKER(__VA_ARGS__)' - CPPFLAGS_COMMAND_LIST += '-Dgrub_register_extcmd(...)=EXTCOMMAND_LIST_MARKER(__VA_ARGS__)' -+CPPFLAGS_COMMAND_LIST += '-Dgrub_register_extcmd_lockdown(...)=EXTCOMMAND_LOCKDOWN_LIST_MARKER(__VA_ARGS__)' - CPPFLAGS_COMMAND_LIST += '-Dgrub_register_command_p1(...)=P1COMMAND_LIST_MARKER(__VA_ARGS__)' - CPPFLAGS_FDT_LIST := '-Dgrub_fdtbus_register(...)=FDT_DRIVER_LIST_MARKER(__VA_ARGS__)' - CPPFLAGS_MARKER = $(CPPFLAGS_FS_LIST) $(CPPFLAGS_VIDEO_LIST) \ -diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi -index ee389fd83..635ec7231 100644 ---- a/docs/grub-dev.texi -+++ b/docs/grub-dev.texi -@@ -86,6 +86,7 @@ This edition documents version @value{VERSION}. - * PFF2 Font File Format:: - * Graphical Menu Software Design:: - * Verifiers framework:: -+* Lockdown framework:: - * Copying This Manual:: Copying This Manual - * Index:: - @end menu -@@ -2086,6 +2087,32 @@ Optionally at the end of the file @samp{fini}, if it exists, is called with just - the context. If you return no error during any of @samp{init}, @samp{write} and - @samp{fini} then the file is considered as having succeded verification. - -+@node Lockdown framework -+@chapter Lockdown framework -+ -+The GRUB can be locked down, which is a restricted mode where some operations -+are not allowed. For instance, some commands cannot be used when the GRUB is -+locked down. -+ -+The function -+@code{grub_lockdown()} is used to lockdown GRUB and the function -+@code{grub_is_lockdown()} function can be used to check whether lockdown is -+enabled or not. When enabled, the function returns @samp{GRUB_LOCKDOWN_ENABLED} -+and @samp{GRUB_LOCKDOWN_DISABLED} when is not enabled. -+ -+The following functions can be used to register the commands that can only be -+used when lockdown is disabled: -+ -+@itemize -+ -+@item @code{grub_cmd_lockdown()} registers command which should not run when the -+GRUB is in lockdown mode. -+ -+@item @code{grub_cmd_lockdown()} registers extended command which should not run -+when the GRUB is in lockdown mode. -+ -+@end itemize -+ - @node Copying This Manual - @appendix Copying This Manual - -diff --git a/docs/grub.texi b/docs/grub.texi -index d3fbc81db..a459a71e4 100644 ---- a/docs/grub.texi -+++ b/docs/grub.texi -@@ -5598,6 +5598,7 @@ environment variables and commands are listed in the same order. - * Using digital signatures:: Booting digitally signed code - * UEFI secure boot and shim:: Booting digitally signed PE files - * Measured Boot:: Measuring boot components -+* Lockdown:: Lockdown when booting on a secure setup - @end menu - - @node Authentication and authorisation -@@ -5812,6 +5813,13 @@ into @file{core.img} in order to avoid a potential gap in measurement between - - Measured boot is currently only supported on EFI platforms. - -+@node Lockdown -+@section Lockdown when booting on a secure setup -+ -+The GRUB can be locked down when booted on a secure boot environment, for example -+if the UEFI secure boot is enabled. On a locked down configuration, the GRUB will -+be restricted and some operations/commands cannot be executed. -+ - @node Platform limitations - @chapter Platform limitations - -diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am -index 3569b7101..6b2e5e139 100644 ---- a/grub-core/Makefile.am -+++ b/grub-core/Makefile.am -@@ -80,6 +80,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fs.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i18n.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/kernel.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/list.h -+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lockdown.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/misc.h - if COND_emu - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/compiler-rt-emu.h -@@ -378,8 +379,10 @@ command.lst: $(MARKER_FILES) - b=`basename $$pp .marker`; \ - sed -n \ - -e "/EXTCOMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \ -+ -e "/EXTCOMMAND_LOCKDOWN_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \ - -e "/P1COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \ -- -e "/COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" $$pp; \ -+ -e "/COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" \ -+ -e "/COMMAND_LOCKDOWN_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" $$pp; \ - done) | sort -u > $@ - platform_DATA += command.lst - CLEANFILES += command.lst -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 8c8f8c579..a00e7f983 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -205,6 +205,7 @@ kernel = { - efi = term/efi/console.c; - efi = kern/acpi.c; - efi = kern/efi/acpi.c; -+ efi = kern/lockdown.c; - efi = lib/envblk.c; - i386_coreboot = kern/i386/pc/acpi.c; - i386_multiboot = kern/i386/pc/acpi.c; -diff --git a/grub-core/commands/extcmd.c b/grub-core/commands/extcmd.c -index 69574e2b0..90a5ca24a 100644 ---- a/grub-core/commands/extcmd.c -+++ b/grub-core/commands/extcmd.c -@@ -19,6 +19,7 @@ - - #include - #include -+#include - #include - #include - #include -@@ -110,6 +111,28 @@ grub_register_extcmd (const char *name, grub_extcmd_func_t func, - summary, description, parser, 1); - } - -+static grub_err_t -+grub_extcmd_lockdown (grub_extcmd_context_t ctxt __attribute__ ((unused)), -+ int argc __attribute__ ((unused)), -+ char **argv __attribute__ ((unused))) -+{ -+ return grub_error (GRUB_ERR_ACCESS_DENIED, -+ N_("%s: the command is not allowed when lockdown is enforced"), -+ ctxt->extcmd->cmd->name); -+} -+ -+grub_extcmd_t -+grub_register_extcmd_lockdown (const char *name, grub_extcmd_func_t func, -+ grub_command_flags_t flags, const char *summary, -+ const char *description, -+ const struct grub_arg_option *parser) -+{ -+ if (grub_is_lockdown () == GRUB_LOCKDOWN_ENABLED) -+ func = grub_extcmd_lockdown; -+ -+ return grub_register_extcmd (name, func, flags, summary, description, parser); -+} -+ - void - grub_unregister_extcmd (grub_extcmd_t ext) - { -diff --git a/grub-core/kern/command.c b/grub-core/kern/command.c -index acd721879..4aabcd4b5 100644 ---- a/grub-core/kern/command.c -+++ b/grub-core/kern/command.c -@@ -17,6 +17,7 @@ - * along with GRUB. If not, see . - */ - -+#include - #include - #include - -@@ -77,6 +78,29 @@ grub_register_command_prio (const char *name, - return cmd; - } - -+static grub_err_t -+grub_cmd_lockdown (grub_command_t cmd __attribute__ ((unused)), -+ int argc __attribute__ ((unused)), -+ char **argv __attribute__ ((unused))) -+ -+{ -+ return grub_error (GRUB_ERR_ACCESS_DENIED, -+ N_("%s: the command is not allowed when lockdown is enforced"), -+ cmd->name); -+} -+ -+grub_command_t -+grub_register_command_lockdown (const char *name, -+ grub_command_func_t func, -+ const char *summary, -+ const char *description) -+{ -+ if (grub_is_lockdown () == GRUB_LOCKDOWN_ENABLED) -+ func = grub_cmd_lockdown; -+ -+ return grub_register_command_prio (name, func, summary, description, 0); -+} -+ - void - grub_unregister_command (grub_command_t cmd) - { -diff --git a/grub-core/kern/lockdown.c b/grub-core/kern/lockdown.c -new file mode 100644 -index 000000000..1e56c0b80 ---- /dev/null -+++ b/grub-core/kern/lockdown.c -@@ -0,0 +1,80 @@ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2020 Free Software Foundation, Inc. -+ * -+ * GRUB is free software: you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation, either version 3 of the License, or -+ * (at your option) any later version. -+ * -+ * GRUB is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with GRUB. If not, see . -+ * -+ */ -+ -+#include -+#include -+#include -+#include -+ -+static int lockdown = GRUB_LOCKDOWN_DISABLED; -+ -+static grub_err_t -+lockdown_verifier_init (grub_file_t io __attribute__ ((unused)), -+ enum grub_file_type type, -+ void **context __attribute__ ((unused)), -+ enum grub_verify_flags *flags) -+{ -+ *flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION; -+ -+ switch (type & GRUB_FILE_TYPE_MASK) -+ { -+ case GRUB_FILE_TYPE_GRUB_MODULE: -+ case GRUB_FILE_TYPE_LINUX_KERNEL: -+ case GRUB_FILE_TYPE_MULTIBOOT_KERNEL: -+ case GRUB_FILE_TYPE_XEN_HYPERVISOR: -+ case GRUB_FILE_TYPE_BSD_KERNEL: -+ case GRUB_FILE_TYPE_XNU_KERNEL: -+ case GRUB_FILE_TYPE_PLAN9_KERNEL: -+ case GRUB_FILE_TYPE_NTLDR: -+ case GRUB_FILE_TYPE_TRUECRYPT: -+ case GRUB_FILE_TYPE_FREEDOS: -+ case GRUB_FILE_TYPE_PXECHAINLOADER: -+ case GRUB_FILE_TYPE_PCCHAINLOADER: -+ case GRUB_FILE_TYPE_COREBOOT_CHAINLOADER: -+ case GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE: -+ case GRUB_FILE_TYPE_ACPI_TABLE: -+ case GRUB_FILE_TYPE_DEVICE_TREE_IMAGE: -+ *flags = GRUB_VERIFY_FLAGS_DEFER_AUTH; -+ -+ /* Fall through. */ -+ -+ default: -+ return GRUB_ERR_NONE; -+ } -+} -+ -+struct grub_file_verifier lockdown_verifier = -+ { -+ .name = "lockdown_verifier", -+ .init = lockdown_verifier_init, -+ }; -+ -+void -+grub_lockdown (void) -+{ -+ lockdown = GRUB_LOCKDOWN_ENABLED; -+ -+ grub_verifier_register (&lockdown_verifier); -+} -+ -+int -+grub_is_lockdown (void) -+{ -+ return lockdown; -+} -diff --git a/include/grub/command.h b/include/grub/command.h -index eee4e847e..2a6f7f846 100644 ---- a/include/grub/command.h -+++ b/include/grub/command.h -@@ -86,6 +86,11 @@ EXPORT_FUNC(grub_register_command_prio) (const char *name, - const char *summary, - const char *description, - int prio); -+grub_command_t -+EXPORT_FUNC(grub_register_command_lockdown) (const char *name, -+ grub_command_func_t func, -+ const char *summary, -+ const char *description); - void EXPORT_FUNC(grub_unregister_command) (grub_command_t cmd); - - static inline grub_command_t -diff --git a/include/grub/extcmd.h b/include/grub/extcmd.h -index 19fe59266..fe9248b8b 100644 ---- a/include/grub/extcmd.h -+++ b/include/grub/extcmd.h -@@ -62,6 +62,13 @@ grub_extcmd_t EXPORT_FUNC(grub_register_extcmd) (const char *name, - const char *description, - const struct grub_arg_option *parser); - -+grub_extcmd_t EXPORT_FUNC(grub_register_extcmd_lockdown) (const char *name, -+ grub_extcmd_func_t func, -+ grub_command_flags_t flags, -+ const char *summary, -+ const char *description, -+ const struct grub_arg_option *parser); -+ - grub_extcmd_t EXPORT_FUNC(grub_register_extcmd_prio) (const char *name, - grub_extcmd_func_t func, - grub_command_flags_t flags, -diff --git a/include/grub/lockdown.h b/include/grub/lockdown.h -new file mode 100644 -index 000000000..40531fa82 ---- /dev/null -+++ b/include/grub/lockdown.h -@@ -0,0 +1,44 @@ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2020 Free Software Foundation, Inc. -+ * -+ * GRUB is free software: you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation, either version 3 of the License, or -+ * (at your option) any later version. -+ * -+ * GRUB is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with GRUB. If not, see . -+ */ -+ -+#ifndef GRUB_LOCKDOWN_H -+#define GRUB_LOCKDOWN_H 1 -+ -+#include -+ -+#define GRUB_LOCKDOWN_DISABLED 0 -+#define GRUB_LOCKDOWN_ENABLED 1 -+ -+#ifdef GRUB_MACHINE_EFI -+extern void -+EXPORT_FUNC (grub_lockdown) (void); -+extern int -+EXPORT_FUNC (grub_is_lockdown) (void); -+#else -+static inline void -+grub_lockdown (void) -+{ -+} -+ -+static inline int -+grub_is_lockdown (void) -+{ -+ return GRUB_LOCKDOWN_DISABLED; -+} -+#endif -+#endif /* ! GRUB_LOCKDOWN_H */ --- -2.26.2 - diff --git a/backport-0002-net-net-Fix-possible-dereference-to-of-a-NULL-pointe.patch b/backport-0002-net-net-Fix-possible-dereference-to-of-a-NULL-pointe.patch deleted file mode 100644 index c4c03e04dc6e8c5aba414722051020c244698d38..0000000000000000000000000000000000000000 --- a/backport-0002-net-net-Fix-possible-dereference-to-of-a-NULL-pointe.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 1600d11874762eab2235555e0171215cf9258da5 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Fri, 27 Nov 2020 15:10:26 +0000 -Subject: [PATCH] net/net: Fix possible dereference to of a NULL pointer - -It is always possible that grub_zalloc() could fail, so we should check for -a NULL return. Otherwise we run the risk of dereferencing a NULL pointer. - -Fixes: CID 296221 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=03f2515ae0c503406f1a99a2178405049c6555db ---- - grub-core/net/net.c | 9 +++++++-- - 1 file changed, 7 insertions(+), 2 deletions(-) - -diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index ad024c9..d2fac17 100644 ---- a/grub-core/net/net.c -+++ b/grub-core/net/net.c -@@ -89,8 +89,13 @@ grub_net_link_layer_add_address (struct grub_net_card *card, - - /* Add sender to cache table. */ - if (card->link_layer_table == NULL) -- card->link_layer_table = grub_zalloc (LINK_LAYER_CACHE_SIZE -- * sizeof (card->link_layer_table[0])); -+ { -+ card->link_layer_table = grub_zalloc (LINK_LAYER_CACHE_SIZE -+ * sizeof (card->link_layer_table[0])); -+ if (card->link_layer_table == NULL) -+ return; -+ } -+ - entry = &(card->link_layer_table[card->new_ll_entry]); - entry->avail = 1; - grub_memcpy (&entry->ll_address, ll, sizeof (entry->ll_address)); --- -2.19.1 - diff --git a/backport-0003-CVE-2020-27749.patch b/backport-0003-CVE-2020-27749.patch deleted file mode 100644 index 4cfac0aab4aff60e63f71e23153586093da78e70..0000000000000000000000000000000000000000 --- a/backport-0003-CVE-2020-27749.patch +++ /dev/null @@ -1,119 +0,0 @@ -From b1c9e9e889e4273fb15712051c887e6078511448 Mon Sep 17 00:00:00 2001 -From: Chris Coulson -Date: Tue, 5 Jan 2021 22:17:28 +0000 -Subject: kern/parser: Introduce process_char() helper - -grub_parser_split_cmdline() iterates over each command line character. -In order to add error checking and to simplify the subsequent error -handling, split the character processing in to a separate function. - -Signed-off-by: Chris Coulson -Reviewed-by: Daniel Kiper ---- - grub-core/kern/parser.c | 74 +++++++++++++++++++++++++---------------- - 1 file changed, 46 insertions(+), 28 deletions(-) - -diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c -index 0163a62..7e1ba99 100644 ---- a/grub-core/kern/parser.c -+++ b/grub-core/kern/parser.c -@@ -1,7 +1,7 @@ - /* parser.c - the part of the parser that can return partial tokens */ - /* - * GRUB -- GRand Unified Bootloader -- * Copyright (C) 2005,2007,2009 Free Software Foundation, Inc. -+ * Copyright (C) 2005,2007,2009,2021 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by -@@ -129,6 +129,46 @@ add_var (char *varname, char **bp, char **vp, - *((*bp)++) = *val; - } - -+static grub_err_t -+process_char (char c, char *buffer, char **bp, char *varname, char **vp, -+ grub_parser_state_t state, int *argc, -+ grub_parser_state_t *newstate) -+{ -+ char use; -+ -+ *newstate = grub_parser_cmdline_state (state, c, &use); -+ -+ /* -+ * If a variable was being processed and this character does -+ * not describe the variable anymore, write the variable to -+ * the buffer. -+ */ -+ add_var (varname, bp, vp, state, *newstate); -+ -+ if (check_varstate (*newstate)) -+ { -+ if (use) -+ *((*vp)++) = use; -+ } -+ else if (*newstate == GRUB_PARSER_STATE_TEXT && -+ state != GRUB_PARSER_STATE_ESC && grub_isspace (use)) -+ { -+ /* -+ * Don't add more than one argument if multiple -+ * spaces are used. -+ */ -+ if (*bp != buffer && *((*bp) - 1) != '\0') -+ { -+ *((*bp)++) = '\0'; -+ (*argc)++; -+ } -+ } -+ else if (use) -+ *((*bp)++) = use; -+ -+ return GRUB_ERR_NONE; -+} -+ - grub_err_t - grub_parser_split_cmdline (const char *cmdline, - grub_reader_getline_t getline, void *getline_data, -@@ -172,35 +212,13 @@ grub_parser_split_cmdline (const char *cmdline, - for (; *rp != '\0'; rp++) - { - grub_parser_state_t newstate; -- char use; -- -- newstate = grub_parser_cmdline_state (state, *rp, &use); - -- /* If a variable was being processed and this character does -- not describe the variable anymore, write the variable to -- the buffer. */ -- add_var (varname, &bp, &vp, state, newstate); -- -- if (check_varstate (newstate)) -- { -- if (use) -- *(vp++) = use; -- } -- else -+ if (process_char (*rp, buffer, &bp, varname, &vp, state, argc, -+ &newstate) != GRUB_ERR_NONE) - { -- if (newstate == GRUB_PARSER_STATE_TEXT -- && state != GRUB_PARSER_STATE_ESC && grub_isspace (use)) -- { -- /* Don't add more than one argument if multiple -- spaces are used. */ -- if (bp != buffer && *(bp - 1)) -- { -- *(bp++) = '\0'; -- (*argc)++; -- } -- } -- else if (use) -- *(bp++) = use; -+ if (rd != cmdline) -+ grub_free (rd); -+ return grub_errno; - } - state = newstate; - } --- -2.23.0 - diff --git a/backport-0003-CVE-2020-27779-and-CVE-2020-14372.patch b/backport-0003-CVE-2020-27779-and-CVE-2020-14372.patch deleted file mode 100644 index e785f4a191a8dc5480ca92cb7b1049c6c42b6926..0000000000000000000000000000000000000000 --- a/backport-0003-CVE-2020-27779-and-CVE-2020-14372.patch +++ /dev/null @@ -1,57 +0,0 @@ -From 959db537b12c5e76c244ccc51cbbed7f27b0abe2 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 2 Feb 2021 19:59:48 +0100 -Subject: [PATCH 10/46] kern/lockdown: Set a variable if the GRUB is locked - down - -It may be useful for scripts to determine whether the GRUB is locked -down or not. Add the lockdown variable which is set to "y" when the GRUB -is locked down. - -Suggested-by: Dimitri John Ledkov -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - docs/grub.texi | 3 +++ - grub-core/kern/lockdown.c | 4 ++++ - 2 files changed, 7 insertions(+) - -diff --git a/docs/grub.texi b/docs/grub.texi -index a459a71e4..3a4d18e06 100644 ---- a/docs/grub.texi -+++ b/docs/grub.texi -@@ -5820,6 +5820,9 @@ The GRUB can be locked down when booted on a secure boot environment, for exampl - if the UEFI secure boot is enabled. On a locked down configuration, the GRUB will - be restricted and some operations/commands cannot be executed. - -+The @samp{lockdown} variable is set to @samp{y} when the GRUB is locked down. -+Otherwise it does not exit. -+ - @node Platform limitations - @chapter Platform limitations - -diff --git a/grub-core/kern/lockdown.c b/grub-core/kern/lockdown.c -index 1e56c0b80..0bc70fd42 100644 ---- a/grub-core/kern/lockdown.c -+++ b/grub-core/kern/lockdown.c -@@ -18,6 +18,7 @@ - */ - - #include -+#include - #include - #include - #include -@@ -71,6 +72,9 @@ grub_lockdown (void) - lockdown = GRUB_LOCKDOWN_ENABLED; - - grub_verifier_register (&lockdown_verifier); -+ -+ grub_env_set ("lockdown", "y"); -+ grub_env_export ("lockdown"); - } - - int --- -2.26.2 - diff --git a/backport-0003-net-tftp-Fix-dangling-memory-pointer.patch b/backport-0003-net-tftp-Fix-dangling-memory-pointer.patch deleted file mode 100644 index 0b058919d997efdb57618b837c0965e1d191f2fe..0000000000000000000000000000000000000000 --- a/backport-0003-net-tftp-Fix-dangling-memory-pointer.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 7d02eb14ad9119643e9727b11efff13662fe9063 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Fri, 19 Feb 2021 17:12:23 +0000 -Subject: [PATCH] net/tftp: Fix dangling memory pointer - -The static code analysis tool, Parfait, reported that the valid of -file->data was left referencing memory that was freed by the call to -grub_free(data) where data was initialized from file->data. - -To ensure that there is no unintentional access to this memory -referenced by file->data we should set the pointer to NULL. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/grub-core/net/tftp.c?id=0cb838b281a68b536a09681f9557ea6a7ac5da7a - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/net/tftp.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c -index c054072..658caa2 100644 ---- a/grub-core/net/tftp.c -+++ b/grub-core/net/tftp.c -@@ -448,6 +448,7 @@ tftp_close (struct grub_file *file) - grub_net_udp_close (data->sock); - } - grub_free (data); -+ file->data = NULL; - return GRUB_ERR_NONE; - } - --- -2.19.1 - diff --git a/backport-0004-CVE-2020-27749.patch b/backport-0004-CVE-2020-27749.patch deleted file mode 100644 index bec946ebe865ede498de3d3e651f0c0ea3ab7cc1..0000000000000000000000000000000000000000 --- a/backport-0004-CVE-2020-27749.patch +++ /dev/null @@ -1,65 +0,0 @@ -From 3d157bbd06506b170fde5ec23980c4bf9f7660e2 Mon Sep 17 00:00:00 2001 -From: Chris Coulson -Date: Thu, 7 Jan 2021 19:53:55 +0000 -Subject: kern/parser: Introduce terminate_arg() helper - -process_char() and grub_parser_split_cmdline() use similar code for -terminating the most recent argument. Add a helper function for this. - -Signed-off-by: Chris Coulson -Reviewed-by: Daniel Kiper ---- - grub-core/kern/parser.c | 23 +++++++++++++---------- - 1 file changed, 13 insertions(+), 10 deletions(-) - -diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c -index 7e1ba99..45d0871 100644 ---- a/grub-core/kern/parser.c -+++ b/grub-core/kern/parser.c -@@ -129,6 +129,16 @@ add_var (char *varname, char **bp, char **vp, - *((*bp)++) = *val; - } - -+static void -+terminate_arg (char *buffer, char **bp, int *argc) -+{ -+ if (*bp != buffer && *((*bp) - 1) != '\0') -+ { -+ *((*bp)++) = '\0'; -+ (*argc)++; -+ } -+} -+ - static grub_err_t - process_char (char c, char *buffer, char **bp, char *varname, char **vp, - grub_parser_state_t state, int *argc, -@@ -157,11 +167,7 @@ process_char (char c, char *buffer, char **bp, char *varname, char **vp, - * Don't add more than one argument if multiple - * spaces are used. - */ -- if (*bp != buffer && *((*bp) - 1) != '\0') -- { -- *((*bp)++) = '\0'; -- (*argc)++; -- } -+ terminate_arg (buffer, bp, argc); - } - else if (use) - *((*bp)++) = use; -@@ -232,11 +238,8 @@ grub_parser_split_cmdline (const char *cmdline, - variable. */ - add_var (varname, &bp, &vp, state, GRUB_PARSER_STATE_TEXT); - -- if (bp != buffer && *(bp - 1)) -- { -- *(bp++) = '\0'; -- (*argc)++; -- } -+ /* Ensure that the last argument is terminated. */ -+ terminate_arg (buffer, &bp, argc); - - /* If there are no args, then we're done. */ - if (!*argc) --- -2.23.0 - diff --git a/backport-0004-CVE-2020-27779-and-CVE-2020-14372.patch b/backport-0004-CVE-2020-27779-and-CVE-2020-14372.patch deleted file mode 100644 index aea97f9e8e3ca80f615711b78b9bbebb80def512..0000000000000000000000000000000000000000 --- a/backport-0004-CVE-2020-27779-and-CVE-2020-14372.patch +++ /dev/null @@ -1,54 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Mon, 28 Sep 2020 20:08:29 +0200 -Subject: [PATCH] efi: Lockdown the GRUB when the UEFI Secure Boot is enabled - -If the UEFI Secure Boot is enabled then the GRUB must be locked down -to prevent executing code that can potentially be used to subvert its -verification mechanisms. - -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - grub-core/kern/efi/init.c | 19 +++++++++++++++++++ - 1 file changed, 19 insertions(+) - -diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c -index 2ffb520..634e3ac 100644 ---- a/grub-core/kern/efi/init.c -+++ b/grub-core/kern/efi/init.c -@@ -20,6 +20,8 @@ - #include - #include - #include -+#include -+#include - #include - #include - #include -@@ -88,6 +90,23 @@ grub_efi_init (void) - /* Initialize the memory management system. */ - grub_efi_mm_init (); - -+ /* -+ * Lockdown the GRUB and register the shim_lock verifier -+ * if the UEFI Secure Boot is enabled. -+ */ -+ if (grub_efi_secure_boot ()) -+ { -+ grub_lockdown (); -+ -+ /* -+ * TODO: Move GRUB to using the shim_lock verifier and -+ * enable the lockdown verifier. -+ */ -+#if 0 -+ grub_shim_lock_verifier_setup (); -+#endif -+ } -+ - efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer, - 0, 0, 0, NULL); - --- -2.23.0 \ No newline at end of file diff --git a/backport-0004-kern-efi-Fix-memory-leak-on-failure.patch b/backport-0004-kern-efi-Fix-memory-leak-on-failure.patch deleted file mode 100644 index dbc8de8000dcd3280e9519376ebb49a2e0e92852..0000000000000000000000000000000000000000 --- a/backport-0004-kern-efi-Fix-memory-leak-on-failure.patch +++ /dev/null @@ -1,31 +0,0 @@ -From b62f77df4d5582bf0999f92f3cf53cb6e3c100ec Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Thu, 5 Nov 2020 10:15:25 +0000 -Subject: [PATCH] kern/efi: Fix memory leak on failure -Free the memory allocated to name before returning on failure. - -Fixes: CID 296222 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=ed286ceba6015d37a9304f04602451c47bf195d7 - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/kern/efi/efi.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index c45c8f4..f3e24f9 100644 ---- a/grub-core/kern/efi/efi.c -+++ b/grub-core/kern/efi/efi.c -@@ -406,6 +406,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, - "malformed EFI Device Path node has length=%d", len); -+ grub_free (name); - return NULL; - } - --- -2.19.1 - diff --git a/backport-0005-CVE-2020-27749.patch b/backport-0005-CVE-2020-27749.patch deleted file mode 100644 index 4cf21e0ace6c9854c50a246eb1247025940096c0..0000000000000000000000000000000000000000 --- a/backport-0005-CVE-2020-27749.patch +++ /dev/null @@ -1,90 +0,0 @@ -From 8bc817014ce3d7a498db44eae33c8b90e2430926 Mon Sep 17 00:00:00 2001 -From: Chris Coulson -Date: Wed, 6 Jan 2021 13:54:26 +0000 -Subject: kern/parser: Refactor grub_parser_split_cmdline() cleanup - -Introduce a common function epilogue used for cleaning up on all -return paths, which will simplify additional error handling to be -introduced in a subsequent commit. - -Signed-off-by: Chris Coulson -Reviewed-by: Daniel Kiper ---- - grub-core/kern/parser.c | 35 ++++++++++++++++++++--------------- - 1 file changed, 20 insertions(+), 15 deletions(-) - -diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c -index 572c67089..e010eaa1f 100644 ---- a/grub-core/kern/parser.c -+++ b/grub-core/kern/parser.c -@@ -221,19 +221,13 @@ grub_parser_split_cmdline (const char *cmdline, - - if (process_char (*rp, buffer, &bp, varname, &vp, state, argc, - &newstate) != GRUB_ERR_NONE) -- { -- if (rd != cmdline) -- grub_free (rd); -- return grub_errno; -- } -+ goto fail; -+ - state = newstate; - } - } - while (state != GRUB_PARSER_STATE_TEXT && !check_varstate (state)); - -- if (rd != cmdline) -- grub_free (rd); -- - /* A special case for when the last character was part of a - variable. */ - add_var (varname, &bp, &vp, state, GRUB_PARSER_STATE_TEXT); -@@ -243,20 +237,20 @@ grub_parser_split_cmdline (const char *cmdline, - - /* If there are no args, then we're done. */ - if (!*argc) -- return 0; -+ { -+ grub_errno = GRUB_ERR_NONE; -+ goto out; -+ } - - /* Reserve memory for the return values. */ - args = grub_malloc (bp - buffer); - if (!args) -- return grub_errno; -+ goto fail; - grub_memcpy (args, buffer, bp - buffer); - - *argv = grub_calloc (*argc + 1, sizeof (char *)); - if (!*argv) -- { -- grub_free (args); -- return grub_errno; -- } -+ goto fail; - - /* The arguments are separated with 0's, setup argv so it points to - the right values. */ -@@ -269,7 +263,18 @@ grub_parser_split_cmdline (const char *cmdline, - bp++; - } - -- return 0; -+ grub_errno = GRUB_ERR_NONE; -+ -+ out: -+ if (rd != cmdline) -+ grub_free (rd); -+ -+ return grub_errno; -+ -+ fail: -+ grub_free (*argv); -+ grub_free (args); -+ goto out; - } - - /* Helper for grub_parser_execute. */ --- -cgit v1.2.1 \ No newline at end of file diff --git a/backport-0005-CVE-2020-27779-and-CVE-2020-14372.patch b/backport-0005-CVE-2020-27779-and-CVE-2020-14372.patch deleted file mode 100644 index 0402b170565dc564cb595db759c18600c411b355..0000000000000000000000000000000000000000 --- a/backport-0005-CVE-2020-27779-and-CVE-2020-14372.patch +++ /dev/null @@ -1,129 +0,0 @@ -From 8f73052885892bc0dbc01e297f79d7cf4925e491 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Mon, 28 Sep 2020 20:08:33 +0200 -Subject: efi: Use grub_is_lockdown() instead of hardcoding a disabled modules - list - -Now the GRUB can check if it has been locked down and this can be used to -prevent executing commands that can be utilized to circumvent the UEFI -Secure Boot mechanisms. So, instead of hardcoding a list of modules that -have to be disabled, prevent the usage of commands that can be dangerous. - -This not only allows the commands to be disabled on other platforms, but -also properly separate the concerns. Since the shim_lock verifier logic -should be only about preventing to run untrusted binaries and not about -defining these kind of policies. - -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - docs/grub.texi | 15 +++++++----- - grub-core/commands/i386/wrmsr.c | 5 ++-- - grub-core/commands/iorw.c | 19 +++++++-------- - grub-core/commands/memrw.c | 19 +++++++-------- - 4 files changed, 32 insertions(+), 67 deletions(-) - -diff --git a/grub-core/commands/i386/wrmsr.c b/grub-core/commands/i386/wrmsr.c -index 9c5e510eb..56a29c29f 100644 ---- a/grub-core/commands/i386/wrmsr.c -+++ b/grub-core/commands/i386/wrmsr.c -@@ -24,6 +24,7 @@ - #include - #include - #include -+#include - #include - #include - #include -@@ -83,8 +84,8 @@ grub_cmd_msr_write (grub_command_t cmd __attribute__ ((unused)), int argc, char - - GRUB_MOD_INIT(wrmsr) - { -- cmd_write = grub_register_command ("wrmsr", grub_cmd_msr_write, N_("ADDR VALUE"), -- N_("Write a value to a CPU model specific register.")); -+ cmd_write = grub_register_command_lockdown ("wrmsr", grub_cmd_msr_write, N_("ADDR VALUE"), -+ N_("Write a value to a CPU model specific register.")); - } - - GRUB_MOD_FINI(wrmsr) -diff --git a/grub-core/commands/iorw.c b/grub-core/commands/iorw.c -index a0c164e54..584baec8f 100644 ---- a/grub-core/commands/iorw.c -+++ b/grub-core/commands/iorw.c -@@ -23,6 +23,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -131,17 +132,17 @@ GRUB_MOD_INIT(memrw) - N_("PORT"), N_("Read 32-bit value from PORT."), - options); - cmd_write_byte = -- grub_register_command ("outb", grub_cmd_write, -- N_("PORT VALUE [MASK]"), -- N_("Write 8-bit VALUE to PORT.")); -+ grub_register_command_lockdown ("outb", grub_cmd_write, -+ N_("PORT VALUE [MASK]"), -+ N_("Write 8-bit VALUE to PORT.")); - cmd_write_word = -- grub_register_command ("outw", grub_cmd_write, -- N_("PORT VALUE [MASK]"), -- N_("Write 16-bit VALUE to PORT.")); -+ grub_register_command_lockdown ("outw", grub_cmd_write, -+ N_("PORT VALUE [MASK]"), -+ N_("Write 16-bit VALUE to PORT.")); - cmd_write_dword = -- grub_register_command ("outl", grub_cmd_write, -- N_("ADDR VALUE [MASK]"), -- N_("Write 32-bit VALUE to PORT.")); -+ grub_register_command_lockdown ("outl", grub_cmd_write, -+ N_("ADDR VALUE [MASK]"), -+ N_("Write 32-bit VALUE to PORT.")); - } - - GRUB_MOD_FINI(memrw) -diff --git a/grub-core/commands/memrw.c b/grub-core/commands/memrw.c -index 98769eadb..d401a6db0 100644 ---- a/grub-core/commands/memrw.c -+++ b/grub-core/commands/memrw.c -@@ -22,6 +22,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -133,17 +134,17 @@ GRUB_MOD_INIT(memrw) - N_("ADDR"), N_("Read 32-bit value from ADDR."), - options); - cmd_write_byte = -- grub_register_command ("write_byte", grub_cmd_write, -- N_("ADDR VALUE [MASK]"), -- N_("Write 8-bit VALUE to ADDR.")); -+ grub_register_command_lockdown ("write_byte", grub_cmd_write, -+ N_("ADDR VALUE [MASK]"), -+ N_("Write 8-bit VALUE to ADDR.")); - cmd_write_word = -- grub_register_command ("write_word", grub_cmd_write, -- N_("ADDR VALUE [MASK]"), -- N_("Write 16-bit VALUE to ADDR.")); -+ grub_register_command_lockdown ("write_word", grub_cmd_write, -+ N_("ADDR VALUE [MASK]"), -+ N_("Write 16-bit VALUE to ADDR.")); - cmd_write_dword = -- grub_register_command ("write_dword", grub_cmd_write, -- N_("ADDR VALUE [MASK]"), -- N_("Write 32-bit VALUE to ADDR.")); -+ grub_register_command_lockdown ("write_dword", grub_cmd_write, -+ N_("ADDR VALUE [MASK]"), -+ N_("Write 32-bit VALUE to ADDR.")); - } - - GRUB_MOD_FINI(memrw) --- -2.23.0 - diff --git a/backport-0005-kern-efi-mm-Fix-possible-NULL-pointer-dereference.patch b/backport-0005-kern-efi-mm-Fix-possible-NULL-pointer-dereference.patch deleted file mode 100644 index 5c79f9be023900c19a9c0631551a03c6b2877bb2..0000000000000000000000000000000000000000 --- a/backport-0005-kern-efi-mm-Fix-possible-NULL-pointer-dereference.patch +++ /dev/null @@ -1,67 +0,0 @@ -From 17e7c7cd02d2cf14b16f9cb8aaad3d62c35b5609 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Fri, 11 Dec 2020 15:03:13 +0000 -Subject: [PATCH] kern/efi/mm: Fix possible NULL pointer dereference - -The model of grub_efi_get_memory_map() is that if memory_map is NULL, -then the purpose is to discover how much memory should be allocated to -it for the subsequent call. - -The problem here is that with grub_efi_is_finished set to 1, there is no -check at all that the function is being called with a non-NULL memory_map. - -While this MAY be true, we shouldn't assume it. - -The solution to this is to behave as expected, and if memory_map is NULL, -then don't try to use it and allow memory_map_size to be filled in, and -return 0 as is done later in the code if the buffer is too small (or NULL). - -Additionally, drop unneeded ret = 1. - -Fixes: CID 96632 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=6aee4bfd6973c714056fb7b56890b8d524e94ee1 - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/kern/efi/mm.c | 19 ++++++++++++++----- - 1 file changed, 14 insertions(+), 5 deletions(-) - -diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c -index d70e5b4..f64f79e 100644 ---- a/grub-core/kern/efi/mm.c -+++ b/grub-core/kern/efi/mm.c -@@ -375,15 +375,24 @@ grub_efi_get_memory_map (grub_efi_uintn_t *memory_map_size, - if (grub_efi_is_finished) - { - int ret = 1; -- if (*memory_map_size < finish_mmap_size) -+ -+ if (memory_map != NULL) - { -- grub_memcpy (memory_map, finish_mmap_buf, *memory_map_size); -- ret = 0; -+ if (*memory_map_size < finish_mmap_size) -+ { -+ grub_memcpy (memory_map, finish_mmap_buf, *memory_map_size); -+ ret = 0; -+ } -+ else -+ grub_memcpy (memory_map, finish_mmap_buf, finish_mmap_size); - } - else - { -- grub_memcpy (memory_map, finish_mmap_buf, finish_mmap_size); -- ret = 1; -+ /* -+ * Incomplete, no buffer to copy into, same as -+ * GRUB_EFI_BUFFER_TOO_SMALL below. -+ */ -+ ret = 0; - } - *memory_map_size = finish_mmap_size; - if (map_key) --- -2.19.1 - diff --git a/backport-0006-CVE-2020-27749.patch b/backport-0006-CVE-2020-27749.patch deleted file mode 100644 index a54feef6d5e945a7c758632965c4d9c9ec5725ea..0000000000000000000000000000000000000000 --- a/backport-0006-CVE-2020-27749.patch +++ /dev/null @@ -1,307 +0,0 @@ -From 030fb6c4fa354cdbd6a8d6903dfed5d36eaf3cb2 Mon Sep 17 00:00:00 2001 -From: Chris Coulson -Date: Thu, 7 Jan 2021 15:15:43 +0000 -Subject: kern/buffer: Add variable sized heap buffer - -Add a new variable sized heap buffer type (grub_buffer_t) with simple -operations for appending data, accessing the data and maintaining -a read cursor. - -Signed-off-by: Chris Coulson -Reviewed-by: Daniel Kiper ---- - grub-core/Makefile.core.def | 1 + - grub-core/kern/buffer.c | 117 +++++++++++++++++++++++++++++++++++ - include/grub/buffer.h | 144 ++++++++++++++++++++++++++++++++++++++++++++ - 3 files changed, 262 insertions(+) - create mode 100644 grub-core/kern/buffer.c - create mode 100644 include/grub/buffer.h - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index b283c50..c7563bb 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -123,6 +123,7 @@ kernel = { - riscv32_efi_startup = kern/riscv/efi/startup.S; - riscv64_efi_startup = kern/riscv/efi/startup.S; - -+ common = kern/buffer.c; - common = kern/command.c; - common = kern/corecmd.c; - common = kern/device.c; -diff --git a/grub-core/kern/buffer.c b/grub-core/kern/buffer.c -new file mode 100644 -index 0000000..b50a187 ---- /dev/null -+++ b/grub-core/kern/buffer.c -@@ -0,0 +1,117 @@ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2021 Free Software Foundation, Inc. -+ * -+ * GRUB is free software: you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation, either version 3 of the License, or -+ * (at your option) any later version. -+ * -+ * GRUB is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with GRUB. If not, see . -+ */ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+ -+grub_buffer_t -+grub_buffer_new (grub_size_t sz) -+{ -+ struct grub_buffer *ret; -+ -+ ret = (struct grub_buffer *) grub_malloc (sizeof (*ret)); -+ if (ret == NULL) -+ return NULL; -+ -+ ret->data = (grub_uint8_t *) grub_malloc (sz); -+ if (ret->data == NULL) -+ { -+ grub_free (ret); -+ return NULL; -+ } -+ -+ ret->sz = sz; -+ ret->pos = 0; -+ ret->used = 0; -+ -+ return ret; -+} -+ -+void -+grub_buffer_free (grub_buffer_t buf) -+{ -+ grub_free (buf->data); -+ grub_free (buf); -+} -+ -+grub_err_t -+grub_buffer_ensure_space (grub_buffer_t buf, grub_size_t req) -+{ -+ grub_uint8_t *d; -+ grub_size_t newsz = 1; -+ -+ /* Is the current buffer size adequate? */ -+ if (buf->sz >= req) -+ return GRUB_ERR_NONE; -+ -+ /* Find the smallest power-of-2 size that satisfies the request. */ -+ while (newsz < req) -+ { -+ if (newsz == 0) -+ return grub_error (GRUB_ERR_OUT_OF_RANGE, -+ N_("requested buffer size is too large")); -+ newsz <<= 1; -+ } -+ -+ d = (grub_uint8_t *) grub_realloc (buf->data, newsz); -+ if (d == NULL) -+ return grub_errno; -+ -+ buf->data = d; -+ buf->sz = newsz; -+ -+ return GRUB_ERR_NONE; -+} -+ -+void * -+grub_buffer_take_data (grub_buffer_t buf) -+{ -+ void *data = buf->data; -+ -+ buf->data = NULL; -+ buf->sz = buf->pos = buf->used = 0; -+ -+ return data; -+} -+ -+void -+grub_buffer_reset (grub_buffer_t buf) -+{ -+ buf->pos = buf->used = 0; -+} -+ -+grub_err_t -+grub_buffer_advance_read_pos (grub_buffer_t buf, grub_size_t n) -+{ -+ grub_size_t newpos; -+ -+ if (grub_add (buf->pos, n, &newpos)) -+ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); -+ -+ if (newpos > buf->used) -+ return grub_error (GRUB_ERR_OUT_OF_RANGE, -+ N_("new read is position beyond the end of the written data")); -+ -+ buf->pos = newpos; -+ -+ return GRUB_ERR_NONE; -+} -diff --git a/include/grub/buffer.h b/include/grub/buffer.h -new file mode 100644 -index 0000000..f4b10cf ---- /dev/null -+++ b/include/grub/buffer.h -@@ -0,0 +1,144 @@ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2021 Free Software Foundation, Inc. -+ * -+ * GRUB is free software: you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation, either version 3 of the License, or -+ * (at your option) any later version. -+ * -+ * GRUB is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with GRUB. If not, see . -+ */ -+ -+#ifndef GRUB_BUFFER_H -+#define GRUB_BUFFER_H 1 -+ -+#include -+#include -+#include -+#include -+#include -+ -+struct grub_buffer -+{ -+ grub_uint8_t *data; -+ grub_size_t sz; -+ grub_size_t pos; -+ grub_size_t used; -+}; -+ -+/* -+ * grub_buffer_t represents a simple variable sized byte buffer with -+ * read and write cursors. It currently only implements -+ * functionality required by the only user in GRUB (append byte[s], -+ * peeking data at a specified position and updating the read cursor. -+ * Some things that this doesn't do yet are: -+ * - Reading a portion of the buffer by copying data from the current -+ * read position in to a caller supplied destination buffer and then -+ * automatically updating the read cursor. -+ * - Dropping the read part at the start of the buffer when an append -+ * requires more space. -+ */ -+typedef struct grub_buffer *grub_buffer_t; -+ -+/* Allocate a new buffer with the specified initial size. */ -+extern grub_buffer_t grub_buffer_new (grub_size_t sz); -+ -+/* Free the buffer and its resources. */ -+extern void grub_buffer_free (grub_buffer_t buf); -+ -+/* Return the number of unread bytes in this buffer. */ -+static inline grub_size_t -+grub_buffer_get_unread_bytes (grub_buffer_t buf) -+{ -+ return buf->used - buf->pos; -+} -+ -+/* -+ * Ensure that the buffer size is at least the requested -+ * number of bytes. -+ */ -+extern grub_err_t grub_buffer_ensure_space (grub_buffer_t buf, grub_size_t req); -+ -+/* -+ * Append the specified number of bytes from the supplied -+ * data to the buffer. -+ */ -+static inline grub_err_t -+grub_buffer_append_data (grub_buffer_t buf, const void *data, grub_size_t len) -+{ -+ grub_size_t req; -+ -+ if (grub_add (buf->used, len, &req)) -+ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); -+ -+ if (grub_buffer_ensure_space (buf, req) != GRUB_ERR_NONE) -+ return grub_errno; -+ -+ grub_memcpy (&buf->data[buf->used], data, len); -+ buf->used = req; -+ -+ return GRUB_ERR_NONE; -+} -+ -+/* Append the supplied character to the buffer. */ -+static inline grub_err_t -+grub_buffer_append_char (grub_buffer_t buf, char c) -+{ -+ return grub_buffer_append_data (buf, &c, 1); -+} -+ -+/* -+ * Forget and return the underlying data buffer. The caller -+ * becomes the owner of this buffer, and must free it when it -+ * is no longer required. -+ */ -+extern void *grub_buffer_take_data (grub_buffer_t buf); -+ -+/* Reset this buffer. Note that this does not deallocate any resources. */ -+void grub_buffer_reset (grub_buffer_t buf); -+ -+/* -+ * Return a pointer to the underlying data buffer at the specified -+ * offset from the current read position. Note that this pointer may -+ * become invalid if the buffer is mutated further. -+ */ -+static inline void * -+grub_buffer_peek_data_at (grub_buffer_t buf, grub_size_t off) -+{ -+ if (grub_add (buf->pos, off, &off)) -+ { -+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected.")); -+ return NULL; -+ } -+ -+ if (off >= buf->used) -+ { -+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("peek out of range")); -+ return NULL; -+ } -+ -+ return &buf->data[off]; -+} -+ -+/* -+ * Return a pointer to the underlying data buffer at the current -+ * read position. Note that this pointer may become invalid if the -+ * buffer is mutated further. -+ */ -+static inline void * -+grub_buffer_peek_data (grub_buffer_t buf) -+{ -+ return grub_buffer_peek_data_at (buf, 0); -+} -+ -+/* Advance the read position by the specified number of bytes. */ -+extern grub_err_t grub_buffer_advance_read_pos (grub_buffer_t buf, grub_size_t n); -+ -+#endif /* GRUB_BUFFER_H */ --- -2.23.0 - diff --git a/backport-0006-CVE-2020-27779-and-CVE-2020-14372.patch b/backport-0006-CVE-2020-27779-and-CVE-2020-14372.patch deleted file mode 100644 index 8e80b98569e44c666433aec61b19c880e2c73fd5..0000000000000000000000000000000000000000 --- a/backport-0006-CVE-2020-27779-and-CVE-2020-14372.patch +++ /dev/null @@ -1,75 +0,0 @@ -From 08c63ad119ce0c0d0de56d9878f0be6811f623d4 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Mon, 28 Sep 2020 20:08:41 +0200 -Subject: [PATCH 13/46] acpi: Don't register the acpi command when locked down -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -The command is not allowed when lockdown is enforced. Otherwise an -attacker can instruct the GRUB to load an SSDT table to overwrite -the kernel lockdown configuration and later load and execute -unsigned code. - -Fixes: CVE-2020-14372 - -Reported-by: Máté Kukri -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - docs/grub.texi | 5 +++++ - grub-core/commands/acpi.c | 15 ++++++++------- - 2 files changed, 13 insertions(+), 7 deletions(-) - -diff --git a/docs/grub.texi b/docs/grub.texi -index 6d8d32b0b..2ee8721a1 100644 ---- a/docs/grub.texi -+++ b/docs/grub.texi -@@ -3986,6 +3986,11 @@ Normally, this command will replace the Root System Description Pointer - (RSDP) in the Extended BIOS Data Area to point to the new tables. If the - @option{--no-ebda} option is used, the new tables will be known only to - GRUB, but may be used by GRUB's EFI emulation. -+ -+Note: The command is not allowed when lockdown is enforced (@pxref{Lockdown}). -+ Otherwise an attacker can instruct the GRUB to load an SSDT table to -+ overwrite the kernel lockdown configuration and later load and execute -+ unsigned code. - @end deffn - - -diff --git a/grub-core/commands/acpi.c b/grub-core/commands/acpi.c -index 5a1499aa0..1215f2a62 100644 ---- a/grub-core/commands/acpi.c -+++ b/grub-core/commands/acpi.c -@@ -27,6 +27,7 @@ - #include - #include - #include -+#include - - #ifdef GRUB_MACHINE_EFI - #include -@@ -775,13 +776,13 @@ static grub_extcmd_t cmd; - - GRUB_MOD_INIT(acpi) - { -- cmd = grub_register_extcmd ("acpi", grub_cmd_acpi, 0, -- N_("[-1|-2] [--exclude=TABLE1,TABLE2|" -- "--load-only=TABLE1,TABLE2] FILE1" -- " [FILE2] [...]"), -- N_("Load host ACPI tables and tables " -- "specified by arguments."), -- options); -+ cmd = grub_register_extcmd_lockdown ("acpi", grub_cmd_acpi, 0, -+ N_("[-1|-2] [--exclude=TABLE1,TABLE2|" -+ "--load-only=TABLE1,TABLE2] FILE1" -+ " [FILE2] [...]"), -+ N_("Load host ACPI tables and tables " -+ "specified by arguments."), -+ options); - } - - GRUB_MOD_FINI(acpi) --- -2.26.2 - diff --git a/backport-0006-zstd-Initialize-seq_t-structure-fully.patch b/backport-0006-zstd-Initialize-seq_t-structure-fully.patch deleted file mode 100644 index 0487a7ad0a4768d1c0d0b154e01e8db6e84cc3dd..0000000000000000000000000000000000000000 --- a/backport-0006-zstd-Initialize-seq_t-structure-fully.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 4567a832aaade9589162e6f7a50af81af151d635 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Thu, 5 Nov 2020 10:29:59 +0000 -Subject: [PATCH] zstd: Initialize seq_t structure fully - -While many compilers will initialize this to zero, not all will, so it -is better to be sure that fields not being explicitly set are at known -values, and there is code that checks this fields value elsewhere in the -code. - -Fixes: CID 292440 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=2777cf4466719921dbe4b30af358a75e7d76f217 - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/lib/zstd/zstd_decompress.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/lib/zstd/zstd_decompress.c b/grub-core/lib/zstd/zstd_decompress.c -index 711b5b6..e4b5670 100644 ---- a/grub-core/lib/zstd/zstd_decompress.c -+++ b/grub-core/lib/zstd/zstd_decompress.c -@@ -1325,7 +1325,7 @@ typedef enum { ZSTD_lo_isRegularOffset, ZSTD_lo_isLongOffset=1 } ZSTD_longOffset - FORCE_INLINE_TEMPLATE seq_t - ZSTD_decodeSequence(seqState_t* seqState, const ZSTD_longOffset_e longOffsets) - { -- seq_t seq; -+ seq_t seq = {0}; - U32 const llBits = seqState->stateLL.table[seqState->stateLL.state].nbAdditionalBits; - U32 const mlBits = seqState->stateML.table[seqState->stateML.state].nbAdditionalBits; - U32 const ofBits = seqState->stateOffb.table[seqState->stateOffb.state].nbAdditionalBits; --- -2.19.1 - diff --git a/backport-0007-CVE-2020-27749.patch b/backport-0007-CVE-2020-27749.patch deleted file mode 100644 index 53089f3ab9a2886fdec0a6fb7341bc9b616a7a6f..0000000000000000000000000000000000000000 --- a/backport-0007-CVE-2020-27749.patch +++ /dev/null @@ -1,247 +0,0 @@ -From 4ea7bae51f97e49c84dc67ea30b466ca8633b9f6 Mon Sep 17 00:00:00 2001 -From: Chris Coulson -Date: Thu, 7 Jan 2021 19:21:03 +0000 -Subject: kern/parser: Fix a stack buffer overflow - -grub_parser_split_cmdline() expands variable names present in the supplied -command line in to their corresponding variable contents and uses a 1 kiB -stack buffer for temporary storage without sufficient bounds checking. If -the function is called with a command line that references a variable with -a sufficiently large payload, it is possible to overflow the stack -buffer via tab completion, corrupt the stack frame and potentially -control execution. - -Fixes: CVE-2020-27749 - -Reported-by: Chris Coulson -Signed-off-by: Chris Coulson -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/kern/parser.c | 110 ++++++++++++++++++++++++---------------- - 1 file changed, 67 insertions(+), 43 deletions(-) - -diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c -index d50538f..89276d5 100644 ---- a/grub-core/kern/parser.c -+++ b/grub-core/kern/parser.c -@@ -18,6 +18,7 @@ - */ - - #include -+#include - #include - #include - #include -@@ -107,8 +108,8 @@ check_varstate (grub_parser_state_t s) - } - - --static void --add_var (char *varname, char **bp, char **vp, -+static grub_err_t -+add_var (grub_buffer_t varname, grub_buffer_t buf, - grub_parser_state_t state, grub_parser_state_t newstate) - { - const char *val; -@@ -116,31 +117,41 @@ add_var (char *varname, char **bp, char **vp, - /* Check if a variable was being read in and the end of the name - was reached. */ - if (!(check_varstate (state) && !check_varstate (newstate))) -- return; -+ return GRUB_ERR_NONE; -+ -+ if (grub_buffer_append_char (varname, '\0') != GRUB_ERR_NONE) -+ return grub_errno; - -- *((*vp)++) = '\0'; -- val = grub_env_get (varname); -- *vp = varname; -+ val = grub_env_get ((const char *) grub_buffer_peek_data (varname)); -+ grub_buffer_reset (varname); - if (!val) -- return; -+ return GRUB_ERR_NONE; - - /* Insert the contents of the variable in the buffer. */ -- for (; *val; val++) -- *((*bp)++) = *val; -+ return grub_buffer_append_data (buf, val, grub_strlen (val)); - } - --static void --terminate_arg (char *buffer, char **bp, int *argc) -+static grub_err_t -+terminate_arg (grub_buffer_t buffer, int *argc) - { -- if (*bp != buffer && *((*bp) - 1) != '\0') -- { -- *((*bp)++) = '\0'; -- (*argc)++; -- } -+ grub_size_t unread = grub_buffer_get_unread_bytes (buffer); -+ -+ if (unread == 0) -+ return GRUB_ERR_NONE; -+ -+ if (*(const char *) grub_buffer_peek_data_at (buffer, unread - 1) == '\0') -+ return GRUB_ERR_NONE; -+ -+ if (grub_buffer_append_char (buffer, '\0') != GRUB_ERR_NONE) -+ return grub_errno; -+ -+ (*argc)++; -+ -+ return GRUB_ERR_NONE; - } - - static grub_err_t --process_char (char c, char *buffer, char **bp, char *varname, char **vp, -+process_char (char c, grub_buffer_t buffer, grub_buffer_t varname, - grub_parser_state_t state, int *argc, - grub_parser_state_t *newstate) - { -@@ -153,12 +164,13 @@ process_char (char c, char *buffer, char **bp, char *varname, char **vp, - * not describe the variable anymore, write the variable to - * the buffer. - */ -- add_var (varname, bp, vp, state, *newstate); -+ if (add_var (varname, buffer, state, *newstate) != GRUB_ERR_NONE) -+ return grub_errno; - - if (check_varstate (*newstate)) - { - if (use) -- *((*vp)++) = use; -+ return grub_buffer_append_char (varname, use); - } - else if (*newstate == GRUB_PARSER_STATE_TEXT && - state != GRUB_PARSER_STATE_ESC && grub_isspace (use)) -@@ -167,10 +179,10 @@ process_char (char c, char *buffer, char **bp, char *varname, char **vp, - * Don't add more than one argument if multiple - * spaces are used. - */ -- terminate_arg (buffer, bp, argc); -+ return terminate_arg (buffer, argc); - } - else if (use) -- *((*bp)++) = use; -+ return grub_buffer_append_char (buffer, use); - - return GRUB_ERR_NONE; - } -@@ -181,19 +193,22 @@ grub_parser_split_cmdline (const char *cmdline, - int *argc, char ***argv) - { - grub_parser_state_t state = GRUB_PARSER_STATE_TEXT; -- /* XXX: Fixed size buffer, perhaps this buffer should be dynamically -- allocated. */ -- char buffer[1024]; -- char *bp = buffer; -+ grub_buffer_t buffer, varname; - char *rd = (char *) cmdline; -- char varname[200]; - char *rp = rd; -- char *vp = varname; -- char *args; - int i; - - *argc = 0; - *argv = NULL; -+ -+ buffer = grub_buffer_new (1024); -+ if (buffer == NULL) -+ return grub_errno; -+ -+ varname = grub_buffer_new (200); -+ if (varname == NULL) -+ goto fail; -+ - do - { - if (rp == NULL || *rp == '\0') -@@ -219,7 +234,7 @@ grub_parser_split_cmdline (const char *cmdline, - { - grub_parser_state_t newstate; - -- if (process_char (*rp, buffer, &bp, varname, &vp, state, argc, -+ if (process_char (*rp, buffer, varname, state, argc, - &newstate) != GRUB_ERR_NONE) - goto fail; - -@@ -230,10 +245,12 @@ grub_parser_split_cmdline (const char *cmdline, - - /* A special case for when the last character was part of a - variable. */ -- add_var (varname, &bp, &vp, state, GRUB_PARSER_STATE_TEXT); -+ if (add_var (varname, buffer, state, GRUB_PARSER_STATE_TEXT) != GRUB_ERR_NONE) -+ goto fail; - - /* Ensure that the last argument is terminated. */ -- terminate_arg (buffer, &bp, argc); -+ if (terminate_arg (buffer, argc) != GRUB_ERR_NONE) -+ goto fail; - - /* If there are no args, then we're done. */ - if (!*argc) -@@ -242,38 +259,45 @@ grub_parser_split_cmdline (const char *cmdline, - goto out; - } - -- /* Reserve memory for the return values. */ -- args = grub_malloc (bp - buffer); -- if (!args) -- goto fail; -- grub_memcpy (args, buffer, bp - buffer); -- - *argv = grub_calloc (*argc + 1, sizeof (char *)); - if (!*argv) - goto fail; - - /* The arguments are separated with 0's, setup argv so it points to - the right values. */ -- bp = args; - for (i = 0; i < *argc; i++) - { -- (*argv)[i] = bp; -- while (*bp) -- bp++; -- bp++; -+ char *arg; -+ -+ if (i > 0) -+ { -+ if (grub_buffer_advance_read_pos (buffer, 1) != GRUB_ERR_NONE) -+ goto fail; -+ } -+ -+ arg = (char *) grub_buffer_peek_data (buffer); -+ if (arg == NULL || -+ grub_buffer_advance_read_pos (buffer, grub_strlen (arg)) != GRUB_ERR_NONE) -+ goto fail; -+ -+ (*argv)[i] = arg; - } - -+ /* Keep memory for the return values. */ -+ grub_buffer_take_data (buffer); -+ - grub_errno = GRUB_ERR_NONE; - - out: - if (rd != cmdline) - grub_free (rd); -+ grub_buffer_free (buffer); -+ grub_buffer_free (varname); - - return grub_errno; - - fail: - grub_free (*argv); -- grub_free (args); - goto out; - } - --- -2.23.0 - diff --git a/backport-0007-CVE-2020-27779-and-CVE-2020-14372.patch b/backport-0007-CVE-2020-27779-and-CVE-2020-14372.patch deleted file mode 100644 index 0efa1f90ee6780e44c0b6b1f76ebc310dd60193a..0000000000000000000000000000000000000000 --- a/backport-0007-CVE-2020-27779-and-CVE-2020-14372.patch +++ /dev/null @@ -1,69 +0,0 @@ -From cbd4d630728847bcc3eb82c4a1667fc7ba6de73a Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Wed, 14 Oct 2020 16:33:42 +0200 -Subject: [PATCH 14/46] mmap: Don't register cutmem and badram commands when - lockdown is enforced - -The cutmem and badram commands can be used to remove EFI memory regions -and potentially disable the UEFI Secure Boot. Prevent the commands to be -registered if the GRUB is locked down. - -Fixes: CVE-2020-27779 - -Reported-by: Teddy Reed -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - docs/grub.texi | 4 ++++ - grub-core/mmap/mmap.c | 13 +++++++------ - 2 files changed, 11 insertions(+), 6 deletions(-) - -diff --git a/docs/grub.texi b/docs/grub.texi -index 2ee8721a1..70bf91f40 100644 ---- a/docs/grub.texi -+++ b/docs/grub.texi -@@ -4051,6 +4051,10 @@ this page is to be filtered. This syntax makes it easy to represent patterns - that are often result of memory damage, due to physical distribution of memory - cells. - -+Note: The command is not allowed when lockdown is enforced (@pxref{Lockdown}). -+ This prevents removing EFI memory regions to potentially subvert the -+ security mechanisms provided by the UEFI secure boot. -+ - @node blocklist - @subsection blocklist - -diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c -index 57b4e9a72..7ebf32e1e 100644 ---- a/grub-core/mmap/mmap.c -+++ b/grub-core/mmap/mmap.c -@@ -20,6 +20,7 @@ - #include - #include - #include -+#include - #include - #include - #include -@@ -534,12 +535,12 @@ static grub_command_t cmd, cmd_cut; - - GRUB_MOD_INIT(mmap) - { -- cmd = grub_register_command ("badram", grub_cmd_badram, -- N_("ADDR1,MASK1[,ADDR2,MASK2[,...]]"), -- N_("Declare memory regions as faulty (badram).")); -- cmd_cut = grub_register_command ("cutmem", grub_cmd_cutmem, -- N_("FROM[K|M|G] TO[K|M|G]"), -- N_("Remove any memory regions in specified range.")); -+ cmd = grub_register_command_lockdown ("badram", grub_cmd_badram, -+ N_("ADDR1,MASK1[,ADDR2,MASK2[,...]]"), -+ N_("Declare memory regions as faulty (badram).")); -+ cmd_cut = grub_register_command_lockdown ("cutmem", grub_cmd_cutmem, -+ N_("FROM[K|M|G] TO[K|M|G]"), -+ N_("Remove any memory regions in specified range.")); - - } - --- -2.26.2 - diff --git a/backport-0007-kern-partition-Check-for-NULL-before-dereferencing-i.patch b/backport-0007-kern-partition-Check-for-NULL-before-dereferencing-i.patch deleted file mode 100644 index c76b81dcfb48168808a88992162e29294e386ff7..0000000000000000000000000000000000000000 --- a/backport-0007-kern-partition-Check-for-NULL-before-dereferencing-i.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 3b75201b76a8b728fc3680be92f7391f75096013 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Fri, 23 Oct 2020 09:49:59 +0000 -Subject: [PATCH] kern/partition: Check for NULL before dereferencing input - string - -There is the possibility that the value of str comes from an external -source and continuing to use it before ever checking its validity is -wrong. So, needs fixing. - -Additionally, drop unneeded part initialization. - -Fixes: CID 292444 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=bc9c468a2ce84bc767234eec888b71f1bc744fff - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/kern/partition.c | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/grub-core/kern/partition.c b/grub-core/kern/partition.c -index 2c401b8..3068c4d 100644 ---- a/grub-core/kern/partition.c -+++ b/grub-core/kern/partition.c -@@ -109,11 +109,14 @@ grub_partition_map_probe (const grub_partition_map_t partmap, - grub_partition_t - grub_partition_probe (struct grub_disk *disk, const char *str) - { -- grub_partition_t part = 0; -+ grub_partition_t part; - grub_partition_t curpart = 0; - grub_partition_t tail; - const char *ptr; - -+ if (str == NULL) -+ return 0; -+ - part = tail = disk->partition; - - for (ptr = str; *ptr;) --- -2.19.1 - diff --git a/backport-0008-CVE-2020-27779-and-CVE-2020-14372.patch b/backport-0008-CVE-2020-27779-and-CVE-2020-14372.patch deleted file mode 100644 index 18a5c1717d209abcd97c5511f2472df10bfb8a16..0000000000000000000000000000000000000000 --- a/backport-0008-CVE-2020-27779-and-CVE-2020-14372.patch +++ /dev/null @@ -1,104 +0,0 @@ -From d1a40f870dbcb55280f57673c1d9c2c7110df42a Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Wed, 24 Feb 2021 09:00:05 +0100 -Subject: [PATCH 15/46] commands: Restrict commands that can load BIOS or DT - blobs when locked down - -There are some more commands that should be restricted when the GRUB is -locked down. Following is the list of commands and reasons to restrict: - - * fakebios: creates BIOS-like structures for backward compatibility with - existing OSes. This should not be allowed when locked down. - - * loadbios: reads a BIOS dump from storage and loads it. This action - should not be allowed when locked down. - - * devicetree: loads a Device Tree blob and passes it to the OS. It replaces - any Device Tree provided by the firmware. This also should - not be allowed when locked down. - -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - docs/grub.texi | 3 +++ - grub-core/commands/efi/loadbios.c | 16 ++++++++-------- - grub-core/loader/arm/linux.c | 6 +++--- - grub-core/loader/efi/fdt.c | 4 ++-- - 4 files changed, 16 insertions(+), 13 deletions(-) - -diff --git a/docs/grub.texi b/docs/grub.texi -index 70bf91f40..cf29a1797 100644 ---- a/docs/grub.texi -+++ b/docs/grub.texi -@@ -4236,6 +4236,9 @@ Load a device tree blob (.dtb) from a filesystem, for later use by a Linux - kernel. Does not perform merging with any device tree supplied by firmware, - but rather replaces it completely. - @ref{GNU/Linux}. -+ -+Note: The command is not allowed when lockdown is enforced (@pxref{Lockdown}). -+ This is done to prevent subverting various security mechanisms. - @end deffn - - @node distrust -diff --git a/grub-core/commands/efi/loadbios.c b/grub-core/commands/efi/loadbios.c -index d41d521a4..5c7725f8b 100644 ---- a/grub-core/commands/efi/loadbios.c -+++ b/grub-core/commands/efi/loadbios.c -@@ -205,14 +205,14 @@ static grub_command_t cmd_fakebios, cmd_loadbios; - - GRUB_MOD_INIT(loadbios) - { -- cmd_fakebios = grub_register_command ("fakebios", grub_cmd_fakebios, -- 0, N_("Create BIOS-like structures for" -- " backward compatibility with" -- " existing OS.")); -- -- cmd_loadbios = grub_register_command ("loadbios", grub_cmd_loadbios, -- N_("BIOS_DUMP [INT10_DUMP]"), -- N_("Load BIOS dump.")); -+ cmd_fakebios = grub_register_command_lockdown ("fakebios", grub_cmd_fakebios, -+ 0, N_("Create BIOS-like structures for" -+ " backward compatibility with" -+ " existing OS.")); -+ -+ cmd_loadbios = grub_register_command_lockdown ("loadbios", grub_cmd_loadbios, -+ N_("BIOS_DUMP [INT10_DUMP]"), -+ N_("Load BIOS dump.")); - } - - GRUB_MOD_FINI(loadbios) -diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c -index d70c17486..ed23dc71e 100644 ---- a/grub-core/loader/arm/linux.c -+++ b/grub-core/loader/arm/linux.c -@@ -493,9 +493,9 @@ GRUB_MOD_INIT (linux) - 0, N_("Load Linux.")); - cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, - 0, N_("Load initrd.")); -- cmd_devicetree = grub_register_command ("devicetree", grub_cmd_devicetree, -- /* TRANSLATORS: DTB stands for device tree blob. */ -- 0, N_("Load DTB file.")); -+ cmd_devicetree = grub_register_command_lockdown ("devicetree", grub_cmd_devicetree, -+ /* TRANSLATORS: DTB stands for device tree blob. */ -+ 0, N_("Load DTB file.")); - my_mod = mod; - current_fdt = (const void *) grub_arm_firmware_get_boot_data (); - machine_type = grub_arm_firmware_get_machine_type (); -diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c -index ee9c5592c..003d07cd8 100644 ---- a/grub-core/loader/efi/fdt.c -+++ b/grub-core/loader/efi/fdt.c -@@ -165,8 +165,8 @@ static grub_command_t cmd_devicetree; - GRUB_MOD_INIT (fdt) - { - cmd_devicetree = -- grub_register_command ("devicetree", grub_cmd_devicetree, 0, -- N_("Load DTB file.")); -+ grub_register_command_lockdown ("devicetree", grub_cmd_devicetree, 0, -+ N_("Load DTB file.")); - } - - GRUB_MOD_FINI (fdt) --- -2.26.2 - diff --git a/backport-0008-disk-ldm-Make-sure-comp-data-is-freed-before-exiting.patch b/backport-0008-disk-ldm-Make-sure-comp-data-is-freed-before-exiting.patch deleted file mode 100644 index 9f78d3210aa88bbee2b93a51dbbf779b9eb81608..0000000000000000000000000000000000000000 --- a/backport-0008-disk-ldm-Make-sure-comp-data-is-freed-before-exiting.patch +++ /dev/null @@ -1,130 +0,0 @@ -From 0397e0712f40fa1d0933da821a0b483b25509680 Mon Sep 17 00:00:00 2001 -From: Marco A Benatto -Date: Mon, 7 Dec 2020 11:53:03 -0300 -Subject: [PATCH] disk/ldm: Make sure comp data is freed before exiting from - make_vg() - -Several error handling paths in make_vg() do not free comp data before -jumping to fail2 label and returning from the function. This will leak -memory. So, let's fix all issues of that kind. - -Fixes: CID 73804 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=23e39f50ca7a107f6b66396ed4d177a914dee035 - -Signed-off-by: Marco A Benatto -Reviewed-by: Daniel Kiper ---- - grub-core/disk/ldm.c | 51 ++++++++++++++++++++++++++++++++++++++------ - 1 file changed, 44 insertions(+), 7 deletions(-) - -diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c -index 58f8a53..428415f 100644 ---- a/grub-core/disk/ldm.c -+++ b/grub-core/disk/ldm.c -@@ -554,7 +554,11 @@ make_vg (grub_disk_t disk, - comp->segments = grub_calloc (comp->segment_alloc, - sizeof (*comp->segments)); - if (!comp->segments) -- goto fail2; -+ { -+ grub_free (comp->internal_id); -+ grub_free (comp); -+ goto fail2; -+ } - } - else - { -@@ -562,7 +566,11 @@ make_vg (grub_disk_t disk, - comp->segment_count = 1; - comp->segments = grub_malloc (sizeof (*comp->segments)); - if (!comp->segments) -- goto fail2; -+ { -+ grub_free (comp->internal_id); -+ grub_free (comp); -+ goto fail2; -+ } - comp->segments->start_extent = 0; - comp->segments->extent_count = lv->size; - comp->segments->layout = 0; -@@ -574,15 +582,26 @@ make_vg (grub_disk_t disk, - comp->segments->layout = GRUB_RAID_LAYOUT_SYMMETRIC_MASK; - } - else -- goto fail2; -+ { -+ grub_free (comp->segments); -+ grub_free (comp->internal_id); -+ grub_free (comp); -+ goto fail2; -+ } - ptr += *ptr + 1; - ptr++; - if (!(vblk[i].flags & 0x10)) -- goto fail2; -+ { -+ grub_free (comp->segments); -+ grub_free (comp->internal_id); -+ grub_free (comp); -+ goto fail2; -+ } - if (ptr >= vblk[i].dynamic + sizeof (vblk[i].dynamic) - || ptr + *ptr + 1 >= vblk[i].dynamic - + sizeof (vblk[i].dynamic)) - { -+ grub_free (comp->segments); - grub_free (comp->internal_id); - grub_free (comp); - goto fail2; -@@ -592,6 +611,7 @@ make_vg (grub_disk_t disk, - if (ptr + *ptr + 1 >= vblk[i].dynamic - + sizeof (vblk[i].dynamic)) - { -+ grub_free (comp->segments); - grub_free (comp->internal_id); - grub_free (comp); - goto fail2; -@@ -601,7 +621,12 @@ make_vg (grub_disk_t disk, - comp->segments->nodes = grub_calloc (comp->segments->node_alloc, - sizeof (*comp->segments->nodes)); - if (!lv->segments->nodes) -- goto fail2; -+ { -+ grub_free (comp->segments); -+ grub_free (comp->internal_id); -+ grub_free (comp); -+ goto fail2; -+ } - } - - if (lv->segments->node_alloc == lv->segments->node_count) -@@ -611,11 +636,23 @@ make_vg (grub_disk_t disk, - - if (grub_mul (lv->segments->node_alloc, 2, &lv->segments->node_alloc) || - grub_mul (lv->segments->node_alloc, sizeof (*lv->segments->nodes), &sz)) -- goto fail2; -+ { -+ grub_free (comp->segments->nodes); -+ grub_free (comp->segments); -+ grub_free (comp->internal_id); -+ grub_free (comp); -+ goto fail2; -+ } - - t = grub_realloc (lv->segments->nodes, sz); - if (!t) -- goto fail2; -+ { -+ grub_free (comp->segments->nodes); -+ grub_free (comp->segments); -+ grub_free (comp->internal_id); -+ grub_free (comp); -+ goto fail2; -+ } - lv->segments->nodes = t; - } - lv->segments->nodes[lv->segments->node_count].pv = 0; --- -2.19.1 - diff --git a/backport-0009-CVE-2020-27779-and-CVE-2020-14372.patch b/backport-0009-CVE-2020-27779-and-CVE-2020-14372.patch deleted file mode 100644 index af2c256b2236b185c2f580aa9306acb55ef627b5..0000000000000000000000000000000000000000 --- a/backport-0009-CVE-2020-27779-and-CVE-2020-14372.patch +++ /dev/null @@ -1,37 +0,0 @@ -From 3e5b0593346fde8d92dd4e87ce15ff07e0cacf88 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Wed, 24 Feb 2021 22:59:59 +0100 -Subject: [PATCH 16/46] commands/setpci: Restrict setpci command when locked - down - -This command can set PCI devices register values, which makes it dangerous -in a locked down configuration. Restrict it so can't be used on this setup. - -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - grub-core/commands/setpci.c | 8 ++++---- - 1 file changed, 4 insertions(+), 4 deletions(-) - -diff --git a/grub-core/commands/setpci.c b/grub-core/commands/setpci.c -index d5bc97d60..fa2ba7d89 100644 ---- a/grub-core/commands/setpci.c -+++ b/grub-core/commands/setpci.c -@@ -329,10 +329,10 @@ static grub_extcmd_t cmd; - - GRUB_MOD_INIT(setpci) - { -- cmd = grub_register_extcmd ("setpci", grub_cmd_setpci, 0, -- N_("[-s POSITION] [-d DEVICE] [-v VAR] " -- "REGISTER[=VALUE[:MASK]]"), -- N_("Manipulate PCI devices."), options); -+ cmd = grub_register_extcmd_lockdown ("setpci", grub_cmd_setpci, 0, -+ N_("[-s POSITION] [-d DEVICE] [-v VAR] " -+ "REGISTER[=VALUE[:MASK]]"), -+ N_("Manipulate PCI devices."), options); - } - - GRUB_MOD_FINI(setpci) --- -2.26.2 - diff --git a/backport-0009-disk-ldm-If-failed-then-free-vg-variable-too.patch b/backport-0009-disk-ldm-If-failed-then-free-vg-variable-too.patch deleted file mode 100644 index 0f9fa56019d4213f5d08db8c8d3573ffeb248907..0000000000000000000000000000000000000000 --- a/backport-0009-disk-ldm-If-failed-then-free-vg-variable-too.patch +++ /dev/null @@ -1,30 +0,0 @@ -From e0cb364719ee0adfc6bc8e27abf4d262075a0062 Mon Sep 17 00:00:00 2001 -From: Paulo Flabiano Smorigo -Date: Mon, 7 Dec 2020 10:07:47 -0300 -Subject: [PATCH] disk/ldm: If failed then free vg variable too - -Fixes: CID 73809 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=e0b83df5da538d2a38f770e60817b3a4b9d5b4d7 - -Signed-off-by: Paulo Flabiano Smorigo -Reviewed-by: Daniel Kiper ---- - grub-core/disk/ldm.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c -index 428415f..54713f4 100644 ---- a/grub-core/disk/ldm.c -+++ b/grub-core/disk/ldm.c -@@ -199,6 +199,7 @@ make_vg (grub_disk_t disk, - { - grub_free (vg->uuid); - grub_free (vg->name); -+ grub_free (vg); - return NULL; - } - grub_memcpy (vg->uuid, label->group_guid, LDM_GUID_STRLEN); --- -2.19.1 - diff --git a/backport-0010-CVE-2020-27779-and-CVE-2020-14372.patch b/backport-0010-CVE-2020-27779-and-CVE-2020-14372.patch deleted file mode 100644 index 5f51396867ebd415e0bed76c0e09992944b6c5b0..0000000000000000000000000000000000000000 --- a/backport-0010-CVE-2020-27779-and-CVE-2020-14372.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 75dd393392f16194904c8958a22fe12034f915a3 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Wed, 24 Feb 2021 12:59:29 +0100 -Subject: [PATCH 17/46] commands/hdparm: Restrict hdparm command when locked - down - -The command can be used to get/set ATA disk parameters. Some of these can -be dangerous since change the disk behavior. Restrict it when locked down. - -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - grub-core/commands/hdparm.c | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/grub-core/commands/hdparm.c b/grub-core/commands/hdparm.c -index d3fa9661e..2e2319e64 100644 ---- a/grub-core/commands/hdparm.c -+++ b/grub-core/commands/hdparm.c -@@ -436,9 +436,9 @@ static grub_extcmd_t cmd; - - GRUB_MOD_INIT(hdparm) - { -- cmd = grub_register_extcmd ("hdparm", grub_cmd_hdparm, 0, -- N_("[OPTIONS] DISK"), -- N_("Get/set ATA disk parameters."), options); -+ cmd = grub_register_extcmd_lockdown ("hdparm", grub_cmd_hdparm, 0, -+ N_("[OPTIONS] DISK"), -+ N_("Get/set ATA disk parameters."), options); - } - - GRUB_MOD_FINI(hdparm) --- -2.26.2 - diff --git a/backport-0010-disk-ldm-Fix-memory-leak-on-uninserted-lv-references.patch b/backport-0010-disk-ldm-Fix-memory-leak-on-uninserted-lv-references.patch deleted file mode 100644 index bfdfc1962afb9a26ac1ee1f13a9bf7a24c4d7775..0000000000000000000000000000000000000000 --- a/backport-0010-disk-ldm-Fix-memory-leak-on-uninserted-lv-references.patch +++ /dev/null @@ -1,49 +0,0 @@ -From f63402685ccd4bfa9c441d63067853db2a1f6c6a Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Tue, 8 Dec 2020 10:00:51 +0000 -Subject: [PATCH] disk/ldm: Fix memory leak on uninserted lv references - -The problem here is that the memory allocated to the variable lv is not -yet inserted into the list that is being processed at the label fail2. - -As we can already see at line 342, which correctly frees lv before going -to fail2, we should also be doing that at these earlier jumps to fail2. - -Fixes: CID 73824 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=156c281a1625dc73fd350530630c6f2d5673d4f6 ---- - grub-core/disk/ldm.c | 10 ++++++++-- - 1 file changed, 8 insertions(+), 2 deletions(-) - -diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c -index 54713f4..e82e989 100644 ---- a/grub-core/disk/ldm.c -+++ b/grub-core/disk/ldm.c -@@ -321,7 +321,10 @@ make_vg (grub_disk_t disk, - lv->visible = 1; - lv->segments = grub_zalloc (sizeof (*lv->segments)); - if (!lv->segments) -- goto fail2; -+ { -+ grub_free (lv); -+ goto fail2; -+ } - lv->segments->start_extent = 0; - lv->segments->type = GRUB_DISKFILTER_MIRROR; - lv->segments->node_count = 0; -@@ -329,7 +332,10 @@ make_vg (grub_disk_t disk, - lv->segments->nodes = grub_calloc (lv->segments->node_alloc, - sizeof (*lv->segments->nodes)); - if (!lv->segments->nodes) -- goto fail2; -+ { -+ grub_free (lv); -+ goto fail2; -+ } - ptr = vblk[i].dynamic; - if (ptr + *ptr + 1 >= vblk[i].dynamic - + sizeof (vblk[i].dynamic)) --- -2.19.1 - diff --git a/backport-0011-CVE-2020-27779-and-CVE-2020-14372.patch b/backport-0011-CVE-2020-27779-and-CVE-2020-14372.patch deleted file mode 100644 index 07fd153d4ab965e70580c02a878bc1366438fa4a..0000000000000000000000000000000000000000 --- a/backport-0011-CVE-2020-27779-and-CVE-2020-14372.patch +++ /dev/null @@ -1,61 +0,0 @@ -From a4df9a0d74376aa4fc82f8c86c280cb087de01be Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Wed, 24 Feb 2021 15:03:26 +0100 -Subject: [PATCH 18/46] gdb: Restrict GDB access when locked down - -The gdbstub* commands allow to start and control a GDB stub running on -local host that can be used to connect from a remote debugger. Restrict -this functionality when the GRUB is locked down. - -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - grub-core/gdb/gdb.c | 32 ++++++++++++++++++-------------- - 1 file changed, 18 insertions(+), 14 deletions(-) - -diff --git a/grub-core/gdb/gdb.c b/grub-core/gdb/gdb.c -index 847a1e1e3..1818cb6f8 100644 ---- a/grub-core/gdb/gdb.c -+++ b/grub-core/gdb/gdb.c -@@ -75,20 +75,24 @@ static grub_command_t cmd, cmd_stop, cmd_break; - GRUB_MOD_INIT (gdb) - { - grub_gdb_idtinit (); -- cmd = grub_register_command ("gdbstub", grub_cmd_gdbstub, -- N_("PORT"), -- /* TRANSLATORS: GDB stub is a small part of -- GDB functionality running on local host -- which allows remote debugger to -- connect to it. */ -- N_("Start GDB stub on given port")); -- cmd_break = grub_register_command ("gdbstub_break", grub_cmd_gdb_break, -- /* TRANSLATORS: this refers to triggering -- a breakpoint so that the user will land -- into GDB. */ -- 0, N_("Break into GDB")); -- cmd_stop = grub_register_command ("gdbstub_stop", grub_cmd_gdbstop, -- 0, N_("Stop GDB stub")); -+ cmd = grub_register_command_lockdown ("gdbstub", grub_cmd_gdbstub, -+ N_("PORT"), -+ /* -+ * TRANSLATORS: GDB stub is a small part of -+ * GDB functionality running on local host -+ * which allows remote debugger to -+ * connect to it. -+ */ -+ N_("Start GDB stub on given port")); -+ cmd_break = grub_register_command_lockdown ("gdbstub_break", grub_cmd_gdb_break, -+ /* -+ * TRANSLATORS: this refers to triggering -+ * a breakpoint so that the user will land -+ * into GDB. -+ */ -+ 0, N_("Break into GDB")); -+ cmd_stop = grub_register_command_lockdown ("gdbstub_stop", grub_cmd_gdbstop, -+ 0, N_("Stop GDB stub")); - } - - GRUB_MOD_FINI (gdb) --- -2.26.2 - diff --git a/backport-0011-hfsplus-Check-that-the-volume-name-length-is-valid.patch b/backport-0011-hfsplus-Check-that-the-volume-name-length-is-valid.patch deleted file mode 100644 index 42c6f04bc7f5dabe2a98c49f927df25551be53f8..0000000000000000000000000000000000000000 --- a/backport-0011-hfsplus-Check-that-the-volume-name-length-is-valid.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 7dd75b3a9750afa151bf72f3a17123e46ea29456 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Fri, 23 Oct 2020 17:09:31 +0000 -Subject: [PATCH] hfsplus: Check that the volume name length is valid - -HFS+ documentation suggests that the maximum filename and volume name is -255 Unicode characters in length. - -So, when converting from big-endian to little-endian, we should ensure -that the name of the volume has a length that is between 0 and 255, -inclusive. - -Fixes: CID 73641 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=2298f6e0d951251bb9ca97d891d1bc8b74515f8c - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/fs/hfsplus.c | 9 +++++++++ - 1 file changed, 9 insertions(+) - -diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c -index 9c4e4c8..8fe7c12 100644 ---- a/grub-core/fs/hfsplus.c -+++ b/grub-core/fs/hfsplus.c -@@ -1012,6 +1012,15 @@ grub_hfsplus_label (grub_device_t device, char **label) - grub_hfsplus_btree_recptr (&data->catalog_tree, node, ptr); - - label_len = grub_be_to_cpu16 (catkey->namelen); -+ -+ /* Ensure that the length is >= 0. */ -+ if (label_len < 0) -+ label_len = 0; -+ -+ /* Ensure label length is at most 255 Unicode characters. */ -+ if (label_len > 255) -+ label_len = 255; -+ - label_name = grub_calloc (label_len, sizeof (*label_name)); - if (!label_name) - { --- -2.19.1 - diff --git a/backport-0012-CVE-2020-27779-and-CVE-2020-14372.patch b/backport-0012-CVE-2020-27779-and-CVE-2020-14372.patch deleted file mode 100644 index 3a5c91cea913075163c2f6ad917da3327d4beca8..0000000000000000000000000000000000000000 --- a/backport-0012-CVE-2020-27779-and-CVE-2020-14372.patch +++ /dev/null @@ -1,60 +0,0 @@ -From da75051bd36ce97b94254f17a6a94b5cbdf77d48 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Wed, 24 Feb 2021 14:44:38 +0100 -Subject: [PATCH 19/46] loader/xnu: Don't allow loading extension and packages - when locked down - -The shim_lock verifier validates the XNU kernels but no its extensions -and packages. Prevent these to be loaded when the GRUB is locked down. - -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - grub-core/loader/xnu.c | 31 +++++++++++++++++-------------- - 1 file changed, 17 insertions(+), 14 deletions(-) - -diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c -index 77d7060e1..07232d2a1 100644 ---- a/grub-core/loader/xnu.c -+++ b/grub-core/loader/xnu.c -@@ -1482,20 +1482,23 @@ GRUB_MOD_INIT(xnu) - N_("Load XNU image.")); - cmd_kernel64 = grub_register_command ("xnu_kernel64", grub_cmd_xnu_kernel64, - 0, N_("Load 64-bit XNU image.")); -- cmd_mkext = grub_register_command ("xnu_mkext", grub_cmd_xnu_mkext, 0, -- N_("Load XNU extension package.")); -- cmd_kext = grub_register_command ("xnu_kext", grub_cmd_xnu_kext, 0, -- N_("Load XNU extension.")); -- cmd_kextdir = grub_register_command ("xnu_kextdir", grub_cmd_xnu_kextdir, -- /* TRANSLATORS: OSBundleRequired is a -- variable name in xnu extensions -- manifests. It behaves mostly like -- GNU/Linux runlevels. -- */ -- N_("DIRECTORY [OSBundleRequired]"), -- /* TRANSLATORS: There are many extensions -- in extension directory. */ -- N_("Load XNU extension directory.")); -+ cmd_mkext = grub_register_command_lockdown ("xnu_mkext", grub_cmd_xnu_mkext, 0, -+ N_("Load XNU extension package.")); -+ cmd_kext = grub_register_command_lockdown ("xnu_kext", grub_cmd_xnu_kext, 0, -+ N_("Load XNU extension.")); -+ cmd_kextdir = grub_register_command_lockdown ("xnu_kextdir", grub_cmd_xnu_kextdir, -+ /* -+ * TRANSLATORS: OSBundleRequired is -+ * a variable name in xnu extensions -+ * manifests. It behaves mostly like -+ * GNU/Linux runlevels. -+ */ -+ N_("DIRECTORY [OSBundleRequired]"), -+ /* -+ * TRANSLATORS: There are many extensions -+ * in extension directory. -+ */ -+ N_("Load XNU extension directory.")); - cmd_ramdisk = grub_register_command ("xnu_ramdisk", grub_cmd_xnu_ramdisk, 0, - /* TRANSLATORS: ramdisk here isn't identifier. It can be translated. */ - N_("Load XNU ramdisk. " --- -2.26.2 - diff --git a/backport-0012-zfs-Fix-possible-negative-shift-operation.patch b/backport-0012-zfs-Fix-possible-negative-shift-operation.patch deleted file mode 100644 index c136e573e5034b17606cd7e7c6edb757d58c7d0f..0000000000000000000000000000000000000000 --- a/backport-0012-zfs-Fix-possible-negative-shift-operation.patch +++ /dev/null @@ -1,44 +0,0 @@ -From c2f4b251269b140e899528f9a824fad5e226d736 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Tue, 24 Nov 2020 16:41:49 +0000 -Subject: [PATCH] zfs: Fix possible negative shift operation - -While it is possible for the return value from zfs_log2() to be zero -(0), it is quite unlikely, given that the previous assignment to blksz -is shifted up by SPA_MINBLOCKSHIFT (9) before 9 is subtracted at the -assignment to epbs. - -But, while unlikely during a normal operation, it may be that a carefully -crafted ZFS filesystem could result in a zero (0) value to the -dn_datalbkszsec field, which means that the shift left does nothing -and assigns zero (0) to blksz, resulting in a negative epbs value. - -Fixes: CID 73608 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=a02091834d3e167320d8a262ff04b8e83c5e616d - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/fs/zfs/zfs.c | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c -index 36d0373..0c42cba 100644 ---- a/grub-core/fs/zfs/zfs.c -+++ b/grub-core/fs/zfs/zfs.c -@@ -2667,6 +2667,11 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, grub_uint8_t type, - blksz = grub_zfs_to_cpu16 (mdn->dn.dn_datablkszsec, - mdn->endian) << SPA_MINBLOCKSHIFT; - epbs = zfs_log2 (blksz) - DNODE_SHIFT; -+ -+ /* While this should never happen, we should check that epbs is not negative. */ -+ if (epbs < 0) -+ epbs = 0; -+ - blkid = objnum >> epbs; - idx = objnum & ((1 << epbs) - 1); - --- -2.19.1 - diff --git a/backport-0013-zfs-Fix-resource-leaks-while-constructing-path.patch b/backport-0013-zfs-Fix-resource-leaks-while-constructing-path.patch deleted file mode 100644 index 4c09cbed7307ad134f09a6f812df3614df865752..0000000000000000000000000000000000000000 --- a/backport-0013-zfs-Fix-resource-leaks-while-constructing-path.patch +++ /dev/null @@ -1,123 +0,0 @@ -From d8f1c05738b877a1035bbc6daaae0e99a1210afb Mon Sep 17 00:00:00 2001 -From: Paulo Flabiano Smorigo -Date: Mon, 14 Dec 2020 18:54:49 -0300 -Subject: [PATCH] zfs: Fix resource leaks while constructing path - -There are several exit points in dnode_get_path() that are causing possible -memory leaks. - -In the while(1) the correct exit mechanism should not be to do a direct return, -but to instead break out of the loop, setting err first if it is not already set. - -The reason behind this is that the dnode_path is a linked list, and while doing -through this loop, it is being allocated and built up - the only way to -correctly unravel it is to traverse it, which is what is being done at the end -of the function outside of the loop. - -Several of the existing exit points correctly did a break, but not all so this -change makes that more consistent and should resolve the leaking of memory as -found by Coverity. - -Fixes: CID 73741 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=89bdab965805e8d54d7f75349024e1a11cbe2eb8 - -Signed-off-by: Paulo Flabiano Smorigo -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/fs/zfs/zfs.c | 30 +++++++++++++++++++++--------- - 1 file changed, 21 insertions(+), 9 deletions(-) - -diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c -index 0c42cba..98567a7 100644 ---- a/grub-core/fs/zfs/zfs.c -+++ b/grub-core/fs/zfs/zfs.c -@@ -2836,8 +2836,8 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn, - - if (dnode_path->dn.dn.dn_type != DMU_OT_DIRECTORY_CONTENTS) - { -- grub_free (path_buf); -- return grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory")); -+ err = grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory")); -+ break; - } - err = zap_lookup (&(dnode_path->dn), cname, &objnum, - data, subvol->case_insensitive); -@@ -2879,11 +2879,18 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn, - << SPA_MINBLOCKSHIFT); - - if (blksz == 0) -- return grub_error(GRUB_ERR_BAD_FS, "0-sized block"); -+ { -+ err = grub_error (GRUB_ERR_BAD_FS, "0-sized block"); -+ break; -+ } - - sym_value = grub_malloc (sym_sz); - if (!sym_value) -- return grub_errno; -+ { -+ err = grub_errno; -+ break; -+ } -+ - for (block = 0; block < (sym_sz + blksz - 1) / blksz; block++) - { - void *t; -@@ -2893,7 +2900,7 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn, - if (err) - { - grub_free (sym_value); -- return err; -+ break; - } - - movesize = sym_sz - block * blksz; -@@ -2903,6 +2910,8 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn, - grub_memcpy (sym_value + block * blksz, t, movesize); - grub_free (t); - } -+ if (err) -+ break; - free_symval = 1; - } - path = path_buf = grub_malloc (sym_sz + grub_strlen (oldpath) + 1); -@@ -2911,7 +2920,8 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn, - grub_free (oldpathbuf); - if (free_symval) - grub_free (sym_value); -- return grub_errno; -+ err = grub_errno; -+ break; - } - grub_memcpy (path, sym_value, sym_sz); - if (free_symval) -@@ -2949,11 +2959,12 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn, - - err = zio_read (bp, dnode_path->dn.endian, &sahdrp, NULL, data); - if (err) -- return err; -+ break; - } - else - { -- return grub_error (GRUB_ERR_BAD_FS, "filesystem is corrupt"); -+ err = grub_error (GRUB_ERR_BAD_FS, "filesystem is corrupt"); -+ break; - } - - hdrsize = SA_HDR_SIZE (((sa_hdr_phys_t *) sahdrp)); -@@ -2974,7 +2985,8 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn, - if (!path_buf) - { - grub_free (oldpathbuf); -- return grub_errno; -+ err = grub_errno; -+ break; - } - grub_memcpy (path, sym_value, sym_sz); - path [sym_sz] = 0; --- -2.19.1 - diff --git a/backport-0014-zfs-Fix-possible-integer-overflows.patch b/backport-0014-zfs-Fix-possible-integer-overflows.patch deleted file mode 100644 index 36db4d5e18d127cf4c7102a57263010b5db0dd5d..0000000000000000000000000000000000000000 --- a/backport-0014-zfs-Fix-possible-integer-overflows.patch +++ /dev/null @@ -1,58 +0,0 @@ -From a005682edd852f7d44903885504d1bfbf313c98a Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Tue, 8 Dec 2020 22:17:04 +0000 -Subject: [PATCH] zfs: Fix possible integer overflows - -In all cases the problem is that the value being acted upon by -a left-shift is a 32-bit number which is then being used in the -context of a 64-bit number. - -To avoid overflow we ensure that the number being shifted is 64-bit -before the shift is done. - -Fixes: CID 73684, CID 73695, CID 73764 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=302c12ff5714bc455949117c1c9548ccb324d55b - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/fs/zfs/zfs.c | 8 ++++---- - 1 file changed, 4 insertions(+), 4 deletions(-) - -diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c -index 98567a7..e3b5f50 100644 ---- a/grub-core/fs/zfs/zfs.c -+++ b/grub-core/fs/zfs/zfs.c -@@ -564,7 +564,7 @@ find_bestub (uberblock_phys_t * ub_array, - ubptr = (uberblock_phys_t *) ((grub_properly_aligned_t *) ub_array - + ((i << ub_shift) - / sizeof (grub_properly_aligned_t))); -- err = uberblock_verify (ubptr, offset, 1 << ub_shift); -+ err = uberblock_verify (ubptr, offset, (grub_size_t) 1 << ub_shift); - if (err) - { - grub_errno = GRUB_ERR_NONE; -@@ -1543,7 +1543,7 @@ read_device (grub_uint64_t offset, struct grub_zfs_device_desc *desc, - - high = grub_divmod64 ((offset >> desc->ashift) + c, - desc->n_children, &devn); -- csize = bsize << desc->ashift; -+ csize = (grub_size_t) bsize << desc->ashift; - if (csize > len) - csize = len; - -@@ -1635,8 +1635,8 @@ read_device (grub_uint64_t offset, struct grub_zfs_device_desc *desc, - - while (len > 0) - { -- grub_size_t csize; -- csize = ((s / (desc->n_children - desc->nparity)) -+ grub_size_t csize = s; -+ csize = ((csize / (desc->n_children - desc->nparity)) - << desc->ashift); - if (csize > len) - csize = len; --- -2.19.1 - diff --git a/backport-0015-zfsinfo-Correct-a-check-for-error-allocating-memory.patch b/backport-0015-zfsinfo-Correct-a-check-for-error-allocating-memory.patch deleted file mode 100644 index ec4bac8106c993940284b907534524e6647df1fb..0000000000000000000000000000000000000000 --- a/backport-0015-zfsinfo-Correct-a-check-for-error-allocating-memory.patch +++ /dev/null @@ -1,37 +0,0 @@ -From 241197448f94998e4bf0bdc32fcb8a93338d11c7 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Thu, 26 Nov 2020 10:56:45 +0000 -Subject: [PATCH] zfsinfo: Correct a check for error allocating memory - -While arguably the check for grub_errno is correct, we should really be -checking the return value from the function since it is always possible -that grub_errno was set elsewhere, making this code behave incorrectly. - -Fixes: CID 73668 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=7aab03418ec6a9b991aa44416cb2585aff4e7972 - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/fs/zfs/zfsinfo.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/fs/zfs/zfsinfo.c b/grub-core/fs/zfs/zfsinfo.c -index c8a28ac..bf29180 100644 ---- a/grub-core/fs/zfs/zfsinfo.c -+++ b/grub-core/fs/zfs/zfsinfo.c -@@ -358,8 +358,8 @@ grub_cmd_zfs_bootfs (grub_command_t cmd __attribute__ ((unused)), int argc, - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); - - devname = grub_file_get_device_name (args[0]); -- if (grub_errno) -- return grub_errno; -+ if (devname == NULL) -+ return GRUB_ERR_OUT_OF_MEMORY; - - dev = grub_device_open (devname); - grub_free (devname); --- -2.19.1 - diff --git a/backport-0016-affs-Fix-memory-leaks.patch b/backport-0016-affs-Fix-memory-leaks.patch deleted file mode 100644 index a779c45783a75a4d68b41603a34642bd3823fd13..0000000000000000000000000000000000000000 --- a/backport-0016-affs-Fix-memory-leaks.patch +++ /dev/null @@ -1,84 +0,0 @@ -From 8f3bc051b74a471f1b083fa80c752dc69566daba Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Thu, 26 Nov 2020 12:48:07 +0000 -Subject: [PATCH] affs: Fix memory leaks - -The node structure reference is being allocated but not freed if it -reaches the end of the function. If any of the hooks had returned -a non-zero value, then node would have been copied in to the context -reference, but otherwise node is not stored and should be freed. - -Similarly, the call to grub_affs_create_node() replaces the allocated -memory in node with a newly allocated structure, leaking the existing -memory pointed by node. - -Finally, when dir->parent is set, then we again replace node with newly -allocated memory, which seems unnecessary when we copy in the values -from dir->parent immediately after. - -Fixes: CID 73759 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=178ac5107389f8e5b32489d743d6824a5ebf342a - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/fs/affs.c | 18 ++++++++---------- - 1 file changed, 8 insertions(+), 10 deletions(-) - -diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c -index 220b371..230e26a 100644 ---- a/grub-core/fs/affs.c -+++ b/grub-core/fs/affs.c -@@ -400,12 +400,12 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir, - { - unsigned int i; - struct grub_affs_file file; -- struct grub_fshelp_node *node = 0; -+ struct grub_fshelp_node *node, *orig_node; - struct grub_affs_data *data = dir->data; - grub_uint32_t *hashtable; - - /* Create the directory entries for `.' and `..'. */ -- node = grub_zalloc (sizeof (*node)); -+ node = orig_node = grub_zalloc (sizeof (*node)); - if (!node) - return 1; - -@@ -414,9 +414,6 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir, - return 1; - if (dir->parent) - { -- node = grub_zalloc (sizeof (*node)); -- if (!node) -- return 1; - *node = *dir->parent; - if (hook ("..", GRUB_FSHELP_DIR, node, hook_data)) - return 1; -@@ -456,17 +453,18 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir, - - if (grub_affs_create_node (dir, hook, hook_data, &node, &hashtable, - next, &file)) -- return 1; -+ { -+ /* Node has been replaced in function. */ -+ grub_free (orig_node); -+ return 1; -+ } - - next = grub_be_to_cpu32 (file.next); - } - } - -- grub_free (hashtable); -- return 0; -- - fail: -- grub_free (node); -+ grub_free (orig_node); - grub_free (hashtable); - return 0; - } --- -2.19.1 - diff --git a/backport-0017-libgcrypt-mpi-Fix-possible-unintended-sign-extension.patch b/backport-0017-libgcrypt-mpi-Fix-possible-unintended-sign-extension.patch deleted file mode 100644 index af3aec5de6c9ecc476323327e539639275628d2f..0000000000000000000000000000000000000000 --- a/backport-0017-libgcrypt-mpi-Fix-possible-unintended-sign-extension.patch +++ /dev/null @@ -1,37 +0,0 @@ -From 6ca2b8bcd83f1da666f390274f9d749f2cebe75c Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Tue, 3 Nov 2020 16:43:37 +0000 -Subject: [PATCH] libgcrypt/mpi: Fix possible unintended sign extension - -The array of unsigned char gets promoted to a signed 32-bit int before -it is finally promoted to a size_t. There is the possibility that this -may result in the signed-bit being set for the intermediate signed -32-bit int. We should ensure that the promotion is to the correct type -before we bitwise-OR the values. - -Fixes: CID 96697 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=e8814c811132a70f9b55418f7567378a34ad3883 - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/lib/libgcrypt/mpi/mpicoder.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/lib/libgcrypt/mpi/mpicoder.c b/grub-core/lib/libgcrypt/mpi/mpicoder.c -index a3435ed..7ecad27 100644 ---- a/grub-core/lib/libgcrypt/mpi/mpicoder.c -+++ b/grub-core/lib/libgcrypt/mpi/mpicoder.c -@@ -458,7 +458,7 @@ gcry_mpi_scan (struct gcry_mpi **ret_mpi, enum gcry_mpi_format format, - if (len && len < 4) - return gcry_error (GPG_ERR_TOO_SHORT); - -- n = (s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); -+ n = ((size_t)s[0] << 24 | (size_t)s[1] << 16 | (size_t)s[2] << 8 | (size_t)s[3]); - s += 4; - if (len) - len -= 4; --- -2.19.1 - diff --git a/backport-0018-libgcrypt-mpi-Fix-possible-NULL-dereference.patch b/backport-0018-libgcrypt-mpi-Fix-possible-NULL-dereference.patch deleted file mode 100644 index 247fb9fde4773be056089c8cda474f797a37734b..0000000000000000000000000000000000000000 --- a/backport-0018-libgcrypt-mpi-Fix-possible-NULL-dereference.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 376207d95a9b4bd824cff943fac190b31f73f9d0 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Thu, 26 Nov 2020 10:41:54 +0000 -Subject: [PATCH] libgcrypt/mpi: Fix possible NULL dereference - -The code in gcry_mpi_scan() assumes that buffer is not NULL, but there -is no explicit check for that, so we add one. - -Fixes: CID 73757 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=ae0f3fabeba7b393113d5dc185b6aff9b728136d - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/lib/libgcrypt/mpi/mpicoder.c | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/grub-core/lib/libgcrypt/mpi/mpicoder.c b/grub-core/lib/libgcrypt/mpi/mpicoder.c -index 7ecad27..6fe3891 100644 ---- a/grub-core/lib/libgcrypt/mpi/mpicoder.c -+++ b/grub-core/lib/libgcrypt/mpi/mpicoder.c -@@ -379,6 +379,9 @@ gcry_mpi_scan (struct gcry_mpi **ret_mpi, enum gcry_mpi_format format, - unsigned int len; - int secure = (buffer && gcry_is_secure (buffer)); - -+ if (!buffer) -+ return gcry_error (GPG_ERR_INV_ARG); -+ - if (format == GCRYMPI_FMT_SSH) - len = 0; - else --- -2.19.1 - diff --git a/backport-0019-syslinux-Fix-memory-leak-while-parsing.patch b/backport-0019-syslinux-Fix-memory-leak-while-parsing.patch deleted file mode 100644 index 457a8f6af233a2f40e2b3caa62847f21f365a75f..0000000000000000000000000000000000000000 --- a/backport-0019-syslinux-Fix-memory-leak-while-parsing.patch +++ /dev/null @@ -1,45 +0,0 @@ -From f15dc85e88c85f08afb67d59099aa150e096264f Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Thu, 26 Nov 2020 15:31:53 +0000 -Subject: [PATCH] syslinux: Fix memory leak while parsing - -In syslinux_parse_real() the 2 points where return is being called -didn't release the memory stored in buf which is no longer required. - -Fixes: CID 176634 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=95bc016dba94cab3d398dd74160665915cd08ad6 - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/lib/syslinux_parse.c | 6 +++++- - 1 file changed, 5 insertions(+), 1 deletion(-) - -diff --git a/grub-core/lib/syslinux_parse.c b/grub-core/lib/syslinux_parse.c -index de9fda0..ff244d2 100644 ---- a/grub-core/lib/syslinux_parse.c -+++ b/grub-core/lib/syslinux_parse.c -@@ -737,7 +737,10 @@ syslinux_parse_real (struct syslinux_menu *menu) - && grub_strncasecmp ("help", ptr3, ptr4 - ptr3) == 0)) - { - if (helptext (ptr5, file, menu)) -- return 1; -+ { -+ grub_free (buf); -+ return 1; -+ } - continue; - } - -@@ -757,6 +760,7 @@ syslinux_parse_real (struct syslinux_menu *menu) - } - fail: - grub_file_close (file); -+ grub_free (buf); - return err; - } - --- -2.19.1 - diff --git a/backport-0020-normal-completion-Fix-leaking-of-memory-when-process.patch b/backport-0020-normal-completion-Fix-leaking-of-memory-when-process.patch deleted file mode 100644 index 6d80085195ff22c84027ccf153f7067641ceab2f..0000000000000000000000000000000000000000 --- a/backport-0020-normal-completion-Fix-leaking-of-memory-when-process.patch +++ /dev/null @@ -1,54 +0,0 @@ -From 2cf1f83fcb5e816144f4352f153a07219e2c2e5a Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Fri, 4 Dec 2020 18:56:48 +0000 -Subject: [PATCH] normal/completion: Fix leaking of memory when processing a - completion - -It is possible for the code to reach the end of the function without -freeing the memory allocated to argv and argc still to be 0. - -We should always call grub_free(argv). The grub_free() will handle -a NULL argument correctly if it reaches that code without the memory -being allocated. - -Fixes: CID 96672 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=9213575b7a95b514bce80be5964a28d407d7d56d - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/normal/completion.c | 10 ++++------ - 1 file changed, 4 insertions(+), 6 deletions(-) - -diff --git a/grub-core/normal/completion.c b/grub-core/normal/completion.c -index c07100a..18cadfa 100644 ---- a/grub-core/normal/completion.c -+++ b/grub-core/normal/completion.c -@@ -401,8 +401,8 @@ char * - grub_normal_do_completion (char *buf, int *restore, - void (*hook) (const char *, grub_completion_type_t, int)) - { -- int argc; -- char **argv; -+ int argc = 0; -+ char **argv = NULL; - - /* Initialize variables. */ - match = 0; -@@ -517,10 +517,8 @@ grub_normal_do_completion (char *buf, int *restore, - - fail: - if (argc != 0) -- { -- grub_free (argv[0]); -- grub_free (argv); -- } -+ grub_free (argv[0]); -+ grub_free (argv); - grub_free (match); - grub_errno = GRUB_ERR_NONE; - --- -2.19.1 - diff --git a/backport-0021-commands-hashsum-Fix-a-memory-leak.patch b/backport-0021-commands-hashsum-Fix-a-memory-leak.patch deleted file mode 100644 index d391cc14a327d3e58898b29c4a9d8f2b1bd779fe..0000000000000000000000000000000000000000 --- a/backport-0021-commands-hashsum-Fix-a-memory-leak.patch +++ /dev/null @@ -1,58 +0,0 @@ -From d172ca13c6fdf9a3daf1539eec9fd6b3a17dc16b Mon Sep 17 00:00:00 2001 -From: Chris Coulson -Date: Tue, 1 Dec 2020 23:41:24 +0000 -Subject: [PATCH] commands/hashsum: Fix a memory leak - -check_list() uses grub_file_getline(), which allocates a buffer. -If the hash list file contains invalid lines, the function leaks -this buffer when it returns an error. - -Fixes: CID 176635 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=8b6f528e52e18b7a69f90b8dc3671d7b1147d9f3 - -Signed-off-by: Chris Coulson -Reviewed-by: Daniel Kiper ---- - grub-core/commands/hashsum.c | 15 ++++++++++++--- - 1 file changed, 12 insertions(+), 3 deletions(-) - -diff --git a/grub-core/commands/hashsum.c b/grub-core/commands/hashsum.c -index 456ba90..b8a22b0 100644 ---- a/grub-core/commands/hashsum.c -+++ b/grub-core/commands/hashsum.c -@@ -128,11 +128,17 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename, - high = hextoval (*p++); - low = hextoval (*p++); - if (high < 0 || low < 0) -- return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list"); -+ { -+ grub_free (buf); -+ return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list"); -+ } - expected[i] = (high << 4) | low; - } - if ((p[0] != ' ' && p[0] != '\t') || (p[1] != ' ' && p[1] != '\t')) -- return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list"); -+ { -+ grub_free (buf); -+ return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list"); -+ } - p += 2; - if (prefix) - { -@@ -140,7 +146,10 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename, - - filename = grub_xasprintf ("%s/%s", prefix, p); - if (!filename) -- return grub_errno; -+ { -+ grub_free (buf); -+ return grub_errno; -+ } - file = grub_file_open (filename, GRUB_FILE_TYPE_TO_HASH - | (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS - : GRUB_FILE_TYPE_NONE)); --- -2.19.1 - diff --git a/backport-0022-video-efi_gop-Remove-unnecessary-return-value-of-gru.patch b/backport-0022-video-efi_gop-Remove-unnecessary-return-value-of-gru.patch deleted file mode 100644 index 1b287712e5f8aa42076321e7cb3e997172409c41..0000000000000000000000000000000000000000 --- a/backport-0022-video-efi_gop-Remove-unnecessary-return-value-of-gru.patch +++ /dev/null @@ -1,96 +0,0 @@ -From cbd9c660d75335e49d928b37a1c4b3c85aee6df3 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Tue, 8 Dec 2020 21:14:31 +0000 -Subject: [PATCH] video/efi_gop: Remove unnecessary return value of - grub_video_gop_fill_mode_info() - -The return value of grub_video_gop_fill_mode_info() is never able to be -anything other than GRUB_ERR_NONE. So, rather than continue to return -a value and checking it each time, it is more correct to redefine the -function to not return anything and remove checks of its return value -altogether. - -Fixes: CID 96701 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=fc5951d3b1616055ef81a019a5affc09d13344d0 - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/video/efi_gop.c | 25 ++++++------------------- - 1 file changed, 6 insertions(+), 19 deletions(-) - -diff --git a/grub-core/video/efi_gop.c b/grub-core/video/efi_gop.c -index be446f8..e6c9372 100644 ---- a/grub-core/video/efi_gop.c -+++ b/grub-core/video/efi_gop.c -@@ -235,7 +235,7 @@ grub_video_gop_fill_real_mode_info (unsigned mode, - return GRUB_ERR_NONE; - } - --static grub_err_t -+static void - grub_video_gop_fill_mode_info (unsigned mode, - struct grub_efi_gop_mode_info *in, - struct grub_video_mode_info *out) -@@ -260,8 +260,6 @@ grub_video_gop_fill_mode_info (unsigned mode, - out->blit_format = GRUB_VIDEO_BLIT_FORMAT_BGRA_8888; - out->mode_type |= (GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED - | GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP); -- -- return GRUB_ERR_NONE; - } - - static int -@@ -274,7 +272,6 @@ grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info, vo - grub_efi_uintn_t size; - grub_efi_status_t status; - struct grub_efi_gop_mode_info *info = NULL; -- grub_err_t err; - struct grub_video_mode_info mode_info; - - status = efi_call_4 (gop->query_mode, gop, mode, &size, &info); -@@ -285,12 +282,7 @@ grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info, vo - continue; - } - -- err = grub_video_gop_fill_mode_info (mode, info, &mode_info); -- if (err) -- { -- grub_errno = GRUB_ERR_NONE; -- continue; -- } -+ grub_video_gop_fill_mode_info (mode, info, &mode_info); - if (hook (&mode_info, hook_arg)) - return 1; - } -@@ -474,13 +466,8 @@ grub_video_gop_setup (unsigned int width, unsigned int height, - - info = gop->mode->info; - -- err = grub_video_gop_fill_mode_info (gop->mode->mode, info, -- &framebuffer.mode_info); -- if (err) -- { -- grub_dprintf ("video", "GOP: couldn't fill mode info\n"); -- return err; -- } -+ grub_video_gop_fill_mode_info (gop->mode->mode, info, -+ &framebuffer.mode_info); - - framebuffer.ptr = (void *) (grub_addr_t) gop->mode->fb_base; - framebuffer.offscreen -@@ -494,8 +481,8 @@ grub_video_gop_setup (unsigned int width, unsigned int height, - { - grub_dprintf ("video", "GOP: couldn't allocate shadow\n"); - grub_errno = 0; -- err = grub_video_gop_fill_mode_info (gop->mode->mode, info, -- &framebuffer.mode_info); -+ grub_video_gop_fill_mode_info (gop->mode->mode, info, -+ &framebuffer.mode_info); - buffer = framebuffer.ptr; - } - --- -2.19.1 - diff --git a/backport-0023-video-fb-fbfill-Fix-potential-integer-overflow.patch b/backport-0023-video-fb-fbfill-Fix-potential-integer-overflow.patch deleted file mode 100644 index 2a7be81bb1f0f03c1d43f1ae9dba340913f37f57..0000000000000000000000000000000000000000 --- a/backport-0023-video-fb-fbfill-Fix-potential-integer-overflow.patch +++ /dev/null @@ -1,80 +0,0 @@ -From 7ad0a046156daf7dfb10018a1c5804e6ec668c6b Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Wed, 4 Nov 2020 15:10:51 +0000 -Subject: [PATCH] video/fb/fbfill: Fix potential integer overflow - -The multiplication of 2 unsigned 32-bit integers may overflow before -promotion to unsigned 64-bit. We should ensure that the multiplication -is done with overflow detection. Additionally, use grub_sub() for -subtraction. - -Fixes: CID 73640, CID 73697, CID 73702, CID 73823 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=7ce3259f67ac2cd93acb0ec0080c24b3b69e66c6 - -Signed-off-by: Darren Kenny -Signed-off-by: Marco A Benatto -Reviewed-by: Daniel Kiper ---- - grub-core/video/fb/fbfill.c | 17 +++++++++++++---- - 1 file changed, 13 insertions(+), 4 deletions(-) - -diff --git a/grub-core/video/fb/fbfill.c b/grub-core/video/fb/fbfill.c -index 11816d0..a37acd1 100644 ---- a/grub-core/video/fb/fbfill.c -+++ b/grub-core/video/fb/fbfill.c -@@ -31,6 +31,7 @@ - #include - #include - #include -+#include - #include - - /* Generic filler that works for every supported mode. */ -@@ -61,7 +62,9 @@ grub_video_fbfill_direct32 (struct grub_video_fbblit_info *dst, - - /* Calculate the number of bytes to advance from the end of one line - to the beginning of the next line. */ -- rowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width; -+ if (grub_mul (dst->mode_info->bytes_per_pixel, width, &rowskip) || -+ grub_sub (dst->mode_info->pitch, rowskip, &rowskip)) -+ return; - - /* Get the start address. */ - dstptr = grub_video_fb_get_video_ptr (dst, x, y); -@@ -98,7 +101,9 @@ grub_video_fbfill_direct24 (struct grub_video_fbblit_info *dst, - #endif - /* Calculate the number of bytes to advance from the end of one line - to the beginning of the next line. */ -- rowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width; -+ if (grub_mul (dst->mode_info->bytes_per_pixel, width, &rowskip) || -+ grub_sub (dst->mode_info->pitch, rowskip, &rowskip)) -+ return; - - /* Get the start address. */ - dstptr = grub_video_fb_get_video_ptr (dst, x, y); -@@ -131,7 +136,9 @@ grub_video_fbfill_direct16 (struct grub_video_fbblit_info *dst, - - /* Calculate the number of bytes to advance from the end of one line - to the beginning of the next line. */ -- rowskip = (dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width); -+ if (grub_mul (dst->mode_info->bytes_per_pixel, width, &rowskip) || -+ grub_sub (dst->mode_info->pitch, rowskip, &rowskip)) -+ return; - - /* Get the start address. */ - dstptr = grub_video_fb_get_video_ptr (dst, x, y); -@@ -161,7 +168,9 @@ grub_video_fbfill_direct8 (struct grub_video_fbblit_info *dst, - - /* Calculate the number of bytes to advance from the end of one line - to the beginning of the next line. */ -- rowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width; -+ if (grub_mul (dst->mode_info->bytes_per_pixel, width, &rowskip) || -+ grub_sub (dst->mode_info->pitch, rowskip, &rowskip)) -+ return; - - /* Get the start address. */ - dstptr = grub_video_fb_get_video_ptr (dst, x, y); --- -2.19.1 - diff --git a/backport-0024-video-fb-video_fb-Fix-multiple-integer-overflows.patch b/backport-0024-video-fb-video_fb-Fix-multiple-integer-overflows.patch deleted file mode 100644 index b93d548a9f7393b825af1b53af37499185f470b6..0000000000000000000000000000000000000000 --- a/backport-0024-video-fb-video_fb-Fix-multiple-integer-overflows.patch +++ /dev/null @@ -1,106 +0,0 @@ -From 57f8f7adde0a9c47e56d8619d2d2d14c5e5ca172 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Wed, 4 Nov 2020 14:43:44 +0000 -Subject: [PATCH] video/fb/video_fb: Fix multiple integer overflows - -The calculation of the unsigned 64-bit value is being generated by -multiplying 2, signed or unsigned, 32-bit integers which may overflow -before promotion to unsigned 64-bit. Fix all of them. - -Fixes: CID 73703, CID 73767, CID 73833 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=08e098b1dbf01e96376f594b337491bc4cfa48dd - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/video/fb/video_fb.c | 52 ++++++++++++++++++++++++----------- - 1 file changed, 36 insertions(+), 16 deletions(-) - -diff --git a/grub-core/video/fb/video_fb.c b/grub-core/video/fb/video_fb.c -index 1a602c8..1c9a138 100644 ---- a/grub-core/video/fb/video_fb.c -+++ b/grub-core/video/fb/video_fb.c -@@ -25,6 +25,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -1417,15 +1418,23 @@ doublebuf_blit_update_screen (void) - { - if (framebuffer.current_dirty.first_line - <= framebuffer.current_dirty.last_line) -- grub_memcpy ((char *) framebuffer.pages[0] -- + framebuffer.current_dirty.first_line -- * framebuffer.back_target->mode_info.pitch, -- (char *) framebuffer.back_target->data -- + framebuffer.current_dirty.first_line -- * framebuffer.back_target->mode_info.pitch, -- framebuffer.back_target->mode_info.pitch -- * (framebuffer.current_dirty.last_line -- - framebuffer.current_dirty.first_line)); -+ { -+ grub_size_t copy_size; -+ -+ if (grub_sub (framebuffer.current_dirty.last_line, -+ framebuffer.current_dirty.first_line, ©_size) || -+ grub_mul (framebuffer.back_target->mode_info.pitch, copy_size, ©_size)) -+ { -+ /* Shouldn't happen, but if it does we've a bug. */ -+ return GRUB_ERR_BUG; -+ } -+ -+ grub_memcpy ((char *) framebuffer.pages[0] + framebuffer.current_dirty.first_line * -+ framebuffer.back_target->mode_info.pitch, -+ (char *) framebuffer.back_target->data + framebuffer.current_dirty.first_line * -+ framebuffer.back_target->mode_info.pitch, -+ copy_size); -+ } - framebuffer.current_dirty.first_line - = framebuffer.back_target->mode_info.height; - framebuffer.current_dirty.last_line = 0; -@@ -1439,7 +1448,7 @@ grub_video_fb_doublebuf_blit_init (struct grub_video_fbrender_target **back, - volatile void *framebuf) - { - grub_err_t err; -- grub_size_t page_size = mode_info.pitch * mode_info.height; -+ grub_size_t page_size = (grub_size_t) mode_info.pitch * mode_info.height; - - framebuffer.offscreen_buffer = grub_zalloc (page_size); - if (! framebuffer.offscreen_buffer) -@@ -1482,12 +1491,23 @@ doublebuf_pageflipping_update_screen (void) - last_line = framebuffer.previous_dirty.last_line; - - if (first_line <= last_line) -- grub_memcpy ((char *) framebuffer.pages[framebuffer.render_page] -- + first_line * framebuffer.back_target->mode_info.pitch, -- (char *) framebuffer.back_target->data -- + first_line * framebuffer.back_target->mode_info.pitch, -- framebuffer.back_target->mode_info.pitch -- * (last_line - first_line)); -+ { -+ grub_size_t copy_size; -+ -+ if (grub_sub (last_line, first_line, ©_size) || -+ grub_mul (framebuffer.back_target->mode_info.pitch, copy_size, ©_size)) -+ { -+ /* Shouldn't happen, but if it does we've a bug. */ -+ return GRUB_ERR_BUG; -+ } -+ -+ grub_memcpy ((char *) framebuffer.pages[framebuffer.render_page] + first_line * -+ framebuffer.back_target->mode_info.pitch, -+ (char *) framebuffer.back_target->data + first_line * -+ framebuffer.back_target->mode_info.pitch, -+ copy_size); -+ } -+ - framebuffer.previous_dirty = framebuffer.current_dirty; - framebuffer.current_dirty.first_line - = framebuffer.back_target->mode_info.height; --- -2.19.1 - diff --git a/backport-0025-video-fb-video_fb-Fix-possible-integer-overflow.patch b/backport-0025-video-fb-video_fb-Fix-possible-integer-overflow.patch deleted file mode 100644 index dcb40c0c7ae65cb4cde96ca3b03447fae38de187..0000000000000000000000000000000000000000 --- a/backport-0025-video-fb-video_fb-Fix-possible-integer-overflow.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 12e144d4c50cee2e773f9994921524e1a342b565 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Fri, 4 Dec 2020 14:51:30 +0000 -Subject: [PATCH] video/fb/video_fb: Fix possible integer overflow - -It is minimal possibility that the values being used here will overflow. -So, change the code to use the safemath function grub_mul() to ensure -that doesn't happen. - -Fixes: CID 73761 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=08413f2f4edec0e2d9bf15f836f6ee5ca2e379cb - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/video/fb/video_fb.c | 8 +++++++- - 1 file changed, 7 insertions(+), 1 deletion(-) - -diff --git a/grub-core/video/fb/video_fb.c b/grub-core/video/fb/video_fb.c -index 1c9a138..ae6b89f 100644 ---- a/grub-core/video/fb/video_fb.c -+++ b/grub-core/video/fb/video_fb.c -@@ -1537,7 +1537,13 @@ doublebuf_pageflipping_init (struct grub_video_mode_info *mode_info, - volatile void *page1_ptr) - { - grub_err_t err; -- grub_size_t page_size = mode_info->pitch * mode_info->height; -+ grub_size_t page_size = 0; -+ -+ if (grub_mul (mode_info->pitch, mode_info->height, &page_size)) -+ { -+ /* Shouldn't happen, but if it does we've a bug. */ -+ return GRUB_ERR_BUG; -+ } - - framebuffer.offscreen_buffer = grub_malloc (page_size); - if (! framebuffer.offscreen_buffer) --- -2.19.1 - diff --git a/backport-0026-video-readers-jpeg-Test-for-an-invalid-next-marker-r.patch b/backport-0026-video-readers-jpeg-Test-for-an-invalid-next-marker-r.patch deleted file mode 100644 index 37eb0d5d1859aaefa9610c9e4e27e103b0cbbd6b..0000000000000000000000000000000000000000 --- a/backport-0026-video-readers-jpeg-Test-for-an-invalid-next-marker-r.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 7317421fa3343bc1aaf2a631a26b17a3a7bff9a7 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Fri, 4 Dec 2020 15:39:00 +0000 -Subject: [PATCH] video/readers/jpeg: Test for an invalid next marker reference - from a jpeg file - -While it may never happen, and potentially could be caught at the end of -the function, it is worth checking up front for a bad reference to the -next marker just in case of a maliciously crafted file being provided. - -Fixes: CID 73694 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=5f5eb7ca8e971227e95745abe541df3e1509360e - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/video/readers/jpeg.c | 6 ++++++ - 1 file changed, 6 insertions(+) - -diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c -index 31359a4..0b6ce3c 100644 ---- a/grub-core/video/readers/jpeg.c -+++ b/grub-core/video/readers/jpeg.c -@@ -253,6 +253,12 @@ grub_jpeg_decode_quan_table (struct grub_jpeg_data *data) - next_marker = data->file->offset; - next_marker += grub_jpeg_get_word (data); - -+ if (next_marker > data->file->size) -+ { -+ /* Should never be set beyond the size of the file. */ -+ return grub_error (GRUB_ERR_BAD_FILE_TYPE, "jpeg: invalid next reference"); -+ } -+ - while (data->file->offset + sizeof (data->quan_table[id]) + 1 - <= next_marker) - { --- -2.19.1 - diff --git a/backport-0027-gfxmenu-gui_list-Remove-code-that-coverity-is-flaggi.patch b/backport-0027-gfxmenu-gui_list-Remove-code-that-coverity-is-flaggi.patch deleted file mode 100644 index e101343fb7f5fd38e37afe3de9c5d9f4c379805f..0000000000000000000000000000000000000000 --- a/backport-0027-gfxmenu-gui_list-Remove-code-that-coverity-is-flaggi.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 19fdfa6f93f586fd7d3ce0be0a94f90cb6bbf09d Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Mon, 7 Dec 2020 14:44:47 +0000 -Subject: [PATCH] gfxmenu/gui_list: Remove code that coverity is flagging as - dead - -The test of value for NULL before calling grub_strdup() is not required, -since the if condition prior to this has already tested for value being -NULL and cannot reach this code if it is. - -Fixes: CID 73659 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=4a1aa5917595650efbd46b581368c470ebee42ab - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/gfxmenu/gui_list.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/gfxmenu/gui_list.c b/grub-core/gfxmenu/gui_list.c -index 01477cd..df334a6 100644 ---- a/grub-core/gfxmenu/gui_list.c -+++ b/grub-core/gfxmenu/gui_list.c -@@ -771,7 +771,7 @@ list_set_property (void *vself, const char *name, const char *value) - { - self->need_to_recreate_boxes = 1; - grub_free (self->selected_item_box_pattern); -- self->selected_item_box_pattern = value ? grub_strdup (value) : 0; -+ self->selected_item_box_pattern = grub_strdup (value); - self->selected_item_box_pattern_inherit = 0; - } - } --- -2.19.1 - diff --git a/backport-0028-loader-bsd-Check-for-NULL-arg-up-front.patch b/backport-0028-loader-bsd-Check-for-NULL-arg-up-front.patch deleted file mode 100644 index 014934f43bcda58833f9562c55cee55966171bf6..0000000000000000000000000000000000000000 --- a/backport-0028-loader-bsd-Check-for-NULL-arg-up-front.patch +++ /dev/null @@ -1,49 +0,0 @@ -From 57e99b2d5e72074ee07264e6c167e444b5419c78 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Tue, 8 Dec 2020 21:47:13 +0000 -Subject: [PATCH] loader/bsd: Check for NULL arg up-front - -The code in the next block suggests that it is possible for .set to be -true but .arg may still be NULL. - -This code assumes that it is never NULL, yet later is testing if it is -NULL - that is inconsistent. - -So we should check first if .arg is not NULL, and remove this check that -is being flagged by Coverity since it is no longer required. - -Fixes: CID 292471 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=5d5391b0a05abe76e04c1eb68dcc6cbef5326c4a - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/loader/i386/bsd.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c -index ff98fb7..a1c0abf 100644 ---- a/grub-core/loader/i386/bsd.c -+++ b/grub-core/loader/i386/bsd.c -@@ -1606,7 +1606,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) - kernel_type = KERNEL_TYPE_OPENBSD; - bootflags = grub_bsd_parse_flags (ctxt->state, openbsd_flags); - -- if (ctxt->state[OPENBSD_ROOT_ARG].set) -+ if (ctxt->state[OPENBSD_ROOT_ARG].set && ctxt->state[OPENBSD_ROOT_ARG].arg != NULL) - { - const char *arg = ctxt->state[OPENBSD_ROOT_ARG].arg; - unsigned type, unit, part; -@@ -1623,7 +1623,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) - "unknown disk type name"); - - unit = grub_strtoul (arg, &arg, 10); -- if (! (arg && *arg >= 'a' && *arg <= 'z')) -+ if (! (*arg >= 'a' && *arg <= 'z')) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "only device specifications of form " - " are supported"); --- -2.19.1 - diff --git a/backport-0029-loader-xnu-Fix-memory-leak.patch b/backport-0029-loader-xnu-Fix-memory-leak.patch deleted file mode 100644 index 90f73040dd95895956f1ec9bb378d542f89855a0..0000000000000000000000000000000000000000 --- a/backport-0029-loader-xnu-Fix-memory-leak.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 9c80754151a398650d7467a94b6c0ca6160f21f8 Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Thu, 26 Nov 2020 12:53:10 +0000 -Subject: [PATCH] loader/xnu: Fix memory leak - -he code here is finished with the memory stored in name, but it only -frees it if there curvalue is valid, while it could actually free it -regardless. - -The fix is a simple relocation of the grub_free() to before the test -of curvalue. - -Fixes: CID 96646 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=bcb59ece3263d118510c4440c4da0950f224bb7f - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - grub-core/loader/xnu.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c -index 36481d8..9d40908 100644 ---- a/grub-core/loader/xnu.c -+++ b/grub-core/loader/xnu.c -@@ -1392,9 +1392,9 @@ grub_xnu_fill_devicetree (void) - name[len] = 0; - - curvalue = grub_xnu_create_value (curkey, name); -+ grub_free (name); - if (!curvalue) - return grub_errno; -- grub_free (name); - - data = grub_malloc (grub_strlen (var->value) + 1); - if (!data) --- -2.19.1 - diff --git a/backport-0030-loader-xnu-Free-driverkey-data-when-an-error-is-dete.patch b/backport-0030-loader-xnu-Free-driverkey-data-when-an-error-is-dete.patch deleted file mode 100644 index 3e2461f23b56c8df161c9ffac97156e51fa4ce96..0000000000000000000000000000000000000000 --- a/backport-0030-loader-xnu-Free-driverkey-data-when-an-error-is-dete.patch +++ /dev/null @@ -1,79 +0,0 @@ -From 0699bb82f8c260161ff11cf28024c7e25f0a5dd5 Mon Sep 17 00:00:00 2001 -From: Marco A Benatto -Date: Mon, 30 Nov 2020 12:18:24 -0300 -Subject: [PATCH] loader/xnu: Free driverkey data when an error is detected in - grub_xnu_writetree_toheap() - -... to avoid memory leaks. - -Fixes: CID 96640 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=4b4027b6b1c877d7ab467896b04c7bd1aadcfa15 - -Signed-off-by: Marco A Benatto -Reviewed-by: Daniel Kiper ---- - grub-core/loader/xnu.c | 24 ++++++++++++++++++++---- - 1 file changed, 20 insertions(+), 4 deletions(-) - -diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c -index 9d40908..8efcbd2 100644 ---- a/grub-core/loader/xnu.c -+++ b/grub-core/loader/xnu.c -@@ -228,26 +228,33 @@ grub_xnu_writetree_toheap (grub_addr_t *target, grub_size_t *size) - if (! memorymap) - return grub_errno; - -- driverkey = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*driverkey)); -+ driverkey = (struct grub_xnu_devtree_key *) grub_zalloc (sizeof (*driverkey)); - if (! driverkey) - return grub_errno; - driverkey->name = grub_strdup ("DeviceTree"); - if (! driverkey->name) -- return grub_errno; -+ { -+ err = grub_errno; -+ goto fail; -+ } -+ - driverkey->datasize = sizeof (*extdesc); - driverkey->next = memorymap->first_child; - memorymap->first_child = driverkey; - driverkey->data = extdesc - = (struct grub_xnu_extdesc *) grub_malloc (sizeof (*extdesc)); - if (! driverkey->data) -- return grub_errno; -+ { -+ err = grub_errno; -+ goto fail; -+ } - - /* Allocate the space based on the size with dummy value. */ - *size = grub_xnu_writetree_get_size (grub_xnu_devtree_root, "/"); - err = grub_xnu_heap_malloc (ALIGN_UP (*size + 1, GRUB_XNU_PAGESIZE), - &src, target); - if (err) -- return err; -+ goto fail; - - /* Put real data in the dummy. */ - extdesc->addr = *target; -@@ -256,6 +263,15 @@ grub_xnu_writetree_toheap (grub_addr_t *target, grub_size_t *size) - /* Write the tree to heap. */ - grub_xnu_writetree_toheap_real (src, grub_xnu_devtree_root, "/"); - return GRUB_ERR_NONE; -+ -+fail: -+ memorymap->first_child = NULL; -+ -+ grub_free (driverkey->data); -+ grub_free (driverkey->name); -+ grub_free (driverkey); -+ -+ return err; - } - - /* Find a key or value in parent key. */ --- -2.19.1 - diff --git a/backport-0031-loader-xnu-Check-if-pointer-is-NULL-before-using-it.patch b/backport-0031-loader-xnu-Check-if-pointer-is-NULL-before-using-it.patch deleted file mode 100644 index acb371c62880d019829e9fb7cbf29eae8447fad2..0000000000000000000000000000000000000000 --- a/backport-0031-loader-xnu-Check-if-pointer-is-NULL-before-using-it.patch +++ /dev/null @@ -1,44 +0,0 @@ -From 650d479e6c326c8579b3fd4fa13d99bf3a775bf2 Mon Sep 17 00:00:00 2001 -From: Paulo Flabiano Smorigo -Date: Mon, 30 Nov 2020 10:36:00 -0300 -Subject: [PATCH] loader/xnu: Check if pointer is NULL before using it - -Fixes: CID 73654 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=7c8a2b5d1421a0f2a33d33531f7561f3da93b844 - -Signed-off-by: Paulo Flabiano Smorigo -Reviewed-by: Daniel Kiper ---- - grub-core/loader/xnu.c | 8 ++++---- - 1 file changed, 4 insertions(+), 4 deletions(-) - -diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c -index 8efcbd2..74f3b4f 100644 ---- a/grub-core/loader/xnu.c -+++ b/grub-core/loader/xnu.c -@@ -671,6 +671,9 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile, - char *name, *nameend; - int namelen; - -+ if (infoplistname == NULL) -+ return grub_error (GRUB_ERR_BAD_FILENAME, N_("missing p-list filename")); -+ - name = get_name_ptr (infoplistname); - nameend = grub_strchr (name, '/'); - -@@ -702,10 +705,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile, - else - macho = 0; - -- if (infoplistname) -- infoplist = grub_file_open (infoplistname, GRUB_FILE_TYPE_XNU_INFO_PLIST); -- else -- infoplist = 0; -+ infoplist = grub_file_open (infoplistname, GRUB_FILE_TYPE_XNU_INFO_PLIST); - grub_errno = GRUB_ERR_NONE; - if (infoplist) - { --- -2.19.1 - diff --git a/backport-0032-util-grub-install-Fix-NULL-pointer-dereferences.patch b/backport-0032-util-grub-install-Fix-NULL-pointer-dereferences.patch deleted file mode 100644 index ecf67ace3716b3ee279ebc9b4d20013d1492f738..0000000000000000000000000000000000000000 --- a/backport-0032-util-grub-install-Fix-NULL-pointer-dereferences.patch +++ /dev/null @@ -1,43 +0,0 @@ -From 11c0550c2a5e0ff79b21294e9decf3c1da66e43b Mon Sep 17 00:00:00 2001 -From: Daniel Kiper -Date: Thu, 25 Feb 2021 18:35:01 +0100 -Subject: [PATCH] util/grub-install: Fix NULL pointer dereferences - -Two grub_device_open() calls does not have associated NULL checks -for returned values. Fix that and appease the Coverity. - -Fixes: CID 314583 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=8b3a95655b4391122e7b0315d8cc6f876caf8183 - -Signed-off-by: Daniel Kiper -Reviewed-by: Javier Martinez Canillas ---- - util/grub-install.c | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/util/grub-install.c b/util/grub-install.c -index dddb757..d4fd549 100644 ---- a/util/grub-install.c -+++ b/util/grub-install.c -@@ -1837,6 +1837,8 @@ main (int argc, char *argv[]) - fill_core_services (core_services); - - ins_dev = grub_device_open (install_drive); -+ if (ins_dev == NULL) -+ grub_util_error ("%s", grub_errmsg); - - bless (ins_dev, core_services, 0); - -@@ -1937,6 +1939,8 @@ main (int argc, char *argv[]) - fill_core_services(core_services); - - ins_dev = grub_device_open (install_drive); -+ if (ins_dev == NULL) -+ grub_util_error ("%s", grub_errmsg); - - bless (ins_dev, boot_efi, 1); - if (!removable && update_nvram) --- -2.19.1 - diff --git a/backport-0033-util-grub-editenv-Fix-incorrect-casting-of-a-signed-.patch b/backport-0033-util-grub-editenv-Fix-incorrect-casting-of-a-signed-.patch deleted file mode 100644 index 70a4cdabdac6da22b5cb5a3d8598a324c5ef83dc..0000000000000000000000000000000000000000 --- a/backport-0033-util-grub-editenv-Fix-incorrect-casting-of-a-signed-.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 9f3d2f056a602df45e41646cf75bd4f379ccc94c Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Thu, 5 Nov 2020 14:33:50 +0000 -Subject: [PATCH] util/grub-editenv: Fix incorrect casting of a signed value - -The return value of ftell() may be negative (-1) on error. While it is -probably unlikely to occur, we should not blindly cast to an unsigned -value without first testing that it is not negative. - -Fixes: CID 73856 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=5dc41edc4eba259c6043ae7698c245ec1baaacc6 - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - util/grub-editenv.c | 8 +++++++- - 1 file changed, 7 insertions(+), 1 deletion(-) - -diff --git a/util/grub-editenv.c b/util/grub-editenv.c -index d848038..948eec8 100644 ---- a/util/grub-editenv.c -+++ b/util/grub-editenv.c -@@ -128,6 +128,7 @@ open_envblk_file (const char *name) - { - FILE *fp; - char *buf; -+ long loc; - size_t size; - grub_envblk_t envblk; - -@@ -146,7 +147,12 @@ open_envblk_file (const char *name) - grub_util_error (_("cannot seek `%s': %s"), name, - strerror (errno)); - -- size = (size_t) ftell (fp); -+ loc = ftell (fp); -+ if (loc < 0) -+ grub_util_error (_("cannot get file location `%s': %s"), name, -+ strerror (errno)); -+ -+ size = (size_t) loc; - - if (fseek (fp, 0, SEEK_SET) < 0) - grub_util_error (_("cannot seek `%s': %s"), name, --- -2.19.1 - diff --git a/backport-0034-util-glue-efi-Fix-incorrect-use-of-a-possibly-negati.patch b/backport-0034-util-glue-efi-Fix-incorrect-use-of-a-possibly-negati.patch deleted file mode 100644 index 96b170d84715f584649daf54520b843e6f2d57de..0000000000000000000000000000000000000000 --- a/backport-0034-util-glue-efi-Fix-incorrect-use-of-a-possibly-negati.patch +++ /dev/null @@ -1,52 +0,0 @@ -From 97292a12c766871e51e3efb2b04948841c1458df Mon Sep 17 00:00:00 2001 -From: Darren Kenny -Date: Fri, 4 Dec 2020 15:04:28 +0000 -Subject: [PATCH] util/glue-efi: Fix incorrect use of a possibly negative value - -It is possible for the ftell() function to return a negative value, -although it is fairly unlikely here, we should be checking for -a negative value before we assign it to an unsigned value. - -Fixes: CID 73744 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=1641d74e16f9d1ca35ba1a87ee4a0bf3afa48e72 - -Signed-off-by: Darren Kenny -Reviewed-by: Daniel Kiper ---- - util/glue-efi.c | 14 ++++++++++++-- - 1 file changed, 12 insertions(+), 2 deletions(-) - -diff --git a/util/glue-efi.c b/util/glue-efi.c -index 68f5316..de0fa6d 100644 ---- a/util/glue-efi.c -+++ b/util/glue-efi.c -@@ -39,13 +39,23 @@ write_fat (FILE *in32, FILE *in64, FILE *out, const char *out_filename, - struct grub_macho_fat_header head; - struct grub_macho_fat_arch arch32, arch64; - grub_uint32_t size32, size64; -+ long size; - char *buf; - - fseek (in32, 0, SEEK_END); -- size32 = ftell (in32); -+ size = ftell (in32); -+ if (size < 0) -+ grub_util_error ("cannot get end of input file '%s': %s", -+ name32, strerror (errno)); -+ size32 = (grub_uint32_t) size; - fseek (in32, 0, SEEK_SET); -+ - fseek (in64, 0, SEEK_END); -- size64 = ftell (in64); -+ size = ftell (in64); -+ if (size < 0) -+ grub_util_error ("cannot get end of input file '%s': %s", -+ name64, strerror (errno)); -+ size64 = (grub_uint64_t) size; - fseek (in64, 0, SEEK_SET); - - head.magic = grub_cpu_to_le32_compile_time (GRUB_MACHO_FAT_EFI_MAGIC); --- -2.19.1 - diff --git a/backport-0035-script-execute-Fix-NULL-dereference-in-grub_script_e.patch b/backport-0035-script-execute-Fix-NULL-dereference-in-grub_script_e.patch deleted file mode 100644 index 2d3110682d8a06c5cd06ab900aeca78039117683..0000000000000000000000000000000000000000 --- a/backport-0035-script-execute-Fix-NULL-dereference-in-grub_script_e.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 502ceabcd34bd4fe666195142694d15f863bc6dc Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Fri, 3 Apr 2020 23:05:13 +1100 -Subject: [PATCH] script/execute: Fix NULL dereference in - grub_script_execute_cmdline() - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=41ae93b2e6c75453514629bcfe684300e3aec0ce - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/script/execute.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c -index d2f02cc..b6e326c 100644 ---- a/grub-core/script/execute.c -+++ b/grub-core/script/execute.c -@@ -978,7 +978,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) - struct grub_script_argv argv = { 0, 0, 0 }; - - /* Lookup the command. */ -- if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args[0]) -+ if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args || ! argv.args[0]) - return grub_errno; - - for (i = 0; i < argv.argc; i++) --- -2.19.1 - diff --git a/backport-0036-commands-ls-Require-device_name-is-not-NULL-before-p.patch b/backport-0036-commands-ls-Require-device_name-is-not-NULL-before-p.patch deleted file mode 100644 index 206359fffaef9a1143e62f534dda0d7a3fc3c1fc..0000000000000000000000000000000000000000 --- a/backport-0036-commands-ls-Require-device_name-is-not-NULL-before-p.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 5955a69bc4281d159a19424917382aa32faa6e95 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Mon, 11 Jan 2021 16:57:37 +1100 -Subject: [PATCH] commands/ls: Require device_name is not NULL before printing - -This can be triggered with: - ls -l (0 0*) -and causes a NULL deref in grub_normal_print_device_info(). - -I'm not sure if there's any implication with the IEEE 1275 platform. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=6afbe6063c95b827372f9ec310c9fc7461311eb1 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/commands/ls.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c -index 5b7491a..326d2d6 100644 ---- a/grub-core/commands/ls.c -+++ b/grub-core/commands/ls.c -@@ -196,7 +196,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) - goto fail; - } - -- if (! *path) -+ if (! *path && device_name) - { - if (grub_errno == GRUB_ERR_UNKNOWN_FS) - grub_errno = GRUB_ERR_NONE; --- -2.19.1 - diff --git a/backport-0037-script-execute-Avoid-crash-when-using-outside-a-func.patch b/backport-0037-script-execute-Avoid-crash-when-using-outside-a-func.patch deleted file mode 100644 index a060016ca757e41c85c13fed98c0607c2e61ac64..0000000000000000000000000000000000000000 --- a/backport-0037-script-execute-Avoid-crash-when-using-outside-a-func.patch +++ /dev/null @@ -1,39 +0,0 @@ -From c7b1dc3c5cbe4d6bf9af4736f3fc6d62405dad31 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Mon, 11 Jan 2021 17:30:42 +1100 -Subject: [PATCH] script/execute: Avoid crash when using "$#" outside a - function scope - -"$#" represents the number of arguments to a function. It is only -defined in a function scope, where "scope" is non-NULL. Currently, -if we attempt to evaluate "$#" outside a function scope, "scope" will -be NULL and we will crash with a NULL pointer dereference. - -Do not attempt to count arguments for "$#" if "scope" is NULL. This -will result in "$#" being interpreted as an empty string if evaluated -outside a function scope. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=fe0586347ee46f927ae27bb9673532da9f5dead5 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/script/execute.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c -index b6e326c..4bf8d38 100644 ---- a/grub-core/script/execute.c -+++ b/grub-core/script/execute.c -@@ -519,7 +519,7 @@ gettext_putvar (const char *str, grub_size_t len, - return 0; - - /* Enough for any number. */ -- if (len == 1 && str[0] == '#') -+ if (len == 1 && str[0] == '#' && scope != NULL) - { - grub_snprintf (*ptr, 30, "%u", scope->argv.argc); - *ptr += grub_strlen (*ptr); --- -2.19.1 - diff --git a/backport-0038-script-execute-Don-t-crash-on-a-for-loop-with-no-ite.patch b/backport-0038-script-execute-Don-t-crash-on-a-for-loop-with-no-ite.patch deleted file mode 100644 index 9fe38031037f220716be2bafff022e22214ec627..0000000000000000000000000000000000000000 --- a/backport-0038-script-execute-Don-t-crash-on-a-for-loop-with-no-ite.patch +++ /dev/null @@ -1,41 +0,0 @@ -From bebb524f8bd54ffe42074d825b8b98913356a670 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Fri, 22 Jan 2021 16:18:26 +1100 -Subject: [PATCH] script/execute: Don't crash on a "for" loop with no items - -The following crashes the parser: - - for x in; do - 0 - done - -This is because grub_script_arglist_to_argv() doesn't consider the -possibility that arglist is NULL. Catch that explicitly. - -This avoids a NULL pointer dereference. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=0a05f88e2bb33ed2a0cfd93f481f471efb7791aa - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/script/execute.c | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c -index 4bf8d38..0c6dd9c 100644 ---- a/grub-core/script/execute.c -+++ b/grub-core/script/execute.c -@@ -658,6 +658,9 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist, - struct grub_script_arg *arg = 0; - struct grub_script_argv result = { 0, 0, 0 }; - -+ if (arglist == NULL) -+ return 1; -+ - for (; arglist && arglist->arg; arglist = arglist->next) - { - if (grub_script_argv_next (&result)) --- -2.19.1 - diff --git a/backport-0039-kern-misc-Always-set-end-in-grub_strtoull.patch b/backport-0039-kern-misc-Always-set-end-in-grub_strtoull.patch deleted file mode 100644 index cba9aa400b1a284791346d66e456afe670986fa4..0000000000000000000000000000000000000000 --- a/backport-0039-kern-misc-Always-set-end-in-grub_strtoull.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 4dee187a7b30a8a666adf01a56cebca1f78e15f0 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Wed, 13 Jan 2021 22:19:01 +1100 -Subject: [PATCH] kern/misc: Always set *end in grub_strtoull() - -Currently, if there is an error in grub_strtoull(), *end is not set. -This differs from the usual behavior of strtoull(), and also means that -some callers may use an uninitialized value for *end. - -Set *end unconditionally. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=f41f0af48ab7f7c135aac17ac862c30bde0bbab7 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/kern/misc.c | 8 ++++++++ - 1 file changed, 8 insertions(+) - -diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index dc5e10b..8f8a32d 100644 ---- a/grub-core/kern/misc.c -+++ b/grub-core/kern/misc.c -@@ -466,6 +466,10 @@ grub_strtoull (const char * restrict str, const char ** const restrict end, - { - grub_error (GRUB_ERR_OUT_OF_RANGE, - N_("overflow is detected")); -+ -+ if (end) -+ *end = (char *) str; -+ - return ~0ULL; - } - -@@ -476,6 +480,10 @@ grub_strtoull (const char * restrict str, const char ** const restrict end, - if (! found) - { - grub_errno = GRUB_ERR_BAD_NUMBER; -+ -+ if (end) -+ *end = (char *) str; -+ - return 0; - } - --- -2.19.1 - diff --git a/backport-0040-video-readers-jpeg-Catch-files-with-unsupported-quan.patch b/backport-0040-video-readers-jpeg-Catch-files-with-unsupported-quan.patch deleted file mode 100644 index 16f3d1c0dbbb36c7d3adc317ce6874e1299840a3..0000000000000000000000000000000000000000 --- a/backport-0040-video-readers-jpeg-Catch-files-with-unsupported-quan.patch +++ /dev/null @@ -1,54 +0,0 @@ -From 05aa64ac71242bff90a2356a319d6373b44d7d10 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Fri, 15 Jan 2021 12:57:04 +1100 -Subject: [PATCH] video/readers/jpeg: Catch files with unsupported quantization - or Huffman tables - -Our decoder only supports 2 quantization tables. If a file asks for -a quantization table with index > 1, reject it. - -Similarly, our decoder only supports 4 Huffman tables. If a file asks -for a Huffman table with index > 3, reject it. - -This fixes some out of bounds reads. It's not clear what degree of control -over subsequent execution could be gained by someone who can carefully -set up the contents of memory before loading an invalid JPEG file. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=693989598fd38c3c0b2a928f4f64865b5681762f - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/video/readers/jpeg.c | 8 ++++++++ - 1 file changed, 8 insertions(+) - -diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c -index 0b6ce3c..23f919a 100644 ---- a/grub-core/video/readers/jpeg.c -+++ b/grub-core/video/readers/jpeg.c -@@ -333,7 +333,11 @@ grub_jpeg_decode_sof (struct grub_jpeg_data *data) - else if (ss != JPEG_SAMPLING_1x1) - return grub_error (GRUB_ERR_BAD_FILE_TYPE, - "jpeg: sampling method not supported"); -+ - data->comp_index[id][0] = grub_jpeg_get_byte (data); -+ if (data->comp_index[id][0] > 1) -+ return grub_error (GRUB_ERR_BAD_FILE_TYPE, -+ "jpeg: too many quantization tables"); - } - - if (data->file->offset != next_marker) -@@ -602,6 +606,10 @@ grub_jpeg_decode_sos (struct grub_jpeg_data *data) - ht = grub_jpeg_get_byte (data); - data->comp_index[id][1] = (ht >> 4); - data->comp_index[id][2] = (ht & 0xF) + 2; -+ -+ if ((data->comp_index[id][1] < 0) || (data->comp_index[id][1] > 3) || -+ (data->comp_index[id][2] < 0) || (data->comp_index[id][2] > 3)) -+ return grub_error (GRUB_ERR_BAD_FILE_TYPE, "jpeg: invalid hufftable index"); - } - - grub_jpeg_get_byte (data); /* Skip 3 unused bytes. */ --- -2.19.1 - diff --git a/backport-0041-video-readers-jpeg-Catch-OOB-reads-writes-in-grub_jp.patch b/backport-0041-video-readers-jpeg-Catch-OOB-reads-writes-in-grub_jp.patch deleted file mode 100644 index bba2d74575e83b8836ff77ab09437d224ef84989..0000000000000000000000000000000000000000 --- a/backport-0041-video-readers-jpeg-Catch-OOB-reads-writes-in-grub_jp.patch +++ /dev/null @@ -1,49 +0,0 @@ -From 420121392a223d772381d5e82a256dcc3a41f080 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Fri, 15 Jan 2021 13:29:53 +1100 -Subject: [PATCH] video/readers/jpeg: Catch OOB reads/writes in - grub_jpeg_decode_du() - -The key line is: - - du[jpeg_zigzag_order[pos]] = val * (int) data->quan_table[qt][pos]; - -jpeg_zigzag_order is grub_uint8_t[64]. - -I don't understand JPEG decoders quite well enough to explain what's -going on here. However, I observe sometimes pos=64, which leads to an -OOB read of the jpeg_zigzag_order global then an OOB write to du. -That leads to various unpleasant memory corruption conditions. - -Catch where pos >= ARRAY_SIZE(jpeg_zigzag_order) and bail. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=34b85a6e07014383ddcad09f99ff239ad752dd1a - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/video/readers/jpeg.c | 8 ++++++++ - 1 file changed, 8 insertions(+) - -diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c -index 23f919a..e514812 100644 ---- a/grub-core/video/readers/jpeg.c -+++ b/grub-core/video/readers/jpeg.c -@@ -526,6 +526,14 @@ grub_jpeg_decode_du (struct grub_jpeg_data *data, int id, jpeg_data_unit_t du) - val = grub_jpeg_get_number (data, num & 0xF); - num >>= 4; - pos += num; -+ -+ if (pos >= ARRAY_SIZE (jpeg_zigzag_order)) -+ { -+ grub_error (GRUB_ERR_BAD_FILE_TYPE, -+ "jpeg: invalid position in zigzag order!?"); -+ return; -+ } -+ - du[jpeg_zigzag_order[pos]] = val * (int) data->quan_table[qt][pos]; - pos++; - } --- -2.19.1 - diff --git a/backport-0042-video-readers-jpeg-Don-t-decode-data-before-start-of.patch b/backport-0042-video-readers-jpeg-Don-t-decode-data-before-start-of.patch deleted file mode 100644 index 02efb183624771668d762fbc3a7666abe97b2956..0000000000000000000000000000000000000000 --- a/backport-0042-video-readers-jpeg-Don-t-decode-data-before-start-of.patch +++ /dev/null @@ -1,41 +0,0 @@ -From cd1d391aa0babd48c3ac2836fc841ce325c54f98 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Fri, 15 Jan 2021 14:06:46 +1100 -Subject: [PATCH] video/readers/jpeg: Don't decode data before start of stream - -When a start of stream marker is encountered, we call grub_jpeg_decode_sos() -which allocates space for a bitmap. - -When a restart marker is encountered, we call grub_jpeg_decode_data() which -then fills in that bitmap. - -If we get a restart marker before the start of stream marker, we will -attempt to write to a bitmap_ptr that hasn't been allocated. Catch this -and bail out. This fixes an attempt to write to NULL. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=8338a8238f08d9f3ae4c2ddfff0603eff80af9e2 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/video/readers/jpeg.c | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c -index e514812..e31602f 100644 ---- a/grub-core/video/readers/jpeg.c -+++ b/grub-core/video/readers/jpeg.c -@@ -646,6 +646,10 @@ grub_jpeg_decode_data (struct grub_jpeg_data *data) - nr1 = (data->image_height + vb - 1) >> (3 + data->log_vs); - nc1 = (data->image_width + hb - 1) >> (3 + data->log_hs); - -+ if (data->bitmap_ptr == NULL) -+ return grub_error(GRUB_ERR_BAD_FILE_TYPE, -+ "jpeg: attempted to decode data before start of stream"); -+ - for (; data->r1 < nr1 && (!data->dri || rst); - data->r1++, data->bitmap_ptr += (vb * data->image_width - hb * nc1) * 3) - for (c1 = 0; c1 < nc1 && (!data->dri || rst); --- -2.19.1 - diff --git a/backport-0043-term-gfxterm-Don-t-set-up-a-font-with-glyphs-that-ar.patch b/backport-0043-term-gfxterm-Don-t-set-up-a-font-with-glyphs-that-ar.patch deleted file mode 100644 index ddd239e154666ad95b387295b6972df91e9fe51f..0000000000000000000000000000000000000000 --- a/backport-0043-term-gfxterm-Don-t-set-up-a-font-with-glyphs-that-ar.patch +++ /dev/null @@ -1,53 +0,0 @@ -From 3f68d043b1624a320fdfdc39a064aabd06ff4a58 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Fri, 15 Jan 2021 20:03:20 +1100 -Subject: [PATCH] term/gfxterm: Don't set up a font with glyphs that are too - big - -Catch the case where we have a font so big that it causes the number of -rows or columns to be 0. Currently we continue and allocate a -virtual_screen.text_buffer of size 0. We then try to use that for glpyhs -and things go badly. - -On the emu platform, malloc() may give us a valid pointer, in which case -we'll access heap memory which we shouldn't. Alternatively, it may give us -NULL, in which case we'll crash. For other platforms, if I understand -grub_memalign() correctly, we will receive a valid but small allocation -that we will very likely later overrun. - -Prevent the creation of a virtual screen that isn't at least 40 cols -by 12 rows. This is arbitrary, but it seems that if your width or height -is half a standard 80x24 terminal, you're probably going to struggle to -read anything anyway. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=829329bddb2c3e623270cc634cc9ab32e6455fe7 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/term/gfxterm.c | 9 +++++++++ - 1 file changed, 9 insertions(+) - -diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c -index af7c090..b40fcce 100644 ---- a/grub-core/term/gfxterm.c -+++ b/grub-core/term/gfxterm.c -@@ -232,6 +232,15 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y, - virtual_screen.columns = virtual_screen.width / virtual_screen.normal_char_width; - virtual_screen.rows = virtual_screen.height / virtual_screen.normal_char_height; - -+ /* -+ * There must be a minimum number of rows and columns for the screen to -+ * make sense. Arbitrarily pick half of 80x24. If either dimensions is 0 -+ * we would allocate 0 bytes for the text_buffer. -+ */ -+ if (virtual_screen.columns < 40 || virtual_screen.rows < 12) -+ return grub_error (GRUB_ERR_BAD_FONT, -+ "font: glyphs too large to fit on screen"); -+ - /* Allocate memory for text buffer. */ - virtual_screen.text_buffer = - (struct grub_colored_char *) grub_malloc (virtual_screen.columns --- -2.19.1 - diff --git a/backport-0044-fs-fshelp-Catch-impermissibly-large-block-sizes-in-r.patch b/backport-0044-fs-fshelp-Catch-impermissibly-large-block-sizes-in-r.patch deleted file mode 100644 index 5761dbdeee2ddedc1658302ed24a0f4523ced443..0000000000000000000000000000000000000000 --- a/backport-0044-fs-fshelp-Catch-impermissibly-large-block-sizes-in-r.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 717b6b29d8b0bff9a1f89a3f602ece385c0e9d3d Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Mon, 18 Jan 2021 11:46:39 +1100 -Subject: [PATCH] fs/fshelp: Catch impermissibly large block sizes in read - helper - -A fuzzed HFS+ filesystem had log2blocksize = 22. This gave -log2blocksize + GRUB_DISK_SECTOR_BITS = 31. 1 << 31 = 0x80000000, -which is -1 as an int. This caused some wacky behavior later on in -the function, leading to out-of-bounds writes on the destination buffer. - -Catch log2blocksize + GRUB_DISK_SECTOR_BITS >= 31. We could be stricter, -but this is the minimum that will prevent integer size weirdness. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=b5bc456f664bc301ab4cd5a17d3d23c6661c259e - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/fs/fshelp.c | 12 ++++++++++++ - 1 file changed, 12 insertions(+) - -diff --git a/grub-core/fs/fshelp.c b/grub-core/fs/fshelp.c -index 4c902ad..a2d0d29 100644 ---- a/grub-core/fs/fshelp.c -+++ b/grub-core/fs/fshelp.c -@@ -362,6 +362,18 @@ grub_fshelp_read_file (grub_disk_t disk, grub_fshelp_node_t node, - grub_disk_addr_t i, blockcnt; - int blocksize = 1 << (log2blocksize + GRUB_DISK_SECTOR_BITS); - -+ /* -+ * Catch blatantly invalid log2blocksize. We could be a lot stricter, but -+ * this is the most permissive we can be before we start to see integer -+ * overflow/underflow issues. -+ */ -+ if (log2blocksize + GRUB_DISK_SECTOR_BITS >= 31) -+ { -+ grub_error (GRUB_ERR_OUT_OF_RANGE, -+ N_("blocksize too large")); -+ return -1; -+ } -+ - if (pos > filesize) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, --- -2.19.1 - diff --git a/backport-0045-fs-hfsplus-Don-t-fetch-a-key-beyond-the-end-of-the-n.patch b/backport-0045-fs-hfsplus-Don-t-fetch-a-key-beyond-the-end-of-the-n.patch deleted file mode 100644 index acad440fbc3228c7c6c10b51c9b8d114e4f5dc17..0000000000000000000000000000000000000000 --- a/backport-0045-fs-hfsplus-Don-t-fetch-a-key-beyond-the-end-of-the-n.patch +++ /dev/null @@ -1,34 +0,0 @@ -From cb045eb0b724ae94dca014ef83a6f0c3ae802d83 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Fri, 22 Jan 2021 18:13:56 +1100 -Subject: [PATCH] fs/hfsplus: Don't fetch a key beyond the end of the node - -Otherwise you get a wild pointer, leading to a bunch of invalid reads. -Check it falls inside the given node. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=58ea11d5b9ca0966bd9c68d8ba5240cf7dc3ba83 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/fs/hfsplus.c | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c -index 8fe7c12..1c7791b 100644 ---- a/grub-core/fs/hfsplus.c -+++ b/grub-core/fs/hfsplus.c -@@ -635,6 +635,10 @@ grub_hfsplus_btree_search (struct grub_hfsplus_btree *btree, - pointer = ((char *) currkey - + grub_be_to_cpu16 (currkey->keylen) - + 2); -+ -+ if ((char *) pointer > node + btree->nodesize - 2) -+ return grub_error (GRUB_ERR_BAD_FS, "HFS+ key beyond end of node"); -+ - currnode = grub_be_to_cpu32 (grub_get_unaligned32 (pointer)); - match = 1; - } --- -2.19.1 - diff --git a/backport-0046-fs-hfsplus-Don-t-use-uninitialized-data-on-corrupt-f.patch b/backport-0046-fs-hfsplus-Don-t-use-uninitialized-data-on-corrupt-f.patch deleted file mode 100644 index 4f9ebeabf122e0d92791da7a11b6d9aab6014ace..0000000000000000000000000000000000000000 --- a/backport-0046-fs-hfsplus-Don-t-use-uninitialized-data-on-corrupt-f.patch +++ /dev/null @@ -1,109 +0,0 @@ -From dbfe338e79d47fc535bd924660ae5bb0881716d3 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Tue, 2 Feb 2021 16:59:35 +1100 -Subject: [PATCH] fs/hfsplus: Don't use uninitialized data on corrupt - filesystems - -Valgrind identified the following use of uninitialized data: - - ==2782220== Conditional jump or move depends on uninitialised value(s) - ==2782220== at 0x42B364: grub_hfsplus_btree_search (hfsplus.c:566) - ==2782220== by 0x42B21D: grub_hfsplus_read_block (hfsplus.c:185) - ==2782220== by 0x42A693: grub_fshelp_read_file (fshelp.c:386) - ==2782220== by 0x42C598: grub_hfsplus_read_file (hfsplus.c:219) - ==2782220== by 0x42C598: grub_hfsplus_mount (hfsplus.c:330) - ==2782220== by 0x42B8C5: grub_hfsplus_dir (hfsplus.c:958) - ==2782220== by 0x4C1AE6: grub_fs_probe (fs.c:73) - ==2782220== by 0x407C94: grub_ls_list_files (ls.c:186) - ==2782220== by 0x407C94: grub_cmd_ls (ls.c:284) - ==2782220== by 0x4D7130: grub_extcmd_dispatcher (extcmd.c:55) - ==2782220== by 0x4045A6: execute_command (grub-fstest.c:59) - ==2782220== by 0x4045A6: fstest (grub-fstest.c:433) - ==2782220== by 0x4045A6: main (grub-fstest.c:772) - ==2782220== Uninitialised value was created by a heap allocation - ==2782220== at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) - ==2782220== by 0x4C0305: grub_malloc (mm.c:42) - ==2782220== by 0x42C21D: grub_hfsplus_mount (hfsplus.c:239) - ==2782220== by 0x42B8C5: grub_hfsplus_dir (hfsplus.c:958) - ==2782220== by 0x4C1AE6: grub_fs_probe (fs.c:73) - ==2782220== by 0x407C94: grub_ls_list_files (ls.c:186) - ==2782220== by 0x407C94: grub_cmd_ls (ls.c:284) - ==2782220== by 0x4D7130: grub_extcmd_dispatcher (extcmd.c:55) - ==2782220== by 0x4045A6: execute_command (grub-fstest.c:59) - ==2782220== by 0x4045A6: fstest (grub-fstest.c:433) - ==2782220== by 0x4045A6: main (grub-fstest.c:772) - -This happens when the process of reading the catalog file goes sufficiently -wrong that there's an attempt to read the extent overflow file, which has -not yet been loaded. Keep track of when the extent overflow file is -fully loaded and refuse to use it before then. - -The load valgrind doesn't like is btree->nodesize, and that's then used -to allocate a data structure. It looks like there are subsequently a lot -of reads based on that pointer so OOB reads are likely, and indeed crashes -(albeit difficult-to-replicate ones) have been observed in fuzzing. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=2ca0e5dbcdcb6fc93ccae39a0f39d0dba4a7ff20 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/fs/hfsplus.c | 14 ++++++++++++++ - include/grub/hfsplus.h | 2 ++ - 2 files changed, 16 insertions(+) - -diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c -index 1c7791b..361e5be 100644 ---- a/grub-core/fs/hfsplus.c -+++ b/grub-core/fs/hfsplus.c -@@ -177,6 +177,17 @@ grub_hfsplus_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) - break; - } - -+ /* -+ * If the extent overflow tree isn't ready yet, we can't look -+ * in it. This can happen where the catalog file is corrupted. -+ */ -+ if (!node->data->extoverflow_tree_ready) -+ { -+ grub_error (GRUB_ERR_BAD_FS, -+ "attempted to read extent overflow tree before loading"); -+ break; -+ } -+ - /* Set up the key to look for in the extent overflow file. */ - extoverflow.extkey.fileid = node->fileid; - extoverflow.extkey.type = 0; -@@ -241,6 +252,7 @@ grub_hfsplus_mount (grub_disk_t disk) - return 0; - - data->disk = disk; -+ data->extoverflow_tree_ready = 0; - - /* Read the bootblock. */ - grub_disk_read (disk, GRUB_HFSPLUS_SBLOCK, 0, sizeof (volheader), -@@ -357,6 +369,8 @@ grub_hfsplus_mount (grub_disk_t disk) - if (data->extoverflow_tree.nodesize < 2) - goto fail; - -+ data->extoverflow_tree_ready = 1; -+ - if (grub_hfsplus_read_file (&data->attr_tree.file, 0, 0, - sizeof (struct grub_hfsplus_btnode), - sizeof (header), (char *) &header) <= 0) -diff --git a/include/grub/hfsplus.h b/include/grub/hfsplus.h -index 117740a..e14dd31 100644 ---- a/include/grub/hfsplus.h -+++ b/include/grub/hfsplus.h -@@ -113,6 +113,8 @@ struct grub_hfsplus_data - struct grub_hfsplus_btree extoverflow_tree; - struct grub_hfsplus_btree attr_tree; - -+ int extoverflow_tree_ready; -+ - struct grub_hfsplus_file dirroot; - struct grub_hfsplus_file opened_file; - --- -2.19.1 - diff --git a/backport-0047-fs-hfs-Disable-under-lockdown.patch b/backport-0047-fs-hfs-Disable-under-lockdown.patch deleted file mode 100644 index 56de3c15240670cf3b5e7f07af25171726ffd4d4..0000000000000000000000000000000000000000 --- a/backport-0047-fs-hfs-Disable-under-lockdown.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 0cb62a411ee329bc3f25e46303c3e458b905bb34 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Mon, 18 Jan 2021 12:19:07 +1100 -Subject: [PATCH] fs/hfs: Disable under lockdown - -HFS has issues such as infinite mutual recursion that are simply too -complex to fix for such a legacy format. So simply do not permit -it to be loaded under lockdown. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=1c15848838d924552611247110723e2a1c17a5a1 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/fs/hfs.c | 7 +++++-- - 1 file changed, 5 insertions(+), 2 deletions(-) - -diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c -index 3fe842b..9a5b7bb 100644 ---- a/grub-core/fs/hfs.c -+++ b/grub-core/fs/hfs.c -@@ -30,6 +30,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -1433,11 +1434,13 @@ static struct grub_fs grub_hfs_fs = - - GRUB_MOD_INIT(hfs) - { -- grub_fs_register (&grub_hfs_fs); -+ if (!grub_is_lockdown ()) -+ grub_fs_register (&grub_hfs_fs); - my_mod = mod; - } - - GRUB_MOD_FINI(hfs) - { -- grub_fs_unregister (&grub_hfs_fs); -+ if (!grub_is_lockdown()) -+ grub_fs_unregister (&grub_hfs_fs); - } --- -2.19.1 - diff --git a/backport-0048-fs-sfs-Fix-over-read-of-root-object-name.patch b/backport-0048-fs-sfs-Fix-over-read-of-root-object-name.patch deleted file mode 100644 index 6a3025049fb92333e15437cff438a9d6bd8bbfaf..0000000000000000000000000000000000000000 --- a/backport-0048-fs-sfs-Fix-over-read-of-root-object-name.patch +++ /dev/null @@ -1,51 +0,0 @@ -From 087dad12b18f238b360aade771d34f4e8d50a8b9 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Mon, 18 Jan 2021 14:34:58 +1100 -Subject: [PATCH] fs/sfs: Fix over-read of root object name - -There's a read of the name of the root object that assumes that the name -is nul-terminated within the root block. This isn't guaranteed - it seems -SFS would require you to read multiple blocks to get a full name in general, -but maybe that doesn't apply to the root object. - -Either way, figure out how much space is left in the root block and don't -over-read it. This fixes some OOB reads. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=8d3ae59dee2930d640add3bba983006e1f5dd1b6 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/fs/sfs.c | 9 ++++++++- - 1 file changed, 8 insertions(+), 1 deletion(-) - -diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c -index de2b107..983e880 100644 ---- a/grub-core/fs/sfs.c -+++ b/grub-core/fs/sfs.c -@@ -373,6 +373,7 @@ grub_sfs_mount (grub_disk_t disk) - struct grub_sfs_objc *rootobjc; - char *rootobjc_data = 0; - grub_uint32_t blk; -+ unsigned int max_len; - - data = grub_malloc (sizeof (*data)); - if (!data) -@@ -421,7 +422,13 @@ grub_sfs_mount (grub_disk_t disk) - data->diropen.data = data; - data->diropen.cache = 0; - data->disk = disk; -- data->label = grub_strdup ((char *) (rootobjc->objects[0].filename)); -+ -+ /* We only read 1 block of data, so truncate the name if needed. */ -+ max_len = ((GRUB_DISK_SECTOR_SIZE << data->log_blocksize) -+ - 24 /* offsetof (struct grub_sfs_objc, objects) */ -+ - 25); /* offsetof (struct grub_sfs_obj, filename) */ -+ data->label = grub_zalloc (max_len + 1); -+ grub_strncpy (data->label, (char *) rootobjc->objects[0].filename, max_len); - - grub_free (rootobjc_data); - return data; --- -2.19.1 - diff --git a/backport-0049-fs-jfs-Do-not-move-to-leaf-level-if-name-length-is-n.patch b/backport-0049-fs-jfs-Do-not-move-to-leaf-level-if-name-length-is-n.patch deleted file mode 100644 index 0c8684c80fd76c498f32daa44aa9f5ce1611bec2..0000000000000000000000000000000000000000 --- a/backport-0049-fs-jfs-Do-not-move-to-leaf-level-if-name-length-is-n.patch +++ /dev/null @@ -1,35 +0,0 @@ -From fb52b550be82812b6e9a4eeb0bc80bf1ae67de0b Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Mon, 18 Jan 2021 14:51:11 +1100 -Subject: [PATCH] fs/jfs: Do not move to leaf level if name length is negative - -Fuzzing JFS revealed crashes where a negative number would be passed -to le_to_cpu16_copy(). There it would be cast to a large positive number -and the copy would read and write off the end of the respective buffers. - -Catch this at the top as well as the bottom of the loop. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=ffd5a46f68710e2781899d0be4d701429a5a817d - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/fs/jfs.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c -index d5a6d65..e5bbda6 100644 ---- a/grub-core/fs/jfs.c -+++ b/grub-core/fs/jfs.c -@@ -567,7 +567,7 @@ grub_jfs_getent (struct grub_jfs_diropen *diro) - - /* Move down to the leaf level. */ - nextent = leaf->next; -- if (leaf->next != 255) -+ if (leaf->next != 255 && len > 0) - do - { - next_leaf = &diro->next_leaf[nextent]; --- -2.19.1 - diff --git a/backport-0050-fs-jfs-Limit-the-extents-that-getblk-can-consider.patch b/backport-0050-fs-jfs-Limit-the-extents-that-getblk-can-consider.patch deleted file mode 100644 index c5f393bb012e5879c78ea3c56ded7a5299b253a1..0000000000000000000000000000000000000000 --- a/backport-0050-fs-jfs-Limit-the-extents-that-getblk-can-consider.patch +++ /dev/null @@ -1,63 +0,0 @@ -From 53d8b876fbe2b507845e81a7758a8bbe5f1d4f2d Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Mon, 18 Jan 2021 14:57:17 +1100 -Subject: [PATCH] fs/jfs: Limit the extents that getblk() can consider - -getblk() implicitly trusts that treehead->count is an accurate count of -the number of extents. However, that value is read from disk and is not -trustworthy, leading to OOB reads and crashes. I am not sure to what -extent the data read from OOB can influence subsequent program execution. - -Require callers to pass in the maximum number of extents for which -they have storage. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=bd0cf8148ccf721f6e39ffbd70f8abad0c8897f0 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/fs/jfs.c | 8 +++++--- - 1 file changed, 5 insertions(+), 3 deletions(-) - -diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c -index e5bbda6..804c42d 100644 ---- a/grub-core/fs/jfs.c -+++ b/grub-core/fs/jfs.c -@@ -261,13 +261,15 @@ static grub_err_t grub_jfs_lookup_symlink (struct grub_jfs_data *data, grub_uint - static grub_int64_t - getblk (struct grub_jfs_treehead *treehead, - struct grub_jfs_tree_extent *extents, -+ int max_extents, - struct grub_jfs_data *data, - grub_uint64_t blk) - { - int found = -1; - int i; - -- for (i = 0; i < grub_le_to_cpu16 (treehead->count) - 2; i++) -+ for (i = 0; i < grub_le_to_cpu16 (treehead->count) - 2 && -+ i < max_extents; i++) - { - if (treehead->flags & GRUB_JFS_TREE_LEAF) - { -@@ -302,7 +304,7 @@ getblk (struct grub_jfs_treehead *treehead, - << (grub_le_to_cpu16 (data->sblock.log2_blksz) - - GRUB_DISK_SECTOR_BITS), 0, - sizeof (*tree), (char *) tree)) -- ret = getblk (&tree->treehead, &tree->extents[0], data, blk); -+ ret = getblk (&tree->treehead, &tree->extents[0], 254, data, blk); - grub_free (tree); - return ret; - } -@@ -316,7 +318,7 @@ static grub_int64_t - grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode, - grub_uint64_t blk) - { -- return getblk (&inode->file.tree, &inode->file.extents[0], data, blk); -+ return getblk (&inode->file.tree, &inode->file.extents[0], 16, data, blk); - } - - --- -2.19.1 - diff --git a/backport-0051-fs-jfs-Catch-infinite-recursion.patch b/backport-0051-fs-jfs-Catch-infinite-recursion.patch deleted file mode 100644 index 44366d5fe1548c1edde1f22553517039e86fb878..0000000000000000000000000000000000000000 --- a/backport-0051-fs-jfs-Catch-infinite-recursion.patch +++ /dev/null @@ -1,47 +0,0 @@ -From 1311dfb93e144af93d6c91949101a802d46a510f Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Mon, 18 Jan 2021 15:47:24 +1100 -Subject: [PATCH] fs/jfs: Catch infinite recursion - -It's possible with a fuzzed filesystem for JFS to keep getblk()-ing -the same data over and over again, leading to stack exhaustion. - -Check if we'd be calling the function with exactly the same data as -was passed in, and if so abort. - -I'm not sure what the performance impact of this is and am open to -better ideas. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=223120dd83745126cb232a0248c9a8901d7e350d - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/fs/jfs.c | 11 ++++++++++- - 1 file changed, 10 insertions(+), 1 deletion(-) - -diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c -index 804c42d..6f7c439 100644 ---- a/grub-core/fs/jfs.c -+++ b/grub-core/fs/jfs.c -@@ -304,7 +304,16 @@ getblk (struct grub_jfs_treehead *treehead, - << (grub_le_to_cpu16 (data->sblock.log2_blksz) - - GRUB_DISK_SECTOR_BITS), 0, - sizeof (*tree), (char *) tree)) -- ret = getblk (&tree->treehead, &tree->extents[0], 254, data, blk); -+ { -+ if (grub_memcmp (&tree->treehead, treehead, sizeof (struct grub_jfs_treehead)) || -+ grub_memcmp (&tree->extents, extents, 254 * sizeof (struct grub_jfs_tree_extent))) -+ ret = getblk (&tree->treehead, &tree->extents[0], 254, data, blk); -+ else -+ { -+ grub_error (GRUB_ERR_BAD_FS, "jfs: infinite recursion detected"); -+ ret = -1; -+ } -+ } - grub_free (tree); - return ret; - } --- -2.19.1 - diff --git a/backport-0052-fs-nilfs2-Reject-too-large-keys.patch b/backport-0052-fs-nilfs2-Reject-too-large-keys.patch deleted file mode 100644 index 8623d8c08efe98948d0069f9c3d547b9a6831829..0000000000000000000000000000000000000000 --- a/backport-0052-fs-nilfs2-Reject-too-large-keys.patch +++ /dev/null @@ -1,47 +0,0 @@ -From 054375c8ae2e78a53b8a098265c18515770cf599 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Mon, 18 Jan 2021 16:49:09 +1100 -Subject: [PATCH] fs/nilfs2: Reject too-large keys - -NILFS2 has up to 7 keys, per the data structure. Do not permit array -indices in excess of that. - -This catches some OOB reads. I don't know how controllable the invalidly -read data is or if that could be used later in the program. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=20ab8cb44bc140a1dedda82a3fccdd45e9bc6929 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/fs/nilfs2.c | 7 ++++++- - 1 file changed, 6 insertions(+), 1 deletion(-) - -diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c -index 7ed148d..fee2242 100644 ---- a/grub-core/fs/nilfs2.c -+++ b/grub-core/fs/nilfs2.c -@@ -569,6 +569,11 @@ grub_nilfs2_btree_lookup (struct grub_nilfs2_data *data, - static inline grub_uint64_t - grub_nilfs2_direct_lookup (struct grub_nilfs2_inode *inode, grub_uint64_t key) - { -+ if (1 + key > 6) -+ { -+ grub_error (GRUB_ERR_BAD_FS, "key is too large"); -+ return 0xffffffffffffffff; -+ } - return grub_le_to_cpu64 (inode->i_bmap[1 + key]); - } - -@@ -584,7 +589,7 @@ grub_nilfs2_bmap_lookup (struct grub_nilfs2_data *data, - { - grub_uint64_t ptr; - ptr = grub_nilfs2_direct_lookup (inode, key); -- if (need_translate) -+ if (ptr != ((grub_uint64_t) 0xffffffffffffffff) && need_translate) - ptr = grub_nilfs2_dat_translate (data, ptr); - return ptr; - } --- -2.19.1 - diff --git a/backport-0053-fs-nilfs2-Don-t-search-children-if-provided-number-i.patch b/backport-0053-fs-nilfs2-Don-t-search-children-if-provided-number-i.patch deleted file mode 100644 index 3a79d1c72a4b436adcee09421eab3885e5574616..0000000000000000000000000000000000000000 --- a/backport-0053-fs-nilfs2-Don-t-search-children-if-provided-number-i.patch +++ /dev/null @@ -1,101 +0,0 @@ -From 1e3762857742b41d0752a9dd52513481bc4ecaf0 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Mon, 18 Jan 2021 16:49:44 +1100 -Subject: [PATCH] fs/nilfs2: Don't search children if provided number is too - large - -NILFS2 reads the number of children a node has from the node. Unfortunately, -that's not trustworthy. Check if it's beyond what the filesystem permits and -reject it if so. - -This blocks some OOB reads. I'm not sure how controllable the read is and what -could be done with invalidly read data later on. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=37c0eb05cdcc64c28d31c4ebd300f14d5239d05e - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/fs/nilfs2.c | 38 +++++++++++++++++++++++--------------- - 1 file changed, 23 insertions(+), 15 deletions(-) - -diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c -index fee2242..43ac1ad 100644 ---- a/grub-core/fs/nilfs2.c -+++ b/grub-core/fs/nilfs2.c -@@ -416,14 +416,34 @@ grub_nilfs2_btree_node_get_key (struct grub_nilfs2_btree_node *node, - } - - static inline int --grub_nilfs2_btree_node_lookup (struct grub_nilfs2_btree_node *node, -+grub_nilfs2_btree_node_nchildren_max (struct grub_nilfs2_data *data, -+ struct grub_nilfs2_btree_node *node) -+{ -+ int node_children_max = ((NILFS2_BLOCK_SIZE (data) - -+ sizeof (struct grub_nilfs2_btree_node) - -+ NILFS_BTREE_NODE_EXTRA_PAD_SIZE) / -+ (sizeof (grub_uint64_t) + sizeof (grub_uint64_t))); -+ -+ return (node->bn_flags & NILFS_BTREE_NODE_ROOT) ? 3 : node_children_max; -+} -+ -+static inline int -+grub_nilfs2_btree_node_lookup (struct grub_nilfs2_data *data, -+ struct grub_nilfs2_btree_node *node, - grub_uint64_t key, int *indexp) - { - grub_uint64_t nkey; - int index, low, high, s; - - low = 0; -+ - high = grub_le_to_cpu16 (node->bn_nchildren) - 1; -+ if (high >= grub_nilfs2_btree_node_nchildren_max (data, node)) -+ { -+ grub_error (GRUB_ERR_BAD_FS, "too many children"); -+ return 0; -+ } -+ - index = 0; - s = 0; - while (low <= high) -@@ -459,18 +479,6 @@ grub_nilfs2_btree_node_lookup (struct grub_nilfs2_btree_node *node, - return s == 0; - } - --static inline int --grub_nilfs2_btree_node_nchildren_max (struct grub_nilfs2_data *data, -- struct grub_nilfs2_btree_node *node) --{ -- int node_children_max = ((NILFS2_BLOCK_SIZE (data) - -- sizeof (struct grub_nilfs2_btree_node) - -- NILFS_BTREE_NODE_EXTRA_PAD_SIZE) / -- (sizeof (grub_uint64_t) + sizeof (grub_uint64_t))); -- -- return (node->bn_flags & NILFS_BTREE_NODE_ROOT) ? 3 : node_children_max; --} -- - static inline grub_uint64_t * - grub_nilfs2_btree_node_dptrs (struct grub_nilfs2_data *data, - struct grub_nilfs2_btree_node *node) -@@ -517,7 +525,7 @@ grub_nilfs2_btree_lookup (struct grub_nilfs2_data *data, - node = grub_nilfs2_btree_get_root (inode); - level = grub_nilfs2_btree_get_level (node); - -- found = grub_nilfs2_btree_node_lookup (node, key, &index); -+ found = grub_nilfs2_btree_node_lookup (data, node, key, &index); - ptr = grub_nilfs2_btree_node_get_ptr (data, node, index); - if (need_translate) - ptr = grub_nilfs2_dat_translate (data, ptr); -@@ -538,7 +546,7 @@ grub_nilfs2_btree_lookup (struct grub_nilfs2_data *data, - } - - if (!found) -- found = grub_nilfs2_btree_node_lookup (node, key, &index); -+ found = grub_nilfs2_btree_node_lookup (data, node, key, &index); - else - index = 0; - --- -2.19.1 - diff --git a/backport-0054-fs-nilfs2-Properly-bail-on-errors-in-grub_nilfs2_btr.patch b/backport-0054-fs-nilfs2-Properly-bail-on-errors-in-grub_nilfs2_btr.patch deleted file mode 100644 index 36e6da0e2cc27546fc3a79980517dc295a0e8776..0000000000000000000000000000000000000000 --- a/backport-0054-fs-nilfs2-Properly-bail-on-errors-in-grub_nilfs2_btr.patch +++ /dev/null @@ -1,69 +0,0 @@ -From 5d69fb2f9cee027c76ff179478ca3ec7069ac7ce Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Mon, 18 Jan 2021 17:06:19 +1100 -Subject: [PATCH] fs/nilfs2: Properly bail on errors in - grub_nilfs2_btree_node_lookup() - -We just introduced an error return in grub_nilfs2_btree_node_lookup(). -Make sure the callers catch it. - -At the same time, make sure that grub_nilfs2_btree_node_lookup() always -inits the index pointer passed to it. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=ca5d9ac206043b1fb4cb06259272fb1c5946bb6d - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/fs/nilfs2.c | 11 ++++++++--- - 1 file changed, 8 insertions(+), 3 deletions(-) - -diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c -index 43ac1ad..aaba002 100644 ---- a/grub-core/fs/nilfs2.c -+++ b/grub-core/fs/nilfs2.c -@@ -433,7 +433,7 @@ grub_nilfs2_btree_node_lookup (struct grub_nilfs2_data *data, - grub_uint64_t key, int *indexp) - { - grub_uint64_t nkey; -- int index, low, high, s; -+ int index = 0, low, high, s; - - low = 0; - -@@ -441,10 +441,10 @@ grub_nilfs2_btree_node_lookup (struct grub_nilfs2_data *data, - if (high >= grub_nilfs2_btree_node_nchildren_max (data, node)) - { - grub_error (GRUB_ERR_BAD_FS, "too many children"); -+ *indexp = index; - return 0; - } - -- index = 0; - s = 0; - while (low <= high) - { -@@ -526,6 +526,10 @@ grub_nilfs2_btree_lookup (struct grub_nilfs2_data *data, - level = grub_nilfs2_btree_get_level (node); - - found = grub_nilfs2_btree_node_lookup (data, node, key, &index); -+ -+ if (grub_errno != GRUB_ERR_NONE) -+ goto fail; -+ - ptr = grub_nilfs2_btree_node_get_ptr (data, node, index); - if (need_translate) - ptr = grub_nilfs2_dat_translate (data, ptr); -@@ -550,7 +554,8 @@ grub_nilfs2_btree_lookup (struct grub_nilfs2_data *data, - else - index = 0; - -- if (index < grub_nilfs2_btree_node_nchildren_max (data, node)) -+ if (index < grub_nilfs2_btree_node_nchildren_max (data, node) && -+ grub_errno == GRUB_ERR_NONE) - { - ptr = grub_nilfs2_btree_node_get_ptr (data, node, index); - if (need_translate) --- -2.19.1 - diff --git a/backport-0055-io-gzio-Bail-if-gzio-tl-td-is-NULL.patch b/backport-0055-io-gzio-Bail-if-gzio-tl-td-is-NULL.patch deleted file mode 100644 index caaa0184bdfc1a3e3cb271809db9699a9249f961..0000000000000000000000000000000000000000 --- a/backport-0055-io-gzio-Bail-if-gzio-tl-td-is-NULL.patch +++ /dev/null @@ -1,68 +0,0 @@ -From 4b1839b9d9220161a20041722458b39b269fb70d Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Wed, 13 Jan 2021 20:59:09 +1100 -Subject: [PATCH] io/gzio: Bail if gzio->tl/td is NULL - -This is an ugly fix that doesn't address why gzio->tl comes to be NULL. -However, it seems to be sufficient to patch up a bunch of NULL derefs. - -It would be good to revisit this in future and see if we can have -a cleaner solution that addresses some of the causes of the unexpected -NULL pointers. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=3334a5e6c86f10e715cca3bf66ce0fc2f164b61b - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/io/gzio.c | 20 ++++++++++++++++++++ - 1 file changed, 20 insertions(+) - -diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c -index 43d98a7..4a8eaea 100644 ---- a/grub-core/io/gzio.c -+++ b/grub-core/io/gzio.c -@@ -669,6 +669,13 @@ inflate_codes_in_window (grub_gzio_t gzio) - { - if (! gzio->code_state) - { -+ -+ if (gzio->tl == NULL) -+ { -+ grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "NULL gzio->tl"); -+ return 1; -+ } -+ - NEEDBITS ((unsigned) gzio->bl); - if ((e = (t = gzio->tl + ((unsigned) b & ml))->e) > 16) - do -@@ -707,6 +714,12 @@ inflate_codes_in_window (grub_gzio_t gzio) - n = t->v.n + ((unsigned) b & mask_bits[e]); - DUMPBITS (e); - -+ if (gzio->td == NULL) -+ { -+ grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "NULL gzio->td"); -+ return 1; -+ } -+ - /* decode distance of block to copy */ - NEEDBITS ((unsigned) gzio->bd); - if ((e = (t = gzio->td + ((unsigned) b & md))->e) > 16) -@@ -917,6 +930,13 @@ init_dynamic_block (grub_gzio_t gzio) - n = nl + nd; - m = mask_bits[gzio->bl]; - i = l = 0; -+ -+ if (gzio->tl == NULL) -+ { -+ grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "NULL gzio->tl"); -+ return; -+ } -+ - while ((unsigned) i < n) - { - NEEDBITS ((unsigned) gzio->bl); --- -2.19.1 - diff --git a/backport-0056-io-gzio-Add-init_dynamic_block-clean-up-if-unpacking.patch b/backport-0056-io-gzio-Add-init_dynamic_block-clean-up-if-unpacking.patch deleted file mode 100644 index d454d9fd247eb8d57e52c9dcf6386e916917d0a2..0000000000000000000000000000000000000000 --- a/backport-0056-io-gzio-Add-init_dynamic_block-clean-up-if-unpacking.patch +++ /dev/null @@ -1,68 +0,0 @@ -From 00c2eb1b68e59d50f8bbd5659d9c4b3bd8fc899a Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Thu, 21 Jan 2021 00:05:58 +1100 -Subject: [PATCH] io/gzio: Add init_dynamic_block() clean up if unpacking codes - fails - -init_dynamic_block() didn't clean up gzio->tl and td in some error -paths. This left td pointing to part of tl. Then in grub_gzio_close(), -when tl was freed the storage for td would also be freed. The code then -attempts to free td explicitly, performing a UAF and then a double free. - -Explicitly clean up tl and td in the error paths. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=18490336d91da2b532277cba56473bfed1376fc4 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/io/gzio.c | 12 +++++++++--- - 1 file changed, 9 insertions(+), 3 deletions(-) - -diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c -index 4a8eaea..d38b43f 100644 ---- a/grub-core/io/gzio.c -+++ b/grub-core/io/gzio.c -@@ -953,7 +953,7 @@ init_dynamic_block (grub_gzio_t gzio) - if ((unsigned) i + j > n) - { - grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "too many codes found"); -- return; -+ goto fail; - } - while (j--) - ll[i++] = l; -@@ -966,7 +966,7 @@ init_dynamic_block (grub_gzio_t gzio) - if ((unsigned) i + j > n) - { - grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "too many codes found"); -- return; -+ goto fail; - } - while (j--) - ll[i++] = 0; -@@ -981,7 +981,7 @@ init_dynamic_block (grub_gzio_t gzio) - if ((unsigned) i + j > n) - { - grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "too many codes found"); -- return; -+ goto fail; - } - while (j--) - ll[i++] = 0; -@@ -1019,6 +1019,12 @@ init_dynamic_block (grub_gzio_t gzio) - /* indicate we're now working on a block */ - gzio->code_state = 0; - gzio->block_len++; -+ return; -+ -+fail: -+ huft_free (gzio->tl); -+ gzio->td = NULL; -+ gzio->tl = NULL; - } - - --- -2.19.1 - diff --git a/backport-0057-io-gzio-Catch-missing-values-in-huft_build-and-bail.patch b/backport-0057-io-gzio-Catch-missing-values-in-huft_build-and-bail.patch deleted file mode 100644 index 13e975ac33e398d353a7d140fe6397a5808dcdca..0000000000000000000000000000000000000000 --- a/backport-0057-io-gzio-Catch-missing-values-in-huft_build-and-bail.patch +++ /dev/null @@ -1,58 +0,0 @@ -From 5c1220e03508fe8155d2c963eb38fe733bc48e40 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Thu, 21 Jan 2021 12:20:49 +1100 -Subject: [PATCH] io/gzio: Catch missing values in huft_build() and bail - -In huft_build(), "v" is a table of values in order of bit length. -The code later (when setting up table entries in "r") assumes that all -elements of this array corresponding to a code are initialized and less -than N_MAX. However, it doesn't enforce this. - -With sufficiently manipulated inputs (e.g. from fuzzing), there can be -elements of "v" that are not filled. Therefore a lookup into "e" or "d" -will use an uninitialized value. This can lead to an invalid/OOB read on -those values, often leading to a crash. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=4e76b08f7171a8603d74fcafb27409a91f578647 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/io/gzio.c | 10 +++++++++- - 1 file changed, 9 insertions(+), 1 deletion(-) - -diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c -index d38b43f..0b95cf3 100644 ---- a/grub-core/io/gzio.c -+++ b/grub-core/io/gzio.c -@@ -507,6 +507,7 @@ huft_build (unsigned *b, /* code lengths in bits (all assumed <= BMAX) */ - } - - /* Make a table of values in order of bit lengths */ -+ grub_memset (v, N_MAX, ARRAY_SIZE (v)); - p = b; - i = 0; - do -@@ -588,11 +589,18 @@ huft_build (unsigned *b, /* code lengths in bits (all assumed <= BMAX) */ - r.v.n = (ush) (*p); /* simple code is just the value */ - p++; /* one compiler does not like *p++ */ - } -- else -+ else if (*p < N_MAX) - { - r.e = (uch) e[*p - s]; /* non-simple--look up in lists */ - r.v.n = d[*p++ - s]; - } -+ else -+ { -+ /* Detected an uninitialised value, abort. */ -+ if (h) -+ huft_free (u[0]); -+ return 2; -+ } - - /* fill code-like entries with r */ - f = 1 << (k - w); --- -2.19.1 - diff --git a/backport-0058-io-gzio-Zero-gzio-tl-td-in-init_dynamic_block-if-huf.patch b/backport-0058-io-gzio-Zero-gzio-tl-td-in-init_dynamic_block-if-huf.patch deleted file mode 100644 index b8d0e0f77e20d1aa6ab2c991b048af1c0175d5f0..0000000000000000000000000000000000000000 --- a/backport-0058-io-gzio-Zero-gzio-tl-td-in-init_dynamic_block-if-huf.patch +++ /dev/null @@ -1,43 +0,0 @@ -From 1d80defcd0db38752fbe94a53ea41c27c1117c80 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Thu, 21 Jan 2021 12:22:28 +1100 -Subject: [PATCH] io/gzio: Zero gzio->tl/td in init_dynamic_block() if - huft_build() fails - -If huft_build() fails, gzio->tl or gzio->td could contain pointers that -are no longer valid. Zero them out. - -This prevents a double free when grub_gzio_close() comes through and -attempts to free them again. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=b5a2b59cc5b8f5ee7ba3b951e7693e402d5b3a6f - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/io/gzio.c | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c -index 0b95cf3..df8cf66 100644 ---- a/grub-core/io/gzio.c -+++ b/grub-core/io/gzio.c -@@ -1010,6 +1010,7 @@ init_dynamic_block (grub_gzio_t gzio) - gzio->bl = lbits; - if (huft_build (ll, nl, 257, cplens, cplext, &gzio->tl, &gzio->bl) != 0) - { -+ gzio->tl = 0; - grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, - "failed in building a Huffman code table"); - return; -@@ -1019,6 +1020,7 @@ init_dynamic_block (grub_gzio_t gzio) - { - huft_free (gzio->tl); - gzio->tl = 0; -+ gzio->td = 0; - grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, - "failed in building a Huffman code table"); - return; --- -2.19.1 - diff --git a/backport-0059-disk-lvm-Don-t-go-beyond-the-end-of-the-data-we-read.patch b/backport-0059-disk-lvm-Don-t-go-beyond-the-end-of-the-data-we-read.patch deleted file mode 100644 index 1c9c24c0bf207fd17cc5de88e55d831f3253bda2..0000000000000000000000000000000000000000 --- a/backport-0059-disk-lvm-Don-t-go-beyond-the-end-of-the-data-we-read.patch +++ /dev/null @@ -1,50 +0,0 @@ -From 9251d03c58041e300f935379e9dd81375106a3ac Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Thu, 21 Jan 2021 17:59:14 +1100 -Subject: [PATCH] disk/lvm: Don't go beyond the end of the data we read from - disk - -We unconditionally trusted offset_xl from the LVM label header, even if -it told us that the PV header/disk locations were way off past the end -of the data we read from disk. - -Require that the offset be sane, fixing an OOB read and crash. - -Fixes: CID 314367, CID 314371 - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=a8cc95de74ccc3ad090e8062ac335c844f13c9f4 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/disk/lvm.c | 14 ++++++++++++++ - 1 file changed, 14 insertions(+) - -diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c -index 9f5630c..25e6c70 100644 ---- a/grub-core/disk/lvm.c -+++ b/grub-core/disk/lvm.c -@@ -142,6 +142,20 @@ grub_lvm_detect (grub_disk_t disk, - goto fail; - } - -+ /* -+ * We read a grub_lvm_pv_header and then 2 grub_lvm_disk_locns that -+ * immediately follow the PV header. Make sure we have space for both. -+ */ -+ if (grub_le_to_cpu32 (lh->offset_xl) >= -+ GRUB_LVM_LABEL_SIZE - sizeof (struct grub_lvm_pv_header) - -+ 2 * sizeof (struct grub_lvm_disk_locn)) -+ { -+#ifdef GRUB_UTIL -+ grub_util_info ("LVM PV header/disk locations are beyond the end of the block"); -+#endif -+ goto fail; -+ } -+ - pvh = (struct grub_lvm_pv_header *) (buf + grub_le_to_cpu32(lh->offset_xl)); - - for (i = 0, j = 0; i < GRUB_LVM_ID_LEN; i++) --- -2.19.1 - diff --git a/backport-0060-disk-lvm-Don-t-blast-past-the-end-of-the-circular-me.patch b/backport-0060-disk-lvm-Don-t-blast-past-the-end-of-the-circular-me.patch deleted file mode 100644 index 6d20ae41acea96ca0ab680c343c6bf0a86cf0c11..0000000000000000000000000000000000000000 --- a/backport-0060-disk-lvm-Don-t-blast-past-the-end-of-the-circular-me.patch +++ /dev/null @@ -1,44 +0,0 @@ -From f702b93b2a023c941a49d6d3e18915fdd6c14c89 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Thu, 21 Jan 2021 18:19:51 +1100 -Subject: [PATCH] disk/lvm: Don't blast past the end of the circular metadata - buffer - -This catches at least some OOB reads, and it's possible I suppose that -if 2 * mda_size is less than GRUB_LVM_MDA_HEADER_SIZE it might catch some -OOB writes too (although that hasn't showed up as a crash in fuzzing yet). - -It's a bit ugly and I'd appreciate better suggestions. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=27a79bf38e6d050e497eb96a3fdddce43af25577 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/disk/lvm.c | 10 ++++++++++ - 1 file changed, 10 insertions(+) - -diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c -index 25e6c70..f25521a 100644 ---- a/grub-core/disk/lvm.c -+++ b/grub-core/disk/lvm.c -@@ -215,6 +215,16 @@ grub_lvm_detect (grub_disk_t disk, - if (grub_le_to_cpu64 (rlocn->offset) + grub_le_to_cpu64 (rlocn->size) > - grub_le_to_cpu64 (mdah->size)) - { -+ if (2 * mda_size < GRUB_LVM_MDA_HEADER_SIZE || -+ (grub_le_to_cpu64 (rlocn->offset) + grub_le_to_cpu64 (rlocn->size) - -+ grub_le_to_cpu64 (mdah->size) > mda_size - GRUB_LVM_MDA_HEADER_SIZE)) -+ { -+#ifdef GRUB_UTIL -+ grub_util_info ("cannot copy metadata wrap in circular buffer"); -+#endif -+ goto fail2; -+ } -+ - /* Metadata is circular. Copy the wrap in place. */ - grub_memcpy (metadatabuf + mda_size, - metadatabuf + GRUB_LVM_MDA_HEADER_SIZE, --- -2.19.1 - diff --git a/backport-0061-disk-lvm-Bail-on-missing-PV-list.patch b/backport-0061-disk-lvm-Bail-on-missing-PV-list.patch deleted file mode 100644 index 3c3471a45a40d2c2f94b56e2ab0c766f446a5179..0000000000000000000000000000000000000000 --- a/backport-0061-disk-lvm-Bail-on-missing-PV-list.patch +++ /dev/null @@ -1,36 +0,0 @@ -From c8ca81d1cd6f486b028c34533c89b36f250870d4 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Thu, 21 Jan 2021 18:54:29 +1100 -Subject: [PATCH] disk/lvm: Bail on missing PV list - -There's an if block for the presence of "physical_volumes {", but if -that block is absent, then p remains NULL and a NULL-deref will result -when looking for logical volumes. - -It doesn't seem like LVM makes sense without physical volumes, so error -out rather than crashing. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=2958695c4cdc785de6ed708709af071a2d20afef - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/disk/lvm.c | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c -index f25521a..944c398 100644 ---- a/grub-core/disk/lvm.c -+++ b/grub-core/disk/lvm.c -@@ -371,6 +371,8 @@ grub_lvm_detect (grub_disk_t disk, - goto fail4; - } - } -+ else -+ goto fail4; - - p = grub_strstr (p, "logical_volumes {"); - if (p) --- -2.19.1 - diff --git a/backport-0062-disk-lvm-Do-not-crash-if-an-expected-string-is-not-f.patch b/backport-0062-disk-lvm-Do-not-crash-if-an-expected-string-is-not-f.patch deleted file mode 100644 index ada14d730f17898572034277114a3754da9f2dac..0000000000000000000000000000000000000000 --- a/backport-0062-disk-lvm-Do-not-crash-if-an-expected-string-is-not-f.patch +++ /dev/null @@ -1,84 +0,0 @@ -From e9b6e755fd0f4fcfac36c149d2c74cc2d483d65a Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Thu, 21 Jan 2021 18:35:22 +1100 -Subject: [PATCH] disk/lvm: Do not crash if an expected string is not found - -Clean up a bunch of cases where we could have strstr() fail and lead to -us dereferencing NULL. - -We'll still leak memory in some cases (loops don't clean up allocations -from earlier iterations if a later iteration fails) but at least we're -not crashing. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=db29073fc7aec71a40dabfc722a96ea9f3280907 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/disk/lvm.c | 22 +++++++++++++++++----- - 1 file changed, 17 insertions(+), 5 deletions(-) - -diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c -index 944c398..85ee89c 100644 ---- a/grub-core/disk/lvm.c -+++ b/grub-core/disk/lvm.c -@@ -540,7 +540,16 @@ grub_lvm_detect (grub_disk_t disk, - } - - if (seg->node_count != 1) -- seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); -+ { -+ seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); -+ if (p == NULL) -+ { -+#ifdef GRUB_UTIL -+ grub_util_info ("unknown stripe_size"); -+#endif -+ goto lvs_segment_fail; -+ } -+ } - - seg->nodes = grub_calloc (seg->node_count, - sizeof (*stripe)); -@@ -560,7 +569,7 @@ grub_lvm_detect (grub_disk_t disk, - { - p = grub_strchr (p, '"'); - if (p == NULL) -- continue; -+ goto lvs_segment_fail2; - q = ++p; - while (*q != '"') - q++; -@@ -579,7 +588,10 @@ grub_lvm_detect (grub_disk_t disk, - stripe->start = grub_lvm_getvalue (&p, ",") - * vg->extent_size; - if (p == NULL) -- continue; -+ { -+ grub_free (stripe->name); -+ goto lvs_segment_fail2; -+ } - - stripe++; - } -@@ -616,7 +628,7 @@ grub_lvm_detect (grub_disk_t disk, - - p = grub_strchr (p, '"'); - if (p == NULL) -- continue; -+ goto lvs_segment_fail2; - q = ++p; - while (*q != '"') - q++; -@@ -704,7 +716,7 @@ grub_lvm_detect (grub_disk_t disk, - p = p ? grub_strchr (p + 1, '"') : 0; - p = p ? grub_strchr (p + 1, '"') : 0; - if (p == NULL) -- continue; -+ goto lvs_segment_fail2; - q = ++p; - while (*q != '"') - q++; --- -2.19.1 - diff --git a/backport-0063-lvm-Add-LVM-cache-logical-volume-handling.patch b/backport-0063-lvm-Add-LVM-cache-logical-volume-handling.patch deleted file mode 100644 index 7613767861ea09d53ace0e96908b5944c1a27c0c..0000000000000000000000000000000000000000 --- a/backport-0063-lvm-Add-LVM-cache-logical-volume-handling.patch +++ /dev/null @@ -1,286 +0,0 @@ -From cd73fa65a8fc466950d49ee854f1b986730d94e7 Mon Sep 17 00:00:00 2001 -From: Michael Chang -Date: Thu, 19 Mar 2020 13:56:13 +0800 -Subject: [PATCH] lvm: Add LVM cache logical volume handling - -The LVM cache logical volume is the logical volume consisting of the original -and the cache pool logical volume. The original is usually on a larger and -slower storage device while the cache pool is on a smaller and faster one. The -performance of the original volume can be improved by storing the frequently -used data on the cache pool to utilize the greater performance of faster -device. - -The default cache mode "writethrough" ensures that any data written will be -stored both in the cache and on the origin LV, therefore grub can be straight -to read the original lv as no data loss is guarenteed. - -The second cache mode is "writeback", which delays writing from the cache pool -back to the origin LV to have increased performance. The drawback is potential -data loss if losing the associated cache device. - -During the boot time grub reads the LVM offline i.e. LVM volumes are not -activated and mounted, hence it should be fine to read directly from original -lv since all cached data should have been flushed back in the process of taking -it offline. - -It is also not much helpful to the situation by adding fsync calls to the -install code. The fsync did not force to write back dirty cache to the original -device and rather it would update associated cache metadata to complete the -write transaction with the cache device. IOW the writes to cached blocks still -go only to the cache device. - -To write back dirty cache, as LVM cache did not support dirty cache flush per -block range, there'no way to do it for file. On the other hand the "cleaner" -policy is implemented and can be used to write back "all" dirty blocks in a -cache, which effectively drain all dirty cache gradually to attain and last in -the "clean" state, which can be useful for shrinking or decommissioning a -cache. The result and effect is not what we are looking for here. - -In conclusion, as it seems no way to enforce file writes to the original -device, grub may suffer from power failure as it cannot assemble the cache -device and read the dirty data from it. However since the case is only -applicable to writeback mode which is sensitive to data lost in nature, I'd -still like to propose my (relatively simple) patch and treat reading dirty -cache as improvement. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/grub-core/disk/lvm.c?id=0454b0445393aafc5600e92ef0c39494e333b135 - -Signed-off-by: Michael Chang -Reviewed-by: Daniel Kiper ---- - grub-core/disk/lvm.c | 191 ++++++++++++++++++++++++++++++++++++++++++- - 1 file changed, 190 insertions(+), 1 deletion(-) - -diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c -index 85ee89c..e5d6c3f 100644 ---- a/grub-core/disk/lvm.c -+++ b/grub-core/disk/lvm.c -@@ -34,7 +34,14 @@ - - GRUB_MOD_LICENSE ("GPLv3+"); - -- -+struct cache_lv -+{ -+ struct grub_diskfilter_lv *lv; -+ char *cache_pool; -+ char *origin; -+ struct cache_lv *next; -+}; -+ - /* Go the string STR and return the number after STR. *P will point - at the number. In case STR is not found, *P will be NULL and the - return value will be 0. */ -@@ -96,6 +103,34 @@ grub_lvm_check_flag (const char *p, const char *str, const char *flag) - } - } - -+static void -+grub_lvm_free_cache_lvs (struct cache_lv *cache_lvs) -+{ -+ struct cache_lv *cache; -+ -+ while ((cache = cache_lvs)) -+ { -+ cache_lvs = cache_lvs->next; -+ -+ if (cache->lv) -+ { -+ unsigned int i; -+ -+ for (i = 0; i < cache->lv->segment_count; ++i) -+ if (cache->lv->segments) -+ grub_free (cache->lv->segments[i].nodes); -+ grub_free (cache->lv->segments); -+ grub_free (cache->lv->fullname); -+ grub_free (cache->lv->idname); -+ grub_free (cache->lv->name); -+ } -+ grub_free (cache->lv); -+ grub_free (cache->origin); -+ grub_free (cache->cache_pool); -+ grub_free (cache); -+ } -+} -+ - static struct grub_diskfilter_vg * - grub_lvm_detect (grub_disk_t disk, - struct grub_diskfilter_pv_id *id, -@@ -281,6 +316,8 @@ grub_lvm_detect (grub_disk_t disk, - - if (! vg) - { -+ struct cache_lv *cache_lvs = NULL; -+ - /* First time we see this volume group. We've to create the - whole volume group structure. */ - vg = grub_malloc (sizeof (*vg)); -@@ -742,6 +779,106 @@ grub_lvm_detect (grub_disk_t disk, - seg->nodes[seg->node_count - 1].name = tmp; - } - } -+ else if (grub_memcmp (p, "cache\"", -+ sizeof ("cache\"") - 1) == 0) -+ { -+ struct cache_lv *cache = NULL; -+ -+ char *p2, *p3; -+ grub_size_t sz; -+ -+ cache = grub_zalloc (sizeof (*cache)); -+ if (!cache) -+ goto cache_lv_fail; -+ cache->lv = grub_zalloc (sizeof (*cache->lv)); -+ if (!cache->lv) -+ goto cache_lv_fail; -+ grub_memcpy (cache->lv, lv, sizeof (*cache->lv)); -+ -+ if (lv->fullname) -+ { -+ cache->lv->fullname = grub_strdup (lv->fullname); -+ if (!cache->lv->fullname) -+ goto cache_lv_fail; -+ } -+ if (lv->idname) -+ { -+ cache->lv->idname = grub_strdup (lv->idname); -+ if (!cache->lv->idname) -+ goto cache_lv_fail; -+ } -+ if (lv->name) -+ { -+ cache->lv->name = grub_strdup (lv->name); -+ if (!cache->lv->name) -+ goto cache_lv_fail; -+ } -+ -+ skip_lv = 1; -+ -+ p2 = grub_strstr (p, "cache_pool = \""); -+ if (!p2) -+ goto cache_lv_fail; -+ -+ p2 = grub_strchr (p2, '"'); -+ if (!p2) -+ goto cache_lv_fail; -+ -+ p3 = ++p2; -+ p3 = grub_strchr (p3, '"'); -+ if (!p3) -+ goto cache_lv_fail; -+ -+ sz = p3 - p2; -+ -+ cache->cache_pool = grub_malloc (sz + 1); -+ if (!cache->cache_pool) -+ goto cache_lv_fail; -+ grub_memcpy (cache->cache_pool, p2, sz); -+ cache->cache_pool[sz] = '\0'; -+ -+ p2 = grub_strstr (p, "origin = \""); -+ if (!p2) -+ goto cache_lv_fail; -+ -+ p2 = grub_strchr (p2, '"'); -+ if (!p2) -+ goto cache_lv_fail; -+ -+ p3 = ++p2; -+ p3 = grub_strchr (p3, '"'); -+ if (!p3) -+ goto cache_lv_fail; -+ -+ sz = p3 - p2; -+ -+ cache->origin = grub_malloc (sz + 1); -+ if (!cache->origin) -+ goto cache_lv_fail; -+ grub_memcpy (cache->origin, p2, sz); -+ cache->origin[sz] = '\0'; -+ -+ cache->next = cache_lvs; -+ cache_lvs = cache; -+ break; -+ -+ cache_lv_fail: -+ if (cache) -+ { -+ grub_free (cache->origin); -+ grub_free (cache->cache_pool); -+ if (cache->lv) -+ { -+ grub_free (cache->lv->fullname); -+ grub_free (cache->lv->idname); -+ grub_free (cache->lv->name); -+ } -+ grub_free (cache->lv); -+ grub_free (cache); -+ } -+ grub_lvm_free_cache_lvs (cache_lvs); -+ goto fail4; -+ } - else - { - #ifdef GRUB_UTIL -@@ -818,6 +955,58 @@ grub_lvm_detect (grub_disk_t disk, - } - - } -+ -+ { -+ struct cache_lv *cache; -+ -+ for (cache = cache_lvs; cache; cache = cache->next) -+ { -+ struct grub_diskfilter_lv *lv; -+ -+ for (lv = vg->lvs; lv; lv = lv->next) -+ if (grub_strcmp (lv->name, cache->origin) == 0) -+ break; -+ if (lv) -+ { -+ cache->lv->segments = grub_malloc (lv->segment_count * sizeof (*lv->segments)); -+ if (!cache->lv->segments) -+ { -+ grub_lvm_free_cache_lvs (cache_lvs); -+ goto fail4; -+ } -+ grub_memcpy (cache->lv->segments, lv->segments, lv->segment_count * sizeof (*lv->segments)); -+ -+ for (i = 0; i < lv->segment_count; ++i) -+ { -+ struct grub_diskfilter_node *nodes = lv->segments[i].nodes; -+ grub_size_t node_count = lv->segments[i].node_count; -+ -+ cache->lv->segments[i].nodes = grub_malloc (node_count * sizeof (*nodes)); -+ if (!cache->lv->segments[i].nodes) -+ { -+ for (j = 0; j < i; ++j) -+ grub_free (cache->lv->segments[j].nodes); -+ grub_free (cache->lv->segments); -+ cache->lv->segments = NULL; -+ grub_lvm_free_cache_lvs (cache_lvs); -+ goto fail4; -+ } -+ grub_memcpy (cache->lv->segments[i].nodes, nodes, node_count * sizeof (*nodes)); -+ } -+ -+ if (cache->lv->segments) -+ { -+ cache->lv->segment_count = lv->segment_count; -+ cache->lv->vg = vg; -+ cache->lv->next = vg->lvs; -+ vg->lvs = cache->lv; -+ cache->lv = NULL; -+ } -+ } -+ } -+ } -+ -+ grub_lvm_free_cache_lvs (cache_lvs); - if (grub_diskfilter_vg_register (vg)) - goto fail4; - } --- -2.19.1 - diff --git a/backport-0064-disk-lvm-Do-not-overread-metadata.patch b/backport-0064-disk-lvm-Do-not-overread-metadata.patch deleted file mode 100644 index 5a77cf7c3bf238292c72181f5de639ddd48ea254..0000000000000000000000000000000000000000 --- a/backport-0064-disk-lvm-Do-not-overread-metadata.patch +++ /dev/null @@ -1,130 +0,0 @@ -From 6a079d978c3c4c77da338b81880799146e47e6bf Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Thu, 21 Jan 2021 18:35:22 +1100 -Subject: [PATCH] disk/lvm: Do not overread metadata - -We could reach the end of valid metadata and not realize, leading to -some buffer overreads. Check if we have reached the end and bail. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=1155d7dffd3337942cb7583706b429d567d4db86 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/disk/lvm.c | 35 +++++++++++++++++++++++++++++------ - 1 file changed, 29 insertions(+), 6 deletions(-) - -diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c -index e5d6c3f..a44861f 100644 ---- a/grub-core/disk/lvm.c -+++ b/grub-core/disk/lvm.c -@@ -351,17 +351,23 @@ grub_lvm_detect (grub_disk_t disk, - while (1) - { - grub_ssize_t s; -- while (grub_isspace (*p)) -+ while (grub_isspace (*p) && p < mda_end) - p++; - -+ if (p == mda_end) -+ goto fail4; -+ - if (*p == '}') - break; - - pv = grub_zalloc (sizeof (*pv)); - q = p; -- while (*q != ' ') -+ while (*q != ' ' && q < mda_end) - q++; - -+ if (q == mda_end) -+ goto pvs_fail_noname; -+ - s = q - p; - pv->name = grub_malloc (s + 1); - grub_memcpy (pv->name, p, s); -@@ -404,6 +410,7 @@ grub_lvm_detect (grub_disk_t disk, - continue; - pvs_fail: - grub_free (pv->name); -+ pvs_fail_noname: - grub_free (pv); - goto fail4; - } -@@ -425,18 +432,24 @@ grub_lvm_detect (grub_disk_t disk, - struct grub_diskfilter_segment *seg; - int is_pvmove; - -- while (grub_isspace (*p)) -+ while (grub_isspace (*p) && p < mda_end) - p++; - -+ if (p == mda_end) -+ goto fail4; -+ - if (*p == '}') - break; - - lv = grub_zalloc (sizeof (*lv)); - - q = p; -- while (*q != ' ') -+ while (*q != ' ' && q < mda_end) - q++; - -+ if (q == mda_end) -+ goto lvs_fail; -+ - s = q - p; - lv->name = grub_strndup (p, s); - if (!lv->name) -@@ -608,9 +621,12 @@ grub_lvm_detect (grub_disk_t disk, - if (p == NULL) - goto lvs_segment_fail2; - q = ++p; -- while (*q != '"') -+ while (q < mda_end && *q != '"') - q++; - -+ if (q == mda_end) -+ goto lvs_segment_fail2; -+ - s = q - p; - - stripe->name = grub_malloc (s + 1); -@@ -667,9 +683,12 @@ grub_lvm_detect (grub_disk_t disk, - if (p == NULL) - goto lvs_segment_fail2; - q = ++p; -- while (*q != '"') -+ while (q < mda_end && *q != '"') - q++; - -+ if (q == mda_end) -+ goto lvs_segment_fail2; -+ - s = q - p; - - lvname = grub_malloc (s + 1); -@@ -825,6 +844,8 @@ grub_lvm_detect (grub_disk_t disk, - goto cache_lv_fail; - - p3 = ++p2; -+ if (p3 == mda_end) -+ goto cache_lv_fail; - p3 = grub_strchr (p3, '"'); - if (!p3) - goto cache_lv_fail; -@@ -846,6 +867,8 @@ grub_lvm_detect (grub_disk_t disk, - goto cache_lv_fail; - - p3 = ++p2; -+ if (p3 == mda_end) -+ goto cache_lv_fail; - p3 = grub_strchr (p3, '"'); - if (!p3) - goto cache_lv_fail; --- -2.19.1 - diff --git a/backport-0065-disk-lvm-Sanitize-rlocn-offset-to-prevent-wild-read.patch b/backport-0065-disk-lvm-Sanitize-rlocn-offset-to-prevent-wild-read.patch deleted file mode 100644 index b7bcdafca322949a2184f2ccc33892ff1498749b..0000000000000000000000000000000000000000 --- a/backport-0065-disk-lvm-Sanitize-rlocn-offset-to-prevent-wild-read.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 6074485c541ef5b96acd051854e5ddad77acc858 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Fri, 22 Jan 2021 14:43:58 +1100 -Subject: [PATCH] disk/lvm: Sanitize rlocn->offset to prevent wild read - -rlocn->offset is read directly from disk and added to the metadatabuf -pointer to create a pointer to a block of metadata. It's a 64-bit -quantity so as long as you don't overflow you can set subsequent -pointers to point anywhere in memory. - -Require that rlocn->offset fits within the metadata buffer size. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=701293684742d00133b39bf957d3642c81dc83f4 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/disk/lvm.c | 8 ++++++++ - 1 file changed, 8 insertions(+) - -diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c -index a44861f..cf8f597 100644 ---- a/grub-core/disk/lvm.c -+++ b/grub-core/disk/lvm.c -@@ -247,6 +247,14 @@ grub_lvm_detect (grub_disk_t disk, - } - - rlocn = mdah->raw_locns; -+ if (grub_le_to_cpu64 (rlocn->offset) >= grub_le_to_cpu64 (mda_size)) -+ { -+#ifdef GRUB_UTIL -+ grub_util_info ("metadata offset is beyond end of metadata area"); -+#endif -+ goto fail2; -+ } -+ - if (grub_le_to_cpu64 (rlocn->offset) + grub_le_to_cpu64 (rlocn->size) > - grub_le_to_cpu64 (mdah->size)) - { --- -2.19.1 - diff --git a/backport-0066-disk-lvm-Do-not-allow-a-LV-to-be-it-s-own-segment-s-.patch b/backport-0066-disk-lvm-Do-not-allow-a-LV-to-be-it-s-own-segment-s-.patch deleted file mode 100644 index 595ad11180d06f7be2ebb69f8f65ee976b4eea60..0000000000000000000000000000000000000000 --- a/backport-0066-disk-lvm-Do-not-allow-a-LV-to-be-it-s-own-segment-s-.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 5ee2584caa3acd9289d2eedee38a9a73101aa1fe Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Fri, 22 Jan 2021 14:42:21 +1100 -Subject: [PATCH] disk/lvm: Do not allow a LV to be it's own segment's node's - LV - -This prevents infinite recursion in the diskfilter verification code. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=e18a00073890021362b4a48097672f1d4b340d3c - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/disk/lvm.c | 10 +++++++--- - 1 file changed, 7 insertions(+), 3 deletions(-) - -diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c -index cf8f597..7fb1b4e 100644 ---- a/grub-core/disk/lvm.c -+++ b/grub-core/disk/lvm.c -@@ -980,9 +980,13 @@ grub_lvm_detect (grub_disk_t disk, - } - if (lv1->segments[i].nodes[j].pv == NULL) - for (lv2 = vg->lvs; lv2; lv2 = lv2->next) -- if (grub_strcmp (lv2->name, -- lv1->segments[i].nodes[j].name) == 0) -- lv1->segments[i].nodes[j].lv = lv2; -+ { -+ if (lv1 == lv2) -+ continue; -+ if (grub_strcmp (lv2->name, -+ lv1->segments[i].nodes[j].name) == 0) -+ lv1->segments[i].nodes[j].lv = lv2; -+ } - } - - } --- -2.19.1 - diff --git a/backport-0067-fs-btrfs-Validate-the-number-of-stripes-parities-in-.patch b/backport-0067-fs-btrfs-Validate-the-number-of-stripes-parities-in-.patch deleted file mode 100644 index bf9c5fa622f4bed63b2a9b29ff3b53964af0acda..0000000000000000000000000000000000000000 --- a/backport-0067-fs-btrfs-Validate-the-number-of-stripes-parities-in-.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 356c74f00ed24b08810dc236f37caaca228e5853 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Mon, 18 Jan 2021 17:17:16 +1100 -Subject: [PATCH] fs/btrfs: Validate the number of stripes/parities in RAID5/6 - -This prevents a divide by zero if nstripes == nparities, and -also prevents propagation of invalid values if nstripes ends up -less than nparities. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=b88a82e78cdd0ab8e0339c1c3f9564c4d8c0c969 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/fs/btrfs.c | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index 0d8c666..a6384a8 100644 ---- a/grub-core/fs/btrfs.c -+++ b/grub-core/fs/btrfs.c -@@ -1105,6 +1105,9 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, - * stripen is computed without the parities - * (0 for A0, A1, A2, 1 for B0, B1, B2, etc.). - */ -+ if (nparities >= nstripes) -+ return grub_error (GRUB_ERR_BAD_FS, -+ "invalid RAID5/6: nparities >= nstripes"); - high = grub_divmod64 (stripe_nr, nstripes - nparities, &stripen); - - /* --- -2.19.1 - diff --git a/backport-0068-fs-btrfs-Squash-some-uninitialized-reads.patch b/backport-0068-fs-btrfs-Squash-some-uninitialized-reads.patch deleted file mode 100644 index 20912d55f631eb55b2a2109f8b2cad4343501dcf..0000000000000000000000000000000000000000 --- a/backport-0068-fs-btrfs-Squash-some-uninitialized-reads.patch +++ /dev/null @@ -1,44 +0,0 @@ -From 498830861020ac6b713d002bb2e72f713860ea04 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Mon, 18 Jan 2021 17:27:18 +1100 -Subject: [PATCH] fs/btrfs: Squash some uninitialized reads - -We need to check errors before calling into a function that uses the result. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=b911884dd707ba1e6f641eb17857df3155013a45 - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - grub-core/fs/btrfs.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index a6384a8..cf3647a 100644 ---- a/grub-core/fs/btrfs.c -+++ b/grub-core/fs/btrfs.c -@@ -410,9 +410,9 @@ next (struct grub_btrfs_data *data, - - err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (node.addr), - &head, sizeof (head), 0); -- check_btrfs_header (data, &head, grub_le_to_cpu64 (node.addr)); - if (err) - return -err; -+ check_btrfs_header (data, &head, grub_le_to_cpu64 (node.addr)); - - save_ref (desc, grub_le_to_cpu64 (node.addr), 0, - grub_le_to_cpu32 (head.nitems), !head.level); -@@ -472,9 +472,9 @@ lower_bound (struct grub_btrfs_data *data, - /* FIXME: preread few nodes into buffer. */ - err = grub_btrfs_read_logical (data, addr, &head, sizeof (head), - recursion_depth + 1); -- check_btrfs_header (data, &head, addr); - if (err) - return err; -+ check_btrfs_header (data, &head, addr); - addr += sizeof (head); - if (head.level) - { --- -2.19.1 - diff --git a/backport-0069-kern-efi-Add-initial-stack-protector-implementation.patch b/backport-0069-kern-efi-Add-initial-stack-protector-implementation.patch deleted file mode 100644 index c59b2c07aa35397d2747ab90444b333a1387b210..0000000000000000000000000000000000000000 --- a/backport-0069-kern-efi-Add-initial-stack-protector-implementation.patch +++ /dev/null @@ -1,305 +0,0 @@ -From f3821a98c9324f0f45bca9a1aed3921084a794ad Mon Sep 17 00:00:00 2001 -From: Chris Coulson -Date: Tue, 1 Dec 2020 23:03:39 +0000 -Subject: [PATCH] kern/efi: Add initial stack protector implementation - -It works only on UEFI platforms but can be quite easily extended to -others architectures and platforms if needed. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=133d73079c5771bbf3d8311281b6772846357ec1 - -Signed-off-by: Chris Coulson -Signed-off-by: Daniel Kiper -Reviewed-by: Marco A Benatto -Reviewed-by: Javier Martinez Canillas ---- - acinclude.m4 | 40 +++++++++++++++++++++++-- - configure.ac | 44 +++++++++++++++++++++++---- - grub-core/Makefile.am | 1 + - grub-core/kern/efi/init.c | 54 ++++++++++++++++++++++++++++++++++ - include/grub/efi/api.h | 19 ++++++++++++ - include/grub/stack_protector.h | 30 +++++++++++++++++++ - 6 files changed, 180 insertions(+), 8 deletions(-) - create mode 100644 include/grub/stack_protector.h - -diff --git a/acinclude.m4 b/acinclude.m4 -index 242e829..8eeed6f 100644 ---- a/acinclude.m4 -+++ b/acinclude.m4 -@@ -323,10 +323,10 @@ else - fi - ]) - -- --dnl Check if the C compiler supports `-fstack-protector'. -+ -+dnl Check if the C compiler supports the stack protector - AC_DEFUN([grub_CHECK_STACK_PROTECTOR],[ --[# Smashing stack protector. -+[# Stack smashing protector. - ssp_possible=yes] - AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector']) - # Is this a reliable test case? -@@ -343,6 +343,40 @@ else - ssp_possible=no] - AC_MSG_RESULT([no]) - [fi] -+[# Strong stack smashing protector. -+ssp_strong_possible=yes] -+AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector-strong']) -+# Is this a reliable test case? -+AC_LANG_CONFTEST([AC_LANG_SOURCE([[ -+void foo (void) { volatile char a[8]; a[3]; } -+]])]) -+[# `$CC -c -o ...' might not be portable. But, oh, well... Is calling -+# `ac_compile' like this correct, after all? -+if eval "$ac_compile -S -fstack-protector-strong -o conftest.s" 2> /dev/null; then] -+ AC_MSG_RESULT([yes]) -+ [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'? -+ rm -f conftest.s -+else -+ ssp_strong_possible=no] -+ AC_MSG_RESULT([no]) -+[fi] -+[# Global stack smashing protector. -+ssp_global_possible=yes] -+AC_MSG_CHECKING([whether `$CC' accepts `-mstack-protector-guard=global']) -+# Is this a reliable test case? -+AC_LANG_CONFTEST([AC_LANG_SOURCE([[ -+void foo (void) { volatile char a[8]; a[3]; } -+]])]) -+[# `$CC -c -o ...' might not be portable. But, oh, well... Is calling -+# `ac_compile' like this correct, after all? -+if eval "$ac_compile -S -fstack-protector -mstack-protector-guard=global -o conftest.s" 2> /dev/null; then] -+ AC_MSG_RESULT([yes]) -+ [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'? -+ rm -f conftest.s -+else -+ ssp_global_possible=no] -+ AC_MSG_RESULT([no]) -+[fi] - ]) - - dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin). -diff --git a/configure.ac b/configure.ac -index 5d33161..da735a6 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -1371,12 +1371,41 @@ fi] - - CFLAGS="$TARGET_CFLAGS" - --# Smashing stack protector. -+# Stack smashing protector. - grub_CHECK_STACK_PROTECTOR --# Need that, because some distributions ship compilers that include --# `-fstack-protector' in the default specs. --if test "x$ssp_possible" = xyes; then -- TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector" -+AC_ARG_ENABLE([stack-protector], -+ AS_HELP_STRING([--enable-stack-protector], -+ [enable the stack protector]), -+ [], -+ [enable_stack_protector=no]) -+if test "x$enable_stack_protector" = xno; then -+ if test "x$ssp_possible" = xyes; then -+ # Need that, because some distributions ship compilers that include -+ # `-fstack-protector' in the default specs. -+ TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector" -+ fi -+elif test "x$platform" != xefi; then -+ AC_MSG_ERROR([--enable-stack-protector is only supported on EFI platforms]) -+elif test "x$ssp_global_possible" != xyes; then -+ AC_MSG_ERROR([--enable-stack-protector is not supported (compiler doesn't support -mstack-protector-guard=global)]) -+else -+ TARGET_CFLAGS="$TARGET_CFLAGS -mstack-protector-guard=global" -+ if test "x$enable_stack_protector" = xyes; then -+ if test "x$ssp_possible" != xyes; then -+ AC_MSG_ERROR([--enable-stack-protector is not supported (compiler doesn't support -fstack-protector)]) -+ fi -+ TARGET_CFLAGS="$TARGET_CFLAGS -fstack-protector" -+ elif test "x$enable_stack_protector" = xstrong; then -+ if test "x$ssp_strong_possible" != xyes; then -+ AC_MSG_ERROR([--enable-stack-protector=strong is not supported (compiler doesn't support -fstack-protector-strong)]) -+ fi -+ TARGET_CFLAGS="$TARGET_CFLAGS -fstack-protector-strong" -+ else -+ # Note, -fstack-protector-all requires that the protector is disabled for -+ # functions that appear in the call stack when the canary is initialized. -+ AC_MSG_ERROR([invalid value $enable_stack_protector for --enable-stack-protector]) -+ fi -+ TARGET_CPPFLAGS="$TARGET_CPPFLAGS -DGRUB_STACK_PROTECTOR=1" - fi - - CFLAGS="$TARGET_CFLAGS" -@@ -2279,5 +2308,10 @@ echo "Without liblzma (no support for XZ-compressed mips images) ($liblzma_excus - else - echo "With liblzma from $LIBLZMA (support for XZ-compressed mips images)" - fi -+if test "x$enable_stack_protector" != xno; then -+echo "With stack smashing protector: Yes" -+else -+echo "With stack smashing protector: No" -+fi - echo "*******************************************************" - ] -diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am -index d75feef..dd49939 100644 ---- a/grub-core/Makefile.am -+++ b/grub-core/Makefile.am -@@ -92,6 +92,7 @@ endif - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/parser.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/partition.h -+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/stack_protector.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/verify.h -diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c -index 634e3ac..8054fdd 100644 ---- a/grub-core/kern/efi/init.c -+++ b/grub-core/kern/efi/init.c -@@ -28,6 +28,58 @@ - #include - #include - #include -+#include -+ -+#ifdef GRUB_STACK_PROTECTOR -+ -+static grub_efi_guid_t rng_protocol_guid = GRUB_EFI_RNG_PROTOCOL_GUID; -+ -+/* -+ * Don't put this on grub_efi_init()'s local stack to avoid it -+ * getting a stack check. -+ */ -+static grub_efi_uint8_t stack_chk_guard_buf[32]; -+ -+grub_addr_t __stack_chk_guard; -+ -+void __attribute__ ((noreturn)) -+__stack_chk_fail (void) -+{ -+ /* -+ * Assume it's not safe to call into EFI Boot Services. Sorry, that -+ * means no console message here. -+ */ -+ do -+ { -+ /* Do not optimize out the loop. */ -+ asm volatile (""); -+ } -+ while (1); -+} -+ -+static void -+stack_protector_init (void) -+{ -+ grub_efi_rng_protocol_t *rng; -+ -+ /* Set up the stack canary. Make errors here non-fatal for now. */ -+ rng = grub_efi_locate_protocol (&rng_protocol_guid, NULL); -+ if (rng != NULL) -+ { -+ grub_efi_status_t status; -+ -+ status = efi_call_4 (rng->get_rng, rng, NULL, sizeof (stack_chk_guard_buf), -+ stack_chk_guard_buf); -+ if (status == GRUB_EFI_SUCCESS) -+ grub_memcpy (&__stack_chk_guard, stack_chk_guard_buf, sizeof (__stack_chk_guard)); -+ } -+} -+#else -+static void -+stack_protector_init (void) -+{ -+} -+#endif - - grub_addr_t grub_modbase; - -@@ -87,6 +139,8 @@ grub_efi_init (void) - messages. */ - grub_console_init (); - -+ stack_protector_init (); -+ - /* Initialize the memory management system. */ - grub_efi_mm_init (); - -diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index fc8a564..0e7e926 100644 ---- a/include/grub/efi/api.h -+++ b/include/grub/efi/api.h -@@ -344,6 +344,11 @@ - { 0x89, 0x29, 0x48, 0xbc, 0xd9, 0x0a, 0xd3, 0x1a } \ - } - -+#define GRUB_EFI_RNG_PROTOCOL_GUID \ -+ { 0x3152bca5, 0xeade, 0x433d, \ -+ { 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44 } \ -+ } -+ - struct grub_efi_sal_system_table - { - grub_uint32_t signature; -@@ -2062,6 +2067,20 @@ struct grub_efi_ip6_config_manual_address { - }; - typedef struct grub_efi_ip6_config_manual_address grub_efi_ip6_config_manual_address_t; - -+typedef grub_efi_guid_t grub_efi_rng_algorithm_t; -+ -+struct grub_efi_rng_protocol -+{ -+ grub_efi_status_t (*get_info) (struct grub_efi_rng_protocol *this, -+ grub_efi_uintn_t *rng_algorithm_list_size, -+ grub_efi_rng_algorithm_t *rng_algorithm_list); -+ grub_efi_status_t (*get_rng) (struct grub_efi_rng_protocol *this, -+ grub_efi_rng_algorithm_t *rng_algorithm, -+ grub_efi_uintn_t rng_value_length, -+ grub_efi_uint8_t *rng_value); -+}; -+typedef struct grub_efi_rng_protocol grub_efi_rng_protocol_t; -+ - #if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \ - || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) \ - || defined(__riscv) -diff --git a/include/grub/stack_protector.h b/include/grub/stack_protector.h -new file mode 100644 -index 0000000..c88dc00 ---- /dev/null -+++ b/include/grub/stack_protector.h -@@ -0,0 +1,30 @@ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2021 Free Software Foundation, Inc. -+ * -+ * GRUB is free software: you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation, either version 3 of the License, or -+ * (at your option) any later version. -+ * -+ * GRUB is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with GRUB. If not, see . -+ */ -+ -+#ifndef GRUB_STACK_PROTECTOR_H -+#define GRUB_STACK_PROTECTOR_H 1 -+ -+#include -+#include -+ -+#ifdef GRUB_STACK_PROTECTOR -+extern grub_addr_t EXPORT_VAR (__stack_chk_guard); -+extern void __attribute__ ((noreturn)) EXPORT_FUNC (__stack_chk_fail) (void); -+#endif -+ -+#endif /* GRUB_STACK_PROTECTOR_H */ --- -2.19.1 - diff --git a/backport-0070-util-mkimage-Remove-unused-code-to-add-BSS-section.patch b/backport-0070-util-mkimage-Remove-unused-code-to-add-BSS-section.patch deleted file mode 100644 index 7b338ce2d51866ead9f583a9679faa9714d5e370..0000000000000000000000000000000000000000 --- a/backport-0070-util-mkimage-Remove-unused-code-to-add-BSS-section.patch +++ /dev/null @@ -1,62 +0,0 @@ -From 5ee52e31fb8bb37ef11cf3dbff933465944d9e32 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Thu, 11 Feb 2021 17:06:49 +0100 -Subject: [PATCH] util/mkimage: Remove unused code to add BSS section - -The code is compiled out so there is no reason to keep it. - -Additionally, don't set bss_size field since we do not add a BSS section. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=d52f78def1b9c4f435fdbf6b24fd899208580c76 - -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - util/mkimage.c | 17 ----------------- - 1 file changed, 17 deletions(-) - -diff --git a/util/mkimage.c b/util/mkimage.c -index 37d6249..048089f 100644 ---- a/util/mkimage.c -+++ b/util/mkimage.c -@@ -1304,7 +1304,6 @@ grub_install_generate_image (const char *dir, const char *prefix, - o->code_size = grub_host_to_target32 (layout.exec_size); - o->data_size = grub_cpu_to_le32 (reloc_addr - layout.exec_size - - header_size); -- o->bss_size = grub_cpu_to_le32 (layout.bss_size); - o->entry_addr = grub_cpu_to_le32 (layout.start_address); - o->code_base = grub_cpu_to_le32 (header_size); - -@@ -1342,7 +1341,6 @@ grub_install_generate_image (const char *dir, const char *prefix, - o->code_size = grub_host_to_target32 (layout.exec_size); - o->data_size = grub_cpu_to_le32 (reloc_addr - layout.exec_size - - header_size); -- o->bss_size = grub_cpu_to_le32 (layout.bss_size); - o->entry_addr = grub_cpu_to_le32 (layout.start_address); - o->code_base = grub_cpu_to_le32 (header_size); - o->image_base = 0; -@@ -1388,21 +1386,6 @@ grub_install_generate_image (const char *dir, const char *prefix, - | GRUB_PE32_SCN_MEM_READ - | GRUB_PE32_SCN_MEM_WRITE); - --#if 0 -- bss_section = data_section + 1; -- strcpy (bss_section->name, ".bss"); -- bss_section->virtual_size = grub_cpu_to_le32 (layout.bss_size); -- bss_section->virtual_address = grub_cpu_to_le32 (header_size + layout.kernel_size); -- bss_section->raw_data_size = 0; -- bss_section->raw_data_offset = 0; -- bss_section->characteristics -- = grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_MEM_READ -- | GRUB_PE32_SCN_MEM_WRITE -- | GRUB_PE32_SCN_ALIGN_64BYTES -- | GRUB_PE32_SCN_CNT_INITIALIZED_DATA -- | 0x80); --#endif -- - mods_section = data_section + 1; - strcpy (mods_section->name, "mods"); - mods_section->virtual_size = grub_cpu_to_le32 (reloc_addr - layout.kernel_size - header_size); --- -2.19.1 - diff --git a/backport-0071-util-mkimage-Use-grub_host_to_target32-instead-of-gr.patch b/backport-0071-util-mkimage-Use-grub_host_to_target32-instead-of-gr.patch deleted file mode 100644 index cdc03b50780e381a01f73ff79f1b908d78284645..0000000000000000000000000000000000000000 --- a/backport-0071-util-mkimage-Use-grub_host_to_target32-instead-of-gr.patch +++ /dev/null @@ -1,114 +0,0 @@ -From fe56aca056a6bb39b3968e37a6e4df079419ca2c Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 15 Feb 2021 13:59:21 +0100 -Subject: [PATCH] util/mkimage: Use grub_host_to_target32() instead of - grub_cpu_to_le32() - -The latter doesn't take into account the target image endianness. There is -a grub_cpu_to_le32_compile_time() but no compile time variant for function -grub_host_to_target32(). So, let's keep using the other one for this case. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=1710452aca05ccdd21e74390ec08c63fdf0ee10a - -Signed-off-by: Peter Jones -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - util/mkimage.c | 44 ++++++++++++++++++++++---------------------- - 1 file changed, 22 insertions(+), 22 deletions(-) - -diff --git a/util/mkimage.c b/util/mkimage.c -index 048089f..47cd705 100644 ---- a/util/mkimage.c -+++ b/util/mkimage.c -@@ -1302,10 +1302,10 @@ grub_install_generate_image (const char *dir, const char *prefix, - + sizeof (struct grub_pe32_coff_header)); - o->magic = grub_host_to_target16 (GRUB_PE32_PE32_MAGIC); - o->code_size = grub_host_to_target32 (layout.exec_size); -- o->data_size = grub_cpu_to_le32 (reloc_addr - layout.exec_size -+ o->data_size = grub_host_to_target32 (reloc_addr - layout.exec_size - - header_size); -- o->entry_addr = grub_cpu_to_le32 (layout.start_address); -- o->code_base = grub_cpu_to_le32 (header_size); -+ o->entry_addr = grub_host_to_target32 (layout.start_address); -+ o->code_base = grub_host_to_target32 (header_size); - - o->data_base = grub_host_to_target32 (header_size + layout.exec_size); - -@@ -1339,10 +1339,10 @@ grub_install_generate_image (const char *dir, const char *prefix, - + sizeof (struct grub_pe32_coff_header)); - o->magic = grub_host_to_target16 (GRUB_PE32_PE64_MAGIC); - o->code_size = grub_host_to_target32 (layout.exec_size); -- o->data_size = grub_cpu_to_le32 (reloc_addr - layout.exec_size -+ o->data_size = grub_host_to_target32 (reloc_addr - layout.exec_size - - header_size); -- o->entry_addr = grub_cpu_to_le32 (layout.start_address); -- o->code_base = grub_cpu_to_le32 (header_size); -+ o->entry_addr = grub_host_to_target32 (layout.start_address); -+ o->code_base = grub_host_to_target32 (header_size); - o->image_base = 0; - o->section_alignment = grub_host_to_target32 (image_target->section_align); - o->file_alignment = grub_host_to_target32 (GRUB_PE32_FILE_ALIGNMENT); -@@ -1366,10 +1366,10 @@ grub_install_generate_image (const char *dir, const char *prefix, - /* The sections. */ - text_section = sections; - strcpy (text_section->name, ".text"); -- text_section->virtual_size = grub_cpu_to_le32 (layout.exec_size); -- text_section->virtual_address = grub_cpu_to_le32 (header_size); -- text_section->raw_data_size = grub_cpu_to_le32 (layout.exec_size); -- text_section->raw_data_offset = grub_cpu_to_le32 (header_size); -+ text_section->virtual_size = grub_host_to_target32 (layout.exec_size); -+ text_section->virtual_address = grub_host_to_target32 (header_size); -+ text_section->raw_data_size = grub_host_to_target32 (layout.exec_size); -+ text_section->raw_data_offset = grub_host_to_target32 (header_size); - text_section->characteristics = grub_cpu_to_le32_compile_time ( - GRUB_PE32_SCN_CNT_CODE - | GRUB_PE32_SCN_MEM_EXECUTE -@@ -1377,10 +1377,10 @@ grub_install_generate_image (const char *dir, const char *prefix, - - data_section = text_section + 1; - strcpy (data_section->name, ".data"); -- data_section->virtual_size = grub_cpu_to_le32 (layout.kernel_size - layout.exec_size); -- data_section->virtual_address = grub_cpu_to_le32 (header_size + layout.exec_size); -- data_section->raw_data_size = grub_cpu_to_le32 (layout.kernel_size - layout.exec_size); -- data_section->raw_data_offset = grub_cpu_to_le32 (header_size + layout.exec_size); -+ data_section->virtual_size = grub_host_to_target32 (layout.kernel_size - layout.exec_size); -+ data_section->virtual_address = grub_host_to_target32 (header_size + layout.exec_size); -+ data_section->raw_data_size = grub_host_to_target32 (layout.kernel_size - layout.exec_size); -+ data_section->raw_data_offset = grub_host_to_target32 (header_size + layout.exec_size); - data_section->characteristics - = grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA - | GRUB_PE32_SCN_MEM_READ -@@ -1388,10 +1388,10 @@ grub_install_generate_image (const char *dir, const char *prefix, - - mods_section = data_section + 1; - strcpy (mods_section->name, "mods"); -- mods_section->virtual_size = grub_cpu_to_le32 (reloc_addr - layout.kernel_size - header_size); -- mods_section->virtual_address = grub_cpu_to_le32 (header_size + layout.kernel_size + layout.bss_size); -- mods_section->raw_data_size = grub_cpu_to_le32 (reloc_addr - layout.kernel_size - header_size); -- mods_section->raw_data_offset = grub_cpu_to_le32 (header_size + layout.kernel_size); -+ mods_section->virtual_size = grub_host_to_target32 (reloc_addr - layout.kernel_size - header_size); -+ mods_section->virtual_address = grub_host_to_target32 (header_size + layout.kernel_size + layout.bss_size); -+ mods_section->raw_data_size = grub_host_to_target32 (reloc_addr - layout.kernel_size - header_size); -+ mods_section->raw_data_offset = grub_host_to_target32 (header_size + layout.kernel_size); - mods_section->characteristics - = grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA - | GRUB_PE32_SCN_MEM_READ -@@ -1399,10 +1399,10 @@ grub_install_generate_image (const char *dir, const char *prefix, - - reloc_section = mods_section + 1; - strcpy (reloc_section->name, ".reloc"); -- reloc_section->virtual_size = grub_cpu_to_le32 (layout.reloc_size); -- reloc_section->virtual_address = grub_cpu_to_le32 (reloc_addr + layout.bss_size); -- reloc_section->raw_data_size = grub_cpu_to_le32 (layout.reloc_size); -- reloc_section->raw_data_offset = grub_cpu_to_le32 (reloc_addr); -+ reloc_section->virtual_size = grub_host_to_target32 (layout.reloc_size); -+ reloc_section->virtual_address = grub_host_to_target32 (reloc_addr + layout.bss_size); -+ reloc_section->raw_data_size = grub_host_to_target32 (layout.reloc_size); -+ reloc_section->raw_data_offset = grub_host_to_target32 (reloc_addr); - reloc_section->characteristics - = grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA - | GRUB_PE32_SCN_MEM_DISCARDABLE --- -2.19.1 - diff --git a/backport-0072-kern-mm-Fix-grub_debug_calloc-compilation-error.patch b/backport-0072-kern-mm-Fix-grub_debug_calloc-compilation-error.patch deleted file mode 100644 index f7c2a2f0e290d23737418c9bb6ad8e6a200924f1..0000000000000000000000000000000000000000 --- a/backport-0072-kern-mm-Fix-grub_debug_calloc-compilation-error.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 4a2ba9ed2b2d058b9692ae86ce06b0d485a86ad5 Mon Sep 17 00:00:00 2001 -From: Marco A Benatto -Date: Tue, 9 Feb 2021 12:33:06 -0300 -Subject: [PATCH] kern/mm: Fix grub_debug_calloc() compilation error - -Fix compilation error due to missing parameter to -grub_printf() when MM_DEBUG is defined. - -Fixes: 64e26162e (calloc: Make sure we always have an overflow-checking calloc() available) - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=a9d8de960834f376087856f9d60a214b47c76f61 - -Signed-off-by: Marco A Benatto -Reviewed-by: Daniel Kiper ---- - grub-core/kern/mm.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c -index 80d0720..d8c8377 100644 ---- a/grub-core/kern/mm.c -+++ b/grub-core/kern/mm.c -@@ -594,7 +594,7 @@ grub_debug_calloc (const char *file, int line, grub_size_t nmemb, grub_size_t si - - if (grub_mm_debug) - grub_printf ("%s:%d: calloc (0x%" PRIxGRUB_SIZE ", 0x%" PRIxGRUB_SIZE ") = ", -- file, line, size); -+ file, line, nmemb, size); - ptr = grub_calloc (nmemb, size); - if (grub_mm_debug) - grub_printf ("%p\n", ptr); --- -2.19.1 - diff --git a/backport-0073-grub-mkconfig-Fix-typo-in-help-output.patch b/backport-0073-grub-mkconfig-Fix-typo-in-help-output.patch deleted file mode 100644 index 1cb04a86073d0f91fb345aa92385487190dc0f6f..0000000000000000000000000000000000000000 --- a/backport-0073-grub-mkconfig-Fix-typo-in-help-output.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 55453a6734278cf820d599b67c03e84e35e1d87b Mon Sep 17 00:00:00 2001 -From: Colin Watson -Date: Fri, 23 Aug 2019 12:00:30 +0100 -Subject: [PATCH] grub-mkconfig: Fix typo in --help output - -The short form of "--version" that grub-mkconfig accepts is "-V", not "-v". - -Fixes Debian bug #935504. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=ff3e91be9cc3d6f040a7f47fac0db1c93f80a9a8 - -Signed-off-by: Colin Watson -Reviewed-by: Vladimir 'phcoder' Serbinenko -Reviewed-by: Daniel Kiper ---- - util/grub-mkconfig.in | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index 2601bdc..0a2c1ce 100644 ---- a/util/grub-mkconfig.in -+++ b/util/grub-mkconfig.in -@@ -63,7 +63,7 @@ usage () { - print_option_help "-o, --output=$(gettext FILE)" "$(gettext "output generated config to FILE [default=stdout]")" - print_option_help "--no-grubenv-update" "$(gettext "do not update variables in the grubenv file")" - print_option_help "-h, --help" "$(gettext "print this message and exit")" -- print_option_help "-v, --version" "$(gettext "print the version information and exit")" -+ print_option_help "-V, --version" "$(gettext "print the version information and exit")" - echo - gettext "Report bugs to ."; echo - } --- -2.19.1 - diff --git a/backport-0074-at_keyboard-Fix-unreliable-key-presses.patch b/backport-0074-at_keyboard-Fix-unreliable-key-presses.patch deleted file mode 100644 index 6240832eeb2e00bffcc550c093d119e3900e83dd..0000000000000000000000000000000000000000 --- a/backport-0074-at_keyboard-Fix-unreliable-key-presses.patch +++ /dev/null @@ -1,53 +0,0 @@ -From 2d3fcce21fc1118449219a8c66b25aefca989493 Mon Sep 17 00:00:00 2001 -From: Michael Bideau -Date: Wed, 2 Oct 2019 23:48:10 +0200 -Subject: [PATCH] at_keyboard: Fix unreliable key presses - -This patch fixes an issue that prevented the at_keyboard module to work -(for me). The cause was a bad/wrong return value in the -grub_at_keyboard_getkey() function in grub-core/term/at_keyboard.c file -at line 237. My symptoms were to have an unresponsive keyboard. Keys -needed to be pressed 10x and more to effectively be printed sometimes -generating multiple key presses (after 1 or 2 sec of no printing). It -was very problematic when typing passphrase in early stage (with -GRUB_ENABLE_CRYPTODISK). When switched to "console" terminal input -keyboard worked perfectly. It also worked great with the GRUB 2.02 -packaged by Debian (2.02+dfsg1-20). It was not an output issue but an -input one. - -I've managed to analyze the issue and found that it came from the commit -216950a4e (at_keyboard: Split protocol from controller code.). Three -lines where moved from the fetch_key() function in -grub-core/term/at_keyboard.c file to the beginning of -grub_at_keyboard_getkey() function (same file). However, returning -1 -made sense when it happened in fetch_key() function but not anymore in -grub_at_keyboard_getkey() function which should return GRUB_TERM_NO_KEY. -I think it was just an incomplete cut-paste missing a small manual -correction. Let's fix it. - -Note: Commit message updated by Daniel Kiper. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=33203ca3484717712b54e199c46ae8a818374284 - -Signed-off-by: Michael Bideau -Reviewed-by: Daniel Kiper ---- - grub-core/term/at_keyboard.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c -index f0a986e..5971110 100644 ---- a/grub-core/term/at_keyboard.c -+++ b/grub-core/term/at_keyboard.c -@@ -234,7 +234,7 @@ grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused))) - return GRUB_TERM_NO_KEY; - - if (! KEYBOARD_ISREADY (grub_inb (KEYBOARD_REG_STATUS))) -- return -1; -+ return GRUB_TERM_NO_KEY; - at_key = grub_inb (KEYBOARD_REG_DATA); - old_led = ps2_state.led_status; - --- -2.19.1 - diff --git a/backport-0075-hostdisk-Set-linux-file-descriptor-to-O_CLOEXEC-as-d.patch b/backport-0075-hostdisk-Set-linux-file-descriptor-to-O_CLOEXEC-as-d.patch deleted file mode 100644 index 9d465942b3b0f43a24f760309df8247ba850e8b2..0000000000000000000000000000000000000000 --- a/backport-0075-hostdisk-Set-linux-file-descriptor-to-O_CLOEXEC-as-d.patch +++ /dev/null @@ -1,70 +0,0 @@ -From 9917f2b39a6a6cd1f8d3ec50773b445158f9b1ef Mon Sep 17 00:00:00 2001 -From: Michael Chang -Date: Tue, 5 Nov 2019 09:19:26 +0000 -Subject: [PATCH] hostdisk: Set linux file descriptor to O_CLOEXEC as default - -We are often bothered by this sort of lvm warning while running grub-install -every now and then: - - File descriptor 4 (/dev/vda1) leaked on vgs invocation. Parent PID 1991: /usr/sbin/grub2-install - -The requirement related to the warning is dictated in the lvm man page: - - "On invocation, lvm requires that only the standard file descriptors stdin, - stdout and stderr are available. If others are found, they get closed and - messages are issued warning about the leak. This warning can be suppressed by - setting the environment variable LVM_SUPPRESS_FD_WARNINGS." - -While it could be disabled through settings, most Linux distributions seem to -enable it by default and the justification provided by the developer looks to -be valid to me: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=466138#15 - -Rather than trying to close and reopen the file descriptor to the same file -multiple times, which is rather cumbersome, for the sake of no vgs invocation -could happen in between. This patch enables the close-on-exec flag (O_CLOEXEC) -for new file descriptor returned by the open() system call, making it closed -thus not inherited by the child process forked and executed by the exec() -family of functions. - -Fixes Debian bug #466138. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=42acdd3b405c44d08439a3bbfdbd3466049d172d - -Signed-off-by: Michael Chang -Reviewed-by: Daniel Kiper ---- - grub-core/osdep/linux/hostdisk.c | 3 +++ - grub-core/osdep/unix/hostdisk.c | 3 +++ - 2 files changed, 6 insertions(+) - -diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c -index 370d027..7bc99ac 100644 ---- a/grub-core/osdep/linux/hostdisk.c -+++ b/grub-core/osdep/linux/hostdisk.c -@@ -366,6 +366,9 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f - #ifdef O_BINARY - flags |= O_BINARY; - #endif -+#ifdef O_CLOEXEC -+ flags |= O_CLOEXEC; -+#endif - - /* Linux has a bug that the disk cache for a whole disk is not consistent - with the one for a partition of the disk. */ -diff --git a/grub-core/osdep/unix/hostdisk.c b/grub-core/osdep/unix/hostdisk.c -index 9115096..3a00d74 100644 ---- a/grub-core/osdep/unix/hostdisk.c -+++ b/grub-core/osdep/unix/hostdisk.c -@@ -164,6 +164,9 @@ grub_util_fd_open (const char *os_dev, int flags) - #ifdef O_BINARY - flags |= O_BINARY; - #endif -+#ifdef O_CLOEXEC -+ flags |= O_CLOEXEC; -+#endif - - return open (os_dev, flags, S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR); - } --- -2.19.1 - diff --git a/backport-0076-squash4-Fix-an-uninitialized-variable.patch b/backport-0076-squash4-Fix-an-uninitialized-variable.patch deleted file mode 100644 index 77af5594d89610a81f8b88ec25844c078d0ed477..0000000000000000000000000000000000000000 --- a/backport-0076-squash4-Fix-an-uninitialized-variable.patch +++ /dev/null @@ -1,40 +0,0 @@ -From eb6d0ed961e6f83ea1cc8f8c81fdb4904a11d984 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 27 Jan 2020 15:01:16 -0500 -Subject: [PATCH] squash4: Fix an uninitialized variable - -gcc says: - -grub-core/fs/squash4.c: In function ‘direct_read’: -grub-core/fs/squash4.c:868:10: error: ‘err’ may be used uninitialized in -this function [-Werror=maybe-uninitialized] - 868 | if (err) - | ^ -cc1: all warnings being treated as errors - -This patch initializes it to GRUB_ERR_NONE. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=598de14d9340137cd7c7a099e8ed53d97f1f68a0 - -Signed-off-by: Peter Jones -Reviewed-by: Daniel Kiper ---- - grub-core/fs/squash4.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c -index 7851238..a5f35c1 100644 ---- a/grub-core/fs/squash4.c -+++ b/grub-core/fs/squash4.c -@@ -769,7 +769,7 @@ direct_read (struct grub_squash_data *data, - struct grub_squash_cache_inode *ino, - grub_off_t off, char *buf, grub_size_t len) - { -- grub_err_t err; -+ grub_err_t err = GRUB_ERR_NONE; - grub_off_t cumulated_uncompressed_size = 0; - grub_uint64_t a = 0; - grub_size_t i; --- -2.19.1 - diff --git a/backport-0077-efi-tpm-Fix-memory-leak-in-grub_tpm1-2_log_event.patch b/backport-0077-efi-tpm-Fix-memory-leak-in-grub_tpm1-2_log_event.patch deleted file mode 100644 index 17b2e24e33b4ccd734b07fad67b2f940c10d906e..0000000000000000000000000000000000000000 --- a/backport-0077-efi-tpm-Fix-memory-leak-in-grub_tpm1-2_log_event.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 0ffa81ce9e0395b113ca3903a064ff7bcdfb4454 Mon Sep 17 00:00:00 2001 -From: Tianjia Zhang -Date: Mon, 23 Mar 2020 19:52:51 +0800 -Subject: [PATCH] efi/tpm: Fix memory leak in grub_tpm1/2_log_event() - -The memory requested for the event is not released here, -causing memory leaks. This patch fixes this problem. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=800de4a1d0e72022694f8773ec5fe7dca8e34ae6 - -Signed-off-by: Jia Zhang -Signed-off-by: Tianjia Zhang -Reviewed-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - grub-core/commands/efi/tpm.c | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/grub-core/commands/efi/tpm.c b/grub-core/commands/efi/tpm.c -index 32909c1..6a6cd0d 100644 ---- a/grub-core/commands/efi/tpm.c -+++ b/grub-core/commands/efi/tpm.c -@@ -247,6 +247,7 @@ grub_tpm1_log_event (grub_efi_handle_t tpm_handle, unsigned char *buf, - algorithm = TCG_ALG_SHA; - status = efi_call_7 (tpm->log_extend_event, tpm, (grub_addr_t) buf, (grub_uint64_t) size, - algorithm, event, &eventnum, &lastevent); -+ grub_free (event); - - switch (status) - { -@@ -297,6 +298,7 @@ grub_tpm2_log_event (grub_efi_handle_t tpm_handle, unsigned char *buf, - - status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, (grub_addr_t) buf, - (grub_uint64_t) size, event); -+ grub_free (event); - - switch (status) - { --- -2.19.1 - diff --git a/backport-0078-powerpc-mkimage-Fix-CHRP-note-descsz.patch b/backport-0078-powerpc-mkimage-Fix-CHRP-note-descsz.patch deleted file mode 100644 index 90faa6def594b767191b08d75af5eb2db163c4fe..0000000000000000000000000000000000000000 --- a/backport-0078-powerpc-mkimage-Fix-CHRP-note-descsz.patch +++ /dev/null @@ -1,54 +0,0 @@ -From 0a18ad3787b0aca65a6a9e246f03d8dd89d9dfdc Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Tue, 7 Apr 2020 16:17:26 +1000 -Subject: [PATCH] powerpc/mkimage: Fix CHRP note descsz - -Currently, an image generated with 'grub-mkimage -n' causes an error when -read with 'readelf -a': - -Displaying notes found at file offset 0x000106f0 with length 0x0000002c: - Owner Data size Description -readelf: Warning: note with invalid namesz and/or descsz found at offset 0x0 -readelf: Warning: type: 0x1275, namesize: 0x00000008, descsize: 0x0000002c, alignment: 4 - -This is because the descsz of the CHRP note is set to - sizeof (struct grub_ieee1275_note) -which is the size of the entire note, including name and elf header. The -desczs should contain only the contents, not the name and header sizes. - -Set the descsz instead to 'sizeof (struct grub_ieee1275_note_desc)' - -Resultant readelf output: - -Displaying notes found at file offset 0x00010710 with length 0x0000002c: - Owner Data size Description - PowerPC 0x00000018 Unknown note type: (0x00001275) - description data: ff ff ff ff 00 c0 00 00 ff ff ff ff ff ff ff ff ff ff ff ff 00 00 40 00 - -So far as I can tell this issue has existed for as long as the note -generation code has existed, but I guess nothing really checks descsz. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=06fd69a3fd9d6b86e4a5af6c0d5da1b12545d27c - -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper ---- - util/grub-mkimagexx.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c -index 52bc9c8..00f49cc 100644 ---- a/util/grub-mkimagexx.c -+++ b/util/grub-mkimagexx.c -@@ -463,7 +463,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc - grub_util_info ("adding CHRP NOTE segment"); - - note_ptr->header.n_namesz = grub_host_to_target32 (sizeof (GRUB_IEEE1275_NOTE_NAME)); -- note_ptr->header.n_descsz = grub_host_to_target32 (note_size); -+ note_ptr->header.n_descsz = grub_host_to_target32 (sizeof (struct grub_ieee1275_note_desc)); - note_ptr->header.n_type = grub_host_to_target32 (GRUB_IEEE1275_NOTE_TYPE); - strcpy (note_ptr->name, GRUB_IEEE1275_NOTE_NAME); - note_ptr->descriptor.real_mode = grub_host_to_target32 (0xffffffff); --- -2.19.1 - diff --git a/backport-0079-efi-tpm-Fix-typo-in-grub_efi_tpm2_protocol-struct.patch b/backport-0079-efi-tpm-Fix-typo-in-grub_efi_tpm2_protocol-struct.patch deleted file mode 100644 index 4df845565bdc29e2257b6e5523a496c898a1a6ad..0000000000000000000000000000000000000000 --- a/backport-0079-efi-tpm-Fix-typo-in-grub_efi_tpm2_protocol-struct.patch +++ /dev/null @@ -1,37 +0,0 @@ -From c98fb6f044005e65186a9dd2964143cb5cadeaa9 Mon Sep 17 00:00:00 2001 -From: Daniel Kiper -Date: Mon, 25 May 2020 21:02:15 +0200 -Subject: [PATCH] efi/tpm: Fix typo in grub_efi_tpm2_protocol struct - -Rename get_active_pcr_blanks() to get_active_pcr_banks(). - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=1e81bf6d2dd57ddee7a24ca9a8b4cac7700d3dc4 - -Signed-off-by: Daniel Kiper -Reviewed-by: Javier Martinez Canillas ---- - include/grub/efi/tpm.h | 8 ++++---- - 1 file changed, 4 insertions(+), 4 deletions(-) - -diff --git a/include/grub/efi/tpm.h b/include/grub/efi/tpm.h -index 3ea6b4d..ec39725 100644 ---- a/include/grub/efi/tpm.h -+++ b/include/grub/efi/tpm.h -@@ -176,10 +176,10 @@ struct grub_efi_tpm2_protocol - OutputParameterBlockSize, - grub_efi_uint8_t * - OutputParameterBlock); -- grub_efi_status_t (*get_active_pcr_blanks) (struct grub_efi_tpm2_protocol * -- this, -- grub_efi_uint32_t * -- ActivePcrBanks); -+ grub_efi_status_t (*get_active_pcr_banks) (struct grub_efi_tpm2_protocol * -+ this, -+ grub_efi_uint32_t * -+ ActivePcrBanks); - grub_efi_status_t (*set_active_pcr_banks) (struct grub_efi_tpm2_protocol * - this, - grub_efi_uint32_t --- -2.19.1 - diff --git a/backport-0080-misc-Add-parentheses-around-ALIGN_UP-and-ALIGN_DOWN-.patch b/backport-0080-misc-Add-parentheses-around-ALIGN_UP-and-ALIGN_DOWN-.patch deleted file mode 100644 index f49bbac36b535eae327ccbc6acb50209b0f7850a..0000000000000000000000000000000000000000 --- a/backport-0080-misc-Add-parentheses-around-ALIGN_UP-and-ALIGN_DOWN-.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 2e5e020db1e1ced5038c5ca9b847f62a224383ff Mon Sep 17 00:00:00 2001 -From: Glenn Washburn -Date: Tue, 8 Dec 2020 16:45:33 -0600 -Subject: [PATCH] misc: Add parentheses around ALIGN_UP() and ALIGN_DOWN() - arguments - -This ensures that expected order of operations is preserved when arguments -are expressions. - -Reference: http://git.savannah.gnu.org/cgit/grub.git/commit/?id=8e8b2316acbaef8c4e6c0839cf27a42217dfb7c3 - -Signed-off-by: Glenn Washburn -Reviewed-by: Patrick Steinhardt -Reviewed-by: Daniel Kiper ---- - include/grub/misc.h | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/include/grub/misc.h b/include/grub/misc.h -index 998e47e..08ea894 100644 ---- a/include/grub/misc.h -+++ b/include/grub/misc.h -@@ -28,10 +28,10 @@ - #include - - #define ALIGN_UP(addr, align) \ -- ((addr + (typeof (addr)) align - 1) & ~((typeof (addr)) align - 1)) -+ (((addr) + (typeof (addr)) (align) - 1) & ~((typeof (addr)) (align) - 1)) - #define ALIGN_UP_OVERHEAD(addr, align) ((-(addr)) & ((typeof (addr)) (align) - 1)) - #define ALIGN_DOWN(addr, align) \ -- ((addr) & ~((typeof (addr)) align - 1)) -+ ((addr) & ~((typeof (addr)) (align) - 1)) - #define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0])) - #define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; } - --- -2.19.1 - diff --git a/backport-0081-verifiers-Fix-calling-uninitialized-function-pointer.patch b/backport-0081-verifiers-Fix-calling-uninitialized-function-pointer.patch deleted file mode 100644 index e692363c60a5a0012b87062aeacd565daffdc078..0000000000000000000000000000000000000000 --- a/backport-0081-verifiers-Fix-calling-uninitialized-function-pointer.patch +++ /dev/null @@ -1,46 +0,0 @@ -From 53d2cf59c7c683f473a43007303a30c1e3e8baad Mon Sep 17 00:00:00 2001 -From: Michael Chang -Date: Tue, 18 Feb 2020 18:08:18 +0800 -Subject: [PATCH] verifiers: Fix calling uninitialized function pointer - -The necessary check for NULL before use of function ver->close is not -taking place in the failure path. This patch simply adds the missing -check and fixes the problem that GRUB hangs indefinitely after booting -rogue image without valid signature if secure boot is turned on. - -Now it displays like this for booting rogue UEFI image: - - error: bad shim signature - error: you need to load the kernel first - - Press any key to continue... - -and then you can go back to boot menu by pressing any key or after a few -seconds expired. - -Reference:https://git.savannah.gnu.org/cgit/grub.git/commit/?id=d0de8b37f651e13886ef0e0fda285a1294adafe8 - -Signed-off-by: Michael Chang -Reviewed-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - grub-core/kern/verifiers.c | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/grub-core/kern/verifiers.c b/grub-core/kern/verifiers.c -index aa3dc7c..3d19bff 100644 ---- a/grub-core/kern/verifiers.c -+++ b/grub-core/kern/verifiers.c -@@ -196,7 +196,8 @@ grub_verifiers_open (grub_file_t io, enum grub_file_type type) - return ret; - - fail: -- ver->close (context); -+ if (ver->close) -+ ver->close (context); - fail_noclose: - verified_free (verified); - grub_free (ret); --- -2.19.1 - diff --git a/backport-Arm-check-for-the-PE-magic-for-the-compiled-arch.patch b/backport-Arm-check-for-the-PE-magic-for-the-compiled-arch.patch deleted file mode 100644 index 5dea6ff620c3bf4533736236990404f8f442ad53..0000000000000000000000000000000000000000 --- a/backport-Arm-check-for-the-PE-magic-for-the-compiled-arch.patch +++ /dev/null @@ -1,65 +0,0 @@ -From 337b3d963d28b3544e8817428fb68ca559613a39 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 9 Sep 2021 10:59:28 -0400 -Subject: [PATCH 2/2] Arm: check for the PE magic for the compiled arch - -In "arm64: Fix EFI loader kernel image allocation", Ben fixed the kernel -alignment to match the alignment given in the PE header. In doing so, a -check for valid PE magic was added, which was hard-coded to the value -seen on Aarch64 (GRUB_PE32_PE64_MAGIC). - -Unfortunately, this code is shared between 64-bit and 32-bit, and so -that value broke 32-bit Arm systems. - -This patch adds a constant definition for GRUB_PE32_PEXX_MAGIC, which is -either GRUB_PE32_PE64_MAGIC or GRUB_PE32_PE32_MAGIC, depending on which -platform is being built, and uses it in the header magic check. - -Resolves: rhbz#2000756 - -Signed-off-by: Peter Jones ---- - grub-core/loader/arm64/linux.c | 2 +- - include/grub/arm/linux.h | 1 + - include/grub/arm64/linux.h | 1 + - 3 files changed, 3 insertions(+), 1 deletion(-) - -diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c -index 1da1886..f0ad052 100644 ---- a/grub-core/loader/arm64/linux.c -+++ b/grub-core/loader/arm64/linux.c -@@ -342,7 +342,7 @@ parse_pe_header (void *kernel, grub_uint64_t *total_size, - - pe = (void *)((unsigned long)kernel + lh->hdr_offset); - -- if (pe->opt.magic != GRUB_PE32_PE64_MAGIC) -+ if (pe->opt.magic != GRUB_PE32_PEXX_MAGIC) - return grub_error(GRUB_ERR_BAD_OS, "Invalid PE optional header magic"); - - *total_size = pe->opt.image_size; -diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h -index b582f67..966a507 100644 ---- a/include/grub/arm/linux.h -+++ b/include/grub/arm/linux.h -@@ -44,6 +44,7 @@ struct grub_arm_linux_pe_header - - #if defined(__arm__) - # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE -+# define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE32_MAGIC - # define linux_arch_kernel_header linux_arm_kernel_header - # define grub_armxx_linux_pe_header grub_arm_linux_pe_header - #endif -diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h -index a3be9dd..20828d9 100644 ---- a/include/grub/arm64/linux.h -+++ b/include/grub/arm64/linux.h -@@ -47,6 +47,7 @@ struct grub_arm64_linux_pe_header - - #if defined(__aarch64__) - # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE -+# define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE64_MAGIC - # define linux_arch_kernel_header linux_arm64_kernel_header - # define grub_armxx_linux_pe_header grub_arm64_linux_pe_header - #endif --- -2.23.0 diff --git a/backport-CVE-2020-25632.patch b/backport-CVE-2020-25632.patch deleted file mode 100644 index 17959771e00e9ef7a5e7aa0e750efe854b1692d6..0000000000000000000000000000000000000000 --- a/backport-CVE-2020-25632.patch +++ /dev/null @@ -1,83 +0,0 @@ -From 7630ec5397fe418276b360f9011934b8c034936c -From: Daniel Kiper -Date: 2021-03-02 15:54:15 +0100 -Subject: [PATCH] dl: Only allow unloading modules that are not dependencies -When a module is attempted to be removed its reference counter is always -decremented. This means that repeated rmmod invocations will cause the -module to be unloaded even if another module depends on it. - -This may lead to a use-after-free scenario allowing an attacker to execute -arbitrary code and by-pass the UEFI Secure Boot protection. - -While being there, add the extern keyword to some function declarations in -that header file. - -Fixes: CVE-2020-25632 - -Reference:http://git.savannah.gnu.org/cgit/grub.git/commit/?id=7630ec5397fe418276b360f9011934b8c034936c - -Reported-by: Chris Coulson -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper -Diffstat --rw-r--r-- grub-core/commands/minicmd.c 7 --rw-r--r-- grub-core/kern/dl.c 9 --rw-r--r-- include/grub/dl.h 8 -3 files changed, 19 insertions, 5 deletions -diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c -index 6bbce3128..fa498931e 100644 ---- a/grub-core/commands/minicmd.c -+++ b/grub-core/commands/minicmd.c -@@ -140,8 +140,11 @@ grub_mini_cmd_rmmod (struct grub_command *cmd __attribute__ ((unused)), - if (grub_dl_is_persistent (mod)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "cannot unload persistent module"); - -- if (grub_dl_unref (mod) <= 0) -- grub_dl_unload (mod); -+ if (grub_dl_ref_count (mod) > 1) -+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "cannot unload referenced module"); -+ -+ grub_dl_unref (mod); -+ grub_dl_unload (mod); - - return 0; - } -diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index 48eb5e7b6..48f8a7907 100644 ---- a/grub-core/kern/dl.c -+++ b/grub-core/kern/dl.c -@@ -549,6 +549,15 @@ grub_dl_unref (grub_dl_t mod) - return --mod->ref_count; - } - -+int -+grub_dl_ref_count (grub_dl_t mod) -+{ -+ if (mod == NULL) -+ return 0; -+ -+ return mod->ref_count; -+} -+ - static void - grub_dl_flush_cache (grub_dl_t mod) - { -diff --git a/include/grub/dl.h b/include/grub/dl.h -index f03c03561..b3753c9ca 100644 ---- a/include/grub/dl.h -+++ b/include/grub/dl.h -@@ -203,9 +203,11 @@ grub_dl_t EXPORT_FUNC(grub_dl_load) (const char *name); - grub_dl_t grub_dl_load_core (void *addr, grub_size_t size); - grub_dl_t EXPORT_FUNC(grub_dl_load_core_noinit) (void *addr, grub_size_t size); - int EXPORT_FUNC(grub_dl_unload) (grub_dl_t mod); --void grub_dl_unload_unneeded (void); --int EXPORT_FUNC(grub_dl_ref) (grub_dl_t mod); --int EXPORT_FUNC(grub_dl_unref) (grub_dl_t mod); -+extern void grub_dl_unload_unneeded (void); -+extern int EXPORT_FUNC(grub_dl_ref) (grub_dl_t mod); -+extern int EXPORT_FUNC(grub_dl_unref) (grub_dl_t mod); -+extern int EXPORT_FUNC(grub_dl_ref_count) (grub_dl_t mod); -+ - extern grub_dl_t EXPORT_VAR(grub_dl_head); - - #ifndef GRUB_UTIL diff --git a/backport-CVE-2020-25647.patch b/backport-CVE-2020-25647.patch deleted file mode 100644 index bdac2375c11eb2026a3eef36421a47853da1d004..0000000000000000000000000000000000000000 --- a/backport-CVE-2020-25647.patch +++ /dev/null @@ -1,110 +0,0 @@ -From 128c16a682034263eb519c89bc0934eeb6fa8cfa -From: Daniel Kiper -Date: 2021-03-02 15:54:15 +0100 -Subject: [PATCH] usb: Avoid possible out-of-bound accesses caused by malicious devices -The maximum number of configurations and interfaces are fixed but there is -no out-of-bound checking to prevent a malicious USB device to report large -values for these and cause accesses outside the arrays' memory. - -Fixes: CVE-2020-25647 -Reference:http://git.savannah.gnu.org/cgit/grub.git/commit/?id=128c16a682034263eb519c89bc0934eeb6fa8cfa - -Reported-by: Joseph Tartaro -Reported-by: Ilja Van Sprundel -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper -Diffstat --rw-r--r-- grub-core/bus/usb/usb.c 15 --rw-r--r-- include/grub/usb.h 10 -2 files changed, 19 insertions, 6 deletions -diff --git a/grub-core/bus/usb/usb.c b/grub-core/bus/usb/usb.c -index 8da5e4c74..7cb3cc230 100644 ---- a/grub-core/bus/usb/usb.c -+++ b/grub-core/bus/usb/usb.c -@@ -75,6 +75,9 @@ grub_usb_controller_iterate (grub_usb_controller_iterate_hook_t hook, - grub_usb_err_t - grub_usb_clear_halt (grub_usb_device_t dev, int endpoint) - { -+ if (endpoint >= GRUB_USB_MAX_TOGGLE) -+ return GRUB_USB_ERR_BADDEVICE; -+ - dev->toggle[endpoint] = 0; - return grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT - | GRUB_USB_REQTYPE_STANDARD -@@ -134,10 +137,10 @@ grub_usb_device_initialize (grub_usb_device_t dev) - return err; - descdev = &dev->descdev; - -- for (i = 0; i < 8; i++) -+ for (i = 0; i < GRUB_USB_MAX_CONF; i++) - dev->config[i].descconf = NULL; - -- if (descdev->configcnt == 0) -+ if (descdev->configcnt == 0 || descdev->configcnt > GRUB_USB_MAX_CONF) - { - err = GRUB_USB_ERR_BADDEVICE; - goto fail; -@@ -172,6 +175,12 @@ grub_usb_device_initialize (grub_usb_device_t dev) - /* Skip the configuration descriptor. */ - pos = dev->config[i].descconf->length; - -+ if (dev->config[i].descconf->numif > GRUB_USB_MAX_IF) -+ { -+ err = GRUB_USB_ERR_BADDEVICE; -+ goto fail; -+ } -+ - /* Read all interfaces. */ - for (currif = 0; currif < dev->config[i].descconf->numif; currif++) - { -@@ -217,7 +226,7 @@ grub_usb_device_initialize (grub_usb_device_t dev) - - fail: - -- for (i = 0; i < 8; i++) -+ for (i = 0; i < GRUB_USB_MAX_CONF; i++) - grub_free (dev->config[i].descconf); - - return err; -diff --git a/include/grub/usb.h b/include/grub/usb.h -index 512ae1dd0..6475c552f 100644 ---- a/include/grub/usb.h -+++ b/include/grub/usb.h -@@ -23,6 +23,10 @@ - #include - #include - -+#define GRUB_USB_MAX_CONF 8 -+#define GRUB_USB_MAX_IF 32 -+#define GRUB_USB_MAX_TOGGLE 256 -+ - typedef struct grub_usb_device *grub_usb_device_t; - typedef struct grub_usb_controller *grub_usb_controller_t; - typedef struct grub_usb_controller_dev *grub_usb_controller_dev_t; -@@ -167,7 +171,7 @@ struct grub_usb_configuration - struct grub_usb_desc_config *descconf; - - /* Interfaces associated to this configuration. */ -- struct grub_usb_interface interf[32]; -+ struct grub_usb_interface interf[GRUB_USB_MAX_IF]; - }; - - struct grub_usb_hub_port -@@ -191,7 +195,7 @@ struct grub_usb_device - struct grub_usb_controller controller; - - /* Device configurations (after opening the device). */ -- struct grub_usb_configuration config[8]; -+ struct grub_usb_configuration config[GRUB_USB_MAX_CONF]; - - /* Device address. */ - int addr; -@@ -203,7 +207,7 @@ struct grub_usb_device - int initialized; - - /* Data toggle values (used for bulk transfers only). */ -- int toggle[256]; -+ int toggle[GRUB_USB_MAX_TOGGLE]; - - /* Used by libusb wrapper. Schedulded for removal. */ - void *data; diff --git a/backport-CVE-2021-20225.patch b/backport-CVE-2021-20225.patch deleted file mode 100644 index e161ad058845820a868422dbae0df41ed7ec04a5..0000000000000000000000000000000000000000 --- a/backport-CVE-2021-20225.patch +++ /dev/null @@ -1,51 +0,0 @@ -From 2a330dba93ff11bc00eda76e9419bc52b0c7ead6 -From: Daniel Kiper -Date: 2021-03-02 15:54:15 +0100 -Subject: [PATCH] lib/arg: Block repeated short options that require an argument -Fuzzing found the following crash: - - search -hhhhhhhhhhhhhf - -We didn't allocate enough option space for 13 hints because the -allocation code counts the number of discrete arguments (i.e. argc). -However, the shortopt parsing code will happily keep processing -a combination of short options without checking if those short -options require an argument. This means you can easily end writing -past the allocated option space. - -This fixes a OOB write which can cause heap corruption. - -Fixes: CVE-2021-20225 - -Reference:http://git.savannah.gnu.org/cgit/grub.git/commit/?id=2a330dba93ff11bc00eda76e9419bc52b0c7ead6 - -Reported-by: Daniel Axtens -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper -Diffstat --rw-r--r-- grub-core/lib/arg.c 13 -1 files changed, 13 insertions, 0 deletions -diff --git a/grub-core/lib/arg.c b/grub-core/lib/arg.c -index 8439a0062..ade82d5dc 100644 ---- a/grub-core/lib/arg.c -+++ b/grub-core/lib/arg.c -@@ -299,6 +299,19 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv, - it can have an argument value. */ - if (*curshort) - { -+ /* -+ * Only permit further short opts if this one doesn't -+ * require a value. -+ */ -+ if (opt->type != ARG_TYPE_NONE && -+ !(opt->flags & GRUB_ARG_OPTION_OPTIONAL)) -+ { -+ grub_error (GRUB_ERR_BAD_ARGUMENT, -+ N_("missing mandatory option for `%s'"), -+ opt->longarg); -+ goto fail; -+ } -+ - if (parse_option (cmd, opt, 0, usr) || grub_errno) - goto fail; - } diff --git a/backport-CVE-2021-20233.patch b/backport-CVE-2021-20233.patch deleted file mode 100644 index 0909104e98eb2d78b56c642934cd40202f13c7ca..0000000000000000000000000000000000000000 --- a/backport-CVE-2021-20233.patch +++ /dev/null @@ -1,44 +0,0 @@ -From 2f533a89a8dfcacbf2c9dbc77d910f111f24bf33 -From: Daniel Kiper -Date: 2021-03-02 15:54:15 +0100 -Subject: [PATCH] commands/menuentry: Fix quoting in setparams_prefix() -Commit 9acdcbf32542 (use single quotes in menuentry setparams command) -says that expressing a quoted single quote will require 3 characters. It -actually requires (and always did require!) 4 characters: - - str: a'b => a'\''b - len: 3 => 6 (2 for the letters + 4 for the quote) - -This leads to not allocating enough memory and thus out of bounds writes -that have been observed to cause heap corruption. - -Allocate 4 bytes for each single quote. - -Commit 22e7dbb2bb81 (Fix quoting in legacy parser.) does the same -quoting, but it adds 3 as extra overhead on top of the single byte that -the quote already needs. So it's correct. - -Fixes: 9acdcbf32542 (use single quotes in menuentry setparams command) -Fixes: CVE-2021-20233 - -Reference:http://git.savannah.gnu.org/cgit/grub.git/commit/?id=2f533a89a8dfcacbf2c9dbc77d910f111f24bf33 - -Reported-by: Daniel Axtens -Signed-off-by: Daniel Axtens -Reviewed-by: Daniel Kiper -Diffstat --rw-r--r-- grub-core/commands/menuentry.c 2 -1 files changed, 1 insertions, 1 deletions -diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c -index 9164df744..720e6d8ea 100644 ---- a/grub-core/commands/menuentry.c -+++ b/grub-core/commands/menuentry.c -@@ -230,7 +230,7 @@ setparams_prefix (int argc, char **args) - len += 3; /* 3 = 1 space + 2 quotes */ - p = args[i]; - while (*p) -- len += (*p++ == '\'' ? 3 : 1); -+ len += (*p++ == '\'' ? 4 : 1); - } - - result = grub_malloc (len + 2); diff --git a/backport-templates-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch b/backport-templates-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch deleted file mode 100644 index 64d395e5088ec13766a311e19a68226e21d58255..0000000000000000000000000000000000000000 --- a/backport-templates-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch +++ /dev/null @@ -1,56 +0,0 @@ -From 8d803482eda7214f33dbef79f3f88886d3a20263 Mon Sep 17 00:00:00 2001 -From: Prarit Bhargava -Date: Mon, 30 Sep 2019 17:00:16 +0200 -Subject: [PATCH] templates: Fix bad test on GRUB_DISABLE_SUBMENU - -The GRUB_DISABLE_SUBMENU option is different than the others in the sense -that it has to be set to "y" instead of "true" to be enabled. - -That causes a lot of confusion to users, some may wrongly set it to "true" -expecting that will work the same than with most options, and some may set -it to "yes" since for other options the value to set is a word and not a -single character. - -This patch changes all the grub.d scripts using the GRUB_DISABLE_SUBMENU -option, so they check if it was set to "true" instead of "y", making it -consistent with all the other options. - -But to keep backward compatibility for users that set the option to "y" in -/etc/default/grub file, keep testing for this value. And also do it for -"yes", since it is a common mistake made by users caused by this option -being inconsistent with the others. - -Reference:https://git.savannah.gnu.org/cgit/grub.git/commit/util/grub.d/30_os-prober.in?id=ee4bd79ef28e6fa4a68bb51c31a5e67a7cbf01ea -Conflict:NA - -Signed-off-by: Prarit Bhargava -Signed-off-by: Javier Martinez Canillas -Reviewed-by: Daniel Kiper ---- - util/grub.d/30_os-prober.in | 10 +++++++++- - 1 file changed, 9 insertions(+), 1 deletion(-) - -diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in -index ab63439..b659aeb 100644 ---- a/util/grub.d/30_os-prober.in -+++ b/util/grub.d/30_os-prober.in -@@ -195,7 +195,15 @@ EOF - prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | grub_add_tab)" - fi - -- if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then -+ # The GRUB_DISABLE_SUBMENU option used to be different than others since it was -+ # mentioned in the documentation that has to be set to 'y' instead of 'true' to -+ # enable it. This caused a lot of confusion to users that set the option to 'y', -+ # 'yes' or 'true'. This was fixed but all of these values must be supported now. -+ if [ "x${GRUB_DISABLE_SUBMENU}" = xyes ] || [ "x${GRUB_DISABLE_SUBMENU}" = xy ]; then -+ GRUB_DISABLE_SUBMENU="true" -+ fi -+ -+ if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then - cat << EOF - menuentry '$(echo "$OS $onstr" | grub_quote)' $CLASS --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-simple-$boot_device_id' { - EOF --- -2.19.1 - diff --git a/bootstrap b/bootstrap new file mode 100644 index 0000000000000000000000000000000000000000..4e1e91f7176352e82832b9b4925022bc4915abc8 --- /dev/null +++ b/bootstrap @@ -0,0 +1,1073 @@ +#!/bin/sh +# Print a version string. +scriptversion=2019-01-04.17; # UTC + +# Bootstrap this package from checked-out sources. + +# Copyright (C) 2003-2019 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Originally written by Paul Eggert. The canonical version of this +# script is maintained as build-aux/bootstrap in gnulib, however, to +# be useful to your project, you should place a copy of it under +# version control in the top-level directory of your project. The +# intent is that all customization can be done with a bootstrap.conf +# file also maintained in your version control; gnulib comes with a +# template build-aux/bootstrap.conf to get you started. + +# Please report bugs or propose patches to bug-gnulib@gnu.org. + +nl=' +' + +# Ensure file names are sorted consistently across platforms. +LC_ALL=C +export LC_ALL + +# Ensure that CDPATH is not set. Otherwise, the output from cd +# would cause trouble in at least one use below. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +local_gl_dir=gl + +# Honor $PERL, but work even if there is none. +PERL="${PERL-perl}" + +me=$0 + +default_gnulib_url=git://git.sv.gnu.org/gnulib + +usage() { + cat <&2 +} + +# warn_ WORD1... +warn_ () +{ + # If IFS does not start with ' ', set it and emit the warning in a subshell. + case $IFS in + ' '*) warnf_ '%s\n' "$*";; + *) (IFS=' '; warn_ "$@");; + esac +} + +# die WORD1... +die() { warn_ "$@"; exit 1; } + +# Configuration. + +# Name of the Makefile.am +gnulib_mk=gnulib.mk + +# List of gnulib modules needed. +gnulib_modules= + +# Any gnulib files needed that are not in modules. +gnulib_files= + +: ${AUTOPOINT=autopoint} +: ${AUTORECONF=autoreconf} + +# A function to be called right after gnulib-tool is run. +# Override it via your own definition in bootstrap.conf. +bootstrap_post_import_hook() { :; } + +# A function to be called after everything else in this script. +# Override it via your own definition in bootstrap.conf. +bootstrap_epilogue() { :; } + +# The command to download all .po files for a specified domain into a +# specified directory. Fill in the first %s with the destination +# directory and the second with the domain name. +po_download_command_format=\ +"wget --mirror --level=1 -nd -q -A.po -P '%s' \ + https://translationproject.org/latest/%s/" + +# Prefer a non-empty tarname (4th argument of AC_INIT if given), else +# fall back to the package name (1st argument with munging) +extract_package_name=' + /^AC_INIT(\[*/{ + s/// + /^[^,]*,[^,]*,[^,]*,[ []*\([^][ ,)]\)/{ + s//\1/ + s/[],)].*// + p + q + } + s/[],)].*// + s/^GNU // + y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ + s/[^abcdefghijklmnopqrstuvwxyz0123456789_]/-/g + p + } +' +package=$(sed -n "$extract_package_name" configure.ac) \ + || die 'cannot find package name in configure.ac' +gnulib_name=lib$package + +build_aux=build-aux +source_base=lib +m4_base=m4 +doc_base=doc +tests_base=tests +gnulib_extra_files=" + build-aux/install-sh + build-aux/mdate-sh + build-aux/texinfo.tex + build-aux/depcomp + build-aux/config.guess + build-aux/config.sub + doc/INSTALL +" + +# Additional gnulib-tool options to use. Use "\newline" to break lines. +gnulib_tool_option_extras= + +# Other locale categories that need message catalogs. +EXTRA_LOCALE_CATEGORIES= + +# Additional xgettext options to use. Use "\\\newline" to break lines. +XGETTEXT_OPTIONS='\\\ + --flag=_:1:pass-c-format\\\ + --flag=N_:1:pass-c-format\\\ + --flag=error:3:c-format --flag=error_at_line:5:c-format\\\ +' + +# Package bug report address and copyright holder for gettext files +COPYRIGHT_HOLDER='Free Software Foundation, Inc.' +MSGID_BUGS_ADDRESS=bug-$package@gnu.org + +# Files we don't want to import. +excluded_files= + +# File that should exist in the top directory of a checked out hierarchy, +# but not in a distribution tarball. +checkout_only_file=README-hacking + +# Whether to use copies instead of symlinks. +copy=false + +# Set this to '.cvsignore .gitignore' in bootstrap.conf if you want +# those files to be generated in directories like lib/, m4/, and po/. +# Or set it to 'auto' to make this script select which to use based +# on which version control system (if any) is used in the source directory. +vc_ignore=auto + +# Set this to true in bootstrap.conf to enable --bootstrap-sync by +# default. +bootstrap_sync=false + +# Use git to update gnulib sources +use_git=true + +check_exists() { + if test "$1" = "--verbose"; then + ($2 --version /dev/null 2>&1 + if test $? -ge 126; then + # If not found, run with diagnostics as one may be + # presented with env variables to set to find the right version + ($2 --version /dev/null 2>&1 + fi + + test $? -lt 126 +} + +# find_tool ENVVAR NAMES... +# ------------------------- +# Search for a required program. Use the value of ENVVAR, if set, +# otherwise find the first of the NAMES that can be run. +# If found, set ENVVAR to the program name, die otherwise. +# +# FIXME: code duplication, see also gnu-web-doc-update. +find_tool () +{ + find_tool_envvar=$1 + shift + find_tool_names=$@ + eval "find_tool_res=\$$find_tool_envvar" + if test x"$find_tool_res" = x; then + for i; do + if check_exists $i; then + find_tool_res=$i + break + fi + done + fi + if test x"$find_tool_res" = x; then + warn_ "one of these is required: $find_tool_names;" + die "alternatively set $find_tool_envvar to a compatible tool" + fi + eval "$find_tool_envvar=\$find_tool_res" + eval "export $find_tool_envvar" +} + +# Override the default configuration, if necessary. +# Make sure that bootstrap.conf is sourced from the current directory +# if we were invoked as "sh bootstrap". +case "$0" in + */*) test -r "$0.conf" && . "$0.conf" ;; + *) test -r "$0.conf" && . ./"$0.conf" ;; +esac + +if test "$vc_ignore" = auto; then + vc_ignore= + test -d .git && vc_ignore=.gitignore + test -d CVS && vc_ignore="$vc_ignore .cvsignore" +fi + +if test x"$gnulib_modules$gnulib_files$gnulib_extra_files" = x; then + use_gnulib=false +else + use_gnulib=true +fi + +# Translate configuration into internal form. + +# Parse options. + +for option +do + case $option in + --help) + usage + exit;; + --gnulib-srcdir=*) + GNULIB_SRCDIR=${option#--gnulib-srcdir=};; + --skip-po) + SKIP_PO=t;; + --force) + checkout_only_file=;; + --copy) + copy=true;; + --bootstrap-sync) + bootstrap_sync=true;; + --no-bootstrap-sync) + bootstrap_sync=false;; + --no-git) + use_git=false;; + *) + die "$option: unknown option";; + esac +done + +$use_git || test -d "$GNULIB_SRCDIR" \ + || die "Error: --no-git requires --gnulib-srcdir" + +if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then + die "Bootstrapping from a non-checked-out distribution is risky." +fi + +# Strip blank and comment lines to leave significant entries. +gitignore_entries() { + sed '/^#/d; /^$/d' "$@" +} + +# If $STR is not already on a line by itself in $FILE, insert it at the start. +# Entries are inserted at the start of the ignore list to ensure existing +# entries starting with ! are not overridden. Such entries support +# whitelisting exceptions after a more generic blacklist pattern. +insert_if_absent() { + file=$1 + str=$2 + test -f $file || touch $file + test -r $file || die "Error: failed to read ignore file: $file" + duplicate_entries=$(gitignore_entries $file | sort | uniq -d) + if [ "$duplicate_entries" ] ; then + die "Error: Duplicate entries in $file: " $duplicate_entries + fi + linesold=$(gitignore_entries $file | wc -l) + linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l) + if [ $linesold != $linesnew ] ; then + { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \ + || die "insert_if_absent $file $str: failed" + fi +} + +# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with +# insert_if_absent. +insert_vc_ignore() { + vc_ignore_file="$1" + pattern="$2" + case $vc_ignore_file in + *.gitignore) + # A .gitignore entry that does not start with '/' applies + # recursively to subdirectories, so prepend '/' to every + # .gitignore entry. + pattern=$(echo "$pattern" | sed s,^,/,);; + esac + insert_if_absent "$vc_ignore_file" "$pattern" +} + +# Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac. +found_aux_dir=no +grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \ + >/dev/null && found_aux_dir=yes +grep '^[ ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \ + >/dev/null && found_aux_dir=yes +test $found_aux_dir = yes \ + || die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it" + +# If $build_aux doesn't exist, create it now, otherwise some bits +# below will malfunction. If creating it, also mark it as ignored. +if test ! -d $build_aux; then + mkdir $build_aux + for dot_ig in x $vc_ignore; do + test $dot_ig = x && continue + insert_vc_ignore $dot_ig $build_aux + done +fi + +# Note this deviates from the version comparison in automake +# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a +# but this should suffice as we won't be specifying old +# version formats or redundant trailing .0 in bootstrap.conf. +# If we did want full compatibility then we should probably +# use m4_version_compare from autoconf. +sort_ver() { # sort -V is not generally available + ver1="$1" + ver2="$2" + + # split on '.' and compare each component + i=1 + while : ; do + p1=$(echo "$ver1" | cut -d. -f$i) + p2=$(echo "$ver2" | cut -d. -f$i) + if [ ! "$p1" ]; then + echo "$1 $2" + break + elif [ ! "$p2" ]; then + echo "$2 $1" + break + elif [ ! "$p1" = "$p2" ]; then + if [ "$p1" -gt "$p2" ] 2>/dev/null; then # numeric comparison + echo "$2 $1" + elif [ "$p2" -gt "$p1" ] 2>/dev/null; then # numeric comparison + echo "$1 $2" + else # numeric, then lexicographic comparison + lp=$(printf "$p1\n$p2\n" | LANG=C sort -n | tail -n1) + if [ "$lp" = "$p2" ]; then + echo "$1 $2" + else + echo "$2 $1" + fi + fi + break + fi + i=$(($i+1)) + done +} + +get_version_sed=' +# Move version to start of line. +s/.*[v ]\([0-9]\)/\1/ + +# Skip lines that do not start with version. +/^[0-9]/!d + +# Remove characters after the version. +s/[^.a-z0-9-].*// + +# The first component must be digits only. +s/^\([0-9]*\)[a-z-].*/\1/ + +#the following essentially does s/5.005/5.5/ +s/\.0*\([1-9]\)/.\1/g +p +q' + +get_version() { + app=$1 + + $app --version >/dev/null 2>&1 || { $app --version; return 1; } + + $app --version 2>&1 | sed -n "$get_version_sed" +} + +check_versions() { + ret=0 + + while read app req_ver; do + # We only need libtoolize from the libtool package. + if test "$app" = libtool; then + app=libtoolize + fi + # Exempt git if --no-git is in effect. + if test "$app" = git; then + $use_git || continue + fi + # Honor $APP variables ($TAR, $AUTOCONF, etc.) + appvar=$(echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_') + test "$appvar" = TAR && appvar=AMTAR + case $appvar in + GZIP) ;; # Do not use $GZIP: it contains gzip options. + PERL::*) ;; # Keep perl modules as-is + *) eval "app=\${$appvar-$app}" ;; + esac + + # Handle the still-experimental Automake-NG programs specially. + # They remain named as the mainstream Automake programs ("automake", + # and "aclocal") to avoid gratuitous incompatibilities with + # pre-existing usages (by, say, autoreconf, or custom autogen.sh + # scripts), but correctly identify themselves (as being part of + # "GNU automake-ng") when asked their version. + case $app in + automake-ng|aclocal-ng) + app=${app%-ng} + ($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || { + warn_ "Error: '$app' not found or not from Automake-NG" + ret=1 + continue + } ;; + # Another check is for perl modules. These can be written as + # e.g. perl::XML::XPath in case of XML::XPath module, etc. + perl::*) + # Extract module name + app="${app#perl::}" + if ! $PERL -m"$app" -e 'exit 0' >/dev/null 2>&1; then + warn_ "Error: perl module '$app' not found" + ret=1 + fi + continue + ;; + esac + if [ "$req_ver" = "-" ]; then + # Merely require app to exist; not all prereq apps are well-behaved + # so we have to rely on $? rather than get_version. + if ! check_exists --verbose $app; then + warn_ "Error: '$app' not found" + ret=1 + fi + else + # Require app to produce a new enough version string. + inst_ver=$(get_version $app) + if [ ! "$inst_ver" ]; then + warn_ "Error: '$app' not found" + ret=1 + else + latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2) + if [ ! "$latest_ver" = "$inst_ver" ]; then + warnf_ '%s\n' \ + "Error: '$app' version == $inst_ver is too old" \ + " '$app' version >= $req_ver is required" + ret=1 + fi + fi + fi + done + + return $ret +} + +print_versions() { + echo "Program Min_version" + echo "----------------------" + printf %s "$buildreq" + echo "----------------------" + # can't depend on column -t +} + +# Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6. +# Also find the compatible sha1 utility on the BSDs +if test x"$SKIP_PO" = x; then + find_tool SHA1SUM sha1sum gsha1sum shasum sha1 +fi + +use_libtool=0 +# We'd like to use grep -E, to see if any of LT_INIT, +# AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac, +# but that's not portable enough (e.g., for Solaris). +grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \ + && use_libtool=1 +grep '^[ ]*LT_INIT' configure.ac >/dev/null \ + && use_libtool=1 +if test $use_libtool = 1; then + find_tool LIBTOOLIZE glibtoolize libtoolize +fi + +# gnulib-tool requires at least automake and autoconf. +# If either is not listed, add it (with minimum version) as a prerequisite. +case $buildreq in + *automake*) ;; + *) buildreq="automake 1.9 +$buildreq" ;; +esac +case $buildreq in + *autoconf*) ;; + *) buildreq="autoconf 2.59 +$buildreq" ;; +esac + +# When we can deduce that gnulib-tool will require patch, +# and when patch is not already listed as a prerequisite, add it, too. +if test -d "$local_gl_dir" \ + && ! find "$local_gl_dir" -name '*.diff' -exec false {} +; then + case $buildreq in + *patch*) ;; + *) buildreq="patch - +$buildreq" ;; + esac +fi + +if ! printf "$buildreq" | check_versions; then + echo >&2 + if test -f README-prereq; then + die "See README-prereq for how to get the prerequisite programs" + else + die "Please install the prerequisite programs" + fi +fi + +# Warn the user if autom4te appears to be broken; this causes known +# issues with at least gettext 0.18.3. +probe=$(echo 'm4_quote([hi])' | autom4te -l M4sugar -t 'm4_quote:$%' -) +if test "x$probe" != xhi; then + warn_ "WARNING: your autom4te wrapper eats stdin;" + warn_ "if bootstrap fails, consider upgrading your autotools" +fi + +echo "$0: Bootstrapping from checked-out $package sources..." + +# See if we can use gnulib's git-merge-changelog merge driver. +if $use_git && test -d .git && check_exists git; then + if git config merge.merge-changelog.driver >/dev/null ; then + : + elif check_exists git-merge-changelog; then + echo "$0: initializing git-merge-changelog driver" + git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver' + git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B' + else + echo "$0: consider installing git-merge-changelog from gnulib" + fi +fi + + +cleanup_gnulib() { + status=$? + rm -fr "$gnulib_path" + exit $status +} + +git_modules_config () { + test -f .gitmodules && git config --file .gitmodules "$@" +} + +if $use_gnulib; then + if $use_git; then + gnulib_path=$(git_modules_config submodule.gnulib.path) + test -z "$gnulib_path" && gnulib_path=gnulib + fi + + # Get gnulib files. Populate $GNULIB_SRCDIR, possibly updating a + # submodule, for use in the rest of the script. + + case ${GNULIB_SRCDIR--} in + -) + # Note that $use_git is necessarily true in this case. + if git_modules_config submodule.gnulib.url >/dev/null; then + echo "$0: getting gnulib files..." + git submodule init -- "$gnulib_path" || exit $? + git submodule update -- "$gnulib_path" || exit $? + + elif [ ! -d "$gnulib_path" ]; then + echo "$0: getting gnulib files..." + + trap cleanup_gnulib 1 2 13 15 + + shallow= + if test -z "$GNULIB_REVISION"; then + git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2' + fi + git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \ + || cleanup_gnulib + + trap - 1 2 13 15 + fi + GNULIB_SRCDIR=$gnulib_path + ;; + *) + # Use GNULIB_SRCDIR directly or as a reference. + if $use_git && test -d "$GNULIB_SRCDIR"/.git && \ + git_modules_config submodule.gnulib.url >/dev/null; then + echo "$0: getting gnulib files..." + if git submodule -h|grep -- --reference > /dev/null; then + # Prefer the one-liner available in git 1.6.4 or newer. + git submodule update --init --reference "$GNULIB_SRCDIR" \ + "$gnulib_path" || exit $? + else + # This fallback allows at least git 1.5.5. + if test -f "$gnulib_path"/gnulib-tool; then + # Since file already exists, assume submodule init already complete. + git submodule update -- "$gnulib_path" || exit $? + else + # Older git can't clone into an empty directory. + rmdir "$gnulib_path" 2>/dev/null + git clone --reference "$GNULIB_SRCDIR" \ + "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \ + && git submodule init -- "$gnulib_path" \ + && git submodule update -- "$gnulib_path" \ + || exit $? + fi + fi + GNULIB_SRCDIR=$gnulib_path + fi + ;; + esac + + if test -d "$GNULIB_SRCDIR"/.git && test -n "$GNULIB_REVISION" \ + && ! git_modules_config submodule.gnulib.url >/dev/null; then + (cd "$GNULIB_SRCDIR" && git checkout "$GNULIB_REVISION") || cleanup_gnulib + fi + + # $GNULIB_SRCDIR now points to the version of gnulib to use, and + # we no longer need to use git or $gnulib_path below here. + + if $bootstrap_sync; then + cmp -s "$0" "$GNULIB_SRCDIR/build-aux/bootstrap" || { + echo "$0: updating bootstrap and restarting..." + case $(sh -c 'echo "$1"' -- a) in + a) ignored=--;; + *) ignored=ignored;; + esac + exec sh -c \ + 'cp "$1" "$2" && shift && exec "${CONFIG_SHELL-/bin/sh}" "$@"' \ + $ignored "$GNULIB_SRCDIR/build-aux/bootstrap" \ + "$0" "$@" --no-bootstrap-sync + } + fi + + gnulib_tool=$GNULIB_SRCDIR/gnulib-tool + <$gnulib_tool || exit $? +fi + +# Get translations. + +download_po_files() { + subdir=$1 + domain=$2 + echo "$me: getting translations into $subdir for $domain..." + cmd=$(printf "$po_download_command_format" "$subdir" "$domain") + eval "$cmd" +} + +# Mirror .po files to $po_dir/.reference and copy only the new +# or modified ones into $po_dir. Also update $po_dir/LINGUAS. +# Note po files that exist locally only are left in $po_dir but will +# not be included in LINGUAS and hence will not be distributed. +update_po_files() { + # Directory containing primary .po files. + # Overwrite them only when we're sure a .po file is new. + po_dir=$1 + domain=$2 + + # Mirror *.po files into this dir. + # Usually contains *.s1 checksum files. + ref_po_dir="$po_dir/.reference" + + test -d $ref_po_dir || mkdir $ref_po_dir || return + download_po_files $ref_po_dir $domain \ + && ls "$ref_po_dir"/*.po 2>/dev/null | + sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return + + langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g') + test "$langs" = '*' && langs=x + for po in $langs; do + case $po in x) continue;; esac + new_po="$ref_po_dir/$po.po" + cksum_file="$ref_po_dir/$po.s1" + if ! test -f "$cksum_file" || + ! test -f "$po_dir/$po.po" || + ! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then + echo "$me: updated $po_dir/$po.po..." + cp "$new_po" "$po_dir/$po.po" \ + && $SHA1SUM < "$new_po" > "$cksum_file" || return + fi + done +} + +case $SKIP_PO in +'') + if test -d po; then + update_po_files po $package || exit + fi + + if test -d runtime-po; then + update_po_files runtime-po $package-runtime || exit + fi;; +esac + +symlink_to_dir() +{ + src=$1/$2 + dst=${3-$2} + + test -f "$src" && { + + # If the destination directory doesn't exist, create it. + # This is required at least for "lib/uniwidth/cjk.h". + dst_dir=$(dirname "$dst") + if ! test -d "$dst_dir"; then + mkdir -p "$dst_dir" + + # If we've just created a directory like lib/uniwidth, + # tell version control system(s) it's ignorable. + # FIXME: for now, this does only one level + parent=$(dirname "$dst_dir") + for dot_ig in x $vc_ignore; do + test $dot_ig = x && continue + ig=$parent/$dot_ig + insert_vc_ignore $ig "${dst_dir##*/}" + done + fi + + if $copy; then + { + test ! -h "$dst" || { + echo "$me: rm -f $dst" && + rm -f "$dst" + } + } && + test -f "$dst" && + cmp -s "$src" "$dst" || { + echo "$me: cp -fp $src $dst" && + cp -fp "$src" "$dst" + } + else + # Leave any existing symlink alone, if it already points to the source, + # so that broken build tools that care about symlink times + # aren't confused into doing unnecessary builds. Conversely, if the + # existing symlink's timestamp is older than the source, make it afresh, + # so that broken tools aren't confused into skipping needed builds. See + # . + test -h "$dst" && + src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 && + dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 && + test "$src_i" = "$dst_i" && + both_ls=$(ls -dt "$src" "$dst") && + test "X$both_ls" = "X$dst$nl$src" || { + dot_dots= + case $src in + /*) ;; + *) + case /$dst/ in + *//* | */../* | */./* | /*/*/*/*/*/) + die "invalid symlink calculation: $src -> $dst";; + /*/*/*/*/) dot_dots=../../../;; + /*/*/*/) dot_dots=../../;; + /*/*/) dot_dots=../;; + esac;; + esac + + echo "$me: ln -fs $dot_dots$src $dst" && + ln -fs "$dot_dots$src" "$dst" + } + fi + } +} + +version_controlled_file() { + parent=$1 + file=$2 + if test -d .git; then + git rm -n "$file" > /dev/null 2>&1 + elif test -d .svn; then + svn log -r HEAD "$file" > /dev/null 2>&1 + elif test -d CVS; then + grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev/null | + grep '^/[^/]*/[0-9]' > /dev/null + else + warn_ "no version control for $file?" + false + fi +} + +# NOTE: we have to be careful to run both autopoint and libtoolize +# before gnulib-tool, since gnulib-tool is likely to provide newer +# versions of files "installed" by these two programs. +# Then, *after* gnulib-tool (see below), we have to be careful to +# run autoreconf in such a way that it does not run either of these +# two just-pre-run programs. + +# Import from gettext. +with_gettext=yes +grep '^[ ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \ + with_gettext=no + +if test $with_gettext = yes || test $use_libtool = 1; then + + tempbase=.bootstrap$$ + trap "rm -f $tempbase.0 $tempbase.1" 1 2 13 15 + + > $tempbase.0 > $tempbase.1 && + find . ! -type d -print | sort > $tempbase.0 || exit + + if test $with_gettext = yes; then + # Released autopoint has the tendency to install macros that have been + # obsoleted in current gnulib, so run this before gnulib-tool. + echo "$0: $AUTOPOINT --force" + $AUTOPOINT --force || exit + fi + + # Autoreconf runs aclocal before libtoolize, which causes spurious + # warnings if the initial aclocal is confused by the libtoolized + # (or worse out-of-date) macro directory. + # libtoolize 1.9b added the --install option; but we support back + # to libtoolize 1.5.22, where the install action was default. + if test $use_libtool = 1; then + install= + case $($LIBTOOLIZE --help) in + *--install*) install=--install ;; + esac + echo "running: $LIBTOOLIZE $install --copy" + $LIBTOOLIZE $install --copy + fi + + find . ! -type d -print | sort >$tempbase.1 + old_IFS=$IFS + IFS=$nl + for file in $(comm -13 $tempbase.0 $tempbase.1); do + IFS=$old_IFS + parent=${file%/*} + version_controlled_file "$parent" "$file" || { + for dot_ig in x $vc_ignore; do + test $dot_ig = x && continue + ig=$parent/$dot_ig + insert_vc_ignore "$ig" "${file##*/}" + done + } + done + IFS=$old_IFS + + rm -f $tempbase.0 $tempbase.1 + trap - 1 2 13 15 +fi + +# Import from gnulib. + +if $use_gnulib; then + gnulib_tool_options="\ + --no-changelog\ + --aux-dir=$build_aux\ + --doc-base=$doc_base\ + --lib=$gnulib_name\ + --m4-base=$m4_base/\ + --source-base=$source_base/\ + --tests-base=$tests_base\ + --local-dir=$local_gl_dir\ + $gnulib_tool_option_extras\ + " + if test $use_libtool = 1; then + case "$gnulib_tool_options " in + *' --libtool '*) ;; + *) gnulib_tool_options="$gnulib_tool_options --libtool" ;; + esac + fi + echo "$0: $gnulib_tool $gnulib_tool_options --import ..." + $gnulib_tool $gnulib_tool_options --import $gnulib_modules \ + || die "gnulib-tool failed" + + for file in $gnulib_files; do + symlink_to_dir "$GNULIB_SRCDIR" $file \ + || die "failed to symlink $file" + done +fi + +bootstrap_post_import_hook \ + || die "bootstrap_post_import_hook failed" + +# Don't proceed if there are uninitialized submodules. In particular, +# the next step will remove dangling links, which might be links into +# uninitialized submodules. +# +# Uninitialized submodules are listed with an initial dash. +if $use_git && git submodule | grep '^-' >/dev/null; then + die "some git submodules are not initialized. " \ + "Run 'git submodule init' and bootstrap again." +fi + +# Remove any dangling symlink matching "*.m4" or "*.[ch]" in some +# gnulib-populated directories. Such .m4 files would cause aclocal to fail. +# The following requires GNU find 4.2.3 or newer. Considering the usual +# portability constraints of this script, that may seem a very demanding +# requirement, but it should be ok. Ignore any failure, which is fine, +# since this is only a convenience to help developers avoid the relatively +# unusual case in which a symlinked-to .m4 file is git-removed from gnulib +# between successive runs of this script. +find "$m4_base" "$source_base" \ + -depth \( -name '*.m4' -o -name '*.[ch]' \) \ + -type l -xtype l -delete > /dev/null 2>&1 + +# Invoke autoreconf with --force --install to ensure upgrades of tools +# such as ylwrap. +AUTORECONFFLAGS="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS" + +# Some systems (RHEL 5) are using ancient autotools, for which the +# --no-recursive option had not been invented. Detect that lack and +# omit the option when it's not supported. FIXME in 2017: remove this +# hack when RHEL 5 autotools are updated, or when they become irrelevant. +case $($AUTORECONF --help) in + *--no-recursive*) AUTORECONFFLAGS="$AUTORECONFFLAGS --no-recursive";; +esac + +# Tell autoreconf not to invoke autopoint or libtoolize; they were run above. +echo "running: AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS" +AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS \ + || die "autoreconf failed" + +# Get some extra files from gnulib, overriding existing files. +for file in $gnulib_extra_files; do + case $file in + */INSTALL) dst=INSTALL;; + build-aux/*) dst=$build_aux/${file#build-aux/};; + *) dst=$file;; + esac + symlink_to_dir "$GNULIB_SRCDIR" $file $dst \ + || die "failed to symlink $file" +done + +if test $with_gettext = yes; then + # Create gettext configuration. + echo "$0: Creating po/Makevars from po/Makevars.template ..." + rm -f po/Makevars + sed ' + /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/ + /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/ + /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$MSGID_BUGS_ADDRESS"'| + /^XGETTEXT_OPTIONS *=/{ + s/$/ \\/ + a\ + '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+} + } + ' po/Makevars.template >po/Makevars \ + || die 'cannot generate po/Makevars' + + # If the 'gettext' module is in use, grab the latest Makefile.in.in. + # If only the 'gettext-h' module is in use, assume autopoint already + # put the correct version of this file into place. + case $gnulib_modules in + *gettext-h*) ;; + *gettext*) + cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in \ + || die "cannot create po/Makefile.in.in" + ;; + esac + + if test -d runtime-po; then + # Similarly for runtime-po/Makevars, but not quite the same. + rm -f runtime-po/Makevars + sed ' + /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/ + /^subdir *=.*/s/=.*/= runtime-po/ + /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/ + /^XGETTEXT_OPTIONS *=/{ + s/$/ \\/ + a\ + '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+} + } + ' po/Makevars.template >runtime-po/Makevars \ + || die 'cannot generate runtime-po/Makevars' + + # Copy identical files from po to runtime-po. + (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po) + fi +fi + +bootstrap_epilogue + +echo "$0: done. Now you can run './configure'." + +# Local variables: +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC0" +# time-stamp-end: "; # UTC" +# End: diff --git a/bootstrap.conf b/bootstrap.conf new file mode 100644 index 0000000000000000000000000000000000000000..6b043fc354c4347d992139e908a6a7b159e28114 --- /dev/null +++ b/bootstrap.conf @@ -0,0 +1,101 @@ +# Bootstrap configuration. + +# Copyright (C) 2006-2019 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +GNULIB_REVISION=d271f868a8df9bbec29049d01e056481b7a1a263 + +# gnulib modules used by this package. +# mbswidth is used by gnulib-fix-width.diff's changes to argp rather than +# directly. +gnulib_modules=" + argp + base64 + error + fnmatch + getdelim + getline + gettext-h + gitlog-to-changelog + mbswidth + progname + realloc-gnu + regex + save-cwd +" + +gnulib_tool_option_extras="\ + --no-conditional-dependencies \ + --no-vc-files \ +" + +gnulib_name=libgnu +source_base=grub-core/lib/gnulib +gnulib_extra_files=" + build-aux/install-sh + build-aux/mdate-sh + build-aux/texinfo.tex + build-aux/depcomp + build-aux/config.guess + build-aux/config.sub +" + +# Additional xgettext options to use. Use "\\\newline" to break lines. +XGETTEXT_OPTIONS=$XGETTEXT_OPTIONS'\\\ + --from-code=UTF-8\\\ +' + +checkout_only_file= +copy=true +vc_ignore= + +SKIP_PO=t + +# Build prerequisites +buildreq="\ +autoconf 2.63 +automake 1.11 +gettext 0.18.3 +git 1.5.5 +tar - +" + +# bootstrap doesn't give us a reasonable way to stop Automake from +# overwriting this, so we just copy our version aside and put it back later. +cp -a INSTALL INSTALL.grub + +bootstrap_post_import_hook () { + set -e + for patchname in fix-base64 fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \ + fix-regexec-null-deref fix-uninit-structure fix-unused-value fix-width no-abort; do + patch -d grub-core/lib/gnulib -p2 \ + < "grub-core/lib/gnulib-patches/$patchname.patch" + done + for patchname in \ + 0001-Support-POTFILES-shell \ + 0002-Handle-gettext_printf-shell-function \ + 0003-Make-msgfmt-output-in-little-endian \ + 0004-Use-SHELL-rather-than-bin-sh; do + patch -d po -p3 \ + < "po/gettext-patches/$patchname.patch" + done + FROM_BOOTSTRAP=1 ./autogen.sh + set +e # bootstrap expects this +} + +bootstrap_epilogue () { + mv INSTALL.grub INSTALL +} diff --git a/gitignore b/gitignore index 819cd185d44b620d05eadad504ec0c171bbbf3df..f6a1bd0517526a19ec4f5a493d38752f46a93ffe 100644 --- a/gitignore +++ b/gitignore @@ -1,237 +1,277 @@ -*~ -00_header -10_* -20_linux_xen -30_os-prober -40_custom -41_custom +# +# Ignore patterns in this directory and all subdirectories. +# *.1 *.8 -ABOUT-NLS -aclocal.m4 -ahci_test -ascii.bitmaps -ascii.h -autom4te.cache -build-aux -build-grub-gen-asciih -build-grub-gen-widthspec -build-grub-mkfont -cdboot_test -cmp_test -config.cache -config.guess -config.h -config-util.h -config-util.h.in -config.log -config.status -config.sub -configure -core_compress_test -DISTLIST -docs/*.info -docs/stamp-vti -docs/version.texi -ehci_test -example_grub_script_test -example_scripted_test -example_unit_test +*.a *.exec *.exec.exe -fddboot_test +*.image +*.image.exe +*.img +*.log +*.lst +*.marker +*.mod +*.o +*.pf2 +*.pp +*.trs +*~ +.deps-core/ +.deps-util/ +.deps/ +.dirstamp +DISTLIST +GPATH +GRTAGS +GSYMS +GTAGS +Makefile +Makefile.in +ascii.bitmaps genkernsyms.sh gensymlist.sh -gentrigtables -gentrigtables.exe -gettext_strings_test -/gnulib grub-bin2h -/grub-bios-setup -/grub-bios-setup.exe -grub_cmd_date -grub_cmd_echo -grub_cmd_regexp -grub_cmd_set_date -grub_cmd_sleep -/grub-editenv -/grub-editenv.exe grub-emu grub-emu-lite -grub-emu.exe grub-emu-lite.exe +grub-emu.exe +grub-macho2img grub_emu_init.c grub_emu_init.h -/grub-file -/grub-file.exe -grub-fstest -grub-fstest.exe -grub_fstest_init.c -grub_fstest_init.h -grub_func_test -grub-install -grub-install.exe -grub-kbdcomp -/grub-macbless -/grub-macbless.exe -grub-macho2img -/grub-menulst2cfg -/grub-menulst2cfg.exe -/grub-mk* -grub-mount -/grub-ofpathname -/grub-ofpathname.exe -grub-core/build-grub-pe2elf.exe -/grub-probe -/grub-probe.exe grub_probe_init.c grub_probe_init.h -/grub-reboot -grub_script_blanklines -grub_script_blockarg -grub_script_break -grub-script-check -grub-script-check.exe -grub_script_check_init.c -grub_script_check_init.h -grub_script_comments -grub_script_continue -grub_script_dollar -grub_script_echo1 -grub_script_echo_keywords -grub_script_escape_comma -grub_script_eval -grub_script_expansion -grub_script_final_semicolon -grub_script_for1 -grub_script_functions -grub_script_gettext -grub_script_if -grub_script_leading_whitespace -grub_script_no_commands -grub_script_not -grub_script_return -grub_script_setparams -grub_script_shift -grub_script_strcmp -grub_script_test -grub_script_vars1 -grub_script_while1 grub_script.tab.c grub_script.tab.h grub_script.yy.c grub_script.yy.h -grub-set-default +grub_script_check_init.c +grub_script_check_init.h grub_setup_init.c grub_setup_init.h -grub-shell -grub-shell-tester -grub-sparc64-setup -grub-sparc64-setup.exe -/grub-syslinux2cfg -/grub-syslinux2cfg.exe -gzcompress_test -hddboot_test -help_test -*.img -*.image -*.image.exe -include/grub/cpu -include/grub/machine -INSTALL.grub -install-sh -lib/libgcrypt-grub -libgrub_a_init.c -*.log -*.lst -lzocompress_test -*.marker -Makefile -/m4 -*.mod +mdate-sh mod-*.c -missing -netboot_test -*.o -*.a -ohci_test -partmap_test -pata_test -*.pf2 -*.pp -po/*.mo -po/grub.pot -po/Makefile.in.in -po/Makevars -po/Makevars.template -po/POTFILES -po/Rules-quot -po/stamp-po -printf_test -priority_queue_unit_test -pseries_test -stamp-h -stamp-h1 -stamp-h.in -symlist.c -symlist.h -trigtables.c -*.trs -uhci_test update-grub_lib -unidata.c -xzcompress_test -Makefile.in -GPATH -GRTAGS -GSYMS -GTAGS -compile -depcomp -mdate-sh -texinfo.tex -grub-core/lib/libgcrypt-grub -.deps -.deps-util -.deps-core -.dirstamp -Makefile.util.am -contrib -grub-core/bootinfo.txt -grub-core/Makefile.core.am -grub-core/Makefile.gcry.def -grub-core/contrib -grub-core/gdb_grub -grub-core/genmod.sh -grub-core/gensyminfo.sh -grub-core/gmodule.pl -grub-core/grub.chrp -grub-core/modinfo.sh -grub-core/*.module -grub-core/*.module.exe -grub-core/*.pp -grub-core/kernel.img.bin -util/bash-completion.d/grub -grub-core/lib/gnulib -grub-core/rs_decoder.h widthspec.bin -widthspec.h -docs/stamp-1 -docs/version-dev.texi -Makefile.utilgcry.def -po/*.po -po/*.gmo -po/LINGUAS -po/remove-potcdate.sed -include/grub/gcrypt/gcrypt.h -include/grub/gcrypt/g10lib.h -po/POTFILES.in -po/POTFILES-shell.in -/grub-glue-efi -/grub-render-label -/grub-glue-efi.exe -/grub-render-label.exe + +# +# Ignore patterns relative to this .gitignore file's directory. +# +/00_header +/10_* +/20_linux_xen +/30_os-prober +/30_uefi-firmware +/40_custom +/41_custom +/ABOUT-NLS +/ChangeLog +/INSTALL.grub +/Makefile.util.am +/Makefile.utilgcry.def +/aclocal.m4 +/ahci_test +/ascii.h +/autom4te.cache/ +/btrfs_test +/build-aux/ +/build-grub-gen-asciih +/build-grub-gen-widthspec +/build-grub-mkfont +/cdboot_test +/cmp_test +/compile +/config-util.h +/config-util.h.in +/config.cache +/config.guess +/config.h +/config.log +/config.status +/config.sub +/configure +/contrib +/core_compress_test +/cpio_test +/date_test +/depcomp +/docs/*.info +/docs/*.info-[0-9]* +/docs/stamp-1 +/docs/stamp-vti +/docs/version-dev.texi +/docs/version.texi +/ehci_test +/example_grub_script_test +/example_scripted_test +/example_unit_test +/exfat_test +/ext234_test +/f2fs_test +/fat_test +/fddboot_test +/file_filter_test /garbage-gen /garbage-gen.exe +/gettext_strings_test +/gnulib/ +/grub-2.[0-9]*/ +/grub-2.[0-9]*.tar.gz +/grub-bios-setup +/grub-bios-setup.exe +/grub-core/*.module +/grub-core/*.module.exe +/grub-core/*.pp +/grub-core/Makefile.core.am +/grub-core/Makefile.gcry.def +/grub-core/bootinfo.txt +/grub-core/build-grub-module-verifier +/grub-core/build-grub-pe2elf.exe +/grub-core/contrib +/grub-core/gdb_grub +/grub-core/genmod.sh +/grub-core/gensyminfo.sh +/grub-core/gentrigtables +/grub-core/gentrigtables.exe +/grub-core/gmodule.pl +/grub-core/grub.chrp +/grub-core/kernel.img.bin +/grub-core/lib/gnulib +/grub-core/lib/libgcrypt-grub +/grub-core/modinfo.sh +/grub-core/rs_decoder.h +/grub-core/symlist.c +/grub-core/symlist.h +/grub-core/trigtables.c +/grub-core/unidata.c +/grub-editenv +/grub-editenv.exe +/grub-file +/grub-file.exe /grub-fs-tester -grub-core/build-grub-module-verifier +/grub-fstest +/grub-fstest.exe +/grub-glue-efi +/grub-glue-efi.exe +/grub-install +/grub-install.exe +/grub-kbdcomp +/grub-macbless +/grub-macbless.exe +/grub-menulst2cfg +/grub-menulst2cfg.exe +/grub-mk* +/grub-mount +/grub-ofpathname +/grub-ofpathname.exe +/grub-probe +/grub-probe.exe +/grub-reboot +/grub-render-label +/grub-render-label.exe +/grub-script-check +/grub-script-check.exe +/grub-set-default +/grub-shell +/grub-shell-tester +/grub-sparc64-setup +/grub-sparc64-setup.exe +/grub-syslinux2cfg +/grub-syslinux2cfg.exe +/grub_cmd_date +/grub_cmd_echo +/grub_cmd_regexp +/grub_cmd_set_date +/grub_cmd_sleep +/grub_cmd_test +/grub_cmd_tr +/grub_fstest_init.c +/grub_fstest_init.h +/grub_func_test +/grub_script_blanklines +/grub_script_blockarg +/grub_script_break +/grub_script_comments +/grub_script_continue +/grub_script_dollar +/grub_script_echo1 +/grub_script_echo_keywords +/grub_script_escape_comma +/grub_script_eval +/grub_script_expansion +/grub_script_final_semicolon +/grub_script_for1 +/grub_script_functions +/grub_script_gettext +/grub_script_if +/grub_script_leading_whitespace +/grub_script_no_commands +/grub_script_not +/grub_script_return +/grub_script_setparams +/grub_script_shift +/grub_script_strcmp +/grub_script_test +/grub_script_vars1 +/grub_script_while1 +/gzcompress_test +/hddboot_test +/help_test +/hfs_test +/hfsplus_test +/include/grub/cpu +/include/grub/gcrypt/g10lib.h +/include/grub/gcrypt/gcrypt.h +/include/grub/machine +/install-sh +/iso9660_test +/jfs_test +/lib/libgcrypt-grub +/libgrub_a_init.c +/lzocompress_test +/m4/ +/minixfs_test +/missing +/netboot_test +/nilfs2_test +/ntfs_test +/ohci_test +/partmap_test +/pata_test +/po/*.gmo +/po/*.mo +/po/*.po +/po/LINGUAS +/po/Makefile.in.in +/po/Makevars +/po/Makevars.template +/po/POTFILES +/po/POTFILES-shell.in +/po/POTFILES.in +/po/Rules-quot +/po/grub.pot +/po/remove-potcdate.sed +/po/stamp-po +/printf_test +/priority_queue_unit_test +/pseries_test +/reiserfs_test +/romfs_test +/squashfs_test +/stamp-h +/stamp-h.in +/stamp-h1 +/syslinux_test +/tar_test +/test_sha512sum +/test_unset +/tests/syslinux/ubuntu10.04_grub.cfg +/texinfo.tex +/udf_test +/uhci_test +/util/bash-completion.d/grub +/widthspec.h +/xfs_test +/xzcompress_test +/zfs_test diff --git a/gnulib-fixes.tar.gz b/gnulib-fixes.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..9b2472311a1a5a0a02b5d34e8e54000522f156f8 Binary files /dev/null and b/gnulib-fixes.tar.gz differ diff --git a/grub-2.04.tar.xz b/grub-2.06.tar.xz similarity index 46% rename from grub-2.04.tar.xz rename to grub-2.06.tar.xz index 88872047855a9de4bd93f3e3912ea4301137f49c..a6a9c6dcb110f96560af778f89e7f64d67417679 100644 Binary files a/grub-2.04.tar.xz and b/grub-2.06.tar.xz differ diff --git a/grub.macros b/grub.macros index 433a8aa08bed5dfdb3bf133c7448d9e5f6778f34..1235c4d4dea33524ff5565f7a306bf747dd5cef8 100644 --- a/grub.macros +++ b/grub.macros @@ -329,6 +329,11 @@ This subpackage provides optional components of grub used with removeable media rm -fv docs/*.info \ cp %{SOURCE6} .gitignore \ cp %{SOURCE9} ./grub-core/tests/strtoull_test.c \ +cp %{SOURCE11} bootstrap \ +cp %{SOURCE12} bootstrap.conf \ +cp %{SOURCE8} gnulib-%{gnulibversion}.tar.gz \ +tar -zxf gnulib-%{gnulibversion}.tar.gz \ +mv gnulib-%{gnulibversion} gnulib \ git init \ echo '![[:digit:]][[:digit:]]_*.in' > util/grub.d/.gitignore \ echo '!*.[[:digit:]]' > util/.gitignore \ @@ -340,27 +345,23 @@ rm -f configure \ git add . \ git commit -a -q -m "%{tarversion} baseline." \ git am --whitespace=nowarn %%{patches} Date: Thu, 2 Sep 2021 17:30:39 +0800 Subject: [PATCH] grub2-set-password prompts to enter the current password and add the password complexity check --- - util/grub-mkpasswd-pbkdf2.c | 95 +++++++++++++++++++++++++++++- + util/grub-mkpasswd-pbkdf2.c | 105 ++++++++++++++++++++++++++++++--- util/grub-set-password.in | 114 ++++++++++++++++++++++++++++++++++++ - 2 files changed, 207 insertions(+), 2 deletions(-) + 2 files changed, 212 insertions(+), 7 deletions(-) diff --git a/util/grub-mkpasswd-pbkdf2.c b/util/grub-mkpasswd-pbkdf2.c -index 5805f3c..68c2032 100644 +index 5805f3c..c9f39a5 100644 --- a/util/grub-mkpasswd-pbkdf2.c +++ b/util/grub-mkpasswd-pbkdf2.c @@ -42,10 +42,14 @@ @@ -150,23 +150,34 @@ index 5805f3c..68c2032 100644 buf = xmalloc (arguments.buflen); salt = xmalloc (arguments.saltlen); -@@ -161,7 +249,10 @@ main (int argc, char *argv[]) +@@ -161,13 +249,16 @@ main (int argc, char *argv[]) } memset (pass2, 0, sizeof (pass2)); - if (grub_get_random (salt, arguments.saltlen)) + if (arguments.salt != NULL) -+ { -+ hextobyte(arguments.salt, salt, arguments.saltlen * 2); -+ } else if (grub_get_random (salt, arguments.saltlen)) { - memset (pass1, 0, sizeof (pass1)); - free (buf); +- memset (pass1, 0, sizeof (pass1)); +- free (buf); +- free (salt); +- grub_util_error ("%s", _("couldn't retrieve random data for salt")); +- } ++ hextobyte(arguments.salt, salt, arguments.saltlen * 2); ++ } else if (grub_get_random (salt, arguments.saltlen)) ++ { ++ memset (pass1, 0, sizeof (pass1)); ++ free (buf); ++ free (salt); ++ grub_util_error ("%s", _("couldn't retrieve random data for salt")); ++ } + + gcry_err = grub_crypto_pbkdf2 (GRUB_MD_SHA512, + (grub_uint8_t *) pass1, strlen (pass1), diff --git a/util/grub-set-password.in b/util/grub-set-password.in -index 487fbb1..3d0be26 100644 +index d8005e5..9369b40 100644 --- a/util/grub-set-password.in +++ b/util/grub-set-password.in -@@ -87,16 +87,130 @@ fixtty() { +@@ -82,16 +82,130 @@ fixtty() { } trap fixtty EXIT @@ -298,5 +309,5 @@ index 487fbb1..3d0be26 100644 getpass() { local P0 -- -2.23.0 +2.19.1 diff --git a/grub2.spec b/grub2.spec index 51dde08258f6ab26105081ffc0b3cc8f793ab84d..cc9ae2f8a051637ae8fdb3497be9dafc359dfd77 100644 --- a/grub2.spec +++ b/grub2.spec @@ -1,40 +1,42 @@ %undefine _hardened_build +%global tarversion 2.06 %if "0%{?product_family}" == "0" %define efi_vendor %{_vendor} %else %define efi_vendor %{product_family} %endif - -%global tarversion 2.04 %undefine _missing_build_ids_terminate_build %global _configure_gnuconfig_hack 0 +%global gnulibversion fixes + Name: grub2 Epoch: 1 -Version: 2.04 -Release: 27 +Version: 2.06 +Release: 1 Summary: Bootloader with support for Linux, Multiboot and more License: GPLv3+ URL: http://www.gnu.org/software/grub/ Source0: https://ftp.gnu.org/gnu/grub/grub-%{tarversion}.tar.xz Source1: grub.macros Source2: grub.patches -Source4: http://unifoundry.com/unifont-5.1.20080820.pcf.gz +Source4: http://unifoundry.com/pub/unifont/unifont-13.0.06/font-builds/unifont-13.0.06.pcf.gz Source5: theme.tar.bz2 Source6: gitignore -Source7: 99-grub-mkconfig.install +Source7: 99-grub-mkconfig.install +Source8: gnulib-%{gnulibversion}.tar.gz Source9: strtoull_test.c Source10: 20-grub.install -Source11: installkernel-bls -Source12: installkernel.in +Source11: bootstrap +Source12: bootstrap.conf %include %{SOURCE1} %include %{SOURCE2} BuildRequires: gcc efi-srpm-macros flex bison binutils python3 ncurses-devel xz-devel BuildRequires: freetype-devel libusb-devel bzip2-devel rpm-devel rpm-libs -BuildRequires: autoconf automake autogen device-mapper-devel freetype-devel git +BuildRequires: autoconf automake device-mapper-devel freetype-devel git BuildRequires: texinfo gettext-devel dejavu-sans-fonts help2man systemd fuse-devel %ifarch %{golang_arches} @@ -167,6 +169,11 @@ cp %{SOURCE4} grub-emu-%{tarversion}/unifont.pcf.gz git add grub-emu-%{tarversion} %endif git commit -m "After making subdirs" +sed -i '/videotest_checksum/d' grub-core/tests/lib/functional_test.c +sed -i '/gfxterm_menu/d' grub-core/tests/lib/functional_test.c +sed -i '/cmdline_cat_test/d' grub-core/tests/lib/functional_test.c +git add grub-core/tests/lib/functional_test.c +git commit -m "Disable partial grub_func_test cases" %build %if 0%{with_efi_arch} @@ -224,22 +231,6 @@ popd %find_lang grub -install -d %{buildroot}%{_sysconfdir}/prelink.conf.d/ - -pushd %{buildroot}%{_sysconfdir}/prelink.conf.d/ -cat << EOF > grub2.conf -# these have execstack, and break under selinux --b /usr/bin/grub2-script-check --b /usr/bin/grub2-mkrelpath --b /usr/bin/grub2-mount --b /usr/bin/grub2-fstest --b /usr/sbin/grub2-bios-setup --b /usr/sbin/grub2-probe --b /usr/sbin/grub2-sparc64-setup -EOF -popd - - mkdir -p %{buildroot}%{_datadir}/grub/themes install -d -m 0755 %{buildroot}%{_prefix}/lib/kernel/install.d/ @@ -258,10 +249,6 @@ install -d -m 0755 %{buildroot}%{_unitdir}/system-update.target.wants install -m 0644 docs/grub-boot-indeterminate.service %{buildroot}%{_unitdir} ln -s ../grub-boot-indeterminate.service %{buildroot}%{_unitdir}/system-update.target.wants -install -d -m 0755 %{buildroot}%{_libexecdir}/installkernel -cp -v %{SOURCE11} %{buildroot}%{_libexecdir}/installkernel -sed -e "s,@@LIBEXECDIR@@,%{_libexecdir}/installkernel,g" %{SOURCE12} > %{buildroot}%{_sbindir}/installkernel - %global finddebugroot "%{_builddir}/%{?buildsubdir}/debug" %global dip RPM_BUILD_ROOT=%{finddebugroot} %{__debug_install_post} @@ -317,29 +304,10 @@ if [ -f /etc/default/grub ]; then fi fi -%triggerun -- grub2 < 1:1.99-4 -mkdir -p /boot/grub2.tmp && -mv -f /boot/grub2/*.mod \ - /boot/grub2/*.img \ - /boot/grub2/*.lst \ - /boot/grub2/device.map \ - /boot/grub2.tmp/ || : - -%triggerpostun -- grub2 < 1:1.99-4 -test ! -f /boot/grub2/device.map && -test -d /boot/grub2.tmp && -mv -f /boot/grub2.tmp/*.mod \ - /boot/grub2.tmp/*.img \ - /boot/grub2.tmp/*.lst \ - /boot/grub2.tmp/device.map \ - /boot/grub2/ && -rm -r /boot/grub2.tmp/ || : - %files common -f grub.lang %defattr(-,root,root) %license COPYING %dir /boot/grub2/themes/system -%attr(0755,root,root) %{_sbindir}/installkernel %attr(0700,root,root) %dir /boot/grub2 %ghost %config(noreplace) /boot/grub2/grubenv %exclude /boot/grub2/* @@ -349,7 +317,6 @@ rm -r /boot/grub2.tmp/ || : %{_prefix}/lib/kernel/install.d/20-grub.install %{_prefix}/lib/kernel/install.d/99-grub-mkconfig.install %{_sysconfdir}/kernel/install.d/*.install -%{_libexecdir}/installkernel/installkernel-bls %dir %attr(0700,root,root) %{efi_esp_dir} %{_datadir}/locale/* @@ -369,12 +336,12 @@ rm -r /boot/grub2.tmp/ || : %{_bindir}/%{name}-mkimage %{_bindir}/%{name}-mkrelpath %{_bindir}/%{name}-script-check +%{_libexecdir}/%{name} %config %{_sysconfdir}/grub.d/??_* %exclude %{_sysconfdir}/grub.d/01_fallback_counting %attr(0644,root,root) %ghost %config(noreplace) %{_sysconfdir}/default/grub %{_sysconfdir}/grub.d/README -%{_sysconfdir}/prelink.conf.d/grub2.conf %{_userunitdir}/* %{_unitdir}/* %{_datarootdir}/grub/* @@ -387,16 +354,16 @@ rm -r /boot/grub2.tmp/ || : %if %{with_legacy_arch} %{_sbindir}/grub2-install %ifarch x86_64 -%{_sbindir}/%{name}-bios-setup +%{_sbindir}/grub2-bios-setup %else %exclude %{_sbindir}/%{name}-bios-setup %endif %ifarch %{sparc} %{_sbindir}/grub2-sparc64-setup -%{_sbindir}/%{name}-ofpathname +%{_sbindir}/grub2-ofpathname %else %exclude %{_sbindir}/grub2-sparc64-setup -%exclude %{_sbindir}/%{name}-ofpathname +%exclude %{_sbindir}/grub2-ofpathname %endif %exclude %{_sbindir}/grub2-ofpathname %endif @@ -404,7 +371,6 @@ rm -r /boot/grub2.tmp/ || : %files tools-minimal %defattr(-,root,root) -%{_sysconfdir}/prelink.conf.d/grub2.conf %attr(4755, root, root) %{_sbindir}/%{name}-set-bootflag %{_sbindir}/%{name}-get-kernel-settings %{_sbindir}/%{name}-set*password @@ -460,6 +426,13 @@ rm -r /boot/grub2.tmp/ || : %{_datadir}/man/man* %changelog +* Tue Mar 22 2022 zhangqiumiao - 2.06-1 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:update to version 2.06 + disable partial grub_func_test cases because they are not supported + * Mon Mar 21 2022 zhangqiumiao - 2.04-27 - Type:bugfix - CVE:NA @@ -471,7 +444,7 @@ rm -r /boot/grub2.tmp/ || : - CVE:NA - SUG:NA - DESC:modify some file permissions - strip kernel.exec and lnboot.image +strip kernel.exec and lnboot.image * Wed Mar 16 2022 xihaochen - 2.04-25 - Type:CVE @@ -479,11 +452,12 @@ rm -r /boot/grub2.tmp/ || : - SUG:NA - DESC:Fix CVE-2021-3981 -* Sat Feb 26 2022 yanan - 2.04-24 +* Mon Feb 28 2022 fengtao - 2.04-24 - Type:bugfix - CVE:NA - SUG:NA -- DESC:Fix arm64 kernel image not aligned on 64k boundary +- DESC:fix arm64 kernel image not aligned on 64k boundary + fix grub.patches file format to unix * Sat Feb 26 2022 zhangqiumiao - 2.04-23 - Type:bugfix @@ -565,7 +539,7 @@ rm -r /boot/grub2.tmp/ || : - DESC:fix the installation failure of grub2-efi-x64/grub-efi-aa64 packages on the /boot partition of VFAT file system. -* Tue Mar 62 2021 hanhui - 2.04-11 +* Tue Mar 16 2021 hanhui - 2.04-11 - Type:cves - Id:CVE-2020-27779 CVE-2020-14372 - SUG:NA @@ -632,7 +606,7 @@ rm -r /boot/grub2.tmp/ || : * Fri Apr 24 2020 fengtao - 2.02-74 - exclude two cmd in grub2-tools -* Wed Mar 3 2020 songnannan - 2.02-73 +* Tue Mar 3 2020 songnannan - 2.02-73 - delete java-1.8.0-openjdk in buildrequires * Thu Feb 20 2020 openEuler Buildteam - 2.02-72 diff --git a/installkernel-bls b/installkernel-bls deleted file mode 100644 index d66c44a7dc339a8c0fc5a081d638565d04d0d5ba..0000000000000000000000000000000000000000 --- a/installkernel-bls +++ /dev/null @@ -1,85 +0,0 @@ -#! /bin/sh -# -# /sbin/installkernel -# -# Copyright 2007-2008 Red Hat, Inc. All rights reserved. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Author(s): tyson@rwii.com -# - -[[ -f /etc/default/grub ]] && . /etc/default/grub - -usage() { - echo "Usage: `basename $0` " >&2 - exit 1 -} - -cfgLoader= - -if [ -z "$INSTALL_PATH" -o "$INSTALL_PATH" == "/boot" ]; then - INSTALL_PATH=/boot - cfgLoader=1 -fi - -LINK_PATH=/boot -RELATIVE_PATH=`echo "$INSTALL_PATH/" | sed "s|^$LINK_PATH/||"` -KERNEL_VERSION=$1 -BOOTIMAGE=$2 -MAPFILE=$3 -ARCH=$(uname -m) -if [ $ARCH = 'ppc64' -o $ARCH = 'ppc' ]; then - KERNEL_NAME=vmlinux -else - KERNEL_NAME=vmlinuz -fi - -if [ -z "$KERNEL_VERSION" -o -z "$BOOTIMAGE" -o -z "$MAPFILE" ]; then - usage -fi - -if [ -f $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION ]; then - mv $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION \ - $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION.old; -fi - -if [ ! -L $INSTALL_PATH/$KERNEL_NAME ]; then - if [ -e $INSTALLPATH/$KERNEL_NAME ]; then - mv $INSTALL_PATH/$KERNEL_NAME $INSTALL_PATH/$KERNEL_NAME.old - fi -fi - -if [ -f $INSTALL_PATH/System.map-$KERNEL_VERSION ]; then - mv $INSTALL_PATH/System.map-$KERNEL_VERSION \ - $INSTALL_PATH/System.map-$KERNEL_VERSION.old; -fi - -if [ ! -L $INSTALL_PATH/System.map ]; then - if [ -e $INSTALLPATH/System.map ]; then - mv $INSTALL_PATH/System.map $INSTALL_PATH/System.map.old - fi -fi -ln -sf ${RELATIVE_PATH}$INSTALL_PATH/System.map-$KERNEL_VERSION $LINK_PATH/System.map - -cat $BOOTIMAGE > $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION -cp $MAPFILE $INSTALL_PATH/System.map-$KERNEL_VERSION - -ln -fs ${RELATIVE_PATH}$INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION $LINK_PATH/$KERNEL_NAME -ln -fs ${RELATIVE_PATH}$INSTALL_PATH/System.map-$KERNEL_VERSION $LINK_PATH/System.map - -if [ -n "$cfgLoader" ] && [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then - kernel-install add $KERNEL_VERSION $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION - exit $? -fi diff --git a/installkernel.in b/installkernel.in deleted file mode 100644 index 87b81ee15a0e24e488b623255624676f54e0a43b..0000000000000000000000000000000000000000 --- a/installkernel.in +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -if [[ -x @@LIBEXECDIR@@/installkernel ]] ; then - exec @@LIBEXECDIR@@/installkernel "${@}" -elif [[ -x @@LIBEXECDIR@@/installkernel-bls ]] ; then - exec @@LIBEXECDIR@@/installkernel-bls "${@}" -fi -echo "installkernel is not installed correctly." >>/dev/stderr -exit 1 diff --git a/support-TPM2.0.patch b/support-TPM2.0.patch index 790a60f3706d996507d0fbe8b1bf73da32243cfc..e5ad77ebbd2f66a2aa3ac23e80bd72087886b24d 100644 --- a/support-TPM2.0.patch +++ b/support-TPM2.0.patch @@ -1,18 +1,18 @@ -From c4c243d19d77cab3591f0272c8e36619ccbbddf3 Mon Sep 17 00:00:00 2001 +From f3d9f0413e8c7304b5bb4a0e927a6608504f2795 Mon Sep 17 00:00:00 2001 From: gaoyusong Date: Thu, 13 May 2021 18:34:23 +0800 Subject: [PATCH] support TPM2.0 --- - grub-core/kern/verifiers.c | 25 +++++++++++++++++++------ + grub-core/kern/verifiers.c | 26 ++++++++++++++++++++------ grub-core/script/execute.c | 12 +++++++++++- - 2 files changed, 30 insertions(+), 7 deletions(-) + 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/grub-core/kern/verifiers.c b/grub-core/kern/verifiers.c -index aa3dc7c..dfd73e5 100644 +index 75d7994..1d3ca2b 100644 --- a/grub-core/kern/verifiers.c +++ b/grub-core/kern/verifiers.c -@@ -84,9 +84,16 @@ grub_verifiers_open (grub_file_t io, enum grub_file_type type) +@@ -84,9 +84,15 @@ grub_verifiers_open (grub_file_t io, enum grub_file_type type) grub_file_t ret = 0; grub_err_t err; int defer = 0; @@ -22,14 +22,13 @@ index aa3dc7c..dfd73e5 100644 grub_dprintf ("verify", "file: %s type: %d\n", io->name, type); + ptr = grub_strstr(io->name, "grubenv"); -+ if (ptr) { ++ if (ptr) + grub_env_flag = 1; -+ } + if ((type & GRUB_FILE_TYPE_MASK) == GRUB_FILE_TYPE_SIGNATURE || (type & GRUB_FILE_TYPE_MASK) == GRUB_FILE_TYPE_VERIFY_SIGNATURE || (type & GRUB_FILE_TYPE_SKIP_SIGNATURE)) -@@ -148,6 +155,8 @@ grub_verifiers_open (grub_file_t io, enum grub_file_type type) +@@ -148,6 +154,8 @@ grub_verifiers_open (grub_file_t io, enum grub_file_type type) verified->buf = grub_malloc (ret->size); if (!verified->buf) { @@ -38,33 +37,35 @@ index aa3dc7c..dfd73e5 100644 goto fail; } if (grub_file_read (io, verified->buf, ret->size) != (grub_ssize_t) ret->size) -@@ -158,9 +167,11 @@ grub_verifiers_open (grub_file_t io, enum grub_file_type type) +@@ -158,9 +166,12 @@ grub_verifiers_open (grub_file_t io, enum grub_file_type type) goto fail; } - err = ver->write (context, verified->buf, ret->size); - if (err) - goto fail; -+ if (!grub_env_flag) { -+ err = ver->write (context, verified->buf, ret->size); -+ if (err) -+ goto fail; -+ } ++ if (!grub_env_flag) ++ { ++ err = ver->write (context, verified->buf, ret->size); ++ if (err) ++ goto fail; ++ } err = ver->fini ? ver->fini (context) : GRUB_ERR_NONE; if (err) -@@ -179,9 +190,11 @@ grub_verifiers_open (grub_file_t io, enum grub_file_type type) +@@ -179,9 +190,12 @@ grub_verifiers_open (grub_file_t io, enum grub_file_type type) /* Verification done earlier. So, we are happy here. */ flags & GRUB_VERIFY_FLAGS_DEFER_AUTH) continue; - err = ver->write (context, verified->buf, ret->size); - if (err) - goto fail; -+ if (!grub_env_flag) { -+ err = ver->write (context, verified->buf, ret->size); -+ if (err) -+ goto fail; -+ } ++ if (!grub_env_flag) ++ { ++ err = ver->write (context, verified->buf, ret->size); ++ if (err) ++ goto fail; ++ } err = ver->fini ? ver->fini (context) : GRUB_ERR_NONE; if (err) diff --git a/unifont-13.0.06.pcf.gz b/unifont-13.0.06.pcf.gz new file mode 100644 index 0000000000000000000000000000000000000000..c2ff77255d6d4259eafc35f0ff17e0dbd2e10105 Binary files /dev/null and b/unifont-13.0.06.pcf.gz differ diff --git a/unifont-5.1.20080820.pcf.gz b/unifont-5.1.20080820.pcf.gz deleted file mode 100644 index 2b1ce37cffaacd33f256acb6716888a3554c7679..0000000000000000000000000000000000000000 Binary files a/unifont-5.1.20080820.pcf.gz and /dev/null differ diff --git a/use-default-timestamp.patch b/use-default-timestamp.patch index 16934bf391d578dc5173cd66800ee739d2e57656..6196ab9cf4ecc35491bf7a8ef49ed6364fa45eff 100644 --- a/use-default-timestamp.patch +++ b/use-default-timestamp.patch @@ -1,7 +1,7 @@ -From 8922ea771163655f1d5dc8da589a6291976ae489 Mon Sep 17 00:00:00 2001 +From 62cb96c5b34bfa68ad3d7ffe3f3098d8cd08f83f Mon Sep 17 00:00:00 2001 From: zhouyihang Date: Thu, 10 Jun 2021 20:01:54 +0800 -Subject: [PATCH] huawei use default timestamp +Subject: [PATCH] use default timestamp --- docs/grub-dev.texi | 4 ++-- @@ -9,7 +9,7 @@ Subject: [PATCH] huawei use default timestamp 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi -index f488e82..355764a 100644 +index 9008377..874b3ea 100644 --- a/docs/grub-dev.texi +++ b/docs/grub-dev.texi @@ -18,7 +18,7 @@ @@ -31,7 +31,7 @@ index f488e82..355764a 100644 @author Colin D Bennett @author Vesa Jääskeläinen diff --git a/docs/grub.texi b/docs/grub.texi -index 262388c..41c1a89 100644 +index a4da9c2..79055be 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -18,7 +18,7 @@ @@ -48,10 +48,10 @@ index 262388c..41c1a89 100644 @sp 10 @title the GNU GRUB manual -@subtitle The GRand Unified Bootloader, version @value{VERSION}, @value{UPDATED}. -+@subtitle The GRand Unified Bootloader, version @value{VERSION}, 24 June 2019. ++@subtitle The GRand Unified Bootloader, version @value{VERSION}, 24 June 2019). @author Gordon Matzigkeit @author Yoshinori K. Okuji @author Colin Watson -- -2.27.0 +2.19.1