gnutls: Don't hang trying to handshake, if early close
authorStef Walter <stefw@gnome.org>
Thu, 29 Nov 2012 12:51:46 +0000 (13:51 +0100)
committerStef Walter <stefw@gnome.org>
Thu, 29 Nov 2012 22:22:40 +0000 (23:22 +0100)
When closing a connection before the handshake, the GTlsConnectionGnutls
code would try to do a handshake. Fix this, and test for it.

https://bugzilla.gnome.org/show_bug.cgi?id=689271

tls/gnutls/gtlsconnection-gnutls.c
tls/tests/connection.c

index e67329d..b1d4d52 100644 (file)
@@ -524,7 +524,8 @@ claim_op (GTlsConnectionGnutls    *gnutls,
       return FALSE;
     }
 
-  if (op != G_TLS_CONNECTION_GNUTLS_OP_HANDSHAKE)
+  if (op != G_TLS_CONNECTION_GNUTLS_OP_HANDSHAKE &&
+      op != G_TLS_CONNECTION_GNUTLS_OP_CLOSE)
     {
       if (gnutls->priv->need_handshake)
        {
index 37ed5a8..0768a46 100644 (file)
@@ -885,6 +885,26 @@ test_simultaneous_sync (TestConnection *test,
 }
 
 static void
+test_close_immediately (TestConnection *test,
+                        gconstpointer   data)
+{
+  GIOStream *connection;
+  GError *error = NULL;
+
+  connection = start_async_server_and_connect_to_it (test, G_TLS_AUTHENTICATION_NONE);
+  test->client_connection = g_tls_client_connection_new (connection, test->identity, &error);
+  g_assert_no_error (error);
+  g_object_unref (connection);
+
+  /*
+   * At this point the server won't get a chance to run. But regardless
+   * closing should not wait on the server, trying to handshake or something.
+   */
+  if (!g_io_stream_close (test->client_connection, NULL, NULL))
+    g_assert_not_reached ();
+}
+
+static void
 test_simultaneous_sync_rehandshake (TestConnection *test,
                                    gconstpointer   data)
 {
@@ -930,6 +950,8 @@ main (int   argc,
               setup_connection, test_simultaneous_async_rehandshake, teardown_connection);
   g_test_add ("/tls/connection/simultaneous-sync-rehandshake", TestConnection, NULL,
              setup_connection, test_simultaneous_sync_rehandshake, teardown_connection);
+  g_test_add ("/tls/connection/close-immediately", TestConnection, NULL,
+              setup_connection, test_close_immediately, teardown_connection);
 
   ret = g_test_run();