Skip to content

Commit 50f47a4

Browse files
ycsincarlescufi
authored andcommitted
lib: posix: mutex: check args of pthread_mutexattr_getprotocol
Perform arguments checking in the `pthread_mutexattr_getprotocol()` function. Signed-off-by: Yong Cong Sin <[email protected]>
1 parent 5690088 commit 50f47a4

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/posix/options/mutex.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ int pthread_mutex_destroy(pthread_mutex_t *mu)
307307
int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr,
308308
int *protocol)
309309
{
310+
if ((attr == NULL) || (protocol == NULL)) {
311+
return EINVAL;
312+
}
313+
310314
*protocol = PTHREAD_PRIO_NONE;
311315
return 0;
312316
}

tests/posix/common/src/mutex.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ static void test_mutex_common(int type, void *(*entry)(void *arg))
6060

6161
zassert_ok(pthread_mutexattr_gettype(&mut_attr, &actual_type),
6262
"reading mutex type is failed");
63+
zassert_not_ok(pthread_mutexattr_getprotocol(NULL, &protocol));
64+
zassert_not_ok(pthread_mutexattr_getprotocol(&mut_attr, NULL));
65+
zassert_not_ok(pthread_mutexattr_getprotocol(NULL, NULL));
6366
zassert_ok(pthread_mutexattr_getprotocol(&mut_attr, &protocol),
6467
"reading mutex protocol is failed");
6568
zassert_ok(pthread_mutexattr_destroy(&mut_attr));

0 commit comments

Comments
 (0)