2010-01-27 Robert Millan <rmh.grub@aybabtu.com>

* util/hostfs.c: Include `<errno.h>'.
	(grub_hostfs_read): Handle errors from fseeko() and fread().
This commit is contained in:
Robert Millan 2010-01-27 03:18:14 +00:00
parent 67667b9ced
commit 27dea7eda4
2 changed files with 17 additions and 4 deletions

View file

@ -1,3 +1,8 @@
2010-01-27 Robert Millan <rmh.grub@aybabtu.com>
* util/hostfs.c: Include `<errno.h>'.
(grub_hostfs_read): Handle errors from fseeko() and fread().
2010-01-27 Robert Millan <rmh.grub@aybabtu.com> 2010-01-27 Robert Millan <rmh.grub@aybabtu.com>
* kern/disk.c (grub_disk_read): Fix bug that would cause infinite * kern/disk.c (grub_disk_read): Fix bug that would cause infinite

View file

@ -1,7 +1,7 @@
/* hostfs.c - Dummy filesystem to provide access to the hosts filesystem */ /* hostfs.c - Dummy filesystem to provide access to the hosts filesystem */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. * Copyright (C) 2007,2008,2009,2010 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -26,6 +26,7 @@
#include <dirent.h> #include <dirent.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h>
/* dirent.d_type is a BSD extension, not part of POSIX */ /* dirent.d_type is a BSD extension, not part of POSIX */
@ -118,10 +119,17 @@ grub_hostfs_read (grub_file_t file, char *buf, grub_size_t len)
FILE *f; FILE *f;
f = (FILE *) file->data; f = (FILE *) file->data;
fseeko (f, file->offset, SEEK_SET); if (fseeko (f, file->offset, SEEK_SET) != 0)
int s = fread (buf, 1, len, f); {
grub_error (GRUB_ERR_OUT_OF_RANGE, "fseeko: %s", strerror (errno));
return -1;
}
return s; unsigned int s = fread (buf, 1, len, f);
if (s != len)
grub_error (GRUB_ERR_FILE_READ_ERROR, "fread: %s", strerror (errno));
return (signed) s;
} }
static grub_err_t static grub_err_t