[libsoup] auth: critical if SoupAuth is cancelled after message is unqueued



commit 41ff5eb299472d220b74b583952f908538210bc0
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Wed Jun 16 14:11:41 2021 +0200

    auth: critical if SoupAuth is cancelled after message is unqueued
    
    libsoup-CRITICAL **: 14:08:13.743: soup_session_unpause_message: assertion 'item != NULL' failed
    
    We should hande the case of item being unqueued in
    soup_session_unpause_message().

 libsoup/soup-session.c |  4 +++-
 tests/auth-test.c      | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)
---
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 9c674e57..89183195 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -2183,7 +2183,9 @@ soup_session_unpause_message (SoupSession *session,
        g_return_if_fail (SOUP_IS_MESSAGE (msg));
 
        item = soup_session_lookup_queue_item (session, msg);
-       g_return_if_fail (item != NULL);
+        if (!item)
+                return;
+
        g_return_if_fail (item->async);
 
        item->paused = FALSE;
diff --git a/tests/auth-test.c b/tests/auth-test.c
index 05e0f82e..c3bef39c 100644
--- a/tests/auth-test.c
+++ b/tests/auth-test.c
@@ -1681,6 +1681,48 @@ do_cancel_on_authenticate (void)
         g_main_loop_unref (loop);
 }
 
+static void
+do_cancel_request_on_authenticate (void)
+{
+        SoupSession *session;
+        SoupMessage *msg;
+        GCancellable *cancellable;
+        SoupAuth *auth = NULL;
+        char *uri;
+
+        SOUP_TEST_SKIP_IF_NO_APACHE;
+
+        session = soup_test_session_new (NULL);
+        loop = g_main_loop_new (NULL, FALSE);
+
+        uri = g_strconcat (base_uri, "Digest/realm1/", NULL);
+        msg = soup_message_new ("GET", uri);
+        g_signal_connect (msg, "authenticate",
+                          G_CALLBACK (async_authenticate),
+                          &auth);
+        g_signal_connect (msg, "finished",
+                          G_CALLBACK (async_no_auth_cache_finished), NULL);
+        cancellable = g_cancellable_new ();
+        soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, cancellable, NULL, NULL);
+        g_main_loop_run (loop);
+
+        soup_test_assert_message_status (msg, SOUP_STATUS_UNAUTHORIZED);
+        g_cancellable_cancel (cancellable);
+        g_main_loop_run (loop);
+
+        soup_auth_cancel (auth);
+
+        while (g_main_context_pending (NULL))
+                g_main_context_iteration (NULL, FALSE);
+
+        g_object_unref (auth);
+        g_object_unref (cancellable);
+        g_object_unref (msg);
+        g_free (uri);
+        soup_test_session_abort_unref (session);
+        g_main_loop_unref (loop);
+}
+
 static const struct {
        const char *url;
        guint status;
@@ -1748,6 +1790,7 @@ main (int argc, char **argv)
        g_test_add_func ("/auth/cancel-after-retry", do_cancel_after_retry_test);
        g_test_add_func ("/auth/cancel-on-authenticate", do_cancel_on_authenticate);
        g_test_add_func ("/auth/auth-uri", do_auth_uri_test);
+        g_test_add_func ("/auth/cancel-request-on-authenticate", do_cancel_request_on_authenticate);
 
        ret = g_test_run ();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]