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-Status: No, score=-4.5 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=unavailable 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 16E6A1F4B4 for ; Wed, 30 Dec 2020 03:39:24 +0000 (UTC) Received: from localhost ([::1]:51876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kuSKZ-0007Yc-7G for normalperson@yhbt.net; Tue, 29 Dec 2020 22:39:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kuSKW-0007YD-6c for bug-gnulib@gnu.org; Tue, 29 Dec 2020 22:39:20 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:45056) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kuSKT-0004E0-Ev for bug-gnulib@gnu.org; Tue, 29 Dec 2020 22:39:19 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 427D21600F7; Tue, 29 Dec 2020 19:39:15 -0800 (PST) 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 74qRFmZ8OZtb; Tue, 29 Dec 2020 19:39:14 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 1F0CB1600F8; Tue, 29 Dec 2020 19:39:14 -0800 (PST) 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 R5AMWQ6RN-JT; Tue, 29 Dec 2020 19:39:14 -0800 (PST) Received: from [192.168.1.9] (cpe-23-243-218-95.socal.res.rr.com [23.243.218.95]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id E470E1600F7; Tue, 29 Dec 2020 19:39:13 -0800 (PST) Subject: Re: [PATCH v3 4/6] stdlib: Sync canonicalize with gnulib [BZ #10635] [BZ #26592] [BZ #26341] [BZ #24970] From: Paul Eggert To: Adhemerval Zanella References: <20201229193454.34558-1-adhemerval.zanella@linaro.org> <20201229193454.34558-5-adhemerval.zanella@linaro.org> Organization: UCLA Computer Science Department Message-ID: <7644672f-434b-be1c-c8f0-288d038b018b@cs.ucla.edu> Date: Tue, 29 Dec 2020 19:39:13 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------CDA4D2B31550D6747C39EF1A" Content-Language: en-US Received-SPF: pass client-ip=131.179.128.68; envelope-from=eggert@cs.ucla.edu; helo=zimbra.cs.ucla.edu X-Spam_score_int: -52 X-Spam_score: -5.3 X-Spam_bar: ----- X-Spam_report: (-5.3 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-1.07, 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: libc-alpha@sourceware.org, bug-gnulib@gnu.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" This is a multi-part message in MIME format. --------------CDA4D2B31550D6747C39EF1A Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 12/29/20 5:21 PM, Paul Eggert wrote: > I installed the attached patch into Gnulib to fix the bug in a way I > hope is better. Unfortunately that patch didn't correctly treat size-calculation overflow like other out-of-memory situations. I installed the attached further patch into Gnulib. --------------CDA4D2B31550D6747C39EF1A Content-Type: text/x-patch; charset=UTF-8; name="0001-canonicalize-fix-size-overflow-treatment.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-canonicalize-fix-size-overflow-treatment.patch" >From 649e713c1e5452204253cb1029ea22c1b6effa2e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 29 Dec 2020 19:34:59 -0800 Subject: [PATCH] canonicalize: fix size overflow treatment This also has some minor cleanups. * lib/canonicalize-lgpl.c, lib/canonicalize.c: No need to include stddef.h, since the code no longer refers directly to ptrdiff_t. * lib/canonicalize-lgpl.c (realpath_stk): * lib/canonicalize.c (canonicalize_filename_mode_stk): Treat size overflow like other out-of-memory. * lib/canonicalize.c: No need to include stdlib.h, since the code no longer refers to stdlib.h functions (other than those that canonicalize.h must declare). * lib/canonicalize.c (canonicalize_filename_mode_stk): Do not bother terminating the string result on error. --- ChangeLog | 15 +++++++++++++++ lib/canonicalize-lgpl.c | 6 +----- lib/canonicalize.c | 9 ++------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index cca14c910..2af7a42c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2020-12-29 Paul Eggert + + canonicalize: fix size overflow treatment + This also has some minor cleanups. + * lib/canonicalize-lgpl.c, lib/canonicalize.c: No need to include + stddef.h, since the code no longer refers directly to ptrdiff_t. + * lib/canonicalize-lgpl.c (realpath_stk): + * lib/canonicalize.c (canonicalize_filename_mode_stk): + Treat size overflow like other out-of-memory. + * lib/canonicalize.c: No need to include stdlib.h, since + the code no longer refers to stdlib.h functions (other + than those that canonicalize.h must declare). + * lib/canonicalize.c (canonicalize_filename_mode_stk): + Do not bother terminating the string result on error. + 2020-12-29 Bruno Haible list-c++, [o]map-c++, [o]set-c++: Fix conflict with 'free-posix' module. diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c index e8b10f0e7..01b06322d 100644 --- a/lib/canonicalize-lgpl.c +++ b/lib/canonicalize-lgpl.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -345,10 +344,7 @@ realpath_stk (const char *name, char *resolved, end_idx = end - extra_buf; size_t len = strlen (end); if (NARROW_ADDRESSES && INT_ADD_OVERFLOW (len, n)) - { - __set_errno (ENOMEM); - goto error; - } + goto error_nomem; while (extra_buffer.length <= len + n) { if (!scratch_buffer_grow_preserve (&extra_buffer)) diff --git a/lib/canonicalize.c b/lib/canonicalize.c index eee3dbee6..26066831c 100644 --- a/lib/canonicalize.c +++ b/lib/canonicalize.c @@ -21,8 +21,6 @@ #include #include #include -#include -#include #include #include #include @@ -396,10 +394,7 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode, end_idx = end - extra_buf; size_t len = strlen (end); if (NARROW_ADDRESSES && INT_ADD_OVERFLOW (len, n)) - { - errno = ENOMEM; - goto error; - } + xalloc_die (); while (extra_buffer.length <= len + n) { if (!scratch_buffer_grow_preserve (&extra_buffer)) @@ -461,7 +456,6 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode, failed = false; error: - *dest++ = '\0'; if (ht) hash_free (ht); scratch_buffer_free (&extra_buffer); @@ -473,6 +467,7 @@ error: return NULL; } + *dest++ = '\0'; char *result = scratch_buffer_dupfree (rname_buf, dest - rname); if (!result) xalloc_die (); -- 2.27.0 --------------CDA4D2B31550D6747C39EF1A--