Commit 0db5a030 authored by Daiki Ueno's avatar Daiki Ueno

ssh-agent: Make EOF handling robuster

https://bugzilla.gnome.org/show_bug.cgi?id=794369
parent a19966ba
......@@ -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;
......
......@@ -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,
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment