Message ID | 20230303063419.1874310-1-abushwangs@gmail.com |
---|---|
State | New |
Headers | show |
Series | nptl: fix pthread_mutexattr_gettype always return 0 | expand |
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,
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,
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(+)