Skip to content

Commit

Permalink
Fix: Handle close_connection when writefds is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
timopollmeier authored Jul 11, 2023
2 parents 0fb48e5 + 72b1e7a commit 5ecc656
Showing 1 changed file with 7 additions and 5 deletions.
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

0 comments on commit 5ecc656

Please sign in to comment.