summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2022-08-29 09:21:44 +0200
committerCarlos Garcia Campos <cgarcia@igalia.com>2022-08-31 11:09:26 +0200
commitfe1e6244678b61a638fb092cbcfa97230cb9bab3 (patch)
tree149bc7a3b4ae6897c6f246377b1ef31c206df337
parent9091c2cadb6e96faeb9b6dfe6f47177a283673c2 (diff)
downloadlibsoup-fe1e6244678b61a638fb092cbcfa97230cb9bab3.tar.gz
http2: handle connection terminated unexpectedly error when reading
-rw-r--r--libsoup/http2/soup-client-message-io-http2.c9
-rw-r--r--libsoup/server/http2/soup-server-message-io-http2.c16
2 files changed, 23 insertions, 2 deletions
diff --git a/libsoup/http2/soup-client-message-io-http2.c b/libsoup/http2/soup-client-message-io-http2.c
index a1ad1880..0ccdf878 100644
--- a/libsoup/http2/soup-client-message-io-http2.c
+++ b/libsoup/http2/soup-client-message-io-http2.c
@@ -359,10 +359,17 @@ io_read (SoupClientMessageIOHTTP2 *io,
blocking, cancellable, error)) < 0)
return FALSE;
+ if (read == 0) {
+ g_set_error_literal (error, G_IO_ERROR,
+ G_IO_ERROR_PARTIAL_INPUT,
+ _("Connection terminated unexpectedly"));
+ return FALSE;
+ }
+
g_warn_if_fail (io->in_callback == 0);
ret = nghttp2_session_mem_recv (io->session, buffer, read);
NGCHECK (ret);
- return ret != 0;
+ return ret > 0;
}
static gboolean
diff --git a/libsoup/server/http2/soup-server-message-io-http2.c b/libsoup/server/http2/soup-server-message-io-http2.c
index 2e32b0aa..81a5dd3c 100644
--- a/libsoup/server/http2/soup-server-message-io-http2.c
+++ b/libsoup/server/http2/soup-server-message-io-http2.c
@@ -406,11 +406,25 @@ io_read (SoupServerMessageIOHTTP2 *io,
{
guint8 buffer[8192];
gssize read;
+ int ret;
if ((read = g_pollable_stream_read (io->istream, buffer, sizeof (buffer), FALSE, NULL, error)) < 0)
return FALSE;
- return nghttp2_session_mem_recv (io->session, buffer, read) != 0;
+ if (read == 0) {
+ g_set_error_literal (error, G_IO_ERROR,
+ G_IO_ERROR_PARTIAL_INPUT,
+ _("Connection terminated unexpectedly"));
+ return FALSE;
+ }
+
+ ret = nghttp2_session_mem_recv (io->session, buffer, read);
+ if (ret < 0) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "HTTP/2 IO error: %s", nghttp2_strerror (ret));
+ return FALSE;
+ }
+
+ return TRUE;
}
static gboolean