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

Fix: fix an issue which produces an interrupted scan, originated on a wrong count of excluded hosts. #1509

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions src/attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1083,9 +1083,44 @@ apply_hosts_preferences_ordering (gvm_hosts_t *hosts)
g_debug ("hosts_ordering: Sequential.");
}

static void
static int
apply_hosts_reverse_lookup_preferences (gvm_hosts_t *hosts)
{
#ifdef FEATURE_REVERSE_LOOKUP_EXCLUDED
const char *exclude_hosts = prefs_get ("exclude_hosts");
int hosts_excluded = 0;

if (prefs_get_bool ("reverse_lookup_unify"))
{
gvm_hosts_t *excluded;

excluded = gvm_hosts_reverse_lookup_unify_excluded (hosts);
g_debug ("reverse_lookup_unify: Skipped %lu host(s).", excluded->count);

// Get the amount of hosts which are excluded now for this option,
// but they are already in the exclude list.
// This is to avoid issues with the scan progress calculation, since
// the amount of excluded host could be duplicated.
hosts_excluded += gvm_hosts_exclude (excluded, exclude_hosts);

gvm_hosts_free (excluded);
}

if (prefs_get_bool ("reverse_lookup_only"))
{
gvm_hosts_t *excluded;

excluded = gvm_hosts_reverse_lookup_only_excluded (hosts);
g_debug ("reverse_lookup_unify: Skipped %lu host(s).", excluded->count);
// Get the amount of hosts which are excluded now for this option,
// but they are already in the exclude list.
// This is to avoid issues with the scan progress calculation, since
// the amount of excluded host could be duplicated.
hosts_excluded += gvm_hosts_exclude (excluded, exclude_hosts);
gvm_hosts_free (excluded);
}
return exclude_hosts ? hosts_excluded : 0;
#else
/* Reverse-lookup unify ? */
if (prefs_get_bool ("reverse_lookup_unify"))
g_debug ("reverse_lookup_unify: Skipped %d host(s).",
Expand All @@ -1095,6 +1130,9 @@ apply_hosts_reverse_lookup_preferences (gvm_hosts_t *hosts)
if (prefs_get_bool ("reverse_lookup_only"))
g_debug ("reverse_lookup_only: Skipped %d host(s).",
gvm_hosts_reverse_lookup_only (hosts));

return 0;
#endif
}

static int
Expand Down Expand Up @@ -1311,7 +1349,9 @@ attack_network (struct scan_globals *globals)

/* Apply Hosts preferences. */
apply_hosts_preferences_ordering (hosts);
apply_hosts_reverse_lookup_preferences (hosts);

int already_excluded = 0;
already_excluded = apply_hosts_reverse_lookup_preferences (hosts);

#ifdef FEATURE_HOSTS_ALLOWED_ONLY
// Remove hosts which are denied and/or keep the ones in the allowed host
Expand All @@ -1322,7 +1362,7 @@ attack_network (struct scan_globals *globals)

/* Send the hosts count to the client, after removing duplicated and
* unresolved hosts.*/
sprintf (buf, "%d", gvm_hosts_count (hosts));
sprintf (buf, "%d", gvm_hosts_count (hosts) + already_excluded);
connect_main_kb (&main_kb);
message_to_client (main_kb, buf, NULL, NULL, "HOSTS_COUNT");
kb_lnk_reset (main_kb);
Expand Down
Loading