openca / libpki

Easy-to-use high-level library for PKI-enabled applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deadlock in PKI_RWLOCK_write_lock

a157634 opened this issue · comments

PKI_RWLOCK_write_lock() creates two locks on the variable lock_mutex, but only one lock is released. Also the n_writers variable is modified incorrectly. This patch should fix this issue:
diff -ur libpki-0.8.7/src/pki_threads_vars.c libpki-0.8.7_patched/src/pki_threads_vars.c
--- libpki-0.8.7/src/pki_threads_vars.c 2014-08-05 19:55:39.000000000 +0200
+++ libpki-0.8.7_patched/src/pki_threads_vars.c 2014-08-14 22:05:40.505266425 +0200
@@ -124,9 +124,9 @@
pthread_mutex_unlock(&l->lock_mutex);

pthread_mutex_lock(&l->data_mutex);

  • pthread_mutex_lock(&l->lock_mutex);
  • //pthread_mutex_lock(&l->lock_mutex);
    l->n_writers_waiting--;
  • l->n_writers--;
  • l->n_writers++;
    pthread_mutex_unlock(&l->lock_mutex);

endif /* HAVE_PTHREAD_RWLOCK */

Thanks! I just applied the patch. Although this applies only to environments where the RWLOCK is not available in pthread (not many) it is important we support that correctly! Thanks again and please let me know if the lock now performs correctly in your environment.

Yes, it works as expected.