summaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorPino Toscano <toscano.pino@tiscali.it>2011-11-06 12:39:04 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2011-11-06 13:12:14 +0100
commit56e25a91e9e25eba8da099efa89c3c487c3490cf (patch)
treee9eef9929fbca4947557a015fcbf571592adefba /sysdeps
parentea6390b2f20a03b7d504bc68a1c95e645d271149 (diff)
pthread_getspecific, pthread_setspecific: check the key validity
When getting a TSD, handle gracefully the case of an invalid key. When setting a TSD, check for the validity of the key as recommended (although not required) by POSIX. This also avoids potentially filling the `thread_specifics' hash of threads with TSD of invalid keys. Add two simple checks in test-7.c for the two situations above. * sysdeps/hurd/pt-getspecific.c (pthread_getspecific): Check the validity of the specified key. * sysdeps/hurd/pt-setspecific.c (pthread_setspecific): Likewise. * tests/test-7.c (main): Add two assertions.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/hurd/pt-getspecific.c4
-rw-r--r--sysdeps/hurd/pt-setspecific.c4
2 files changed, 7 insertions, 1 deletions
diff --git a/sysdeps/hurd/pt-getspecific.c b/sysdeps/hurd/pt-getspecific.c
index 3060598..71ec63c 100644
--- a/sysdeps/hurd/pt-getspecific.c
+++ b/sysdeps/hurd/pt-getspecific.c
@@ -27,7 +27,9 @@ pthread_getspecific (pthread_key_t key)
{
struct __pthread *self;
- assert (key < __pthread_key_count);
+ if (key < 0 || key >= __pthread_key_count
+ || __pthread_key_destructors[key] == PTHREAD_KEY_INVALID)
+ return NULL;
self = _pthread_self ();
if (! self->thread_specifics)
diff --git a/sysdeps/hurd/pt-setspecific.c b/sysdeps/hurd/pt-setspecific.c
index 89ca4d7..d0b7302 100644
--- a/sysdeps/hurd/pt-setspecific.c
+++ b/sysdeps/hurd/pt-setspecific.c
@@ -28,6 +28,10 @@ pthread_setspecific (pthread_key_t key, const void *value)
error_t err;
struct __pthread *self = _pthread_self ();
+ if (key < 0 || key >= __pthread_key_count
+ || __pthread_key_destructors[key] == PTHREAD_KEY_INVALID)
+ return EINVAL;
+
if (! self->thread_specifics)
{
err = hurd_ihash_create (&self->thread_specifics, HURD_IHASH_NO_LOCP);