Skip to content

Commit

Permalink
Bug #594 Add some additional headroom to cached packets
Browse files Browse the repository at this point in the history
When using '--preload-pcap' option any additional VLAN headers
results in Heap Buffer Overflow. Add 512 bytes additional buffer
space.

TODO: Add intelligence to understand when and how much memory
to allocate/reallocate based on tcpedit function.
  • Loading branch information
fklassen committed Jun 3, 2020
1 parent 4bb7c56 commit 13e555a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/defines.h.in
Expand Up @@ -161,6 +161,8 @@ typedef struct tcpr_speed_s {
* couple VLAN headers or a L2 header
*/

#define PACKET_HEADROOM 512 /* additional headroom allocated for packets to accommodate editing */

#define DNS_RESOLVE 1
#define DNS_DONT_RESOLVE 0

Expand Down
2 changes: 1 addition & 1 deletion src/send_packets.c
Expand Up @@ -1055,7 +1055,7 @@ get_next_packet(tcpreplay_t *ctx, pcap_t *pcap, struct pcap_pkthdr *pkthdr, int
(*prev_packet)->next = NULL;
pktlen = pkthdr->len;

(*prev_packet)->pktdata = safe_malloc(pktlen);
(*prev_packet)->pktdata = safe_malloc(pktlen + PACKET_HEADROOM);
memcpy((*prev_packet)->pktdata, pktdata, pktlen);
memcpy(&((*prev_packet)->pkthdr), pkthdr, sizeof(struct pcap_pkthdr));
}
Expand Down

0 comments on commit 13e555a

Please sign in to comment.