Make validate_dhcp_packet()'s magic cookie length check clearer by using
offsetof().
This commit is contained in:
parent
0e12b4620b
commit
e8687ba29f
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user