]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Fix handling of tar numbers occupying the whole field.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 23 Dec 2011 13:11:31 +0000 (14:11 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 23 Dec 2011 13:11:31 +0000 (14:11 +0100)
* grub-core/fs/cpio.c (read_number): New function.
(grub_cpio_find_file): Use read_number instead of strtoull.

ChangeLog
grub-core/fs/cpio.c

index de2ec0406ce814c1c07e0a1ff9e29b0c47eda743..8a9e25f70187cf22a61621d115972aa6770faddd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-12-23  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Fix handling of tar numbers occupying the whole field.
+
+       * grub-core/fs/cpio.c (read_number): New function.
+       (grub_cpio_find_file): Use read_number instead of strtoull.
+
 2011-12-23  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/fs/cpio.c (grub_cpio_find_file): Fix handling of names
index a40d4f0a2690783f567a778d7f1d8ce5580945d7..cfa1b555bb2a8931d27feb7590dae46c81036efd 100644 (file)
@@ -108,6 +108,15 @@ canonicalize (char *name)
   *optr = 0;
 }
 
+static inline unsigned long long
+read_number (const char *str, grub_size_t size)
+{
+  long long ret = 0;
+  while (size-- && *str >= '0' && *str <= '7')
+    ret = (ret << 3) | (*str++ & ~'0');
+  return ret;
+}
+
 static grub_err_t
 grub_cpio_find_file (struct grub_cpio_data *data, char **name,
                     grub_int32_t *mtime, grub_disk_addr_t *ofs,
@@ -178,7 +187,7 @@ grub_cpio_find_file (struct grub_cpio_data *data, char **name,
       if (hd.typeflag == 'L')
        {
          grub_err_t err;
-         grub_size_t namesize = grub_strtoull (hd.size, NULL, 8);
+         grub_size_t namesize = read_number (hd.size, sizeof (hd.size));
          *name = grub_malloc (namesize + 1);
          if (*name == NULL)
            return grub_errno;
@@ -198,7 +207,7 @@ grub_cpio_find_file (struct grub_cpio_data *data, char **name,
       if (hd.typeflag == 'K')
        {
          grub_err_t err;
-         grub_size_t linksize = grub_strtoull (hd.size, NULL, 8);
+         grub_size_t linksize = read_number (hd.size, sizeof (hd.size));
          if (data->linkname_alloc < linksize + 1)
            {
              char *n;
@@ -230,15 +239,15 @@ grub_cpio_find_file (struct grub_cpio_data *data, char **name,
            return grub_errno;
        }
 
-      data->size = grub_strtoull (hd.size, NULL, 8);
+      data->size = read_number (hd.size, sizeof (hd.size));
       data->dofs = data->hofs + GRUB_DISK_SECTOR_SIZE;
       *ofs = data->dofs + ((data->size + GRUB_DISK_SECTOR_SIZE - 1) &
                           ~(GRUB_DISK_SECTOR_SIZE - 1));
       if (mtime)
-       *mtime = grub_strtoul (hd.mtime, NULL, 8);
+       *mtime = read_number (hd.mtime, sizeof (hd.mtime));
       if (mode)
        {
-         *mode = grub_strtoul (hd.mode, NULL, 8);
+         *mode = read_number (hd.mode, sizeof (hd.mode));
          switch (hd.typeflag)
            {
            case '2':