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

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