Skip to content

Commit

Permalink
Fix: memory leak in pcap related functions (#1338)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Feb 20, 2023
1 parent a5b7c0f commit b59f09b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions misc/bpf_share.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ bpf_open_live (char *iface, char *filter)
if (ret == NULL)
{
g_message ("%s", errbuf);
if (alldevsp != NULL)
pcap_freealldevs (alldevsp);
return -1;
}

if (pcap_lookupnet (iface, &network, &netmask, errbuf) < 0)
{
g_message ("pcap_lookupnet failed: %s", errbuf);
if (alldevsp != NULL)
pcap_freealldevs (alldevsp);
pcap_close (ret);
return -1;
}
Expand All @@ -100,6 +104,8 @@ bpf_open_live (char *iface, char *filter)
char buffer[2048];
snprintf (buffer, sizeof (buffer), "pcap_compile: Filter \"%s\"", filter);
print_pcap_error (ret, buffer);
if (alldevsp != NULL)
pcap_freealldevs (alldevsp);
pcap_close (ret);
return -1;
}
Expand All @@ -114,6 +120,9 @@ bpf_open_live (char *iface, char *filter)
if (pcap_setfilter (ret, &filter_prog) < 0)
{
print_pcap_error (ret, "pcap_setfilter\n");
if (alldevsp != NULL)
pcap_freealldevs (alldevsp);
pcap_freecode (&filter_prog);
pcap_close (ret);
return -1;
}
Expand Down
4 changes: 4 additions & 0 deletions nasl/nasl_packet_forgery.c
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,8 @@ nasl_send_capture (lex_ctxt *lexic)
if (bpf < 0)
{
nasl_perror (lexic, "pcap_next: Could not get a bpf\n");
if (alldevsp != NULL)
pcap_freealldevs (alldevsp);
return NULL;
}
else
Expand Down Expand Up @@ -2615,6 +2617,8 @@ nasl_send_capture (lex_ctxt *lexic)
}
else
{
if (alldevsp != NULL)
pcap_freealldevs (alldevsp);
bpf_close (bpf);
return NULL;
}
Expand Down

0 comments on commit b59f09b

Please sign in to comment.