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