* [PATCH] nptl: fix pthread_mutexattr_gettype always return 0
@ 2023-03-03 6:34 abushwang
2023-03-03 13:01 ` Adhemerval Zanella Netto
0 siblings, 1 reply; 2+ messages in thread
From: abushwang @ 2023-03-03 6:34 UTC (permalink / raw)
To: libc-alpha, drepper.fsp; +Cc: abushwang
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] nptl: fix pthread_mutexattr_gettype always return 0
2023-03-03 6:34 [PATCH] nptl: fix pthread_mutexattr_gettype always return 0 abushwang
@ 2023-03-03 13:01 ` Adhemerval Zanella Netto
0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella Netto @ 2023-03-03 13:01 UTC (permalink / raw)
To: abushwang, libc-alpha, drepper.fsp
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,
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-03 13:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-03 6:34 [PATCH] nptl: fix pthread_mutexattr_gettype always return 0 abushwang
2023-03-03 13:01 ` Adhemerval Zanella Netto
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).