diff --git a/CHANGELOG.md b/CHANGELOG.md index 34f0c7c9f..bb3a3f50e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - Use fchmod to change file permission instead of on open to prevent race conditions [860](https://github.com/greenbone/openvas-scanner/pull/860) - Fix plugins upload. Backport #878. [#879](https://github.com/greenbone/openvas/pull/879) +- Fix Segmentation fault when freeing hosts and alive hosts [#888](https://github.com/greenbone/openvas/pull/888) ## [21.10] (unreleased) diff --git a/src/attack.c b/src/attack.c index c5eb32c75..649fa0559 100644 --- a/src/attack.c +++ b/src/attack.c @@ -1188,6 +1188,7 @@ attack_network (struct scan_globals *globals) if (test_alive_hosts_only) { struct in6_addr tmpaddr; + gvm_host_t *buf; while (1) { @@ -1231,13 +1232,16 @@ attack_network (struct scan_globals *globals) break; } - if (gvm_host_get_addr6 (host, &tmpaddr) == 0) - host = gvm_host_find_in_hosts (host, &tmpaddr, hosts); - - if (host) + if (host && gvm_host_get_addr6 (host, &tmpaddr) == 0) { - gvm_hosts_add (alive_hosts_list, host); + buf = host; + host = gvm_host_find_in_hosts (host, &tmpaddr, hosts); + gvm_host_free (buf); + buf = NULL; } + + if (host) + gvm_hosts_add (alive_hosts_list, gvm_duplicate_host (host)); else g_debug ("%s: got NULL host, stop/finish scan", __func__); }