Skip to content

Commit

Permalink
Detect reading of packet errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Andras Fekete committed Sep 13, 2024
1 parent b0a402f commit cc22b59
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions sslSniffer/sslSnifferTest/snifftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ int main(int argc, char** argv)
#endif

while (1) {
struct pcap_pkthdr header;
struct pcap_pkthdr *header;
const unsigned char* packet = NULL;
byte* data = NULL; /* pointer to decrypted data */
#ifdef THREADED_SNIFFTEST
Expand All @@ -1290,13 +1290,16 @@ int main(int argc, char** argv)
if (data == NULL) {
/* grab next pcap packet */
packetNumber++;
packet = pcap_next(pcap, &header);
if(pcap_next_ex(pcap, &header, &packet) < 0) {
hadBadPacket = 1;
break;
}
}

if (packet) {
if (header.caplen > 40) { /* min ip(20) + min tcp(20) */
if (header->caplen > 40) { /* min ip(20) + min tcp(20) */
packet += frame;
header.caplen -= frame;
header->caplen -= frame;
}
else {
/* packet doesn't contain minimum ip/tcp header */
Expand All @@ -1311,7 +1314,7 @@ int main(int argc, char** argv)
#ifdef THREADED_SNIFFTEST
XMEMSET(&info, 0, sizeof(SnifferStreamInfo));

ret = ssl_DecodePacket_GetStream(&info, packet, header.caplen, err);
ret = ssl_DecodePacket_GetStream(&info, packet, header->caplen, err);

/* calculate SnifferStreamInfo checksum */
infoSum = 0;
Expand All @@ -1334,7 +1337,7 @@ int main(int argc, char** argv)

/* add the packet to the worker's linked list */
if (SnifferWorkerPacketAdd(&workers[threadNum], ret, (byte*)packet,
header.caplen, packetNumber)) {
header->caplen, packetNumber)) {
printf("Unable to add packet %d to worker", packetNumber);
break;
}
Expand All @@ -1343,7 +1346,7 @@ int main(int argc, char** argv)
#else
/* Decode Packet, ret value will indicate whether a
* bad packet was encountered */
hadBadPacket = DecodePacket((byte*)packet, header.caplen,
hadBadPacket = DecodePacket((byte*)packet, header->caplen,
packetNumber,err);
#endif
}
Expand Down

0 comments on commit cc22b59

Please sign in to comment.