fuzz: limit packet payload allocation

To detect bug like 8856 of overread, which did not trigger
ASAN as we alloc default-packet-size or MAX_PAYLOAD_SIZE
for each packet, instead of just what we need
pull/16179/head
Philippe Antoine 1 week ago committed by Victor Julien
parent 011f52379c
commit 9747f2fbde

@ -357,7 +357,11 @@ inline int PacketCopyDataOffset(Packet *p, uint32_t offset, const uint8_t *data,
memcpy(GET_PKT_DIRECT_DATA(p) + offset, data, datalen);
} else {
/* here we need a dynamic allocation */
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
p->ext_pkt = SCMalloc(offset + datalen);
#else
p->ext_pkt = SCMalloc(MAX_PAYLOAD_SIZE);
#endif
if (unlikely(p->ext_pkt == NULL)) {
SET_PKT_LEN(p, 0);
return -1;
@ -497,6 +501,15 @@ Packet *PacketDefragPktSetup(Packet *parent, const uint8_t *pkt, uint32_t len, u
/* tell new packet it's part of a tunnel */
p->ttype = PacketTunnelChild;
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if (!p->ext_pkt) {
p->ext_pkt = SCMalloc(MAX_PAYLOAD_SIZE);
if (unlikely(p->ext_pkt == NULL)) {
PacketFreeOrRelease(p);
return NULL;
}
}
#endif
/* copy packet and set length, proto */
if (pkt && len) {
PacketCopyData(p, pkt, len);

@ -28,6 +28,7 @@ const char configNoChecksum[] = "\
pcap-file:\n\
\n\
checksum-checks: no\n\
default-packet-size: 0\n\
";
ThreadVars *tv;

Loading…
Cancel
Save