1From 1641d74e16f9d1ca35ba1a87ee4a0bf3afa48e72 Mon Sep 17 00:00:00 2001 2From: Darren Kenny <darren.kenny@oracle.com> 3Date: Fri, 4 Dec 2020 15:04:28 +0000 4Subject: [PATCH] util/glue-efi: Fix incorrect use of a possibly negative value 5 6It is possible for the ftell() function to return a negative value, 7although it is fairly unlikely here, we should be checking for 8a negative value before we assign it to an unsigned value. 9 10Fixes: CID 73744 11 12Signed-off-by: Darren Kenny <darren.kenny@oracle.com> 13Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> 14Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com> 15--- 16 util/glue-efi.c | 14 ++++++++++++-- 17 1 file changed, 12 insertions(+), 2 deletions(-) 18 19diff --git a/util/glue-efi.c b/util/glue-efi.c 20index 68f5316..de0fa6d 100644 21--- a/util/glue-efi.c 22+++ b/util/glue-efi.c 23@@ -39,13 +39,23 @@ write_fat (FILE *in32, FILE *in64, FILE *out, const char *out_filename, 24 struct grub_macho_fat_header head; 25 struct grub_macho_fat_arch arch32, arch64; 26 grub_uint32_t size32, size64; 27+ long size; 28 char *buf; 29 30 fseek (in32, 0, SEEK_END); 31- size32 = ftell (in32); 32+ size = ftell (in32); 33+ if (size < 0) 34+ grub_util_error ("cannot get end of input file '%s': %s", 35+ name32, strerror (errno)); 36+ size32 = (grub_uint32_t) size; 37 fseek (in32, 0, SEEK_SET); 38+ 39 fseek (in64, 0, SEEK_END); 40- size64 = ftell (in64); 41+ size = ftell (in64); 42+ if (size < 0) 43+ grub_util_error ("cannot get end of input file '%s': %s", 44+ name64, strerror (errno)); 45+ size64 = (grub_uint64_t) size; 46 fseek (in64, 0, SEEK_SET); 47 48 head.magic = grub_cpu_to_le32_compile_time (GRUB_MACHO_FAT_EFI_MAGIC); 49-- 502.14.2 51 52