]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2010-01-27 Robert Millan <rmh.grub@aybabtu.com>
authorRobert Millan <rmh@aybabtu.com>
Wed, 27 Jan 2010 03:18:14 +0000 (03:18 +0000)
committerRobert Millan <rmh@aybabtu.com>
Wed, 27 Jan 2010 03:18:14 +0000 (03:18 +0000)
* util/hostfs.c: Include `<errno.h>'.
(grub_hostfs_read): Handle errors from fseeko() and fread().

ChangeLog
util/hostfs.c

index e0ee80d227d8a21c8bd288aa2e65878428f974ec..60ce328bf00bcab404625a4424bd90438474526f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
        * kern/disk.c (grub_disk_read): Fix bug that would cause infinite
index df930b42e600e95320203cac27cb6540d898a550..501ad466461c975e75737488b27ece418c11e82d 100644 (file)
@@ -1,7 +1,7 @@
 /* hostfs.c - Dummy filesystem to provide access to the hosts filesystem  */
 /*
  *  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
  *  it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@
 
 #include <dirent.h>
 #include <stdio.h>
+#include <errno.h>
 
 
 /* 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;
 
   f = (FILE *) file->data;
-  fseeko (f, file->offset, SEEK_SET);
-  int s = fread (buf, 1, len, f);
+  if (fseeko (f, file->offset, SEEK_SET) != 0)
+    {
+      grub_error (GRUB_ERR_OUT_OF_RANGE, "fseeko: %s", strerror (errno));
+      return -1;
+    }
+
+  unsigned int s = fread (buf, 1, len, f);
+  if (s != len)
+    grub_error (GRUB_ERR_FILE_READ_ERROR, "fread: %s", strerror (errno));
 
-  return s;
+  return (signed) s;
 }
 
 static grub_err_t