From patchwork Wed Apr 20 16:48:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 11819 Received: (qmail 112569 invoked by alias); 20 Apr 2016 16:49:15 -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 112551 invoked by uid 89); 20 Apr 2016 16:49:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=ensured X-HELO: mail-wm0-f48.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=0qqbgExHfK6ADMbElICSfhnFZfX+4R8dsTLuFPI3z/8=; b=QMCNhOCn6FmMIOp5vE1C6pJKBi+bywS3EGBfaJP9SYbKW8DcPkMYSzE6ImSyi91Jza +Bd30NqJZs9SQoJMXCq0TGZFo/GNojKfhYWE9aI1Kkg2RJMjPwxF8TtciNZ+aTYEw5wK YcbOzNDQtSFvnuWRH3Hq8OW26JJ39aHKWITRWcpWHPsBj7ix0CrqVEKraR4Kv5gHuNpX lBZU4PEZw3gpb5IZxVmOYd6txwGtaG7bAgf0sLQ4po2Rr8vH0sTg1ykLl1UEvuR90qxd Ej/Oprc6XW3OzWmt1a3vRy73wuuL8c9M0jKkje6nXap4Zq3qnYcvjXVfQkJYrslFli/5 JeuA== X-Gm-Message-State: AOPr4FXsDS3bMw45Gygz2vaiXpd8ZcHlhRnfJonfaqX2/TXzhLXVczXPwGgoZq2ZPyL1zxib X-Received: by 10.28.150.193 with SMTP id y184mr11633199wmd.41.1461170941911; Wed, 20 Apr 2016 09:49:01 -0700 (PDT) To: GNU C Library From: Mark Thompson Subject: [PATCH] Don't divide by zero when trying to destroy an uninitialised barrier. Message-ID: <5717B2F4.9050105@starleaf.com> Date: Wed, 20 Apr 2016 17:48:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.6.0 MIME-Version: 1.0 --- nptl/pthread_barrier_destroy.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nptl/pthread_barrier_destroy.c b/nptl/pthread_barrier_destroy.c index 92d2027..d114084 100644 --- a/nptl/pthread_barrier_destroy.c +++ b/nptl/pthread_barrier_destroy.c @@ -36,6 +36,15 @@ pthread_barrier_destroy (pthread_barrier_t *barrier) they have exited as well. To get the notification, pretend that we have reached the reset threshold. */ unsigned int count = bar->count; + + /* For an initialised barrier, count must be greater than zero here. An + uninitialised barrier may still have zero, however, and in this case it is + preferable to fail immediately rather than to invoke undefined behaviour + by dividing by zero on the next line. (POSIX allows the implementation to + diagnose invalid state and return EINVAL in this case.) */ + if (__glibc_unlikely (count == 0)) + return EINVAL; + unsigned int max_in_before_reset = BARRIER_IN_THRESHOLD - BARRIER_IN_THRESHOLD % count; /* Relaxed MO sufficient because the program must have ensured that all