From patchwork Mon Jan 13 18:43:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 37355 Received: (qmail 83948 invoked by alias); 13 Jan 2020 18:43:19 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 83939 invoked by uid 89); 13 Jan 2020 18:43:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault , commit-hurd@gnu.org Subject: [hurd, commited] htl: Avoid crashing when passed invalid pthread_t values Date: Mon, 13 Jan 2020 19:43:11 +0100 Message-Id: <20200113184311.36780-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 --- htl/pt-internal.h | 6 ++++-- 1 file 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; })