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: 1222297 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-108636-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha1 header.s=default header.b=uViOkv0p; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47xMt622Hmz9sP3 for ; Tue, 14 Jan 2020 05:43:25 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; q=dns; s=default; b=bPD ZB5Q1VIW1I0OKHZH8dR831x7FRkpLKLP/f4SeuiL7J88fn2rTRgpZhgVOfl2IAXf YW88BxFADIKXgJC5RoT1BvVPoGsunboCu3JlqufFPDg/S3ybk13ZyOJWOpY8oFAy tVHeICZwWvhdQSRhA0sw5JJiMlAp6q8uWUuI8mBo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; s=default; bh=JXJWJN+g8 hXyxA7jEbCtD5MBA3c=; b=uViOkv0pPGz3tTOFCRHQDOW5/4VXk517hZ2oHtOkg h9+QGIBqsk93R54R89UUs6oa/yeW3TzRbda7/d+1DOv2Z+dS+kT0v/VhHhNwstWb gc07lXvXo5On0xCRSxS7V9TVTumK4LkBYSMSAmOIJO9Zv/QYfmGnj8PLDErSt+SJ RI= 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; })