[PATCH] nptl: fix pthread_mutexattr_gettype always return 0

abushwang abushwangs@gmail.com
Fri Mar 3 06:34:19 GMT 2023


According to posix, pthread_mutexattr_gettype will return EINVAL
when the value specified by attr is invalid.

Signed-off-by: abushwang <abushwangs@gmail.com>
---
 nptl/pthread_mutexattr_gettype.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/nptl/pthread_mutexattr_gettype.c b/nptl/pthread_mutexattr_gettype.c
index 21e0a9e946..e09dc41e76 100644
--- a/nptl/pthread_mutexattr_gettype.c
+++ b/nptl/pthread_mutexattr_gettype.c
@@ -28,6 +28,9 @@ __pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *kind)
   *kind = (iattr->mutexkind & ~PTHREAD_MUTEXATTR_FLAG_BITS
 	   & ~PTHREAD_MUTEX_NO_ELISION_NP);
 
+  if (*kind < PTHREAD_MUTEX_NORMAL || *kind > PTHREAD_MUTEX_ADAPTIVE_NP)
+    return EINVAL;
+
   return 0;
 }
 versioned_symbol (libc, __pthread_mutexattr_gettype,
-- 
2.36.1



More information about the Libc-alpha mailing list