Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #557 Attempt to correct corrupt packets #603

Merged
merged 1 commit into from
Jun 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,21 @@ u_char *_our_safe_pcap_next(pcap_t *pcap, struct pcap_pkthdr *pkthdr,
exit(-1);
}

if (!pkthdr->len || pkthdr->len < pkthdr->caplen) {
if (!pkthdr->len || !pkthdr->caplen) {
fprintf(stderr, "safe_pcap_next ERROR: Invalid packet length in %s:%s() line %d: packet length=%u capture length=%u\n",
file, funcname, line, pkthdr->len, pkthdr->caplen);
exit(-1);
}

/* attempt to correct invalid captures */
if (pkthdr->len < pkthdr->caplen) {
dbgx(1, "Correcting invalid packet capture length %d: packet length=%u",
pkthdr->caplen, pkthdr->len);
pkthdr->caplen = pkthdr->len;
}
} else {
/* this will be reported as a failed packet in final report */
dbg(1, "No data found in packet");
}

return pktdata;
Expand All @@ -165,6 +175,16 @@ int _our_safe_pcap_next_ex(pcap_t *pcap, struct pcap_pkthdr **pkthdr,
file, funcname, line, (*pkthdr)->len, (*pkthdr)->caplen);
exit(-1);
}

if ((*pkthdr)->len < (*pkthdr)->caplen) {
dbgx(1, "Correcting invalid packet capture length %d: packet length=%u",
(*pkthdr)->caplen, (*pkthdr)->len);
(*pkthdr)->caplen = (*pkthdr)->len;
}
} else {
/* this will be reported as a failed packet in final report */
dbgx(1, "No data found in packet 0x%p and/or header 0x%p",
*pktdata, *pkthdr);
}

return res;
Expand Down