* grub-core/partmap/dvh.c (grub_dvh_is_valid): Make argument

uint32_t * to ensure alignment.
	(dvh_partition_map_iterate): Make `block' a union to ensure alignment.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-12-13 14:44:38 +01:00
parent 93018f6400
commit 85c85365bb
2 changed files with 20 additions and 10 deletions

View file

@ -1,3 +1,9 @@
2011-12-13 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/partmap/dvh.c (grub_dvh_is_valid): Make argument
uint32_t * to ensure alignment.
(dvh_partition_map_iterate): Make `block' a union to ensure alignment.
2011-12-13 Vladimir Serbinenko <phcoder@gmail.com> 2011-12-13 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/partmap/sunpc.c (grub_sun_is_valid): Make argument * grub-core/partmap/sunpc.c (grub_sun_is_valid): Make argument

View file

@ -49,13 +49,13 @@ static struct grub_partition_map grub_dvh_partition_map;
/* Verify checksum (true=ok). */ /* Verify checksum (true=ok). */
static int static int
grub_dvh_is_valid (struct grub_dvh_block *label) grub_dvh_is_valid (grub_uint32_t *label)
{ {
grub_uint32_t *pos; grub_uint32_t *pos;
grub_uint32_t sum = 0; grub_uint32_t sum = 0;
for (pos = (grub_uint32_t *) label; for (pos = label;
pos < (grub_uint32_t *) (label + 1); pos < (label + sizeof (struct grub_dvh_block) / 4);
pos++) pos++)
sum += *pos; sum += *pos;
@ -68,7 +68,11 @@ dvh_partition_map_iterate (grub_disk_t disk,
const grub_partition_t partition)) const grub_partition_t partition))
{ {
struct grub_partition p; struct grub_partition p;
struct grub_dvh_block block; union
{
struct grub_dvh_block dvh;
grub_uint32_t raw[0];
} block;
unsigned partnum; unsigned partnum;
grub_err_t err; grub_err_t err;
@ -78,24 +82,24 @@ dvh_partition_map_iterate (grub_disk_t disk,
if (err) if (err)
return err; return err;
if (DVH_MAGIC != grub_be_to_cpu32 (block.magic)) if (DVH_MAGIC != grub_be_to_cpu32 (block.dvh.magic))
return grub_error (GRUB_ERR_BAD_PART_TABLE, "not a dvh partition table"); return grub_error (GRUB_ERR_BAD_PART_TABLE, "not a dvh partition table");
if (! grub_dvh_is_valid (&block)) if (! grub_dvh_is_valid (block.raw))
return grub_error (GRUB_ERR_BAD_PART_TABLE, "invalid checksum"); return grub_error (GRUB_ERR_BAD_PART_TABLE, "invalid checksum");
/* Maybe another error value would be better, because partition /* Maybe another error value would be better, because partition
table _is_ recognized but invalid. */ table _is_ recognized but invalid. */
for (partnum = 0; partnum < ARRAY_SIZE (block.parts); partnum++) for (partnum = 0; partnum < ARRAY_SIZE (block.dvh.parts); partnum++)
{ {
if (block.parts[partnum].length == 0) if (block.dvh.parts[partnum].length == 0)
continue; continue;
if (partnum == 10) if (partnum == 10)
continue; continue;
p.start = grub_be_to_cpu32 (block.parts[partnum].start); p.start = grub_be_to_cpu32 (block.dvh.parts[partnum].start);
p.len = grub_be_to_cpu32 (block.parts[partnum].length); p.len = grub_be_to_cpu32 (block.dvh.parts[partnum].length);
p.number = p.index = partnum; p.number = p.index = partnum;
if (hook (disk, &p)) if (hook (disk, &p))
break; break;