about summary refs log tree commit diff
path: root/src/thread
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-03-30 10:32:45 -0400
committerRich Felker <dalias@aerifal.cx>2011-03-30 10:32:45 -0400
commita1eb8cb5dab06dd23c256d03d82ef6b0efc4b6c6 (patch)
tree460a8ef2e7cfd22d87927bb62b2a214e6eac77db /src/thread
parent620a1346382f9e10b516bc168f86d499b6716769 (diff)
downloadmusl-a1eb8cb5dab06dd23c256d03d82ef6b0efc4b6c6.tar.gz
musl-a1eb8cb5dab06dd23c256d03d82ef6b0efc4b6c6.tar.xz
musl-a1eb8cb5dab06dd23c256d03d82ef6b0efc4b6c6.zip
avoid crash on stupid but allowable usage of pthread_mutex_unlock
unlocking an unlocked mutex is not UB for robust or error-checking
mutexes, so we must avoid calling __pthread_self (which might crash
due to lack of thread-register initialization) until after checking
that the mutex is locked.
Diffstat (limited to 'src/thread')
-rw-r--r--src/thread/pthread_mutex_unlock.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/thread/pthread_mutex_unlock.c b/src/thread/pthread_mutex_unlock.c
index 5855db0b..6c4d7f22 100644
--- a/src/thread/pthread_mutex_unlock.c
+++ b/src/thread/pthread_mutex_unlock.c
@@ -5,9 +5,11 @@ int pthread_mutex_unlock(pthread_mutex_t *m)
 	pthread_t self;
 
 	if (m->_m_type != PTHREAD_MUTEX_NORMAL) {
+		if (!m->_m_lock)
+			return EPERM;
 		self = __pthread_self();
 		if ((m->_m_lock&0x1fffffff) != self->tid)
-		 	return EPERM;
+			return EPERM;
 		if ((m->_m_type&3) == PTHREAD_MUTEX_RECURSIVE && --m->_m_count)
 			return 0;
 		if (m->_m_type >= 4) {