From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4C294385C019 for ; Tue, 25 Jan 2022 17:46:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C294385C019 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-632-TyLmIKAIN1e_PiMBn487vw-1; Tue, 25 Jan 2022 12:46:56 -0500 X-MC-Unique: TyLmIKAIN1e_PiMBn487vw-1 Received: by mail-qt1-f198.google.com with SMTP id 4-20020ac85744000000b002b2f329efc2so12553961qtx.12 for ; Tue, 25 Jan 2022 09:46:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:organization:in-reply-to :content-transfer-encoding; bh=k0Wdc6oubceio3ZKNM4QebGCsOOYYduGapMugUfKoAs=; b=E31D/xchlgAsCUtEjiy6L0k0C0wPl6nlWcvan94R79VMeADtLTfz3MqSfd5VH5n8uV 19e8rz5FVJkmN8CTQMfYMcvKznsjbAqK8lOe06IKyUuGE1j8Qp1s6QS5Tqbem2GHdsQ2 WuzmdUNlXqg8xzpU2HQcOIWQWvIN17frL6tl9HgEqSfzMUuokRt4BP8ksnbwiHvsFb6J P65Ac/eLd/dNi+ZK4frAWlymvViU9le0el21Z60RbMDbWYARrGpBBG4ovPqw82xz/MWP VXT4RUarYocJxSH2w5X5my73z4l0i7jMNVsKdpqiQlvTvmT3t0sxdLt0apSAnT1T3exQ oZbQ== X-Gm-Message-State: AOAM53309gf3H0uTzL8NkXlHLQhjBfpwsMtA24+053Hp8Pzbv4CtZY7u xgvltbn7I+NpzfO4D5eSRtLGHVu4T/xha5VzLCa7E+Q77WOgkzemIWzS6W/tm5/snwofg8nYMBw lY4hAlqf5oijHnZhMKt/n X-Received: by 2002:a37:852:: with SMTP id 79mr1893192qki.131.1643132816079; Tue, 25 Jan 2022 09:46:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxXZ1CnSbC3EF7jWO9lBi0/UIlCDY49xNB0PqWOsHZavqs3WNywvIi7RBd5m1mLYUNBz54ZOQ== X-Received: by 2002:a37:852:: with SMTP id 79mr1893179qki.131.1643132815866; Tue, 25 Jan 2022 09:46:55 -0800 (PST) Received: from [192.168.0.241] (135-23-175-80.cpe.pppoe.ca. [135.23.175.80]) by smtp.gmail.com with ESMTPSA id s4sm9913512qko.113.2022.01.25.09.46.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Jan 2022 09:46:55 -0800 (PST) Message-ID: <9832af8d-9d0d-d7bf-cd8b-91b73b6634df@redhat.com> Date: Tue, 25 Jan 2022 12:46:54 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v2 2/5] avoid -Wuse-after-free [BZ #26779] To: Martin Sebor , libc-alpha@sourceware.org References: <53f20975-a2c9-674d-2a43-b1b323ee545c@gmail.com> From: Carlos O'Donell Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jan 2022 17:47:00 -0000 On 1/24/22 19:58, Martin Sebor via Libc-alpha wrote: > On 1/24/22 17:52, Martin Sebor wrote: >> This is a repost of the original patch but broken down by source >> file and with some suppression done by #pragma GCC diagnostic >> instead of conversion to intptr_t.  It also adds fixes for >> the same problem in the test suite that I overlooked before. > > The attached patch suppresses the -Wuse-after-free instance in > intl/localealias.c. > >> >> On 1/15/22 17:21, Martin Sebor wrote: >>> GCC 12 features a couple of new warnings designed to detect uses >>> of pointers made invalid by the pointees lifetimes having ended. >>> Building Glibc with the enhanced GCC exposes a few such uses, >>> mostly after successful calls to realloc.  The attached patch >>> avoids the new warnings by converting the pointers to uintptr_t >>> first and using the converted integers instead. >>> >>> The patch suppresses all instances of the warning at the strictest >>> setting (-Wuse-after-free=3), which includes even uses in equality >>> expressions.  The default setting approved for GCC 12 is >>> -Wuse-after-free=2, which doesn't warn on such uses to accommodate >>> the pointer-adjustment-after-realloc idiom.  At the default setting, >>> the changes to ldconfig.c and setenv are not necessary. >>> >>> Martin >> OK for glibc 2.35, please push this commit. This file is shared with GNU Gettext, and the upstream gettext code still uses pointers into the reallocated block. Expected commit message (three lines): ~~~ intl: Avoid -Wuse-after-free [BZ #26779] Reviewed-by: Carlos O'Donell ~~~ Reviewed-by: Carlos O'Donell > diff --git a/intl/localealias.c b/intl/localealias.c > index 3ae360f40d..b36092363a 100644 > --- a/intl/localealias.c > +++ b/intl/localealias.c > @@ -318,7 +318,15 @@ read_alias_file (const char *fname, int fname_len) > > if (string_space_act + alias_len + value_len > string_space_max) > { > - /* Increase size of memory pool. */ > +#pragma GCC diagnostic push > + > +#if defined __GNUC__ && __GNUC__ >= 12 > + /* Suppress the valid GCC 12 warning until the code below is changed > + to avoid using pointers to the reallocated block. */ > +# pragma GCC diagnostic ignored "-Wuse-after-free" > +#endif OK. Need to use general pragma because this is shared with upstream GNU Gettext. > + > + /* Increase size of memory pool. */ > size_t new_size = (string_space_max > + (alias_len + value_len > 1024 > ? alias_len + value_len : 1024)); > @@ -351,6 +359,8 @@ read_alias_file (const char *fname, int fname_len) > value, value_len); > string_space_act += value_len; > > +#pragma GCC diagnostic pop OK. > + > ++nmap; > ++added; > } -- Cheers, Carlos.