Skip to content

Commit

Permalink
Fix: openvas-nasl can not read KB when forking (#1621)
Browse files Browse the repository at this point in the history
Jira: SC-1052

Allows the parent process to return to main function and perform a kb cleanup.
All children processes return as well, but they can't cleanup the kb, since it could be still in use by other fork()ed child.
  • Loading branch information
jjnicola authored Apr 16, 2024
1 parent 5575c0f commit 12f7eed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions misc/plugutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,12 @@ plug_get_key (struct script_infos *args, char *name, int *type, size_t *len,
res = res->next;
}
kb_item_free (res_list);

// Allow to return to the main process if parent process is openvas-nasl.
// So, the main process can do e.g. a kb clean up
if (args->standalone)
return NULL;

_exit (0);
}

Expand Down
7 changes: 7 additions & 0 deletions nasl/nasl.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ main (int argc, char **argv)
struct in6_addr ip6;
kb_t kb;
int rc;
int process_id;

if (prefs_get_bool ("expand_vhosts"))
gvm_host_add_reverse_lookup (host);
Expand All @@ -341,6 +342,8 @@ main (int argc, char **argv)
exit (1);

set_main_kb (kb);
process_id = getpid ();

script_infos = init (&ip6, host->vhosts, kb);
for (int i = 0; nasl_filenames[i] != NULL; i++)
{
Expand Down Expand Up @@ -386,6 +389,10 @@ main (int argc, char **argv)
}
g_free (script_infos->globals);
g_free (script_infos);

if (process_id != getpid ())
exit (0);

kb_delete (kb);
}

Expand Down

0 comments on commit 12f7eed

Please sign in to comment.