summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@src.gnome.org>2018-03-16 12:19:33 +0100
committerDaiki Ueno <dueno@src.gnome.org>2018-03-19 12:36:55 +0100
commit0db5a03011040fb68021ed4d034627e1ac06b86f (patch)
treeb22a800c22cccd0524ab1eb50637fd58d7950425
parenta19966ba0ef403e8eed733cc9be8b1d45a3787e4 (diff)
downloadgnome-keyring-0db5a03011040fb68021ed4d034627e1ac06b86f.tar.gz
ssh-agent: Make EOF handling robuster
https://bugzilla.gnome.org/show_bug.cgi?id=794369
-rw-r--r--daemon/ssh-agent/gkd-ssh-agent-service.c3
-rw-r--r--daemon/ssh-agent/gkd-ssh-agent-util.c6
-rw-r--r--daemon/ssh-agent/test-gkd-ssh-agent-service.c8
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 e9c20975..8f385437 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 a35da152..f0934b5f 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 d02d1639..9a9ead99 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