From b6e87c6f26d64accc06b000b07ad9e92fed3e024 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 22 Jan 2025 09:11:46 +0000 Subject: [PATCH] Call ftpl_init before using monotonic_conds_lock Otherwise we can use this in an uninitialised state, which is not allowed. We call ftpl_init in pthread_cond_init_232, but the application might not have called that. For example, it might have a static condition variable set up with PTHREAD_COND_INITIALIZER. --- src/libfaketime.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libfaketime.c b/src/libfaketime.c index 4ba5165..7f4d0e6 100644 --- a/src/libfaketime.c +++ b/src/libfaketime.c @@ -3705,6 +3705,8 @@ int pthread_cond_destroy_232(pthread_cond_t *cond) { struct pthread_cond_monotonic* e; + ftpl_init(); + if (pthread_rwlock_trywrlock(&monotonic_conds_lock) != 0) { sched_yield(); return EBUSY; @@ -3787,6 +3789,8 @@ int pthread_cond_timedwait_common(pthread_cond_t *cond, pthread_mutex_t *mutex, clockid_t clk_id; int result = 0; + ftpl_init(); + if (abstime != NULL) { if (pthread_rwlock_tryrdlock(&monotonic_conds_lock) != 0) {