From b585b86648ba2bdaec7d886daa8242e1b1fc3143 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Mon, 3 Feb 2025 08:17:14 -0300 Subject: [PATCH] Change: scan progress calculation. Since the information send by openvasd changed. --- openvasd/openvasd.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/openvasd/openvasd.c b/openvasd/openvasd.c index a8de82c7b..941b533c3 100644 --- a/openvasd/openvasd.c +++ b/openvasd/openvasd.c @@ -1006,7 +1006,26 @@ openvasd_get_scan_progress_ext (openvasd_connector_t conn, cJSON *host = scanning->child; while (host) { - running_hosts_progress_sum += cJSON_GetNumberValue (host); + int finished_tests, total_tests, single_host_progress; + + if (!cJSON_IsObject (host)) + { + progress = 0; + goto cleanup; + } + + finished_tests = get_member_value_or_fail (host, "finished_tests"); + total_tests = get_member_value_or_fail (host, "total_tests"); + + if (total_tests <= 0 || finished_tests < 0) + { + progress = 0; + goto cleanup; + } + + single_host_progress = (100 * finished_tests / total_tests); + + running_hosts_progress_sum += single_host_progress; host = host->next; } } @@ -1021,7 +1040,7 @@ openvasd_get_scan_progress_ext (openvasd_connector_t conn, progress = (running_hosts_progress_sum + 100 * (alive + finished)) / (all + finished - dead); else - progress = 100; + progress = 0; cleanup: if (err != NULL)