Don't do unaligned access when parsing DHCP packet

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-06-26 22:37:19 +02:00
parent e552d93a8b
commit d36f20db46
2 changed files with 12 additions and 4 deletions

View file

@ -879,7 +879,10 @@ parse_dhcp_vendor (const char *name, void *vend, int limit)
ptr = ptr0 = vend;
if (grub_be_to_cpu32 (*(grub_uint32_t *) ptr) != GRUB_NET_BOOTP_RFC1048_MAGIC)
if (ptr[0] != GRUB_NET_BOOTP_RFC1048_MAGIC_0
|| ptr[1] != GRUB_NET_BOOTP_RFC1048_MAGIC_1
|| ptr[2] != GRUB_NET_BOOTP_RFC1048_MAGIC_2
|| ptr[3] != GRUB_NET_BOOTP_RFC1048_MAGIC_3)
return;
ptr = ptr + sizeof (grub_uint32_t);
while (ptr - ptr0 < limit)
@ -1078,8 +1081,10 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)),
ptr = inter->dhcp_ack->vendor;
if (grub_be_to_cpu32 (*(grub_uint32_t *) ptr)
!= GRUB_NET_BOOTP_RFC1048_MAGIC)
if (ptr[0] != GRUB_NET_BOOTP_RFC1048_MAGIC_0
|| ptr[1] != GRUB_NET_BOOTP_RFC1048_MAGIC_1
|| ptr[2] != GRUB_NET_BOOTP_RFC1048_MAGIC_2
|| ptr[3] != GRUB_NET_BOOTP_RFC1048_MAGIC_3)
return grub_error (GRUB_ERR_IO, N_("no DHCP options found"));
ptr = ptr + sizeof (grub_uint32_t);
while (1)

View file

@ -394,7 +394,10 @@ struct grub_net_bootp_packet
grub_uint8_t vendor[0];
} __attribute__ ((packed));
#define GRUB_NET_BOOTP_RFC1048_MAGIC 0x63825363L
#define GRUB_NET_BOOTP_RFC1048_MAGIC_0 0x63
#define GRUB_NET_BOOTP_RFC1048_MAGIC_1 0x82
#define GRUB_NET_BOOTP_RFC1048_MAGIC_2 0x53
#define GRUB_NET_BOOTP_RFC1048_MAGIC_3 0x63
struct grub_net_network_level_interface *
grub_net_configure_by_dhcp_ack (const char *name,