From 58eba9eec7f815f8e6f320c527c8e62db6583e9f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 23 Dec 2011 14:11:31 +0100 Subject: [PATCH] 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. --- ChangeLog | 7 +++++++ grub-core/fs/cpio.c | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index de2ec0406..8a9e25f70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-12-23 Vladimir Serbinenko + + 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 * grub-core/fs/cpio.c (grub_cpio_find_file): Fix handling of names diff --git a/grub-core/fs/cpio.c b/grub-core/fs/cpio.c index a40d4f0a2..cfa1b555b 100644 --- a/grub-core/fs/cpio.c +++ b/grub-core/fs/cpio.c @@ -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': -- 2.39.5