Skip to content

Commit

Permalink
Merge pull request #595 from appneta/Bug_#594_double_free_enet-vlan-add
Browse files Browse the repository at this point in the history
Bug #594 double free enet vlan add
  • Loading branch information
fklassen committed Jun 3, 2020
2 parents 00ef0e8 + 13e555a commit 5f9b2c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/common/flows.c
Expand Up @@ -90,7 +90,7 @@ static inline flow_hash_entry_t *hash_add_entry(flow_hash_table_t *fht, const ui

assert(hv < fht->num_buckets);

he = malloc(sizeof (*he));
he = safe_malloc(sizeof (*he));
if (!he) {
warn("out of memory");
return NULL;
Expand Down Expand Up @@ -321,6 +321,7 @@ flow_entry_type_t flow_decode(flow_hash_table_t *fht, const struct pcap_pkthdr *
icmp_hdr = (icmpv4_hdr_t*)(pktdata + ip_len + l2_len);
entry.src_port = icmp_hdr->icmp_type;
entry.dst_port = icmp_hdr->icmp_code;
break;
}

/* hash the 5-tuple */
Expand All @@ -332,15 +333,15 @@ flow_entry_type_t flow_decode(flow_hash_table_t *fht, const struct pcap_pkthdr *
static void flow_cache_clear(flow_hash_table_t *fht)
{
flow_hash_entry_t *fhe = NULL;
flow_hash_entry_t *fhe_tmp = NULL;
flow_hash_entry_t *fhe_next = NULL;
size_t i;

for (i = 0; i < fht->num_buckets; i++) {
if ( (fhe = fht->buckets[i]) ) {
if ((fhe = fht->buckets[i]) != NULL) {
while (fhe) {
fhe_tmp = fhe;
fhe = fhe->next;
free(fhe_tmp);
fhe_next = fhe->next;
safe_free(fhe);
fhe = fhe_next;
}
fht->buckets[i] = NULL;
}
Expand All @@ -366,6 +367,6 @@ void flow_hash_table_release(flow_hash_table_t *fht)
return;

flow_cache_clear(fht);
free(fht->buckets);
free(fht);
safe_free(fht->buckets);
safe_free(fht);
}
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 5f9b2c2

Please sign in to comment.