Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve double free #430

Merged
merged 1 commit into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- The logging of the NASL internal regexp functions was extended to include the pattern in case of a failed regcomp(). [#397](https://github.com/greenbone/openvas/pull/397)
- Add config for gpg keyring path (OPENVAS_GPG_BASE_DIR) [#407](https://github.com/greenbone/openvas/pull/407)
- Use __func__ instead of __FUNCTION__ [#419](https://github.com/greenbone/openvas/pull/419)
- Use pcap_findalldevs() instead of deprecated function pcap_lookupdev() [#422](https://github.com/greenbone/openvas/pull/422)
- Use pcap_findalldevs() instead of deprecated function pcap_lookupdev() [#422](https://github.com/greenbone/openvas/pull/422) [#430](https://github.com/greenbone/openvas/pull/430)

[Unreleased]: https://github.com/greenbone/openvas/compare/openvas-7.0...master

Expand Down
10 changes: 5 additions & 5 deletions misc/bpf_share.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ print_pcap_error (pcap_t *p, char *prefix)
}

/**
* @param iface Name of interface. String has to be freed by caller.
* @return -1 in case of error, index of the opened pcap_t in pcaps
* otherwise.
*/
Expand All @@ -70,12 +69,10 @@ bpf_open_live (char *iface, char *filter)

if (iface == NULL)
{
if (pcap_findalldevs (&alldevsp, errbuf) == -1)
if (pcap_findalldevs (&alldevsp, errbuf) < 0)
g_message ("Error for pcap_findalldevs(): %s", errbuf);
if (alldevsp != NULL)
/* get first device in list */
iface = g_strdup (alldevsp->name);
pcap_freealldevs (alldevsp);
iface = alldevsp->name;
}

ret = pcap_open_live (iface, 1500, 0, 1, errbuf);
Expand Down Expand Up @@ -114,6 +111,9 @@ bpf_open_live (char *iface, char *filter)
}
pcaps[i] = ret;
pcap_freecode (&filter_prog);
if (alldevsp != NULL)
pcap_freealldevs (alldevsp);

return i;
}

Expand Down
18 changes: 8 additions & 10 deletions nasl/capture_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,18 @@ init_capture_device (struct in_addr src, struct in_addr dest, char *filter)
}
else
{
if (pcap_findalldevs (&alldevsp, errbuf) == -1)
if (pcap_findalldevs (&alldevsp, errbuf) < 0)
g_message ("Error for pcap_findalldevs(): %s", errbuf);
if (alldevsp != NULL)
/* get first device in list */
interface = g_strdup (alldevsp->name);
interface = alldevsp->name;
ret = bpf_open_live (interface, filter);
pcap_freealldevs (alldevsp);
}

if (free_filter != 0)
g_free (filter);

g_free (interface);
if (alldevsp != NULL)
pcap_freealldevs (alldevsp);

return ret;
}
Expand Down Expand Up @@ -193,19 +192,18 @@ init_v6_capture_device (struct in6_addr src, struct in6_addr dest, char *filter)
}
else
{
if (pcap_findalldevs (&alldevsp, errbuf) == -1)
if (pcap_findalldevs (&alldevsp, errbuf) < 0)
g_message ("Error for pcap_findalldevs(): %s", errbuf);
if (alldevsp != NULL)
/* get first device in list */
interface = g_strdup (alldevsp->name);
interface = alldevsp->name;
ret = bpf_open_live (interface, filter);
pcap_freealldevs (alldevsp);
}

if (free_filter != 0)
g_free (filter);

g_free (interface);
if (alldevsp != NULL)
pcap_freealldevs (alldevsp);

return ret;
}
Expand Down
20 changes: 10 additions & 10 deletions nasl/nasl_packet_forgery.c
Original file line number Diff line number Diff line change
Expand Up @@ -1538,20 +1538,17 @@ nasl_pcap_next (lex_ctxt *lexic)
}
if (interface == NULL)
{
if (pcap_findalldevs (&alldevsp, errbuf) == -1)
if (pcap_findalldevs (&alldevsp, errbuf) < 0)
g_message ("Error for pcap_findalldevs(): %s", errbuf);
if (alldevsp != NULL)
/* get first device in list */
interface = g_strdup (alldevsp->name);
pcap_freealldevs (alldevsp);
interface = alldevsp->name;
}
}

if (interface != NULL)
{
bpf = bpf_open_live (interface, filter);
}
g_free (interface);

if (bpf < 0)
{
Expand Down Expand Up @@ -1637,6 +1634,9 @@ nasl_pcap_next (lex_ctxt *lexic)
retc->x.str_val = (char *) ret6;
retc->size = sz;

if (alldevsp != NULL)
pcap_freealldevs (alldevsp);

return retc;
}

Expand Down Expand Up @@ -1678,18 +1678,15 @@ nasl_send_capture (lex_ctxt *lexic)
}
if (interface == NULL)
{
if (pcap_findalldevs (&alldevsp, errbuf) == -1)
if (pcap_findalldevs (&alldevsp, errbuf) < 0)
g_message ("Error for pcap_findalldevs(): %s", errbuf);
if (alldevsp != NULL)
/* get first device in list */
interface = g_strdup (alldevsp->name);
pcap_freealldevs (alldevsp);
interface = alldevsp->name;
}
}

if (interface != NULL)
bpf = bpf_open_live (interface, filter);
g_free (interface);

if (bpf < 0)
{
Expand Down Expand Up @@ -1774,5 +1771,8 @@ nasl_send_capture (lex_ctxt *lexic)
retc->x.str_val = (char *) ret6;
retc->size = sz;

if (alldevsp != NULL)
pcap_freealldevs (alldevsp);

return retc;
}