Make validate_dhcp_packet()'s magic cookie length check clearer by using

offsetof().
This commit is contained in:
Nicholas J. Kain 2014-03-18 01:36:14 -04:00
parent 0e12b4620b
commit e8687ba29f

View File

@ -27,6 +27,7 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -499,7 +500,7 @@ void set_listen_none(struct client_state_t *cs)
static int validate_dhcp_packet(struct client_state_t *cs, size_t len, static int validate_dhcp_packet(struct client_state_t *cs, size_t len,
struct dhcpmsg *packet, uint8_t *msgtype) struct dhcpmsg *packet, uint8_t *msgtype)
{ {
if (len < sizeof *packet - sizeof packet->options) { if (len < offsetof(struct dhcpmsg, options)) {
log_line("Packet is too short to contain magic cookie. Ignoring."); log_line("Packet is too short to contain magic cookie. Ignoring.");
return 0; return 0;
} }