diff options
author | 2011-07-05 00:42:46 +0000 | |
---|---|---|
committer | 2011-07-05 00:42:46 +0000 | |
commit | 6d86f5038d712b3799af7f4c5555a9704f02cc88 (patch) | |
tree | 7eae9e306a7b725fbeb6fd395164f06cc8220202 | |
parent | When calling nfs_request() for what could be an async request, pass (diff) | |
download | wireguard-openbsd-6d86f5038d712b3799af7f4c5555a9704f02cc88.tar.xz wireguard-openbsd-6d86f5038d712b3799af7f4c5555a9704f02cc88.zip |
check that thread specific keys are valid, and cleanup code a little.
ok guenther
-rw-r--r-- | lib/libpthread/uthread/uthread_spec.c | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/lib/libpthread/uthread/uthread_spec.c b/lib/libpthread/uthread/uthread_spec.c index f01e91bbf0e..2e2e9c96303 100644 --- a/lib/libpthread/uthread/uthread_spec.c +++ b/lib/libpthread/uthread/uthread_spec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_spec.c,v 1.11 2011/07/03 15:26:44 guenther Exp $ */ +/* $OpenBSD: uthread_spec.c,v 1.12 2011/07/05 00:42:46 tedu Exp $ */ /* * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -80,7 +80,7 @@ pthread_key_delete(pthread_key_t key) int ret = 0; pthread_t pthread; - if (key < PTHREAD_KEYS_MAX) { + if (key >= 0 && key < PTHREAD_KEYS_MAX) { /* Lock the key table entry: */ _SPINLOCK(&key_table[key].lock); @@ -162,14 +162,14 @@ int pthread_setspecific(pthread_key_t key, const void *value) { struct pthread *pthread; - int ret = 0; + int ret = EINVAL; /* Point to the running thread: */ pthread = _get_curthread(); if ((pthread->specific_data) || (pthread->specific_data = pthread_key_allocate_data())) { - if (key < PTHREAD_KEYS_MAX) { + if (key >= 0 && key < PTHREAD_KEYS_MAX) { if (key_table[key].allocated) { if (pthread->specific_data[key] == NULL) { if (value != NULL) @@ -180,12 +180,11 @@ pthread_setspecific(pthread_key_t key, const void *value) } pthread->specific_data[key] = value; ret = 0; - } else - ret = EINVAL; - } else - ret = EINVAL; - } else + } + } + } else { ret = ENOMEM; + } return (ret); } @@ -193,27 +192,21 @@ void * pthread_getspecific(pthread_key_t key) { struct pthread *pthread; - void *data; + void *data = NULL; /* Point to the running thread: */ pthread = _get_curthread(); /* Check if there is specific data: */ - if (pthread->specific_data != NULL && key < PTHREAD_KEYS_MAX) { + if (pthread->specific_data != NULL && + key >= 0 && key < PTHREAD_KEYS_MAX) { /* Check if this key has been used before: */ if (key_table[key].allocated) { /* Return the value: */ - data = (void *) pthread->specific_data[key]; - } else { - /* - * This key has not been used before, so return NULL - * instead: - */ - data = NULL; + data = (void *)pthread->specific_data[key]; } - } else - /* No specific data has been created, so just return NULL: */ - data = NULL; + } + return (data); } #endif |