Skip to content

Commit ec69e64

Browse files
Christopher Friedtfabiobaltieri
authored andcommitted
posix: pthread_setspecific: fix for coverity issue cid 334906
* return EINVAL if pthread_self() is not a valid pthread Signed-off-by: Christopher Friedt <[email protected]>
1 parent 3458527 commit ec69e64

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/posix/key.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,18 @@ int pthread_key_delete(pthread_key_t key)
174174
int pthread_setspecific(pthread_key_t key, const void *value)
175175
{
176176
pthread_key_obj *key_obj;
177-
struct posix_thread *thread = to_posix_thread(pthread_self());
177+
struct posix_thread *thread;
178178
struct pthread_key_data *key_data;
179179
pthread_thread_data *thread_spec_data;
180180
k_spinlock_key_t key_key;
181181
sys_snode_t *node_l;
182182
int retval = 0;
183183

184+
thread = to_posix_thread(pthread_self());
185+
if (thread == NULL) {
186+
return EINVAL;
187+
}
188+
184189
/* Traverse the list of keys set by the thread, looking for key.
185190
* If the key is already in the list, re-assign its value.
186191
* Else add the key to the thread's list.

0 commit comments

Comments
 (0)