get_raw_packet(): Perform the UDP checksum after the packet length

checks.

This change makes it easier to verify that there can be no reads
beyond a buffer end by udp_checksum().
This commit is contained in:
Nicholas J. Kain 2015-01-06 04:32:58 -05:00
parent c8dcf5a06b
commit 6548b5ce54

View File

@ -198,11 +198,6 @@ static ssize_t get_raw_packet(struct client_state_t *cs,
client_config.interface); client_config.interface);
return -2; return -2;
} }
if (packet.udp.check && !udp_checksum(&packet)) {
log_error("%s: Packet with bad UDP checksum received. Ignoring.",
client_config.interface);
return -2;
}
if (iphdrlen <= sizeof packet.ip + sizeof packet.udp) { if (iphdrlen <= sizeof packet.ip + sizeof packet.udp) {
log_error("%s: Packet received that is too small (%zu bytes).", log_error("%s: Packet received that is too small (%zu bytes).",
iphdrlen); iphdrlen);
@ -214,6 +209,11 @@ static ssize_t get_raw_packet(struct client_state_t *cs,
l); l);
return -2; return -2;
} }
if (packet.udp.check && !udp_checksum(&packet)) {
log_error("%s: Packet with bad UDP checksum received. Ignoring.",
client_config.interface);
return -2;
}
memcpy(payload, &packet.data, l); memcpy(payload, &packet.data, l);
return l; return l;
} }