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