[gnome-keyring] ssh-agent: Make EOF handling robuster
- From: Daiki Ueno <dueno src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] ssh-agent: Make EOF handling robuster
- Date: Mon, 19 Mar 2018 11:37:29 +0000 (UTC)
commit 0db5a03011040fb68021ed4d034627e1ac06b86f
Author: Daiki Ueno <dueno src gnome org>
Date: Fri Mar 16 12:19:33 2018 +0100
ssh-agent: Make EOF handling robuster
https://bugzilla.gnome.org/show_bug.cgi?id=794369
daemon/ssh-agent/gkd-ssh-agent-service.c | 3 ++-
daemon/ssh-agent/gkd-ssh-agent-util.c | 6 ++++++
daemon/ssh-agent/test-gkd-ssh-agent-service.c | 8 ++++----
3 files changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/daemon/ssh-agent/gkd-ssh-agent-service.c b/daemon/ssh-agent/gkd-ssh-agent-service.c
index e9c2097..8f38543 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-service.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-service.c
@@ -307,7 +307,8 @@ on_run (GThreadedSocketService *service,
/* Read in the request */
error = NULL;
if (!_gkd_ssh_agent_read_packet (connection, &req, self->cancellable, &error)) {
- if (error->code != G_IO_ERROR_CANCELLED)
+ if (error->code != G_IO_ERROR_CANCELLED &&
+ error->code != G_IO_ERROR_CONNECTION_CLOSED)
g_message ("couldn't read from client: %s", error->message);
g_error_free (error);
break;
diff --git a/daemon/ssh-agent/gkd-ssh-agent-util.c b/daemon/ssh-agent/gkd-ssh-agent-util.c
index a35da15..f0934b5 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-util.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-util.c
@@ -45,6 +45,12 @@ _gkd_ssh_agent_read_packet (GSocketConnection *connection,
if (!g_input_stream_read_all (stream, buffer->buf, 4, &bytes_read, cancellable, error))
return FALSE;
+ if (bytes_read < 4) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED,
+ "connection closed by peer");
+ return FALSE;
+ }
+
if (!egg_buffer_get_uint32 (buffer, 0, NULL, &packet_size) ||
packet_size < 1) {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
diff --git a/daemon/ssh-agent/test-gkd-ssh-agent-service.c b/daemon/ssh-agent/test-gkd-ssh-agent-service.c
index d02d163..9a9ead9 100644
--- a/daemon/ssh-agent/test-gkd-ssh-agent-service.c
+++ b/daemon/ssh-agent/test-gkd-ssh-agent-service.c
@@ -217,7 +217,7 @@ call_unparseable_add (Test *test)
prepare_add_identity (&test->req);
egg_buffer_set_uint32 (&test->req, 5, 0x80000000);
- call_error_or_failure (test, G_IO_ERROR, G_IO_ERROR_FAILED);
+ call_error_or_failure (test, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED);
}
static void
@@ -228,7 +228,7 @@ call_unparseable_remove (Test *test)
prepare_remove_identity (&test->req);
egg_buffer_set_uint32 (&test->req, 5, 0x80000000);
- call_error_or_failure (test, G_IO_ERROR, G_IO_ERROR_FAILED);
+ call_error_or_failure (test, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED);
}
static void
@@ -239,7 +239,7 @@ call_unparseable_sign (Test *test)
prepare_sign_request (&test->req);
egg_buffer_set_uint32 (&test->req, 5, 0x80000000);
- call_error_or_failure (test, G_IO_ERROR, G_IO_ERROR_FAILED);
+ call_error_or_failure (test, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED);
}
static void
@@ -308,7 +308,7 @@ call_empty (Test *test)
error = NULL;
ret = _gkd_ssh_agent_read_packet (test->connection, &test->resp, NULL, &error);
g_assert_false (ret);
- g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED);
+ g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]