Blame SOURCES/0269-unix-platform-Initialize-variable-to-fix-grub-instal.patch

eefaf6
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
eefaf6
From: Paul Menzel <pmenzel@molgen.mpg.de>
eefaf6
Date: Tue, 23 Oct 2018 15:00:13 +0200
eefaf6
Subject: [PATCH] unix/platform: Initialize variable to fix grub-install on
eefaf6
 UEFI system
eefaf6
MIME-Version: 1.0
eefaf6
Content-Type: text/plain; charset=UTF-8
eefaf6
Content-Transfer-Encoding: 8bit
eefaf6
eefaf6
On a UEFI system, were no boot entry *grub* is present, currently,
eefaf6
`grub-install` fails with an error.
eefaf6
eefaf6
    $ efibootmgr
eefaf6
    BootCurrent: 0000
eefaf6
    Timeout: 0 seconds
eefaf6
    BootOrder: 0001,0006,0003,0004,0005
eefaf6
    Boot0001  Diskette Drive
eefaf6
    Boot0003* USB Storage Device
eefaf6
    Boot0004* CD/DVD/CD-RW Drive
eefaf6
    Boot0005  Onboard NIC
eefaf6
    Boot0006* WDC WD2500AAKX-75U6AA0
eefaf6
    $ sudo grub-install /dev/sda
eefaf6
    Installing for x86_64-efi platform.
eefaf6
    grub-install: error: efibootmgr failed to register the boot entry: Unknown error 22020.
eefaf6
eefaf6
The error code is always different, and the error message (incorrectly)
eefaf6
points to efibootmgr.
eefaf6
eefaf6
But, the error is in GRUB’s function
eefaf6
`grub_install_remove_efi_entries_by_distributor()`, where the variable
eefaf6
`rc` for the return value, is uninitialized and never set, when no boot
eefaf6
entry for the distributor is found.
eefaf6
eefaf6
The content of that uninitialized variable is then returned as the error
eefaf6
code of efibootmgr.
eefaf6
eefaf6
Set the variable to 0, so that success is returned, when no entry needs
eefaf6
to be deleted.
eefaf6
eefaf6
Tested on Dell OptiPlex 7010 with firmware A28.
eefaf6
eefaf6
    $ sudo ./grub-install /dev/sda
eefaf6
    Installing for x86_64-efi platform.
eefaf6
    Installation finished. No error reported.
eefaf6
eefaf6
[1]: https://github.com/rhboot/efibootmgr/issues/100
eefaf6
eefaf6
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
eefaf6
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
eefaf6
---
eefaf6
 grub-core/osdep/unix/platform.c | 2 +-
eefaf6
 1 file changed, 1 insertion(+), 1 deletion(-)
eefaf6
eefaf6
diff --git a/grub-core/osdep/unix/platform.c b/grub-core/osdep/unix/platform.c
09e3cc
index ca448bc11..55b8f4016 100644
eefaf6
--- a/grub-core/osdep/unix/platform.c
eefaf6
+++ b/grub-core/osdep/unix/platform.c
eefaf6
@@ -85,7 +85,7 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
eefaf6
   pid_t pid = grub_util_exec_pipe ((const char * []){ "efibootmgr", NULL }, &fd;;
eefaf6
   char *line = NULL;
eefaf6
   size_t len = 0;
eefaf6
-  int rc;
eefaf6
+  int rc = 0;
eefaf6
 
eefaf6
   if (!pid)
eefaf6
     {