* grub-core/kern/file.c (grub_file_read): Read nothing if len = 0.

Special behaviour for len = 0 to read whole file isn't used anywhere and
	can cause buffer ovewrflows in several places.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-05-01 15:08:29 +02:00
parent f0a53ed2c2
commit a188012e6c
2 changed files with 10 additions and 1 deletions

View file

@ -1,3 +1,9 @@
2012-05-01 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/file.c (grub_file_read): Read nothing if len = 0.
Special behaviour for len = 0 to read whole file isn't used anywhere and
can cause buffer ovewrflows in several places.
2012-05-01 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/normal/autofs.c (read_fs_list): Fix memory leak.

View file

@ -143,7 +143,10 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len)
return -1;
}
if (len == 0 || len > file->size - file->offset)
if (len == 0)
return 0;
if (len > file->size - file->offset)
len = file->size - file->offset;
/* Prevent an overflow. */