+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.
{
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,
}
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);
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;
}
}
- if (hook (name, filetype, node))
+ if (hook ((char *) name, filetype, node))
{
grub_free (name);
return 1;