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 d2f2c34
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 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,28 +1290,30 @@ 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 */
continue;
}
int ptype = pcap_datalink(pcap);
printf("Packet type: %d\n",ptype);
if (ptype == DLT_LINUX_SLL) {
packet += 2;
header->caplen -= 2;
}
#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 +1336,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 +1345,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 d2f2c34

Please sign in to comment.