CBL-Mariner/SPECS/grub2/0170-fix-memory-alloc-errno...

28 строки
1.1 KiB
Diff

diff -ruN grub-2.06/grub-core/loader/i386/efi/linux.c grub-2.06-inst/grub-core/loader/i386/efi/linux.c
--- grub-2.06/grub-core/loader/i386/efi/linux.c 2022-03-18 11:44:56.489594673 -0700
+++ grub-2.06-inst/grub-core/loader/i386/efi/linux.c 2022-03-24 11:25:09.561150736 -0700
@@ -161,6 +161,23 @@
while (!bbuf && bbufsz)
{
+ /* Make sure to reset the global grub_errno in case it was left over
+ from a previous failed grub call.
+
+ There is a bug in grub_malloc() where it does not reset grub_errno
+ on success.
+
+ Such behavior leads to exiting this loop with grub_errno set to
+ GRUB_ERR_OUT_OF_MEMORY even though the last call to grub_malloc()
+ actually succeeds. A caller up the stack who checks grub_errno
+ will report a failure where it should not.
+
+ This problem manifested with larger initrd files that left less
+ memory available and caused the default size allocation below to
+ fail. A smaller allocation size, then, works fine as expected.
+ */
+ grub_errno = GRUB_ERR_NONE;
+
bbuf = grub_malloc(bbufsz);
if (!bbuf)
bbufsz >>= 1;