nptl: fix pthread_mutexattr_gettype always return 0
Checks
Context |
Check |
Description |
dj/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
dj/TryBot-32bit |
success
|
Build for i686
|
Commit Message
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(+)
Comments
On 03/03/23 03:34, abushwang via Libc-alpha wrote:
> 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;
POSIX states that pthread_mutexattr_*set*type should return EINVAL, having
an invalid pthread_mutexattr_t kind means that either the application is
not creating the object using pthread_mutex_init or a glibc bug that is
setting the value to unspecified behavior.
> }
> versioned_symbol (libc, __pthread_mutexattr_gettype,
@@ -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,