nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0425-util-grub-editenv-Fix-incorrect-casting-of-a-signed-.patch

468bd4
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
468bd4
From: Darren Kenny <darren.kenny@oracle.com>
468bd4
Date: Thu, 5 Nov 2020 14:33:50 +0000
468bd4
Subject: [PATCH] util/grub-editenv: Fix incorrect casting of a signed value
468bd4
468bd4
The return value of ftell() may be negative (-1) on error. While it is
468bd4
probably unlikely to occur, we should not blindly cast to an unsigned
468bd4
value without first testing that it is not negative.
468bd4
468bd4
Fixes: CID 73856
468bd4
468bd4
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
468bd4
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
468bd4
---
468bd4
 util/grub-editenv.c | 8 +++++++-
468bd4
 1 file changed, 7 insertions(+), 1 deletion(-)
468bd4
468bd4
diff --git a/util/grub-editenv.c b/util/grub-editenv.c
f6e916
index 2918bb71c..e9011e0fb 100644
468bd4
--- a/util/grub-editenv.c
468bd4
+++ b/util/grub-editenv.c
468bd4
@@ -128,6 +128,7 @@ open_envblk_file (const char *name)
468bd4
 {
468bd4
   FILE *fp;
468bd4
   char *buf;
468bd4
+  long loc;
468bd4
   size_t size;
468bd4
   grub_envblk_t envblk;
468bd4
 
468bd4
@@ -146,7 +147,12 @@ open_envblk_file (const char *name)
468bd4
     grub_util_error (_("cannot seek `%s': %s"), name,
468bd4
 		     strerror (errno));
468bd4
 
468bd4
-  size = (size_t) ftell (fp);
468bd4
+  loc = ftell (fp);
468bd4
+  if (loc < 0)
468bd4
+    grub_util_error (_("cannot get file location `%s': %s"), name,
468bd4
+		     strerror (errno));
468bd4
+
468bd4
+  size = (size_t) loc;
468bd4
 
468bd4
   if (fseek (fp, 0, SEEK_SET) < 0)
468bd4
     grub_util_error (_("cannot seek `%s': %s"), name,