]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
credential-factory: Avoid deadlock during unit tests 2850-keygen-timeout
authorTobias Brunner <tobias@strongswan.org>
Mon, 4 Aug 2025 08:16:31 +0000 (10:16 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 4 Aug 2025 08:16:31 +0000 (10:16 +0200)
If a unit test times out while generating a private key (e.g. because of
a lack of entropy), this avoids a deadlock by still releasing the read
lock that'd prevent acquiring the write lock when plugins are unloaded.

src/libstrongswan/credentials/credential_factory.c

index 1fa34192d84afe723e08c5f3860de5026e6ae9ed..07e1de76e80a746351fc4446c38874568d4dd121 100644 (file)
@@ -140,6 +140,8 @@ METHOD(credential_factory_t, create, void*,
        this->recursive->set(this->recursive, (void*)level + 1);
 
        this->lock->read_lock(this->lock);
+       /* push this in case of a timeout during unit tests */
+       thread_cleanup_push((thread_cleanup_t)this->lock->unlock, this->lock);
        enumerator = this->constructors->create_enumerator(this->constructors);
        while (enumerator->enumerate(enumerator, &entry))
        {
@@ -159,7 +161,7 @@ METHOD(credential_factory_t, create, void*,
                }
        }
        enumerator->destroy(enumerator);
-       this->lock->unlock(this->lock);
+       thread_cleanup_pop(TRUE);
 
        if (!construct && !level)
        {