Blame SOURCES/0426-util-glue-efi-Fix-incorrect-use-of-a-possibly-negati.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Darren Kenny <darren.kenny@oracle.com>
80913e
Date: Fri, 4 Dec 2020 15:04:28 +0000
80913e
Subject: [PATCH] util/glue-efi: Fix incorrect use of a possibly negative value
80913e
80913e
It is possible for the ftell() function to return a negative value,
80913e
although it is fairly unlikely here, we should be checking for
80913e
a negative value before we assign it to an unsigned value.
80913e
80913e
Fixes: CID 73744
80913e
80913e
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
80913e
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
80913e
---
80913e
 util/glue-efi.c | 14 ++++++++++++--
80913e
 1 file changed, 12 insertions(+), 2 deletions(-)
80913e
80913e
diff --git a/util/glue-efi.c b/util/glue-efi.c
b32e65
index 68f53168b..de0fa6d33 100644
80913e
--- a/util/glue-efi.c
80913e
+++ b/util/glue-efi.c
80913e
@@ -39,13 +39,23 @@ write_fat (FILE *in32, FILE *in64, FILE *out, const char *out_filename,
80913e
   struct grub_macho_fat_header head;
80913e
   struct grub_macho_fat_arch arch32, arch64;
80913e
   grub_uint32_t size32, size64;
80913e
+  long size;
80913e
   char *buf;
80913e
 
80913e
   fseek (in32, 0, SEEK_END);
80913e
-  size32 = ftell (in32);
80913e
+  size = ftell (in32);
80913e
+  if (size < 0)
80913e
+    grub_util_error ("cannot get end of input file '%s': %s",
80913e
+		     name32, strerror (errno));
80913e
+  size32 = (grub_uint32_t) size;
80913e
   fseek (in32, 0, SEEK_SET);
80913e
+
80913e
   fseek (in64, 0, SEEK_END);
80913e
-  size64 = ftell (in64);
80913e
+  size = ftell (in64);
80913e
+  if (size < 0)
80913e
+    grub_util_error ("cannot get end of input file '%s': %s",
80913e
+		     name64, strerror (errno));
80913e
+  size64 = (grub_uint64_t) size;
80913e
   fseek (in64, 0, SEEK_SET);
80913e
 
80913e
   head.magic = grub_cpu_to_le32_compile_time (GRUB_MACHO_FAT_EFI_MAGIC);