commit:     8dbb3cc8736bc4379a465f5b147f448d7e5023b8
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Sat May  3 01:05:37 2025 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Sat May  3 01:05:37 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8dbb3cc8

sys-boot/efibootmgr: backport fixes

Closes: https://bugs.gentoo.org/955279
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>

 ...ootmgr-18-r1.ebuild => efibootmgr-18-r2.ebuild} |  6 +-
 .../efibootmgr/files/efibootmgr-18-backports.patch | 76 ++++++++++++++++++++++
 2 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/sys-boot/efibootmgr/efibootmgr-18-r1.ebuild 
b/sys-boot/efibootmgr/efibootmgr-18-r2.ebuild
similarity index 87%
rename from sys-boot/efibootmgr/efibootmgr-18-r1.ebuild
rename to sys-boot/efibootmgr/efibootmgr-18-r2.ebuild
index 7ff93176d029..c2d815de8d80 100644
--- a/sys-boot/efibootmgr/efibootmgr-18-r1.ebuild
+++ b/sys-boot/efibootmgr/efibootmgr-18-r2.ebuild
@@ -1,4 +1,4 @@
-# Copyright 1999-2022 Gentoo Authors
+# Copyright 1999-2025 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=8
@@ -21,6 +21,10 @@ RDEPEND="
 DEPEND="${RDEPEND}"
 BDEPEND="virtual/pkgconfig"
 
+PATCHES=(
+       "${FILESDIR}"/efibootmgr-18-backports.patch
+)
+
 src_prepare() {
        default
        sed -i 's/-Werror //' Make.defaults || die

diff --git a/sys-boot/efibootmgr/files/efibootmgr-18-backports.patch 
b/sys-boot/efibootmgr/files/efibootmgr-18-backports.patch
new file mode 100644
index 000000000000..70422efd1165
--- /dev/null
+++ b/sys-boot/efibootmgr/files/efibootmgr-18-backports.patch
@@ -0,0 +1,76 @@
+From dcd232d0458b962627f727dc8a1cef3c000a5bf4 Mon Sep 17 00:00:00 2001
+From: kmicki <[email protected]>
+Date: Tue, 15 Nov 2022 14:37:25 +0100
+Subject: [PATCH] Update efibootmgr.c
+
+get_entry: return entry if it was found before reaching the end of the list
+
+Signed-off-by: kmicki <[email protected]>
+---
+ src/efibootmgr.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/src/efibootmgr.c b/src/efibootmgr.c
+index b980bcd..4b15d6d 100644
+--- a/src/efibootmgr.c
++++ b/src/efibootmgr.c
+@@ -1192,6 +1192,7 @@ get_entry(list_t *entries, uint16_t num)
+                       entry = NULL;
+                       continue;
+               }
++              return entry;
+       }
+ 
+       return entry;
+From c2ef7876f4cc0ad5a52f40577e7636a841100bec Mon Sep 17 00:00:00 2001
+From: kamillo <[email protected]>
+Date: Fri, 17 Feb 2023 21:55:17 +0100
+Subject: [PATCH 1/2] Add missing short option handling for --index (-I)
+
+Signed-off-by: kamillo <[email protected]>
+---
+ src/efibootmgr.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/efibootmgr.c b/src/efibootmgr.c
+index 4b15d6d..255f61f 100644
+--- a/src/efibootmgr.c
++++ b/src/efibootmgr.c
+@@ -1509,7 +1509,7 @@ parse_opts(int argc, char **argv)
+               };
+ 
+               c = getopt_long(argc, argv,
+-                              
"aAb:BcCd:De:E:fFgi:kl:L:m:M:n:No:Op:qrt:Tuv::Vwy@:h",
++                              
"aAb:BcCd:De:E:fFgi:I:kl:L:m:M:n:No:Op:qrt:Tuv::Vwy@:h",
+                               long_options, &option_index);
+               if (c == -1)
+                       break;
+
+From fe0a2c9569bd22e51000081226998419cb07c6ce Mon Sep 17 00:00:00 2001
+From: kamillo <[email protected]>
+Date: Fri, 17 Feb 2023 22:02:22 +0100
+Subject: [PATCH 2/2] Fix segfault when passed --index is greater than current
+ boot order size
+
+Size of the order entry size (uint16_t) hasn't been taken into account for all 
calculations and caused memory corruption.
+
+Signed-off-by: kamillo <[email protected]>
+---
+ src/efibootmgr.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/efibootmgr.c b/src/efibootmgr.c
+index 255f61f..ded21a1 100644
+--- a/src/efibootmgr.c
++++ b/src/efibootmgr.c
+@@ -420,8 +420,8 @@ add_to_order(const char *name, uint16_t num, uint16_t 
insert_at)
+               return -1;
+ 
+       if (insert_at != 0) {
+-              if (insert_at > order->data_size)
+-                      insert_at = order->data_size;
++              if (insert_at * sizeof(uint16_t) > order->data_size)
++                      insert_at = order->data_size / sizeof(uint16_t);
+               memcpy(new_data, old_data, insert_at * sizeof(uint16_t));
+       }
+       new_data[insert_at] = num;

Reply via email to