public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: libc-alpha@sourceware.org
Subject: Re: [PATCH v2 3/5] avoid -Wuse-after-free [BZ #26779]
Date: Mon, 24 Jan 2022 17:58:07 -0700	[thread overview]
Message-ID: <73343f8d-74b8-74a8-6097-c2c786c5423a@gmail.com> (raw)
In-Reply-To: <53f20975-a2c9-674d-2a43-b1b323ee545c@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1219 bytes --]

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
io/ftw.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
> 

[-- Attachment #2: glibc-26779-3.diff --]
[-- Type: text/x-patch, Size: 803 bytes --]

diff --git a/io/ftw.c b/io/ftw.c
index 2742541f36..08ccbdd523 100644
--- a/io/ftw.c
+++ b/io/ftw.c
@@ -323,8 +323,8 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
 	  buf[actsize++] = '\0';
 
 	  /* Shrink the buffer to what we actually need.  */
-	  data->dirstreams[data->actdir]->content = realloc (buf, actsize);
-	  if (data->dirstreams[data->actdir]->content == NULL)
+	  void *content = realloc (buf, actsize);
+	  if (content == NULL)
 	    {
 	      int save_err = errno;
 	      free (buf);
@@ -338,6 +338,7 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
 	      data->dirstreams[data->actdir]->streamfd = -1;
 	      data->dirstreams[data->actdir] = NULL;
 	    }
+	  data->dirstreams[data->actdir]->content = content;
 	}
     }
 

  parent reply	other threads:[~2022-01-25  0:58 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-16  0:21 [PATCH] " Martin Sebor
2022-01-16  2:25 ` Paul Eggert
2022-01-21 23:14   ` Martin Sebor
2022-01-22  0:42     ` Paul Eggert
2022-01-25  0:42       ` Martin Sebor
2022-01-25  1:08         ` Jeff Law
2022-01-18  9:48 ` Florian Weimer
2022-01-20 21:50   ` Martin Sebor
2022-01-25  0:52 ` [PATCH v2 0/5] " Martin Sebor
2022-01-25  0:57   ` [PATCH v2 1/5] " Martin Sebor
2022-01-25 17:46     ` Carlos O'Donell
2022-01-25  0:58   ` [PATCH v2 2/5] " Martin Sebor
2022-01-25 17:46     ` Carlos O'Donell
2022-01-25  0:58   ` Martin Sebor [this message]
2022-01-25 17:47     ` [PATCH v2 3/5] " Carlos O'Donell
2022-01-25  0:58   ` [PATCH v2 4/5] " Martin Sebor
2022-01-25 17:49     ` Carlos O'Donell
2022-01-25 17:51       ` Carlos O'Donell
2022-01-25 21:47         ` Florian Weimer
2022-01-26 13:55           ` Carlos O'Donell
2022-01-25  0:58   ` [PATCH v2 5/5] " Martin Sebor
2022-01-25 17:49     ` Carlos O'Donell
2022-01-25 22:50       ` [PATCH v3 " Martin Sebor
2022-01-26 14:56         ` Carlos O'Donell
2022-01-28 13:10           ` Joseph Myers
2022-01-28 17:33             ` Carlos O'Donell
2022-01-28 17:51               ` Joseph Myers
2022-01-28 23:21                 ` Jeff Law
2022-01-31 15:12                 ` Carlos O'Donell
2022-02-04 20:40                   ` Joseph Myers
2022-01-25 17:46   ` [PATCH v2 0/5] " Carlos O'Donell
2022-01-26  3:08     ` Martin Sebor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=73343f8d-74b8-74a8-6097-c2c786c5423a@gmail.com \
    --to=msebor@gmail.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).