Skip to content

Commit 3a9dea0

Browse files
committed
Change: scan progress calculation.
Since the information send by openvasd changed.
1 parent 30895c9 commit 3a9dea0

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

openvasd/openvasd.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ get_member_value_or_fail (cJSON *reader, const gchar *member)
12641264
{
12651265
cJSON *item = NULL;
12661266
if ((item = cJSON_GetObjectItem (reader, member)) == NULL
1267-
&& cJSON_IsNumber (item))
1267+
|| !cJSON_IsNumber (item))
12681268
return -1;
12691269

12701270
return item->valueint;
@@ -1330,7 +1330,27 @@ openvasd_get_scan_progress_ext (openvasd_connector_t conn,
13301330
cJSON *host = scanning->child;
13311331
while (host)
13321332
{
1333-
running_hosts_progress_sum += cJSON_GetNumberValue (host);
1333+
int finished_tests, total_tests, single_host_progress;
1334+
1335+
if (!cJSON_IsObject (host))
1336+
{
1337+
g_message ("NO ES OBJETO");
1338+
progress = 0;
1339+
goto cleanup;
1340+
}
1341+
1342+
finished_tests = get_member_value_or_fail (host, "finished_tests");
1343+
total_tests = get_member_value_or_fail (host, "total_tests");
1344+
1345+
if (total_tests < 0 || finished_tests < 0)
1346+
{
1347+
progress = 0;
1348+
goto cleanup;
1349+
}
1350+
1351+
single_host_progress = (100 * finished_tests / total_tests);
1352+
1353+
running_hosts_progress_sum += single_host_progress;
13341354
host = host->next;
13351355
}
13361356

@@ -1347,7 +1367,7 @@ openvasd_get_scan_progress_ext (openvasd_connector_t conn,
13471367
progress = (running_hosts_progress_sum + 100 * (alive + finished))
13481368
/ (all + finished - dead);
13491369
else
1350-
progress = 100;
1370+
progress = 0;
13511371

13521372
cleanup:
13531373
if (err != NULL)

0 commit comments

Comments
 (0)