From af435524cd39f0967cd46e650e4312ecfeb158ed Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Tue, 20 Jan 2015 12:58:17 +0100 Subject: [PATCH] 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 80ef35c62..c18ab2da6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-01-20 Vladimir Serbinenko + + * grub-core/fs/fshelp.c (grub_fshelp_read_file): Don't attempt to read + past the end of file. + 2015-01-20 Vladimir Serbinenko * grub-core/script/lexer.c (grub_script_lexer_yywrap): Update len diff --git a/grub-core/fs/fshelp.c b/grub-core/fs/fshelp.c index 42bd542bb..b899bed04 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;