0091-util-glue-efi-Fix-incorrect-use-of-a-possibly-negati.patch 1.6 KB

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