Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Handle close_connection when writefds is 0 #2042

Merged
merged 4 commits into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/gmpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,15 @@ serve_gmp (gvm_connection_t *client_connection, const db_conn_info_t *database,
/** @todo Shutdown on failure (for example, if a read fails). */

/* See whether to read from the client. */
if (from_client_end < from_buffer_size)
if ((close_connection == 0)
&& (from_client_end < from_buffer_size))
FD_SET (client_connection->socket, &readfds);

/* See whether to write to the client. */
if (to_client_start < to_client_end)
FD_SET (client_connection->socket, &writefds);
else if (close_connection)
goto client_free;

/* Select, then handle result. Due to GNUTLS internal buffering
* we test for pending records first and emulate a select call
Expand Down Expand Up @@ -550,8 +554,7 @@ serve_gmp (gvm_connection_t *client_connection, const db_conn_info_t *database,
}

/* Read any data from the client. */
if (close_connection == 0
&& client_connection->socket > 0
if (client_connection->socket > 0
&& FD_ISSET (client_connection->socket, &readfds))
{
buffer_size_t initial_start = from_client_end;
Expand All @@ -568,8 +571,7 @@ serve_gmp (gvm_connection_t *client_connection, const db_conn_info_t *database,
break;
case -3: /* End of file. */
g_debug (" EOF reading from client");
if (client_connection->socket > 0
&& FD_ISSET (client_connection->socket, &writefds))
if (client_connection->socket > 0)
/* Stop reading, but process rest of input and output. */
close_connection = 1;
break;
Expand Down