From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 574651F5AE for ; Wed, 21 Apr 2021 18:12:27 +0000 (UTC) Received: from localhost ([::1]:38084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZHKr-0000Fs-VQ for normalperson@yhbt.net; Wed, 21 Apr 2021 14:12:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZHKZ-0000FQ-Db for bug-gnulib@gnu.org; Wed, 21 Apr 2021 14:12:07 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:43472) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZHKV-0007cc-HA for bug-gnulib@gnu.org; Wed, 21 Apr 2021 14:12:07 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 22DA4160156 for ; Wed, 21 Apr 2021 11:12:02 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 3l4KPhjLWFKe; Wed, 21 Apr 2021 11:12:01 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 459001600EB; Wed, 21 Apr 2021 11:12:01 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id QLjepPlgDxO3; Wed, 21 Apr 2021 11:12:01 -0700 (PDT) Received: from day.example.com (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 1E0171600C2; Wed, 21 Apr 2021 11:12:01 -0700 (PDT) From: Paul Eggert To: bug-gnulib@gnu.org Subject: [PATCH 3/3] malloca: avoid ptrdiff_t overflow Date: Wed, 21 Apr 2021 11:11:50 -0700 Message-Id: <20210421181150.1530263-3-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210421181150.1530263-1-eggert@cs.ucla.edu> References: <20210421181150.1530263-1-eggert@cs.ucla.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=131.179.128.68; envelope-from=eggert@cs.ucla.edu; helo=zimbra.cs.ucla.edu X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Eggert Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" * lib/malloca.c: Include idx.h, intprops.h. (mmalloca): Check for ptrdiff_t overflow. Since this module uses _GL_USE_STDLIB_ALLOC, it cannot assume GNU malloc semantics. * modules/malloca (Depends-on): Add idx, intprops. --- ChangeLog | 6 ++++++ lib/malloca.c | 8 +++++--- modules/malloca | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1e6cbd07f..e72362077 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2021-04-21 Paul Eggert =20 + malloca: avoid ptrdiff_t overflow + * lib/malloca.c: Include idx.h, intprops.h. + (mmalloca): Check for ptrdiff_t overflow. Since this module uses + _GL_USE_STDLIB_ALLOC, it cannot assume GNU malloc semantics. + * modules/malloca (Depends-on): Add idx, intprops. + careadlinkat: avoid ptrdiff_t overflow * lib/careadlinkat.c: Include idx.h, minmax.h. (readlink_stk): Avoid ptrdiff_t overflow in object allocation. diff --git a/lib/malloca.c b/lib/malloca.c index f4ee1563b..4077bf708 100644 --- a/lib/malloca.c +++ b/lib/malloca.c @@ -21,6 +21,8 @@ /* Specification. */ #include "malloca.h" =20 +#include "idx.h" +#include "intprops.h" #include "verify.h" =20 /* The speed critical point in this file is freea() applied to an alloca= () @@ -45,9 +47,9 @@ mmalloca (size_t n) #if HAVE_ALLOCA /* Allocate one more word, used to determine the address to pass to fr= eea(), and room for the alignment =E2=89=A1 sa_alignment_max mod 2*sa_alig= nment_max. */ - size_t nplus =3D n + sizeof (small_t) + 2 * sa_alignment_max - 1; - - if (nplus >=3D n) + int plus =3D sizeof (small_t) + 2 * sa_alignment_max - 1; + idx_t nplus; + if (!INT_ADD_WRAPV (n, plus, &nplus) && !xalloc_oversized (nplus, 1)) { char *mem =3D (char *) malloc (nplus); =20 diff --git a/modules/malloca b/modules/malloca index 9b7a3dbd2..346d33251 100644 --- a/modules/malloca +++ b/modules/malloca @@ -9,6 +9,8 @@ m4/eealloc.m4 =20 Depends-on: alloca-opt +idx +intprops stdint verify xalloc-oversized --=20 2.27.0