* grub-core/fs/romfs.c (grub_romfs_iterate_dir): Properly align
name for checksum and fix allocation algorithm.
This commit is contained in:
parent
1f313b942b
commit
20993fbb9f
2 changed files with 15 additions and 8 deletions
|
@ -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>
|
2011-12-13 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
* include/grub/types.h (grub_properly_aligned_t): New type.
|
* include/grub/types.h (grub_properly_aligned_t): New type.
|
||||||
|
|
|
@ -166,17 +166,18 @@ grub_romfs_iterate_dir (grub_fshelp_node_t dir,
|
||||||
{
|
{
|
||||||
grub_disk_addr_t caddr;
|
grub_disk_addr_t caddr;
|
||||||
struct grub_romfs_file_header hdr;
|
struct grub_romfs_file_header hdr;
|
||||||
grub_size_t a = 0;
|
|
||||||
char *name = NULL;
|
|
||||||
unsigned nptr;
|
unsigned nptr;
|
||||||
unsigned i, j;
|
unsigned i, j;
|
||||||
|
grub_size_t a = 0;
|
||||||
|
grub_properly_aligned_t *name = NULL;
|
||||||
|
|
||||||
for (caddr = dir->data_addr; caddr;
|
for (caddr = dir->data_addr; caddr;
|
||||||
caddr = grub_be_to_cpu32 (hdr.next_file) & ~(GRUB_ROMFS_ALIGN - 1))
|
caddr = grub_be_to_cpu32 (hdr.next_file) & ~(GRUB_ROMFS_ALIGN - 1))
|
||||||
{
|
{
|
||||||
grub_disk_addr_t naddr = caddr + sizeof (hdr);
|
grub_disk_addr_t naddr = caddr + sizeof (hdr);
|
||||||
grub_uint32_t csum = 0;
|
grub_uint32_t csum = 0;
|
||||||
enum grub_fshelp_filetype filetype = GRUB_FSHELP_UNKNOWN;
|
enum grub_fshelp_filetype filetype = GRUB_FSHELP_UNKNOWN;
|
||||||
struct grub_fshelp_node *node;
|
struct grub_fshelp_node *node = NULL;
|
||||||
grub_err_t err;
|
grub_err_t err;
|
||||||
|
|
||||||
err = grub_disk_read (dir->data->disk, caddr >> GRUB_DISK_SECTOR_BITS,
|
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)
|
for (nptr = 0; ; nptr++, naddr += 16)
|
||||||
{
|
{
|
||||||
if (a >= nptr)
|
if (a <= nptr)
|
||||||
{
|
{
|
||||||
char *on;
|
grub_properly_aligned_t *on;
|
||||||
a = 2 * (nptr + 1);
|
a = 2 * (nptr + 1);
|
||||||
on = name;
|
on = name;
|
||||||
name = grub_realloc (name, a * 16);
|
name = grub_realloc (name, a * 16);
|
||||||
|
@ -201,13 +202,14 @@ grub_romfs_iterate_dir (grub_fshelp_node_t dir,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
COMPILE_TIME_ASSERT (16 % sizeof (name[0]) == 0);
|
||||||
err = grub_disk_read (dir->data->disk, naddr >> GRUB_DISK_SECTOR_BITS,
|
err = grub_disk_read (dir->data->disk, naddr >> GRUB_DISK_SECTOR_BITS,
|
||||||
naddr & (GRUB_DISK_SECTOR_SIZE - 1),
|
naddr & (GRUB_DISK_SECTOR_SIZE - 1),
|
||||||
16, name + 16 * nptr);
|
16, name + (16 / sizeof (name[0])) * nptr);
|
||||||
if (err)
|
if (err)
|
||||||
return 1;
|
return 1;
|
||||||
for (j = 0; j < 16; j++)
|
for (j = 0; j < 16; j++)
|
||||||
if (!name[16 * nptr + j])
|
if (!((char *) name)[16 * nptr + j])
|
||||||
break;
|
break;
|
||||||
if (j != 16)
|
if (j != 16)
|
||||||
break;
|
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);
|
grub_free (name);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue