Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package grub2 for openSUSE:Factory checked 
in at 2026-11-16 09:07:31
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/grub2 (Old)
 and      /work/SRC/openSUSE:Factory/.grub2.new.1251 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "grub2"

Mon Nov 16 09:07:31 2026 rev:404 rq:1397218 version:2.16

Changes:
--------
--- /work/SRC/openSUSE:Factory/grub2/grub2.changes      2026-10-28 
17:44:25.095726869 +0100
+++ /work/SRC/openSUSE:Factory/.grub2.new.1251/grub2.changes    2026-11-16 
09:11:22.091088053 +0100
@@ -1,0 +2,30 @@
+Mon Nov  9 11:29:08 UTC 2026 - Michael Chang <[email protected]>
+
+- CVE-2026-97876: Bypass of GRUB lockdown restriction in Secure Boot mode via
+  serial command MMIO base address (bsc#1284208)
+  * already fixed in GRUB 2.16 release
+- grub2.spec: Bump upstream SBAT generation to 7, to align with the SBAT level
+  future shim release may enforce
+  * 0001-configure.ac-bump-SBAT-for-September-2026-CVE.patch
+- grub2.spec: add check_sbat_generation to ensure built images report the same
+  SBAT generation as the RPM metadata
+
+-------------------------------------------------------------------
+Tue Oct 27 08:56:58 UTC 2026 - Michael Chang <[email protected]>
+
+- CVE-2026-109905: Fix integer underflow could lead to heap buffer overflow in
+  set_bli_loader_entries (bsc#1284765)
+  * 0001-blsuki-harden-LoaderEntries-size-checks-in-set_bli_l.patch
+  * 0002-blsuki-Refactor-set_bli_loader_entries-error-handlin.patch
+  * 0003-blsuki-clean-up-UTF-16-size-handling-in-LoaderEntrie.patch
+  * 0004-blsuki-Cleanup-indentation-without-code-change.patch
+- CVE-2026-109906: Fix UUID pointer length mismatch, Fix Use-After-Free in the
+  OOM error cleanup and return path (bsc#1284765)
+  * 0001-commands-crypttab-harden-cryptokey-update-path.patch
+- CVE-2026-109907: Fix allocation failure handling in insert_dir (bsc#1284765)
+  * 0001-linux-fix-insert_dir-OOM-error-return.patch
+- Add an assertion to the nvme driver to ensure the PRP list is allocated below
+  4G (bsc#1284765)
+  * 0001-nvme-guard-PRP-list-DMA-addresses-above-4-GiB.patch
+
+-------------------------------------------------------------------

New:
----
  0001-blsuki-harden-LoaderEntries-size-checks-in-set_bli_l.patch
  0001-commands-crypttab-harden-cryptokey-update-path.patch
  0001-configure.ac-bump-SBAT-for-September-2026-CVE.patch
  0001-linux-fix-insert_dir-OOM-error-return.patch
  0001-nvme-guard-PRP-list-DMA-addresses-above-4-GiB.patch
  0002-blsuki-Refactor-set_bli_loader_entries-error-handlin.patch
  0003-blsuki-clean-up-UTF-16-size-handling-in-LoaderEntrie.patch
  0004-blsuki-Cleanup-indentation-without-code-change.patch

----------(New B)----------
  New:  set_bli_loader_entries (bsc#1284765)
  * 0001-blsuki-harden-LoaderEntries-size-checks-in-set_bli_l.patch
  * 0002-blsuki-Refactor-set_bli_loader_entries-error-handlin.patch
  New:  OOM error cleanup and return path (bsc#1284765)
  * 0001-commands-crypttab-harden-cryptokey-update-path.patch
- CVE-2026-109907: Fix allocation failure handling in insert_dir (bsc#1284765)
  New:  future shim release may enforce
  * 0001-configure.ac-bump-SBAT-for-September-2026-CVE.patch
- grub2.spec: add check_sbat_generation to ensure built images report the same
  New:- CVE-2026-109907: Fix allocation failure handling in insert_dir 
(bsc#1284765)
  * 0001-linux-fix-insert_dir-OOM-error-return.patch
- Add an assertion to the nvme driver to ensure the PRP list is allocated below
  New:  4G (bsc#1284765)
  * 0001-nvme-guard-PRP-list-DMA-addresses-above-4-GiB.patch
  New:  * 0001-blsuki-harden-LoaderEntries-size-checks-in-set_bli_l.patch
  * 0002-blsuki-Refactor-set_bli_loader_entries-error-handlin.patch
  * 0003-blsuki-clean-up-UTF-16-size-handling-in-LoaderEntrie.patch
  New:  * 0002-blsuki-Refactor-set_bli_loader_entries-error-handlin.patch
  * 0003-blsuki-clean-up-UTF-16-size-handling-in-LoaderEntrie.patch
  * 0004-blsuki-Cleanup-indentation-without-code-change.patch
  New:  * 0003-blsuki-clean-up-UTF-16-size-handling-in-LoaderEntrie.patch
  * 0004-blsuki-Cleanup-indentation-without-code-change.patch
- CVE-2026-109906: Fix UUID pointer length mismatch, Fix Use-After-Free in the
----------(New E)----------

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ grub2.spec ++++++
--- /var/tmp/diff_new_pack.NrAkOM/_old  2026-11-16 09:11:28.533358142 +0100
+++ /var/tmp/diff_new_pack.NrAkOM/_new  2026-11-16 09:11:28.535358226 +0100
@@ -402,6 +402,14 @@
 Patch:          0001-linux-allocate-EFI-kernel-buffer-as-GRUB_EFI_LOADER_.patch
 Patch:          0001-insmod-ignore-efi_uga-on-EFI.patch
 Patch:          0001-Skip-in-place-verifier-for-the-synthesized-initrd.patch
+Patch:          0001-commands-crypttab-harden-cryptokey-update-path.patch
+Patch:          0001-linux-fix-insert_dir-OOM-error-return.patch
+Patch:          0001-nvme-guard-PRP-list-DMA-addresses-above-4-GiB.patch
+Patch:          0001-blsuki-harden-LoaderEntries-size-checks-in-set_bli_l.patch
+Patch:          0002-blsuki-Refactor-set_bli_loader_entries-error-handlin.patch
+Patch:          0003-blsuki-clean-up-UTF-16-size-handling-in-LoaderEntrie.patch
+Patch:          0004-blsuki-Cleanup-indentation-without-code-change.patch
+Patch:          0001-configure.ac-bump-SBAT-for-September-2026-CVE.patch
 
 %if 0%{?suse_version} < 1600
 Requires:       gettext-runtime
@@ -431,17 +439,7 @@
 %endif
 %endif
 
-%global sbat_generation_grub %(tar -xOf %{SOURCE0} 
grub-%{version}/configure.ac | sed -n '/^GLOBAL_SBAT_LEVEL=/s///p')
-
-%ifarch %{efi}
-%if "%{?sbat_generation_grub}" == ""
-%{error: GLOBAL_SBAT_LEVEL is not found in %{SOURCE0}}
-%endif
-%endif
-
-%if "%{platform}" == "ieee1275" && "%{?sbat_generation_grub}" == ""
-%{error: GLOBAL_SBAT_LEVEL is not found in %{SOURCE0}}
-%endif
+%global sbat_generation_grub 7
 
 %if 0%{?suse_version} >= 1600
 # Always requires a default cpu-platform package
@@ -718,6 +716,20 @@
 %autosetup -p1 -n grub-%{version}
 
 %build
+
+%ifarch %{efi} ppc64 ppc64le
+# Verify that the upstream SBAT generation embedded in an EFI image matches
+# the expected value. Usage: check_sbat_generation <image> <generation>
+check_sbat_generation() {
+    local img="$1" expected="$2" found
+    found=$(strings -a "$img" | sed -n 's/^grub,\([0-9]\+\),.*/\1/p' | head 
-n1)
+    if [ "$found" != "$expected" ]; then
+        echo "ERROR: $img SBAT generation ($found) != $expected"
+        exit 1
+    fi
+}
+%endif
+
 # collect evidence to debug spurious build failure on SLE15
 ulimit -a
 # patches above may update the timestamp of grub.texi
@@ -853,6 +865,8 @@
 ./grub-mkimage -O %{grubefiarch} -o grub.efi --memdisk=./memdisk.sqsh 
--prefix= %{?sbat_generation:--sbat=} \
                -d grub-core ${GRUB_MODULES}
 
+check_sbat_generation grub.efi %{sbat_generation_grub}
+
 %if 0%{?suse_version} >= 1600
 rm memdisk.sqsh
 
@@ -899,6 +913,8 @@
     -d grub-core \
     all_video boot font gfxmenu gfxterm gzio halt jpeg minicmd normal part_gpt 
png reboot video \
     fat tpm tss2 tpm2_key_protector memdisk tar squash4 xzio blsuki 
bls_bumpcounter linux bli regexp loadenv test echo true sleep efifwsetup 
efibootnext
+
+check_sbat_generation grubbls.efi %{sbat_generation_grub}
 %endif
 
 %ifarch x86_64 aarch64
@@ -1083,6 +1099,8 @@
             -c %{platform}-config -s "" --appended-signature-size 
%brp_pesign_reservation ${GRUB_MODULES}
         ls -l "grub.elf"
         # truncate -s -%brp_pesign_reservation "grub.elf"
+
+        check_sbat_generation grub.elf %{sbat_generation_grub}
 fi
 %endif
 cd ..

++++++ 0001-blsuki-harden-LoaderEntries-size-checks-in-set_bli_l.patch ++++++
>From e3e7d3a48ad4c20020d8cc4daa66e917df0776f1 Mon Sep 17 00:00:00 2001
From: Michael Chang <[email protected]>
Date: Wed, 14 Oct 2026 15:22:15 +0800
Subject: [PATCH 1/4] blsuki: harden LoaderEntries size checks in
 set_bli_loader_entries()

Prevent integer underflow and potential heap buffer overflow when
composing the EFI LoaderEntries variable.

Add explicit bounds checks before copying previous UTF-16 entries and
before appending a new entry, ensuring `remaining_size` can hold data
plus the terminating NUL. Also reserve space for the explicit terminator
by passing `remaining_size - 1` to `grub_utf8_to_utf16()`.

Additionally, free `prev_entries_start` on `efi_entries` allocation
failure to avoid leaking the previously fetched variable buffer.

This fixes unsafe `remaining_size` subtraction and out-of-bounds write
cases triggered by malformed or crafted LoaderEntries contents.

Signed-off-by: Michael Chang <[email protected]>
---
 grub-core/commands/blsuki.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/grub-core/commands/blsuki.c b/grub-core/commands/blsuki.c
index f878290e9..5101e4f59 100644
--- a/grub-core/commands/blsuki.c
+++ b/grub-core/commands/blsuki.c
@@ -1654,7 +1654,10 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
     }
   efi_entries = grub_malloc (size * sizeof (grub_efi_char16_t) + 
prev_entries_start_size);
   if (efi_entries == NULL)
-    return grub_errno;
+    {
+      grub_free (prev_entries_start);
+      return grub_errno;
+    }
 
   prev_entries = prev_entries_start;
   prev_entries_size = prev_entries_start_size;
@@ -1740,6 +1743,13 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
 
                if (rc > 0)
                  {
+                   if (remaining_size < len16 + 1)
+                     {
+                       grub_free (prev_entry);
+                       grub_free (prev_entries_start);
+                       grub_free (efi_entries);
+                       return grub_error (GRUB_ERR_OUT_OF_RANGE, 
"LoaderEntries buffer too small for previous entries");
+                     }
                    grub_memcpy (p, prev_entries, len16 * sizeof 
(*prev_entries));
                    p += len16;
                    *p++ = (grub_efi_char16_t) '\0';
@@ -1751,7 +1761,13 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
              } while (prev_entries_size > 0 && rc > 0);
            }
 
-         written = grub_utf8_to_utf16 (p, remaining_size,
+         if (remaining_size < len + 1)
+           {
+             grub_free (prev_entries_start);
+             grub_free (efi_entries);
+             return grub_error (GRUB_ERR_OUT_OF_RANGE, "LoaderEntries buffer 
too small for new entry");
+           }
+         written = grub_utf8_to_utf16 (p, remaining_size - 1,
                                        (grub_uint8_t*) entry->filename, len, 
NULL);
          p += written;
          *p++ = (grub_efi_char16_t) '\0';
-- 
2.56.0


++++++ 0001-commands-crypttab-harden-cryptokey-update-path.patch ++++++
>From 2a858deb74196340df8ae2249e0c545a14a9334e Mon Sep 17 00:00:00 2001
From: Michael Chang <[email protected]>
Date: Wed, 14 Oct 2026 11:45:42 +0800
Subject: [PATCH] commands/crypttab: harden cryptokey update path

Fix `grub_cryptokey_add_or_update()` to safely handle updates and
allocation failures.

Validate required UUID input, use bounded UUID comparison with
`GRUB_CRYPTODISK_MAX_UUID_LENGTH`, and stage new allocations (`uuid`,
`key`, `path`) before mutating an existing entry.  On failure, free only
temporary allocations and preserve existing list entries and state. When
replacing key material, wipe the old key before freeing it.

This avoids incorrect UUID matching and prevents destructive behavior on
failed updates while keeping key handling robust.

Signed-off-by: Michael Chang <[email protected]>
---
 grub-core/commands/crypttab.c | 69 ++++++++++++++++++++++++-----------
 1 file changed, 47 insertions(+), 22 deletions(-)

diff --git a/grub-core/commands/crypttab.c b/grub-core/commands/crypttab.c
index 66b3915f7..fd5e4c237 100644
--- a/grub-core/commands/crypttab.c
+++ b/grub-core/commands/crypttab.c
@@ -7,6 +7,7 @@
 #include <grub/list.h>
 #include <grub/crypttab.h>
 #include <grub/file.h>
+#include <grub/cryptodisk.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -51,48 +52,72 @@ grub_err_t
 grub_cryptokey_add_or_update (const char *uuid, const char *key, grub_size_t 
key_len, const char *path, int is_tpmkey)
 {
   grub_crypto_key_list_t *cur = NULL;
+  char *key_copy = NULL;
+  char *path_copy = NULL;
+
+  if (!uuid)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("UUID is required"));
 
   FOR_LIST_ELEMENTS (cur, cryptokey_lst)
-    if (grub_uuidcasecmp (cur->name, uuid, sizeof (cur->name)) == 0)
+    if (cur->name && grub_uuidcasecmp (cur->name, uuid, 
GRUB_CRYPTODISK_MAX_UUID_LENGTH) == 0)
       break;
 
-  if (!cur && !uuid)
-    return GRUB_ERR_NONE;
+  if (key && key_len)
+    {
+      key_copy = grub_malloc (key_len);
+      if (!key_copy)
+       goto fail;
+      grub_memcpy (key_copy, key, key_len);
+    }
 
-  if (!cur)
-    cur = grub_zalloc (sizeof (*cur));
-  if (!cur)
-    return grub_errno;
+  if (path)
+    {
+      path_copy = grub_strdup (path);
+      if (!path_copy)
+       goto fail;
+    }
 
-  if (key && key_len)
+  if (!cur)
     {
-      grub_free (cur->key);
-      cur->key = grub_malloc (key_len);
-      if (!cur->key)
+      char *uuid_copy = grub_strdup (uuid);
+      if (!uuid_copy)
+       goto fail;
+      cur = grub_zalloc (sizeof (*cur));
+      if (!cur)
        {
-         grub_free (cur);
-         return grub_errno;
+         grub_free (uuid_copy);
+         goto fail;
        }
-      grub_memcpy (cur->key, key, key_len);
+      cur->name = uuid_copy;
+      grub_list_push (GRUB_AS_LIST_P (&cryptokey_lst), GRUB_AS_LIST (cur));
+    }
+
+  if (key_copy)
+    {
+      if (cur->key)
+       grub_memset (cur->key, 0, cur->key_len);
+      grub_free (cur->key);
+      cur->key = key_copy;
       cur->key_len = key_len;
     }
 
-  if (path)
+  if (path_copy)
     {
       grub_free (cur->path);
-      cur->path = grub_strdup (path);
+      cur->path = path_copy;
     }
 
   if (is_tpmkey >= 0)
     cur->is_tpmkey = is_tpmkey;
 
-  if (!cur->name)
-    {
-      cur->name = grub_strdup (uuid);
-      grub_list_push (GRUB_AS_LIST_P (&cryptokey_lst), GRUB_AS_LIST (cur));
-    }
-
   return GRUB_ERR_NONE;
+
+ fail:
+  grub_error_push ();
+  grub_free (key_copy);
+  grub_free (path_copy);
+  grub_error_pop ();
+  return grub_errno;
 }
 
 void
-- 
2.56.0


++++++ 0001-configure.ac-bump-SBAT-for-September-2026-CVE.patch ++++++
>From 035e74b5778f84b67f86ca4dce35028bb3d42e53 Mon Sep 17 00:00:00 2001
From: Michael Chang <[email protected]>
Date: Tue, 6 Oct 2026 15:23:44 +0800
Subject: [PATCH] configure.ac: bump SBAT for September 2026 CVE

Update configure.ac to raise GLOBAL_SBAT_LEVEL from 6 to 7.

Add the CVE-2026-97876 reference alongside the SBAT level history
comment for the new revocation level.

Signed-off-by: Michael Chang <[email protected]>
Reviewed-by: Avnish Chouhan <[email protected]>
Reviewed-by: Sudhakar Kuppusamy <[email protected]>
Part-of: <https://gitlab.freedesktop.org/gnu-grub/grub/-/merge_requests/295>
---
 configure.ac | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 4b7ba96c0..c86ed14d6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,13 +36,15 @@ dnl description of the relationships between them.
 
 AC_INIT([GRUB2],[2.16],[[email protected]])
 
+# The SBAT level should always be in sync with 
https://github.com/rhboot/shim/blob/main/SbatLevel_Variable.txt
 # 1: Initial value
 # 2: https://lists.gnu.org/archive/html/grub-devel/2022-06/msg00035.html
 # 3: https://lists.gnu.org/archive/html/grub-devel/2022-11/msg00059.html
 # 4: https://lists.gnu.org/archive/html/grub-devel/2023-10/msg00028.html
 # 5: https://lists.gnu.org/archive/html/grub-devel/2025-02/msg00024.html
 # 6: https://lists.gnu.org/archive/html/grub-devel/2025-11/msg00155.html
-GLOBAL_SBAT_LEVEL=6
+# 7: https://www.cve.org/CVERecord?id=CVE-2026-97876
+GLOBAL_SBAT_LEVEL=7
 AC_SUBST([GLOBAL_SBAT_LEVEL])
 AC_DEFINE_UNQUOTED([GLOBAL_SBAT_LEVEL], [$GLOBAL_SBAT_LEVEL], [GRUB Global 
SBAT level])
 
-- 
2.56.0


++++++ 0001-linux-fix-insert_dir-OOM-error-return.patch ++++++
>From 1dfd8ccc8a1c2c192987584ec72067001dad6780 Mon Sep 17 00:00:00 2001
From: Michael Chang <[email protected]>
Date: Wed, 14 Oct 2026 11:59:19 +0800
Subject: [PATCH] linux: fix insert_dir OOM error return

Return grub_errno on grub_zalloc() failure instead of 0 (GRUB_ERR_NONE).

Signed-off-by: Michael Chang <[email protected]>
---
 grub-core/loader/linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c
index b68886add..5cfb403b5 100644
--- a/grub-core/loader/linux.c
+++ b/grub-core/loader/linux.c
@@ -130,7 +130,7 @@ insert_dir (const char *name, struct dir **root,
          struct dir *n;
          n = grub_zalloc (sizeof (*n));
          if (!n)
-           return 0;
+           return grub_errno;
          n->next = *head;
          n->name = grub_strndup (cb, ce - cb);
          if (ptr)
-- 
2.56.0


++++++ 0001-nvme-guard-PRP-list-DMA-addresses-above-4-GiB.patch ++++++
>From 8ac1e9554ed5b6c5544fd0b8d306ebe03bbe8eda Mon Sep 17 00:00:00 2001
From: Michael Chang <[email protected]>
Date: Fri, 16 Oct 2026 12:56:11 +0800
Subject: [PATCH] nvme: guard PRP list DMA addresses above 4 GiB

nvme_readwrite() builds a PRP list for multi-page transfers. The PRP
list is allocated with grub_memalign_dma32(), so it is expected to stay
below 4 GiB by design.

Add an explicit assertion to fail cleanly if that assumption is ever
violated, instead of silently passing an invalid PRP list address to the
controller.

Signed-off-by: Michael Chang <[email protected]>
---
 grub-core/disk/nvme.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/grub-core/disk/nvme.c b/grub-core/disk/nvme.c
index 8f299682e..123300f0d 100644
--- a/grub-core/disk/nvme.c
+++ b/grub-core/disk/nvme.c
@@ -632,6 +632,11 @@ nvme_readwrite (struct grub_nvme_device *dev, int 
namespace,
     /* Use a single page as PRP list, PRP2 points to the list */
     unsigned int i;
     volatile grub_uint64_t *prp_list = grub_dma_get_virt(dev->prp_list);
+    grub_uint64_t prp_list_phys = grub_dma_get_phys (dev->prp_list);
+    /* The PRP list is allocated with grub_memalign_dma32(), so it must be 
below 4 GiB. */
+    if (prp_list_phys >> 32)
+      return grub_error (GRUB_ERR_BAD_ARGUMENT,
+                        "NVMe PRP list above 4 GiB is not supported");
     for (i = 0; i < end_page - start_page; ++i) {
       buffer_phys += 0x1000;
       prp_list[i] = buffer_phys & ~0xfff;
-- 
2.56.0


++++++ 0002-blsuki-Refactor-set_bli_loader_entries-error-handlin.patch ++++++
>From 9523dc0bc146db43080196e733422a0e36ede16e Mon Sep 17 00:00:00 2001
From: Michael Chang <[email protected]>
Date: Fri, 16 Oct 2026 15:12:05 +0800
Subject: [PATCH 2/4] blsuki: Refactor set_bli_loader_entries() error handling
 and naming

Factor the duplicated entry ID length calculation (strip boot counting
suffix, ".conf" or ".efi" extension) into a new helper,
blsuki_entry_id_len().

Replace the repeated free-and-return error paths in
set_bli_loader_entries() with a single "fail" label that releases
efi_entries and prev_entries_start and returns grub_errno. This removes
the risk of leaking memory when a new error path is added.

Rename the size variables to make their units explicit:
 - size              -> total_u16
 - remaining_size    -> remaining_u16
 - prev_entries_size -> prev_remaining_bytes
 - prev_entries_start_size -> prev_total_bytes
 - len16             -> prev_id_u16
 - len/written       -> id_u8/written_u16

Also fix the final copy of leftover previous entries to use
prev_remaining_u16 * sizeof (*prev_entries) instead of the byte count
that was previously mixed with UTF-16 unit counts, and narrow the scope
of prev_entry to the loop body.

No functional change intended other than the unit fix noted above.

Signed-off-by: Michael Chang <[email protected]>
---
 grub-core/commands/blsuki.c | 187 +++++++++++++++++-------------------
 1 file changed, 89 insertions(+), 98 deletions(-)

diff --git a/grub-core/commands/blsuki.c b/grub-core/commands/blsuki.c
index 5101e4f59..38caf5a66 100644
--- a/grub-core/commands/blsuki.c
+++ b/grub-core/commands/blsuki.c
@@ -1594,16 +1594,37 @@ blsuki_is_default_entry (const char *def_entry, 
grub_blsuki_entry_t *entry, int
 }
 
 #ifdef GRUB_MACHINE_EFI
+
+static grub_size_t
+blsuki_entry_id_len (const char *filename)
+{
+  grub_size_t len = grub_strlen (filename);
+  const char *boot_counting_idx = grub_strrchr (filename, '+');
+
+  /* Skip boot counting if found */
+  if (boot_counting_idx != NULL)
+    return boot_counting_idx - filename;
+
+  /* Skip ".conf" or ".efi" extension if found */
+  if (len > BLS_EXT_LEN
+      && grub_strcmp (filename + len - BLS_EXT_LEN, ".conf") == 0)
+    return len - BLS_EXT_LEN;
+  if (len > UKI_EXT_LEN
+      && grub_strcmp (filename + len - UKI_EXT_LEN, ".efi") == 0)
+    return len - UKI_EXT_LEN;
+
+  return len;
+}
+
 /* Set LoaderEntries for uki and blscfg generated entries */
 static grub_err_t
 set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
 {
   grub_blsuki_entry_t *entry = NULL;
-  grub_size_t size = 0, remaining_size, len, written, prev_entries_size = 0, 
len16;
+  grub_size_t total_u16 = 0, remaining_u16, prev_remaining_bytes = 0;
   grub_efi_char16_t *prev_entries_start = NULL;
-  grub_size_t prev_entries_start_size = 0;
+  grub_size_t prev_total_bytes = 0;
   grub_efi_char16_t *efi_entries = NULL, *prev_entries = NULL, *p = NULL;
-  char *boot_counting_idx, *prev_entry;
   const char* env = NULL;
   grub_efi_status_t status;
   int rc;
@@ -1613,20 +1634,7 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
       if (entry->visible)
        {
          /* Calculate the size of LoaderEntries string */
-         len = grub_strlen (entry->filename);
-         /* Skip boot counting if found */
-         boot_counting_idx = grub_strrchr(entry->filename, '+');
-         if (boot_counting_idx != NULL)
-           len = boot_counting_idx - entry->filename;
-         /* Skip ".conf" extension if found */
-         else if (len > BLS_EXT_LEN
-             && grub_strcmp (entry->filename + len - BLS_EXT_LEN, ".conf") == 
0)
-           len -= BLS_EXT_LEN;
-         else if (len > UKI_EXT_LEN
-             && grub_strcmp (entry->filename + len - UKI_EXT_LEN, ".efi") == 0)
-           len -= UKI_EXT_LEN;
-
-         size += len + 1;
+         total_u16 += blsuki_entry_id_len (entry->filename) + 1;
        }
     }
 
@@ -1643,135 +1651,116 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
     {
       status = grub_efi_get_variable ("LoaderEntries",
                                      &bli_vendor_guid,
-                                     &prev_entries_start_size,
+                                     &prev_total_bytes,
                                      (void**) &prev_entries_start);
       /* Get the value of the other generated entries */
-      if (status != GRUB_EFI_SUCCESS || prev_entries_start_size == 0)
+      if (status != GRUB_EFI_SUCCESS || prev_total_bytes == 0)
        {
          prev_entries_start = NULL;
-         prev_entries_start_size = 0;
+         prev_total_bytes = 0;
        }
     }
-  efi_entries = grub_malloc (size * sizeof (grub_efi_char16_t) + 
prev_entries_start_size);
+  efi_entries = grub_malloc (total_u16 * sizeof (grub_efi_char16_t) + 
prev_total_bytes);
   if (efi_entries == NULL)
-    {
-      grub_free (prev_entries_start);
-      return grub_errno;
-    }
+    goto fail;
 
   prev_entries = prev_entries_start;
-  prev_entries_size = prev_entries_start_size;
+  prev_remaining_bytes = prev_total_bytes;
   p = efi_entries;
-  remaining_size = size + (prev_entries_start_size / sizeof (*efi_entries));
+  remaining_u16 = total_u16 + (prev_total_bytes / sizeof (*efi_entries));
   /* Create a null separated list of all entries (with the extension removed) 
*/
   FOR_BLSUKI_ENTRIES (entry)
     {
       if (entry->visible)
        {
-         len = grub_strlen (entry->filename);
-
-         boot_counting_idx = grub_strrchr(entry->filename, '+');
-         if (boot_counting_idx != NULL)
-           len = boot_counting_idx - entry->filename;
-         else if ((len > BLS_EXT_LEN)
-             && grub_strcmp (entry->filename + len - BLS_EXT_LEN, ".conf") == 
0)
-           len -= BLS_EXT_LEN;
-         else if ((len > UKI_EXT_LEN)
-             && grub_strcmp (entry->filename + len - UKI_EXT_LEN, ".efi") == 0)
-           len -= UKI_EXT_LEN;
-
-         if (remaining_size < len + 1)
+         grub_size_t id_u8, written_u16;
+
+         id_u8 = blsuki_entry_id_len (entry->filename);
+
+         if (remaining_u16 < id_u8 + 1)
            {
              grub_dprintf ("blsuki", "LoaderEntries buffer too small\n");
              break;
            }
 
-         if (prev_entries_size != 0 && prev_entries)
+         if (prev_remaining_bytes != 0 && prev_entries)
            {
              do {
-               grub_size_t prev_entry_size;
-               grub_size_t prev_entries_size16 = prev_entries_size / sizeof 
(*prev_entries);
+               grub_size_t prev_id_u16;
+               grub_size_t prev_utf8_bytes;
+               grub_size_t prev_remaining_u16 = prev_remaining_bytes / sizeof 
(*prev_entries);
+               char *prev_entry = NULL;
 
-               len16 = 0;
+               prev_id_u16 = 0;
                /*
                 * LoaderEntries comes from EFI variable storage, so it is only
                 * trusted up to prev_entries_size16 UTF-16 code units. Bound
                 * the scan in case a malformed variable is missing a
                 * terminator.
                 */
-               while (len16 < prev_entries_size16 && prev_entries[len16] != 
'\0')
-                   len16++;
+               while (prev_id_u16 < prev_remaining_u16 && 
prev_entries[prev_id_u16] != '\0')
+                 prev_id_u16++;
 
                /*
                 * If we reached the end of the buffer without finding a null
                 * terminator, the variable is malformed and we should bail
                 * instead of risking an out-of-bounds read.
                 */
-               if (len16 == prev_entries_size16)
+               if (prev_id_u16 == prev_remaining_u16)
                  {
-                   grub_free (prev_entries_start);
-                   grub_free (efi_entries);
-                   return grub_error (GRUB_ERR_BAD_ARGUMENT, "malformed 
LoaderEntries variable");
+                   grub_error (GRUB_ERR_BAD_ARGUMENT, "malformed LoaderEntries 
variable");
+                   goto fail;
                  }
 
-               if (grub_mul (len16, GRUB_MAX_UTF8_PER_UTF16, &prev_entry_size) 
||
-                   grub_add (prev_entry_size, 1, &prev_entry_size))
+               if (grub_mul (prev_id_u16, GRUB_MAX_UTF8_PER_UTF16, 
&prev_utf8_bytes) ||
+                   grub_add (prev_utf8_bytes, 1, &prev_utf8_bytes))
                  {
-                   grub_free (prev_entries_start);
-                   grub_free (efi_entries);
-                   return grub_error (GRUB_ERR_OUT_OF_RANGE,
-                                      "LoaderEntries entry is too large");
+                   grub_error (GRUB_ERR_OUT_OF_RANGE, "LoaderEntries entry is 
too large");
+                   goto fail;
                  }
 
-               prev_entry = grub_malloc (prev_entry_size);
+               prev_entry = grub_malloc (prev_utf8_bytes);
                if (prev_entry == NULL)
-                 {
-                   grub_free (prev_entries_start);
-                   grub_free (efi_entries);
-                   return grub_errno;
-                 }
+                 goto fail;
 
-               *grub_utf16_to_utf8 ((grub_uint8_t*) prev_entry, prev_entries, 
len16) = '\0';
+               *grub_utf16_to_utf8 ((grub_uint8_t*) prev_entry, prev_entries, 
prev_id_u16) = '\0';
                rc = filevercmp (prev_entry, entry->filename);
                if (rc == 0)
                  {
                    grub_free (prev_entry);
-                   grub_free (prev_entries_start);
-                   grub_free (efi_entries);
-                   return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("duplicate 
file: `%s'"), entry->filename);
+                   grub_error (GRUB_ERR_BAD_ARGUMENT, N_("duplicate file: 
`%s'"), entry->filename);
+                   goto fail;
                  }
 
                if (rc > 0)
                  {
-                   if (remaining_size < len16 + 1)
+                   if (remaining_u16 < prev_id_u16 + 1)
                      {
                        grub_free (prev_entry);
-                       grub_free (prev_entries_start);
-                       grub_free (efi_entries);
-                       return grub_error (GRUB_ERR_OUT_OF_RANGE, 
"LoaderEntries buffer too small for previous entries");
+                       grub_error (GRUB_ERR_OUT_OF_RANGE, "LoaderEntries 
buffer too small for previous entries");
+                       goto fail;
                      }
-                   grub_memcpy (p, prev_entries, len16 * sizeof 
(*prev_entries));
-                   p += len16;
+                   grub_memcpy (p, prev_entries, prev_id_u16 * sizeof 
(*prev_entries));
+                   p += prev_id_u16;
                    *p++ = (grub_efi_char16_t) '\0';
-                   remaining_size -= len16 + 1;
-                   prev_entries += len16 + 1;
-                   prev_entries_size -= (len16 + 1) * sizeof (*prev_entries);
+                   remaining_u16 -= prev_id_u16 + 1;
+                   prev_entries += prev_id_u16 + 1;
+                   prev_remaining_bytes -= (prev_id_u16 + 1) * sizeof 
(*prev_entries);
                  }
                grub_free (prev_entry);
-             } while (prev_entries_size > 0 && rc > 0);
+             } while (prev_remaining_bytes > 0 && rc > 0);
            }
 
-         if (remaining_size < len + 1)
+         if (remaining_u16 < id_u8 + 1)
            {
-             grub_free (prev_entries_start);
-             grub_free (efi_entries);
-             return grub_error (GRUB_ERR_OUT_OF_RANGE, "LoaderEntries buffer 
too small for new entry");
+             grub_error (GRUB_ERR_OUT_OF_RANGE, "LoaderEntries buffer too 
small for new entry");
+             goto fail;
            }
-         written = grub_utf8_to_utf16 (p, remaining_size - 1,
-                                       (grub_uint8_t*) entry->filename, len, 
NULL);
-         p += written;
+         written_u16 = grub_utf8_to_utf16 (p, remaining_u16 - 1,
+                                       (grub_uint8_t*) entry->filename, id_u8, 
NULL);
+         p += written_u16;
          *p++ = (grub_efi_char16_t) '\0';
-         remaining_size -= written + 1;
+         remaining_u16 -= written_u16 + 1;
        }
     }
 
@@ -1781,28 +1770,25 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
      * sort before the current new entry; otherwise they remain pending until
      * here.
      */
-    if (prev_entries_size != 0 && prev_entries != NULL)
+    if (prev_remaining_bytes != 0 && prev_entries != NULL)
       {
-       grub_size_t remaining_entries_size;
+       grub_size_t prev_remaining_u16;
 
-       remaining_entries_size = prev_entries_size / sizeof (*prev_entries);
+       prev_remaining_u16 = prev_remaining_bytes / sizeof (*prev_entries);
        /*
-        * remaining_size is tracked in UTF-16 code units, so compare it
+        * remaining_u16 is tracked in UTF-16 code units, so compare it
         * against the number of UTF-16 elements left in the previous buffer.
         */
-       if (remaining_size < remaining_entries_size)
+       if (remaining_u16 < prev_remaining_u16)
          {
-           grub_free (prev_entries_start);
-           grub_free (efi_entries);
-           return grub_error (
-               GRUB_ERR_OUT_OF_RANGE,
-               "LoaderEntries buffer too small for previous entries");
+           grub_error (GRUB_ERR_OUT_OF_RANGE, "LoaderEntries buffer too small 
for previous entries");
+           goto fail;
          }
 
-       grub_memcpy (p, prev_entries, prev_entries_size);
-       p += remaining_entries_size;
-       remaining_size -= remaining_entries_size;
-       prev_entries_size = 0;
+       grub_memcpy (p, prev_entries, prev_remaining_u16 * sizeof 
(*prev_entries));
+       p += prev_remaining_u16;
+       remaining_u16 -= prev_remaining_u16;
+       prev_remaining_bytes = 0;
       }
 
   status = grub_efi_set_variable_with_attributes ("LoaderEntries", 
&bli_vendor_guid,
@@ -1819,6 +1805,11 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
   grub_free (prev_entries_start);
 
   return status;
+
+ fail:
+  grub_free (efi_entries);
+  grub_free (prev_entries_start);
+  return grub_errno;
 }
 #endif
 
-- 
2.56.0


++++++ 0003-blsuki-clean-up-UTF-16-size-handling-in-LoaderEntrie.patch ++++++
>From 84b2c6c7c8170ef784bbfebf0ffdffca4eba75e4 Mon Sep 17 00:00:00 2001
From: Michael Chang <[email protected]>
Date: Tue, 20 Oct 2026 14:50:47 +0800
Subject: [PATCH 3/4] blsuki: clean up UTF-16 size handling in LoaderEntries
 merge

Add UTF16_BYTES() and UTF16_CHARS() helpers and use them in
set_bli_loader_entries() for allocation, bounds accounting, memcpy
sizes, and EFI variable write size.

Also simplify visible entry filtering by early-continue, initialize
prev_id_u16 at declaration, and free prev_entry immediately after
filevercmp() so cleanup is centralized and duplicated free paths are
removed.

Signed-off-by: Michael Chang <[email protected]>
---
 grub-core/commands/blsuki.c | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/grub-core/commands/blsuki.c b/grub-core/commands/blsuki.c
index 38caf5a66..f5f80a499 100644
--- a/grub-core/commands/blsuki.c
+++ b/grub-core/commands/blsuki.c
@@ -59,6 +59,9 @@ GRUB_MOD_LICENSE ("GPLv3+");
 #define BLS_EXT_LEN (sizeof (".conf") - 1)
 #define UKI_EXT_LEN (sizeof (".efi") - 1)
 
+#define UTF16_BYTES(num_chars) ((num_chars) * sizeof (grub_efi_char16_t))
+#define UTF16_CHARS(num_bytes) ((num_bytes) / sizeof (grub_efi_char16_t))
+
 /*
  * It is highly unlikely to ever receive a large amount of keyval pairs. A
  * limit of 10000 is more than enough.
@@ -1660,20 +1663,21 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
          prev_total_bytes = 0;
        }
     }
-  efi_entries = grub_malloc (total_u16 * sizeof (grub_efi_char16_t) + 
prev_total_bytes);
+  efi_entries = grub_malloc (UTF16_BYTES(total_u16) + prev_total_bytes);
   if (efi_entries == NULL)
     goto fail;
 
   prev_entries = prev_entries_start;
   prev_remaining_bytes = prev_total_bytes;
   p = efi_entries;
-  remaining_u16 = total_u16 + (prev_total_bytes / sizeof (*efi_entries));
+  remaining_u16 = total_u16 + UTF16_CHARS(prev_total_bytes);
   /* Create a null separated list of all entries (with the extension removed) 
*/
   FOR_BLSUKI_ENTRIES (entry)
     {
-      if (entry->visible)
-       {
-         grub_size_t id_u8, written_u16;
+      grub_size_t id_u8, written_u16;
+
+      if (!entry->visible)
+        continue;
 
          id_u8 = blsuki_entry_id_len (entry->filename);
 
@@ -1686,12 +1690,11 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
          if (prev_remaining_bytes != 0 && prev_entries)
            {
              do {
-               grub_size_t prev_id_u16;
+               grub_size_t prev_id_u16 = 0;
                grub_size_t prev_utf8_bytes;
-               grub_size_t prev_remaining_u16 = prev_remaining_bytes / sizeof 
(*prev_entries);
+               grub_size_t prev_remaining_u16 = 
UTF16_CHARS(prev_remaining_bytes);
                char *prev_entry = NULL;
 
-               prev_id_u16 = 0;
                /*
                 * LoaderEntries comes from EFI variable storage, so it is only
                 * trusted up to prev_entries_size16 UTF-16 code units. Bound
@@ -1725,9 +1728,9 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
 
                *grub_utf16_to_utf8 ((grub_uint8_t*) prev_entry, prev_entries, 
prev_id_u16) = '\0';
                rc = filevercmp (prev_entry, entry->filename);
+               grub_free (prev_entry);
                if (rc == 0)
                  {
-                   grub_free (prev_entry);
                    grub_error (GRUB_ERR_BAD_ARGUMENT, N_("duplicate file: 
`%s'"), entry->filename);
                    goto fail;
                  }
@@ -1736,18 +1739,16 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
                  {
                    if (remaining_u16 < prev_id_u16 + 1)
                      {
-                       grub_free (prev_entry);
                        grub_error (GRUB_ERR_OUT_OF_RANGE, "LoaderEntries 
buffer too small for previous entries");
                        goto fail;
                      }
-                   grub_memcpy (p, prev_entries, prev_id_u16 * sizeof 
(*prev_entries));
+                   grub_memcpy (p, prev_entries, UTF16_BYTES(prev_id_u16));
                    p += prev_id_u16;
                    *p++ = (grub_efi_char16_t) '\0';
                    remaining_u16 -= prev_id_u16 + 1;
                    prev_entries += prev_id_u16 + 1;
-                   prev_remaining_bytes -= (prev_id_u16 + 1) * sizeof 
(*prev_entries);
+                   prev_remaining_bytes -= UTF16_BYTES(prev_id_u16 + 1);
                  }
-               grub_free (prev_entry);
              } while (prev_remaining_bytes > 0 && rc > 0);
            }
 
@@ -1761,7 +1762,6 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
          p += written_u16;
          *p++ = (grub_efi_char16_t) '\0';
          remaining_u16 -= written_u16 + 1;
-       }
     }
 
     /*
@@ -1772,9 +1772,8 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
      */
     if (prev_remaining_bytes != 0 && prev_entries != NULL)
       {
-       grub_size_t prev_remaining_u16;
+       grub_size_t prev_remaining_u16 = UTF16_CHARS(prev_remaining_bytes);
 
-       prev_remaining_u16 = prev_remaining_bytes / sizeof (*prev_entries);
        /*
         * remaining_u16 is tracked in UTF-16 code units, so compare it
         * against the number of UTF-16 elements left in the previous buffer.
@@ -1785,7 +1784,7 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
            goto fail;
          }
 
-       grub_memcpy (p, prev_entries, prev_remaining_u16 * sizeof 
(*prev_entries));
+       grub_memcpy (p, prev_entries, UTF16_BYTES(prev_remaining_u16));
        p += prev_remaining_u16;
        remaining_u16 -= prev_remaining_u16;
        prev_remaining_bytes = 0;
@@ -1793,7 +1792,7 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
 
   status = grub_efi_set_variable_with_attributes ("LoaderEntries", 
&bli_vendor_guid,
                                         efi_entries,
-                                        (p - efi_entries) * sizeof 
(*efi_entries),
+                                        UTF16_BYTES(p - efi_entries),
                                         GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS |
                                         GRUB_EFI_VARIABLE_RUNTIME_ACCESS);
   /* Record that we set the generated entries by this command to LoaderEntries 
*/
-- 
2.56.0


++++++ 0004-blsuki-Cleanup-indentation-without-code-change.patch ++++++
>From 6cadcdb200e5d5e03678f25e8749d69c7f1819cf Mon Sep 17 00:00:00 2001
From: Michael Chang <[email protected]>
Date: Tue, 20 Oct 2026 14:56:18 +0800
Subject: [PATCH 4/4] blsuki: Cleanup indentation without code change.

Signed-off-by: Michael Chang <[email protected]>
---
 grub-core/commands/blsuki.c | 152 ++++++++++++++++++------------------
 1 file changed, 76 insertions(+), 76 deletions(-)

diff --git a/grub-core/commands/blsuki.c b/grub-core/commands/blsuki.c
index f5f80a499..98bfacf13 100644
--- a/grub-core/commands/blsuki.c
+++ b/grub-core/commands/blsuki.c
@@ -1679,89 +1679,89 @@ set_bli_loader_entries (enum blsuki_cmd_type cmd_type)
       if (!entry->visible)
         continue;
 
-         id_u8 = blsuki_entry_id_len (entry->filename);
+      id_u8 = blsuki_entry_id_len (entry->filename);
 
-         if (remaining_u16 < id_u8 + 1)
-           {
-             grub_dprintf ("blsuki", "LoaderEntries buffer too small\n");
-             break;
-           }
-
-         if (prev_remaining_bytes != 0 && prev_entries)
-           {
-             do {
-               grub_size_t prev_id_u16 = 0;
-               grub_size_t prev_utf8_bytes;
-               grub_size_t prev_remaining_u16 = 
UTF16_CHARS(prev_remaining_bytes);
-               char *prev_entry = NULL;
-
-               /*
-                * LoaderEntries comes from EFI variable storage, so it is only
-                * trusted up to prev_entries_size16 UTF-16 code units. Bound
-                * the scan in case a malformed variable is missing a
-                * terminator.
-                */
-               while (prev_id_u16 < prev_remaining_u16 && 
prev_entries[prev_id_u16] != '\0')
-                 prev_id_u16++;
-
-               /*
-                * If we reached the end of the buffer without finding a null
-                * terminator, the variable is malformed and we should bail
-                * instead of risking an out-of-bounds read.
-                */
-               if (prev_id_u16 == prev_remaining_u16)
-                 {
-                   grub_error (GRUB_ERR_BAD_ARGUMENT, "malformed LoaderEntries 
variable");
-                   goto fail;
-                 }
-
-               if (grub_mul (prev_id_u16, GRUB_MAX_UTF8_PER_UTF16, 
&prev_utf8_bytes) ||
-                   grub_add (prev_utf8_bytes, 1, &prev_utf8_bytes))
-                 {
-                   grub_error (GRUB_ERR_OUT_OF_RANGE, "LoaderEntries entry is 
too large");
-                   goto fail;
-                 }
+      if (remaining_u16 < id_u8 + 1)
+       {
+         grub_dprintf ("blsuki", "LoaderEntries buffer too small\n");
+         break;
+       }
 
-               prev_entry = grub_malloc (prev_utf8_bytes);
-               if (prev_entry == NULL)
-                 goto fail;
+      if (prev_remaining_bytes != 0 && prev_entries)
+       {
+         do {
+           grub_size_t prev_id_u16 = 0;
+           grub_size_t prev_utf8_bytes;
+           grub_size_t prev_remaining_u16 = UTF16_CHARS(prev_remaining_bytes);
+           char *prev_entry = NULL;
+
+           /*
+            * LoaderEntries comes from EFI variable storage, so it is only
+            * trusted up to prev_entries_size16 UTF-16 code units. Bound
+            * the scan in case a malformed variable is missing a
+            * terminator.
+            */
+           while (prev_id_u16 < prev_remaining_u16 && 
prev_entries[prev_id_u16] != '\0')
+             prev_id_u16++;
+
+           /*
+            * If we reached the end of the buffer without finding a null
+            * terminator, the variable is malformed and we should bail
+            * instead of risking an out-of-bounds read.
+            */
+           if (prev_id_u16 == prev_remaining_u16)
+             {
+               grub_error (GRUB_ERR_BAD_ARGUMENT, "malformed LoaderEntries 
variable");
+               goto fail;
+             }
+
+           if (grub_mul (prev_id_u16, GRUB_MAX_UTF8_PER_UTF16, 
&prev_utf8_bytes) ||
+               grub_add (prev_utf8_bytes, 1, &prev_utf8_bytes))
+             {
+               grub_error (GRUB_ERR_OUT_OF_RANGE, "LoaderEntries entry is too 
large");
+               goto fail;
+             }
+
+           prev_entry = grub_malloc (prev_utf8_bytes);
+           if (prev_entry == NULL)
+             goto fail;
 
-               *grub_utf16_to_utf8 ((grub_uint8_t*) prev_entry, prev_entries, 
prev_id_u16) = '\0';
-               rc = filevercmp (prev_entry, entry->filename);
-               grub_free (prev_entry);
-               if (rc == 0)
+           *grub_utf16_to_utf8 ((grub_uint8_t*) prev_entry, prev_entries, 
prev_id_u16) = '\0';
+           rc = filevercmp (prev_entry, entry->filename);
+           grub_free (prev_entry);
+           if (rc == 0)
+             {
+               grub_error (GRUB_ERR_BAD_ARGUMENT, N_("duplicate file: `%s'"), 
entry->filename);
+               goto fail;
+             }
+
+           if (rc > 0)
+             {
+               if (remaining_u16 < prev_id_u16 + 1)
                  {
-                   grub_error (GRUB_ERR_BAD_ARGUMENT, N_("duplicate file: 
`%s'"), entry->filename);
+                   grub_error (GRUB_ERR_OUT_OF_RANGE, "LoaderEntries buffer 
too small for previous entries");
                    goto fail;
                  }
+               grub_memcpy (p, prev_entries, UTF16_BYTES(prev_id_u16));
+               p += prev_id_u16;
+               *p++ = (grub_efi_char16_t) '\0';
+               remaining_u16 -= prev_id_u16 + 1;
+               prev_entries += prev_id_u16 + 1;
+               prev_remaining_bytes -= UTF16_BYTES(prev_id_u16 + 1);
+             }
+         } while (prev_remaining_bytes > 0 && rc > 0);
+       }
 
-               if (rc > 0)
-                 {
-                   if (remaining_u16 < prev_id_u16 + 1)
-                     {
-                       grub_error (GRUB_ERR_OUT_OF_RANGE, "LoaderEntries 
buffer too small for previous entries");
-                       goto fail;
-                     }
-                   grub_memcpy (p, prev_entries, UTF16_BYTES(prev_id_u16));
-                   p += prev_id_u16;
-                   *p++ = (grub_efi_char16_t) '\0';
-                   remaining_u16 -= prev_id_u16 + 1;
-                   prev_entries += prev_id_u16 + 1;
-                   prev_remaining_bytes -= UTF16_BYTES(prev_id_u16 + 1);
-                 }
-             } while (prev_remaining_bytes > 0 && rc > 0);
-           }
-
-         if (remaining_u16 < id_u8 + 1)
-           {
-             grub_error (GRUB_ERR_OUT_OF_RANGE, "LoaderEntries buffer too 
small for new entry");
-             goto fail;
-           }
-         written_u16 = grub_utf8_to_utf16 (p, remaining_u16 - 1,
-                                       (grub_uint8_t*) entry->filename, id_u8, 
NULL);
-         p += written_u16;
-         *p++ = (grub_efi_char16_t) '\0';
-         remaining_u16 -= written_u16 + 1;
+      if (remaining_u16 < id_u8 + 1)
+       {
+         grub_error (GRUB_ERR_OUT_OF_RANGE, "LoaderEntries buffer too small 
for new entry");
+         goto fail;
+       }
+      written_u16 = grub_utf8_to_utf16 (p, remaining_u16 - 1,
+                                   (grub_uint8_t*) entry->filename, id_u8, 
NULL);
+      p += written_u16;
+      *p++ = (grub_efi_char16_t) '\0';
+      remaining_u16 -= written_u16 + 1;
     }
 
     /*
-- 
2.56.0

Reply via email to