* grub-core/fs/romfs.c (grub_romfs_iterate_dir): Properly align

name for checksum and fix allocation algorithm.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-12-13 01:57:07 +01:00
parent 1f313b942b
commit 20993fbb9f
2 changed files with 15 additions and 8 deletions

View File

@ -1,3 +1,8 @@
2011-12-13 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/fs/romfs.c (grub_romfs_iterate_dir): Properly align
name for checksum and fix allocation algorithm.
2011-12-13 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/types.h (grub_properly_aligned_t): New type.

View File

@ -166,17 +166,18 @@ grub_romfs_iterate_dir (grub_fshelp_node_t dir,
{
grub_disk_addr_t caddr;
struct grub_romfs_file_header hdr;
grub_size_t a = 0;
char *name = NULL;
unsigned nptr;
unsigned i, j;
grub_size_t a = 0;
grub_properly_aligned_t *name = NULL;
for (caddr = dir->data_addr; caddr;
caddr = grub_be_to_cpu32 (hdr.next_file) & ~(GRUB_ROMFS_ALIGN - 1))
{
grub_disk_addr_t naddr = caddr + sizeof (hdr);
grub_uint32_t csum = 0;
enum grub_fshelp_filetype filetype = GRUB_FSHELP_UNKNOWN;
struct grub_fshelp_node *node;
struct grub_fshelp_node *node = NULL;
grub_err_t err;
err = grub_disk_read (dir->data->disk, caddr >> GRUB_DISK_SECTOR_BITS,
@ -189,9 +190,9 @@ grub_romfs_iterate_dir (grub_fshelp_node_t dir,
}
for (nptr = 0; ; nptr++, naddr += 16)
{
if (a >= nptr)
if (a <= nptr)
{
char *on;
grub_properly_aligned_t *on;
a = 2 * (nptr + 1);
on = name;
name = grub_realloc (name, a * 16);
@ -201,13 +202,14 @@ grub_romfs_iterate_dir (grub_fshelp_node_t dir,
return 1;
}
}
COMPILE_TIME_ASSERT (16 % sizeof (name[0]) == 0);
err = grub_disk_read (dir->data->disk, naddr >> GRUB_DISK_SECTOR_BITS,
naddr & (GRUB_DISK_SECTOR_SIZE - 1),
16, name + 16 * nptr);
16, name + (16 / sizeof (name[0])) * nptr);
if (err)
return 1;
for (j = 0; j < 16; j++)
if (!name[16 * nptr + j])
if (!((char *) name)[16 * nptr + j])
break;
if (j != 16)
break;
@ -292,7 +294,7 @@ grub_romfs_iterate_dir (grub_fshelp_node_t dir,
}
}
if (hook (name, filetype, node))
if (hook ((char *) name, filetype, node))
{
grub_free (name);
return 1;