lib: posix: mutex: check args of pthread_mutexattr_getprotocol

Perform arguments checking in the
`pthread_mutexattr_getprotocol()` function.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
This commit is contained in:
Yong Cong Sin 2024-06-17 14:54:24 +08:00 committed by Carles Cufí
commit 50f47a44b7
2 changed files with 7 additions and 0 deletions

View file

@ -307,6 +307,10 @@ int pthread_mutex_destroy(pthread_mutex_t *mu)
int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr,
int *protocol)
{
if ((attr == NULL) || (protocol == NULL)) {
return EINVAL;
}
*protocol = PTHREAD_PRIO_NONE;
return 0;
}

View file

@ -60,6 +60,9 @@ static void test_mutex_common(int type, void *(*entry)(void *arg))
zassert_ok(pthread_mutexattr_gettype(&mut_attr, &actual_type),
"reading mutex type is failed");
zassert_not_ok(pthread_mutexattr_getprotocol(NULL, &protocol));
zassert_not_ok(pthread_mutexattr_getprotocol(&mut_attr, NULL));
zassert_not_ok(pthread_mutexattr_getprotocol(NULL, NULL));
zassert_ok(pthread_mutexattr_getprotocol(&mut_attr, &protocol),
"reading mutex protocol is failed");
zassert_ok(pthread_mutexattr_destroy(&mut_attr));