Skip to content

Commit

Permalink
Bug #844 PR# 846: reject invalid header length packets
Browse files Browse the repository at this point in the history
Triggers when attempting a checksum update but packet length does not match header length.

Example:

```
tcprewrite -i test.pcap -o test2.rewrite_1ttl --ttl=58
Warning: skipping packet 11 because caplen 122 minus L2 length 22 does not equal IPv4 header length 255. Consider option '--fixhdrlen'.
Warning: skipping packet 12 because caplen 114 minus L2 length 14 does not equal IPv4 header length 84. Consider option '--fixhdrlen'.
Warning: skipping packet 14 because caplen 60 minus L2 length 14 does not equal IPv4 header length 28. Consider option '--fixhdrlen'.
Warning: skipping packet 15 because caplen 60 minus L2 length 14 does not equal IPv4 header length 28. Consider option '--fixhdrlen'.
Warning: skipping packet 16 because caplen 60 minus L2 length 14 does not equal IPv4 header length 28. Consider option '--fixhdrlen'.
```
  • Loading branch information
fklassen committed Jun 1, 2024
1 parent 859728b commit 4789dee
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/tcpedit/edit_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ fix_ipv4_checksums(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, ipv4_hdr_t *i
/* calc the L4 checksum if we have the whole packet && not a frag or first frag */
if (pkthdr->caplen == pkthdr->len && (htons(ip_hdr->ip_off) & (IP_MF | IP_OFFMASK)) == 0) {
if (ip_len != (int)(pkthdr->caplen - l2len)) {
tcpedit_seterr(tcpedit,
"caplen minus L2 length %u does IPv4 header length %u: pkt=" COUNTER_SPEC,
pkthdr->caplen - l2len,
ip_len,
tcpedit->runtime.packetnum);
return TCPEDIT_ERROR;
tcpedit_setwarn(tcpedit,
"skipping packet " COUNTER_SPEC " because caplen %u minus L2 length %u does not equal IPv4 header length %u. Consider option '--fixhdrlen'.",
tcpedit->runtime.packetnum,
pkthdr->caplen,
l2len,
ip_len);
return TCPEDIT_WARN;
}
ret1 = do_checksum(tcpedit,
(u_char *)ip_hdr,
Expand Down

0 comments on commit 4789dee

Please sign in to comment.