Skip to content

Commit

Permalink
FIX: Avoid closing manager socket FDs twice
Browse files Browse the repository at this point in the history
When closing the manager socket file descriptors, set them back to -1
so forked processes will not try closing them again in the cleanup.

This could cause problems if closed file descriptors are re-used,
for example for log output channels.
  • Loading branch information
timopollmeier committed Nov 29, 2021
1 parent 29c1b98 commit 12c7003
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,17 @@ cleanup ()
/** @todo These should happen via gmp, maybe with "cleanup_gmp ();". */
cleanup_manage_process (TRUE);
g_strfreev (disabled_commands);
if (manager_socket > -1) close (manager_socket);
if (manager_socket_2 > -1) close (manager_socket_2);
if (manager_socket > -1)
{
close (manager_socket);
manager_socket = -1;
}
if (manager_socket_2 > -1)
{
close (manager_socket_2);
manager_socket_2 = -1;
}

#if LOG
if (log_stream != NULL)
{
Expand Down Expand Up @@ -1206,8 +1215,16 @@ fork_update_nvt_cache ()
pthread_sigmask (SIG_SETMASK, &sigmask_current, NULL);
/** @todo This should happen via gmp, maybe with "cleanup_gmp ();". */
cleanup_manage_process (FALSE);
if (manager_socket > -1) close (manager_socket);
if (manager_socket_2 > -1) close (manager_socket_2);
if (manager_socket > -1)
{
close (manager_socket);
manager_socket = -1;
}
if (manager_socket_2 > -1)
{
close (manager_socket_2);
manager_socket_2 = -1;
}

/* Update the cache. */

Expand Down Expand Up @@ -1309,8 +1326,16 @@ fork_feed_sync ()
pthread_sigmask (SIG_SETMASK, &sigmask_current, NULL);
/** @todo This should happen via gmp, maybe with "cleanup_gmp ();". */
cleanup_manage_process (FALSE);
if (manager_socket > -1) close (manager_socket);
if (manager_socket_2 > -1) close (manager_socket_2);
if (manager_socket > -1)
{
close (manager_socket);
manager_socket = -1;
}
if (manager_socket_2 > -1)
{
close (manager_socket_2);
manager_socket_2 = -1;
}

/* Check the feed version. */

Expand Down

0 comments on commit 12c7003

Please sign in to comment.