summaryrefslogtreecommitdiff
path: root/sysdeps/hurd/pt-setspecific.c
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
commit384808e214350e3f4cae9fdabde70aea410c4a21 (patch)
treebcfed9f14f97c88ce8fca25f6730abface2a0065 /sysdeps/hurd/pt-setspecific.c
parent710717fec5f135c65a2856fd2e2360d99742e058 (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/hurd/pt-setspecific.c')
-rw-r--r--sysdeps/hurd/pt-setspecific.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/sysdeps/hurd/pt-setspecific.c b/sysdeps/hurd/pt-setspecific.c
index 89ca4d7f..d0b7302f 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);