diff options
author | davidxu <davidxu@FreeBSD.org> | 2003-08-16 05:19:00 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2003-08-16 05:19:00 +0000 |
commit | 206928815a48228f66978426e413fcc5fcfaa82d (patch) | |
tree | 5843d89a734a5ab4dbdb88cc4a5dd007c585a8e3 /lib | |
parent | 8f6b3a6b1b815311b090b321cafaa973b56b5356 (diff) | |
download | FreeBSD-src-206928815a48228f66978426e413fcc5fcfaa82d.zip FreeBSD-src-206928815a48228f66978426e413fcc5fcfaa82d.tar.gz |
Access user provided pointer out of lock, and also check the case when
a key is less than 0.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libkse/thread/thr_spec.c | 18 | ||||
-rw-r--r-- | lib/libpthread/thread/thr_spec.c | 18 |
2 files changed, 20 insertions, 16 deletions
diff --git a/lib/libkse/thread/thr_spec.c b/lib/libkse/thread/thr_spec.c index 2cd18d1..e2b6e2d 100644 --- a/lib/libkse/thread/thr_spec.c +++ b/lib/libkse/thread/thr_spec.c @@ -58,18 +58,20 @@ int _pthread_key_create(pthread_key_t *key, void (*destructor) (void *)) { struct pthread *curthread = _get_curthread(); + int i; /* Lock the key table: */ THR_LOCK_ACQUIRE(curthread, &_keytable_lock); - for ((*key) = 0; (*key) < PTHREAD_KEYS_MAX; (*key)++) { + for (i = 0; i < PTHREAD_KEYS_MAX; i++) { - if (key_table[(*key)].allocated == 0) { - key_table[(*key)].allocated = 1; - key_table[(*key)].destructor = destructor; - key_table[(*key)].seqno++; + if (key_table[i].allocated == 0) { + key_table[i].allocated = 1; + key_table[i].destructor = destructor; + key_table[i].seqno++; /* Unlock the key table: */ THR_LOCK_RELEASE(curthread, &_keytable_lock); + *key = i; return (0); } @@ -85,7 +87,7 @@ _pthread_key_delete(pthread_key_t key) struct pthread *curthread = _get_curthread(); int ret = 0; - if (key < PTHREAD_KEYS_MAX) { + if ((unsigned int)key < PTHREAD_KEYS_MAX) { /* Lock the key table: */ THR_LOCK_ACQUIRE(curthread, &_keytable_lock); @@ -172,7 +174,7 @@ _pthread_setspecific(pthread_key_t key, const void *value) if ((pthread->specific) || (pthread->specific = pthread_key_allocate_data())) { - if (key < PTHREAD_KEYS_MAX) { + if ((unsigned int)key < PTHREAD_KEYS_MAX) { if (key_table[key].allocated) { if (pthread->specific[key].data == NULL) { if (value != NULL) @@ -204,7 +206,7 @@ _pthread_getspecific(pthread_key_t key) pthread = _get_curthread(); /* Check if there is specific data: */ - if (pthread->specific != NULL && key < PTHREAD_KEYS_MAX) { + if (pthread->specific != NULL && (unsigned int)key < PTHREAD_KEYS_MAX) { /* Check if this key has been used before: */ if (key_table[key].allocated && (pthread->specific[key].seqno == key_table[key].seqno)) { diff --git a/lib/libpthread/thread/thr_spec.c b/lib/libpthread/thread/thr_spec.c index 2cd18d1..e2b6e2d 100644 --- a/lib/libpthread/thread/thr_spec.c +++ b/lib/libpthread/thread/thr_spec.c @@ -58,18 +58,20 @@ int _pthread_key_create(pthread_key_t *key, void (*destructor) (void *)) { struct pthread *curthread = _get_curthread(); + int i; /* Lock the key table: */ THR_LOCK_ACQUIRE(curthread, &_keytable_lock); - for ((*key) = 0; (*key) < PTHREAD_KEYS_MAX; (*key)++) { + for (i = 0; i < PTHREAD_KEYS_MAX; i++) { - if (key_table[(*key)].allocated == 0) { - key_table[(*key)].allocated = 1; - key_table[(*key)].destructor = destructor; - key_table[(*key)].seqno++; + if (key_table[i].allocated == 0) { + key_table[i].allocated = 1; + key_table[i].destructor = destructor; + key_table[i].seqno++; /* Unlock the key table: */ THR_LOCK_RELEASE(curthread, &_keytable_lock); + *key = i; return (0); } @@ -85,7 +87,7 @@ _pthread_key_delete(pthread_key_t key) struct pthread *curthread = _get_curthread(); int ret = 0; - if (key < PTHREAD_KEYS_MAX) { + if ((unsigned int)key < PTHREAD_KEYS_MAX) { /* Lock the key table: */ THR_LOCK_ACQUIRE(curthread, &_keytable_lock); @@ -172,7 +174,7 @@ _pthread_setspecific(pthread_key_t key, const void *value) if ((pthread->specific) || (pthread->specific = pthread_key_allocate_data())) { - if (key < PTHREAD_KEYS_MAX) { + if ((unsigned int)key < PTHREAD_KEYS_MAX) { if (key_table[key].allocated) { if (pthread->specific[key].data == NULL) { if (value != NULL) @@ -204,7 +206,7 @@ _pthread_getspecific(pthread_key_t key) pthread = _get_curthread(); /* Check if there is specific data: */ - if (pthread->specific != NULL && key < PTHREAD_KEYS_MAX) { + if (pthread->specific != NULL && (unsigned int)key < PTHREAD_KEYS_MAX) { /* Check if this key has been used before: */ if (key_table[key].allocated && (pthread->specific[key].seqno == key_table[key].seqno)) { |