public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug build/26779] benign use after realloc at localealias.c:329
Date: Fri, 23 Oct 2020 21:14:36 +0000	[thread overview]
Message-ID: <bug-26779-131-TUEcO7heO4@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-26779-131@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=26779

--- Comment #1 from Martin Sebor <msebor at gmail dot com> ---
Another instance of the same idiom that triggers the new warning is in
setenv.c:

setenv.c: In function ‘__add_to_environ’:
setenv.c:162:10: warning: statement uses a freed pointer [-Wuse-after-free=]
  162 |       if (__environ != last_environ)
      |          ^
setenv.c:154:31: note: freed by ‘realloc’ here
  154 |       new_environ = (char **) realloc (last_environ,
      |                               ^~~~~~~~~~~~~~~~~~~~~~
  155 |                                        (size + 2) * sizeof (char *));
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The code:

      /* We allocated this space; we can extend it.  */
      new_environ = (char **) realloc (last_environ,
                                       (size + 2) * sizeof (char *));
      if (new_environ == NULL)
        {
          UNLOCK;
          return -1;
        }

      if (__environ != last_environ)
        memcpy ((char *) new_environ, (char *) __environ,
                size * sizeof (char *));

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  reply	other threads:[~2020-10-23 21:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-23 17:12 [Bug build/26779] New: " msebor at gmail dot com
2020-10-23 21:14 ` msebor at gmail dot com [this message]
2020-10-27 21:21 ` [Bug build/26779] " msebor at gmail dot com
2020-10-27 21:41 ` msebor at gmail dot com
2022-01-12 17:16 ` msebor at gmail dot com
2022-01-12 17:20 ` msebor at gmail dot com
2022-01-14  0:28 ` msebor at gmail dot com
2022-01-26 17:43 ` msebor at gmail dot com
2022-01-26 20:24 ` carlos at redhat dot com
2022-02-09 14:05 ` vvinayag at arm dot com
2022-02-09 14:59 ` schwab@linux-m68k.org
2022-02-09 16:13 ` vvinayag at arm dot com
2024-01-11  9:33 ` fweimer at redhat dot com

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=bug-26779-131-TUEcO7heO4@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@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).