From 14b999d48188ca1faf6fe1668f39628e05c118ac Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Mon, 10 Jul 2023 16:03:16 +0200 Subject: [PATCH 1/3] Also set close_connection when writefds is zero --- src/gmpd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gmpd.c b/src/gmpd.c index 772a405c0..2494ec722 100644 --- a/src/gmpd.c +++ b/src/gmpd.c @@ -568,8 +568,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; From abd78a3bd8fcc1ef4ef255079a71bfced586b468 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Mon, 10 Jul 2023 16:06:34 +0200 Subject: [PATCH 2/3] If everything is written and close_connection is set then exit --- src/gmpd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gmpd.c b/src/gmpd.c index 2494ec722..7cb4c9c34 100644 --- a/src/gmpd.c +++ b/src/gmpd.c @@ -515,9 +515,12 @@ serve_gmp (gvm_connection_t *client_connection, const db_conn_info_t *database, /* See whether to read from the client. */ if (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 From b3150cb6f5394b2e9e9f0abacb53675871b98525 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Mon, 10 Jul 2023 16:10:22 +0200 Subject: [PATCH 3/3] Check close_connection before FD_SET instead of before read --- src/gmpd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gmpd.c b/src/gmpd.c index 7cb4c9c34..056ee9bb4 100644 --- a/src/gmpd.c +++ b/src/gmpd.c @@ -513,7 +513,8 @@ 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. */ @@ -553,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;