[hurd,commited] htl: Avoid crashing when passed invalid pthread_t values
diff mbox series

Message ID 20200113184311.36780-1-samuel.thibault@ens-lyon.org
State New
Headers show
Series
  • [hurd,commited] htl: Avoid crashing when passed invalid pthread_t values
Related show

Commit Message

Samuel Thibault Jan. 13, 2020, 6:43 p.m. UTC
---
 htl/pt-internal.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Patch
diff mbox series

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; })