mirror of
https://git.savannah.gnu.org/git/grub.git
synced 2026-10-28 18:19:23 +00:00
util/grub-editenv: Fix incorrect casting of a signed value
The return value of ftell() may be negative (-1) on error. While it is probably unlikely to occur, we should not blindly cast to an unsigned value without first testing that it is not negative. Fixes: CID 73856 Signed-off-by: Darren Kenny <darren.kenny@oracle.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
1 parent
8b3a95655b
commit
5dc41edc4e
1 file changed
+7
-1
+7
-1
@@ -125,6 +125,7 @@ open_envblk_file (const char *name)
|
|||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
long loc;
|
||||||
size_t size;
|
size_t size;
|
||||||
grub_envblk_t envblk;
|
grub_envblk_t envblk;
|
||||||
|
|
||||||
@@ -143,7 +144,12 @@ open_envblk_file (const char *name)
|
|||||||
grub_util_error (_("cannot seek `%s': %s"), name,
|
grub_util_error (_("cannot seek `%s': %s"), name,
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
|
|
||||||
size = (size_t) ftell (fp);
|
loc = ftell (fp);
|
||||||
|
if (loc < 0)
|
||||||
|
grub_util_error (_("cannot get file location `%s': %s"), name,
|
||||||
|
strerror (errno));
|
||||||
|
|
||||||
|
size = (size_t) loc;
|
||||||
|
|
||||||
if (fseek (fp, 0, SEEK_SET) < 0)
|
if (fseek (fp, 0, SEEK_SET) < 0)
|
||||||
grub_util_error (_("cannot seek `%s': %s"), name,
|
grub_util_error (_("cannot seek `%s': %s"), name,
|
||||||
|
|||||||
Reference in new issue
Block a user