mirror of
https://git.musl-libc.org/git/musl
synced 2025-01-10 08:42:02 +03:00
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.
This commit is contained in:
parent
620a134638
commit
a1eb8cb5da
@ -5,6 +5,8 @@ int pthread_mutex_unlock(pthread_mutex_t *m)
|
|||||||
pthread_t self;
|
pthread_t self;
|
||||||
|
|
||||||
if (m->_m_type != PTHREAD_MUTEX_NORMAL) {
|
if (m->_m_type != PTHREAD_MUTEX_NORMAL) {
|
||||||
|
if (!m->_m_lock)
|
||||||
|
return EPERM;
|
||||||
self = __pthread_self();
|
self = __pthread_self();
|
||||||
if ((m->_m_lock&0x1fffffff) != self->tid)
|
if ((m->_m_lock&0x1fffffff) != self->tid)
|
||||||
return EPERM;
|
return EPERM;
|
||||||
|
Loading…
Reference in New Issue
Block a user