]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2008-02-06 Christian Franke <franke@computer.org>
authorbean <bean@localhost>
Wed, 6 Feb 2008 19:57:40 +0000 (19:57 +0000)
committerbean <bean@localhost>
Wed, 6 Feb 2008 19:57:40 +0000 (19:57 +0000)
* fs/cpio.c (grub_cpio_find_file): Return GRUB_ERR_NONE
(and set *ofs = 0) instead of GRUB_ERR_FILE_NOT_FOUND on
last block of a cpio or tar stream.
Check for "TRAILER!!!" instead of any empty data
block to detect last block of a cpio stream.
(grub_cpio_dir): Fix constness of variable np.
(grub_cpio_open): Return GRUB_ERR_FILE_NOT_FOUND if
cpio or tar trailer is detected.  This fixes a crash
on open of a non existing file.

ChangeLog
fs/cpio.c

index a6ff8faf021e4602381a00e6f9c492ed97447a48..e69d6332dac9afbfe87cf56e710bdd8675c6bc36 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-02-06  Christian Franke  <franke@computer.org>
+
+       * fs/cpio.c (grub_cpio_find_file): Return GRUB_ERR_NONE
+       (and set *ofs = 0) instead of GRUB_ERR_FILE_NOT_FOUND on
+       last block of a cpio or tar stream.
+       Check for "TRAILER!!!" instead of any empty data
+       block to detect last block of a cpio stream.
+       (grub_cpio_dir): Fix constness of variable np.
+       (grub_cpio_open): Return GRUB_ERR_FILE_NOT_FOUND if
+       cpio or tar trailer is detected.  This fixes a crash
+       on open of a non existing file.
+
 2008-02-05  Bean  <bean123ch@gmail.com>
 
        * loader/i386/pc/multiboot.c (grub_multiboot_load_elf32): Get physical
index fcf614a41d613daf52b5fd018c3c34146b307e54..ad9f2a85ea078a61a9cafbc81a51aab83c201465 100644 (file)
--- a/fs/cpio.c
+++ b/fs/cpio.c
@@ -98,11 +98,6 @@ grub_cpio_find_file (struct grub_cpio_data *data, char **name,
        return grub_error (GRUB_ERR_BAD_FS, "Invalid cpio archive");
 
       data->size = (((grub_uint32_t) hd.filesize_1) << 16) + hd.filesize_2;
-      if (data->size == 0)
-       {
-         *ofs = 0;
-         return GRUB_ERR_FILE_NOT_FOUND;
-       }
 
       if (hd.namesize & 1)
        hd.namesize++;
@@ -117,6 +112,13 @@ grub_cpio_find_file (struct grub_cpio_data *data, char **name,
          return grub_errno;
        }
 
+      if (data->size == 0 && hd.mode == 0 && hd.namesize == 11 + 1
+         && ! grub_memcmp(*name, "TRAILER!!!", 11))
+       {
+         *ofs = 0;
+         return GRUB_ERR_NONE;
+       }
+
       data->dofs = data->hofs + sizeof (hd) + hd.namesize;
       *ofs = data->dofs + data->size;
       if (data->size & 1)
@@ -133,7 +135,7 @@ grub_cpio_find_file (struct grub_cpio_data *data, char **name,
       if (!hd.name[0])
        {
          *ofs = 0;
-         return GRUB_ERR_FILE_NOT_FOUND;
+         return GRUB_ERR_NONE;
        }
 
       if (grub_memcmp (hd.magic, MAGIC_USTAR, sizeof (MAGIC_USTAR) - 1))
@@ -188,7 +190,8 @@ grub_cpio_dir (grub_device_t device, const char *path,
 {
   struct grub_cpio_data *data;
   grub_uint32_t ofs;
-  char *prev, *name, *np;
+  char *prev, *name;
+  const char *np;
   int len;
 
 #ifndef GRUB_UTIL
@@ -275,7 +278,10 @@ grub_cpio_open (grub_file_t file, const char *name)
        goto fail;
 
       if (!ofs)
-       break;
+       {
+         grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
+         break;
+       }
 
       if (grub_strcmp (name + 1, fn) == 0)
        {