grub2/grub2-ppc64-cas-fix-double-free.patch
Michael Chang 62e3547e57 Accepting request 741033 from home:michael-chang:devel
- Version bump to 2.04
  * removed
    - translations-20170427.tar.xz
  * grub2.spec
    - Make signed grub-tpm.efi specific to x86_64-efi build, the platform
      currently shipped with tpm module from upstream codebase
    - Add shim_lock to signed grub.efi in x86_64-efi build
    - x86_64: linuxefi now depends on linux, both will verify kernel via
      shim_lock
    - Remove translation tarball and po file hacks as it's been included in
      upstream tarball
  * rediff
    - grub2-setup-try-fs-embed-if-mbr-gap-too-small.patch
    - grub2-commands-introduce-read_file-subcommand.patch
    - grub2-secureboot-add-linuxefi.patch
    - 0001-add-support-for-UEFI-network-protocols.patch
    - grub2-efi-HP-workaround.patch
    - grub2-secureboot-install-signed-grub.patch
    - grub2-linux.patch
    - use-grub2-as-a-package-name.patch
    - grub2-pass-corret-root-for-nfsroot.patch
    - grub2-secureboot-use-linuxefi-on-uefi.patch
    - grub2-secureboot-no-insmod-on-sb.patch
    - grub2-secureboot-provide-linuxefi-config.patch
    - grub2-secureboot-chainloader.patch
    - grub2-s390x-01-Changes-made-and-files-added-in-order-to-allow-s390x.patch
    - grub2-s390x-02-kexec-module-added-to-emu.patch
    - grub2-s390x-04-grub2-install.patch
    - grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch
    - grub2-efi-chainloader-root.patch

OBS-URL: https://build.opensuse.org/request/show/741033
OBS-URL: https://build.opensuse.org/package/show/Base:System/grub2?expand=0&rev=340
2019-10-18 10:18:53 +00:00

101 lines
3.8 KiB
Diff

Index: grub-2.04~rc1/grub-core/kern/ieee1275/openfw.c
===================================================================
--- grub-2.04~rc1.orig/grub-core/kern/ieee1275/openfw.c
+++ grub-2.04~rc1/grub-core/kern/ieee1275/openfw.c
@@ -595,7 +595,7 @@ grub_ieee1275_canonicalise_devname (cons
/* Check if it's a CAS reboot. If so, set the script to be executed. */
int
-grub_ieee1275_cas_reboot (char *script)
+grub_ieee1275_cas_reboot (char **script)
{
grub_uint32_t ibm_ca_support_reboot;
grub_uint32_t ibm_fw_nbr_reboots;
@@ -628,16 +628,37 @@ grub_ieee1275_cas_reboot (char *script)
if (ibm_ca_support_reboot || ibm_fw_nbr_reboots)
{
- if (! grub_ieee1275_get_property_length (options, "boot-last-label", &actual))
- {
- if (actual > 1024)
- script = grub_realloc (script, actual + 1);
- grub_ieee1275_get_property (options, "boot-last-label", script, actual,
- &actual);
- return 0;
- }
+ grub_ssize_t len;
+ char *buf;
+
+ if (grub_ieee1275_get_property_length (options, "boot-last-label", &len)
+ || len <= 0)
+ {
+ grub_dprintf ("ieee1275", "boot-last-label missing or invalid\n");
+ goto out;
+ }
+ /* The returned property string length may not include terminating null byte, and in
+ a bid to avoid out of bound access we allocate one more byte to add it back */
+ buf = grub_malloc ((grub_size_t)len + 1);
+ if (!buf)
+ {
+ grub_print_error ();
+ goto out;
+ }
+ if (grub_ieee1275_get_property (options, "boot-last-label", buf, (grub_size_t)len + 1, &actual)
+ || actual < 0)
+ {
+ grub_dprintf ("ieee1275", "error while get boot-last-label property\n");
+ grub_free (buf);
+ goto out;
+ }
+ /* Add terminating null byte */
+ buf[len] = '\0';
+ *script = buf;
+ return 0;
}
+out:
grub_ieee1275_set_boot_last_label ("");
return -1;
@@ -651,8 +672,9 @@ int grub_ieee1275_set_boot_last_label (c
grub_dprintf("ieee1275", "set boot_last_label (size: %" PRIxGRUB_SIZE ")\n", grub_strlen(text));
if (! grub_ieee1275_finddevice ("/options", &options) &&
options != (grub_ieee1275_ihandle_t) -1)
+ /* To be on the safe side, set the property string with terminating null byte */
grub_ieee1275_set_property (options, "boot-last-label", text,
- grub_strlen (text), &actual);
+ grub_strlen (text) + 1, &actual);
return 0;
}
Index: grub-2.04~rc1/grub-core/normal/main.c
===================================================================
--- grub-2.04~rc1.orig/grub-core/normal/main.c
+++ grub-2.04~rc1/grub-core/normal/main.c
@@ -281,10 +281,9 @@ grub_normal_execute (const char *config,
#ifdef GRUB_MACHINE_IEEE1275
int boot;
boot = 0;
- char *script;
+ char *script = NULL;
char *dummy[1] = { NULL };
- script = grub_malloc (1024);
- if (! grub_ieee1275_cas_reboot (script))
+ if (! grub_ieee1275_cas_reboot (&script) && script)
{
if (! grub_script_execute_new_scope (script, 0, dummy))
boot = 1;
Index: grub-2.04~rc1/include/grub/ieee1275/ieee1275.h
===================================================================
--- grub-2.04~rc1.orig/include/grub/ieee1275/ieee1275.h
+++ grub-2.04~rc1/include/grub/ieee1275/ieee1275.h
@@ -263,7 +263,7 @@ int EXPORT_FUNC(grub_ieee1275_devalias_n
void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias);
void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,
struct grub_ieee1275_devalias *alias);
-int EXPORT_FUNC(grub_ieee1275_cas_reboot) (char *script);
+int EXPORT_FUNC(grub_ieee1275_cas_reboot) (char **script);
int EXPORT_FUNC(grub_ieee1275_set_boot_last_label) (const char *text);
char *EXPORT_FUNC(grub_ieee1275_get_boot_dev) (void);