Skip to content

Commit 9542a1c

Browse files
authored
Fix: fix an issue which produces an interrupted scan, originated on a wrong count of excluded hosts. (#1509)
Since excluded hosts are handled in OSPD, we need to keep the total host count which includes the hosts which will be excluded later
1 parent 6022fd8 commit 9542a1c

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

src/attack.c

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,9 +1083,44 @@ apply_hosts_preferences_ordering (gvm_hosts_t *hosts)
10831083
g_debug ("hosts_ordering: Sequential.");
10841084
}
10851085

1086-
static void
1086+
static int
10871087
apply_hosts_reverse_lookup_preferences (gvm_hosts_t *hosts)
10881088
{
1089+
#ifdef FEATURE_REVERSE_LOOKUP_EXCLUDED
1090+
const char *exclude_hosts = prefs_get ("exclude_hosts");
1091+
int hosts_excluded = 0;
1092+
1093+
if (prefs_get_bool ("reverse_lookup_unify"))
1094+
{
1095+
gvm_hosts_t *excluded;
1096+
1097+
excluded = gvm_hosts_reverse_lookup_unify_excluded (hosts);
1098+
g_debug ("reverse_lookup_unify: Skipped %lu host(s).", excluded->count);
1099+
1100+
// Get the amount of hosts which are excluded now for this option,
1101+
// but they are already in the exclude list.
1102+
// This is to avoid issues with the scan progress calculation, since
1103+
// the amount of excluded host could be duplicated.
1104+
hosts_excluded += gvm_hosts_exclude (excluded, exclude_hosts);
1105+
1106+
gvm_hosts_free (excluded);
1107+
}
1108+
1109+
if (prefs_get_bool ("reverse_lookup_only"))
1110+
{
1111+
gvm_hosts_t *excluded;
1112+
1113+
excluded = gvm_hosts_reverse_lookup_only_excluded (hosts);
1114+
g_debug ("reverse_lookup_unify: Skipped %lu host(s).", excluded->count);
1115+
// Get the amount of hosts which are excluded now for this option,
1116+
// but they are already in the exclude list.
1117+
// This is to avoid issues with the scan progress calculation, since
1118+
// the amount of excluded host could be duplicated.
1119+
hosts_excluded += gvm_hosts_exclude (excluded, exclude_hosts);
1120+
gvm_hosts_free (excluded);
1121+
}
1122+
return exclude_hosts ? hosts_excluded : 0;
1123+
#else
10891124
/* Reverse-lookup unify ? */
10901125
if (prefs_get_bool ("reverse_lookup_unify"))
10911126
g_debug ("reverse_lookup_unify: Skipped %d host(s).",
@@ -1095,6 +1130,9 @@ apply_hosts_reverse_lookup_preferences (gvm_hosts_t *hosts)
10951130
if (prefs_get_bool ("reverse_lookup_only"))
10961131
g_debug ("reverse_lookup_only: Skipped %d host(s).",
10971132
gvm_hosts_reverse_lookup_only (hosts));
1133+
1134+
return 0;
1135+
#endif
10981136
}
10991137

11001138
static int
@@ -1311,7 +1349,9 @@ attack_network (struct scan_globals *globals)
13111349

13121350
/* Apply Hosts preferences. */
13131351
apply_hosts_preferences_ordering (hosts);
1314-
apply_hosts_reverse_lookup_preferences (hosts);
1352+
1353+
int already_excluded = 0;
1354+
already_excluded = apply_hosts_reverse_lookup_preferences (hosts);
13151355

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

13231363
/* Send the hosts count to the client, after removing duplicated and
13241364
* unresolved hosts.*/
1325-
sprintf (buf, "%d", gvm_hosts_count (hosts));
1365+
sprintf (buf, "%d", gvm_hosts_count (hosts) + already_excluded);
13261366
connect_main_kb (&main_kb);
13271367
message_to_client (main_kb, buf, NULL, NULL, "HOSTS_COUNT");
13281368
kb_lnk_reset (main_kb);

0 commit comments

Comments
 (0)