]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
windows: Fix invalid pointer dereference when terminating service thread
authorTobias Brunner <tobias@strongswan.org>
Tue, 7 Mar 2023 15:57:27 +0000 (16:57 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 21 Mar 2023 15:27:10 +0000 (16:27 +0100)
When running as a service, the libraries are initialized/deinitialized
not by the main thread but by a separate thread that runs the registered
main service procedure.  When the service is stopped, the libraries are
deinitialized by that thread and the thread lock and hashtable are
destroyed.  But afterwards the DllMain callback is also triggered for
that thread so we have to prevent it from accessing these objects again.

References strongswan/strongswan#1567

src/libstrongswan/threading/windows/thread.c

index e70e4497b076d36ef62c1fc27f7fc92301b2ef31..cb1b0c54d8cf80abb31e7fb1c90858049db29c60 100644 (file)
@@ -637,6 +637,12 @@ static void cleanup_tls()
        private_thread_t *this;
        bool old;
 
+       /* ignore this if called for the thread that called threads_deinit() */
+       if (!threads_lock)
+       {
+               return;
+       }
+
        old = set_leak_detective(FALSE);
        threads_lock->lock(threads_lock);
 
@@ -698,5 +704,6 @@ void threads_deinit()
        destroy(this);
 
        threads_lock->destroy(threads_lock);
+       threads_lock = NULL;
        threads->destroy(threads);
 }