From d36f20db4608fa7a8e66bdc86993fcd813e22c08 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 22:37:19 +0200 Subject: [PATCH] Don't do unaligned access when parsing DHCP packet --- grub-core/net/net.c | 11 ++++++++--- include/grub/net.h | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 2932986b2..560fa7a31 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -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) diff --git a/include/grub/net.h b/include/grub/net.h index 6595a8276..ee94ebcc6 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -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,