Skip to content

Commit

Permalink
remalloc packets before padding to ensure not overwriting memory - cl…
Browse files Browse the repository at this point in the history
…oses appneta#80
  • Loading branch information
fklassen committed Jul 22, 2014
1 parent 16abc7f commit 69831b8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Fix max replay rate for all loops except first when omitting --mbps (#85)
- Seg fault on some IPv6 files when using -C option with tcprewrite (#83)
- Support for PF_RING DNA version of libpcap (#82)
- Fix segfault when using '-F pad' (#80)
- Fix build for FreeBSD version 8.4 (#78)

06/19/2014 Version 4.0.5-beta1
Expand Down
9 changes: 7 additions & 2 deletions src/tcpedit/edit_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,17 @@ randomize_ipv6(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr,

int
untrunc_packet(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr,
u_char *pktdata, ipv4_hdr_t *ip_hdr, ipv6_hdr_t *ip6_hdr)
u_char **pktdata, ipv4_hdr_t *ip_hdr, ipv6_hdr_t *ip6_hdr)
{
int l2len;
u_char *packet;
assert(tcpedit);
assert(pkthdr);
assert(pktdata);

packet = *pktdata;
assert(packet);

/* if actual len == cap len or there's no IP header, don't do anything */
if ((pkthdr->caplen == pkthdr->len) || (ip_hdr == NULL && ip6_hdr == NULL)) {
/* unless we're in MTU truncate mode */
Expand All @@ -268,7 +272,8 @@ untrunc_packet(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr,
* which seems like a corrupted pcap
*/
if (pkthdr->len > pkthdr->caplen) {
memset(pktdata + pkthdr->caplen, '\0', pkthdr->len - pkthdr->caplen);
packet = safe_realloc(packet, pkthdr->len);
memset(packet + pkthdr->caplen, '\0', pkthdr->len - pkthdr->caplen);
pkthdr->caplen = pkthdr->len;
} else if (pkthdr->len < pkthdr->caplen) {
/* i guess this is necessary if we've got a bogus pcap */
Expand Down
2 changes: 1 addition & 1 deletion src/tcpedit/edit_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "common.h"

int untrunc_packet(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr,
u_char *pktdata, ipv4_hdr_t *ip_hdr, ipv6_hdr_t *ip6_hdr);
u_char **pktdata, ipv4_hdr_t *ip_hdr, ipv6_hdr_t *ip6_hdr);

int randomize_ipv4(tcpedit_t *tcpedit, struct pcap_pkthdr *pktdhr,
u_char *pktdata, ipv4_hdr_t *ip_hdr);
Expand Down
2 changes: 1 addition & 1 deletion src/tcpedit/tcpedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ tcpedit_packet(tcpedit_t *tcpedit, struct pcap_pkthdr **pkthdr,

/* (Un)truncate or MTU truncate packet? */
if (tcpedit->fixlen || tcpedit->mtu_truncate) {
if ((retval = untrunc_packet(tcpedit, *pkthdr, packet, ip_hdr, ip6_hdr)) < 0)
if ((retval = untrunc_packet(tcpedit, *pkthdr, pktdata, ip_hdr, ip6_hdr)) < 0)
return TCPEDIT_ERROR;
needtorecalc += retval;
}
Expand Down

0 comments on commit 69831b8

Please sign in to comment.