about summary refs log tree commit diff
path: root/htl/pt-internal.h
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2020-01-13 19:41:57 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2020-01-13 19:41:57 +0100
commit1d62a403734b18367eb0aa47493d0de644edd00b (patch)
treeecc4e57a3c54be4be9217114e9ba38bc25e31cca /htl/pt-internal.h
parentbc487d714191e91789ad420de274e789f710cac3 (diff)
downloadglibc-1d62a403734b18367eb0aa47493d0de644edd00b.tar.gz
glibc-1d62a403734b18367eb0aa47493d0de644edd00b.tar.xz
glibc-1d62a403734b18367eb0aa47493d0de644edd00b.zip
htl: Avoid crashing when passed invalid pthread_t values
Diffstat (limited to 'htl/pt-internal.h')
-rw-r--r--htl/pt-internal.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/htl/pt-internal.h b/htl/pt-internal.h
index 8754f386a6..f8d7d74244 100644
--- a/htl/pt-internal.h
+++ b/htl/pt-internal.h
@@ -173,12 +173,14 @@ extern int __pthread_concurrency;
    brain-dead users of the pthread interface incorrectly assume that 0
    is an invalid pthread id.)  */
 extern struct __pthread **__pthread_threads;
+extern int __pthread_max_threads;
 extern pthread_rwlock_t __pthread_threads_lock;
 
 #define __pthread_getid(thread) \
-  ({ struct __pthread *__t;                                                  \
+  ({ struct __pthread *__t = NULL;                                           \
      __pthread_rwlock_rdlock (&__pthread_threads_lock);                      \
-     __t = __pthread_threads[thread - 1];                                    \
+     if (thread <= __pthread_max_threads)                                    \
+       __t = __pthread_threads[thread - 1];                                  \
      __pthread_rwlock_unlock (&__pthread_threads_lock);                      \
      __t; })