grub2/0139-grub_fshelp_read_file-Don-t-attempt-to-read-past-the.patch
Peter Jones 8c6b1ac71e Reconcile with upstream once again.
Also include some minor fixes for gcc 5.1.1

Signed-off-by: Peter Jones <pjones@redhat.com>
2015-07-22 09:46:32 -04:00

48 lines
1.4 KiB
Diff

From af435524cd39f0967cd46e650e4312ecfeb158ed Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <phcoder@gmail.com>
Date: Tue, 20 Jan 2015 12:58:17 +0100
Subject: [PATCH 139/506] grub_fshelp_read_file: Don't attempt to read past the
end of file.
---
ChangeLog | 5 +++++
grub-core/fs/fshelp.c | 7 +++++++
2 files changed, 12 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index 80ef35c..c18ab2d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2015-01-20 Vladimir Serbinenko <phcoder@gmail.com>
+ * grub-core/fs/fshelp.c (grub_fshelp_read_file): Don't attempt to read
+ past the end of file.
+
+2015-01-20 Vladimir Serbinenko <phcoder@gmail.com>
+
* grub-core/script/lexer.c (grub_script_lexer_yywrap): Update len
synchronously with line.
diff --git a/grub-core/fs/fshelp.c b/grub-core/fs/fshelp.c
index 42bd542..b899bed 100644
--- a/grub-core/fs/fshelp.c
+++ b/grub-core/fs/fshelp.c
@@ -252,6 +252,13 @@ grub_fshelp_read_file (grub_disk_t disk, grub_fshelp_node_t node,
grub_disk_addr_t i, blockcnt;
int blocksize = 1 << (log2blocksize + GRUB_DISK_SECTOR_BITS);
+ if (pos > filesize)
+ {
+ grub_error (GRUB_ERR_OUT_OF_RANGE,
+ N_("attempt to read past the end of file"));
+ return -1;
+ }
+
/* Adjust LEN so it we can't read past the end of the file. */
if (pos + len > filesize)
len = filesize - pos;
--
2.4.3