public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug build/26779] New: benign use after realloc at localealias.c:329
@ 2020-10-23 17:12 msebor at gmail dot com
  2020-10-23 21:14 ` [Bug build/26779] " msebor at gmail dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: msebor at gmail dot com @ 2020-10-23 17:12 UTC (permalink / raw)
  To: glibc-bugs

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

            Bug ID: 26779
           Summary: benign use after realloc at localealias.c:329
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: build
          Assignee: unassigned at sourceware dot org
          Reporter: msebor at gmail dot com
                CC: carlos at redhat dot com
  Target Milestone: ---

Testing a GCC 11 enhancement to detect invalid uses of freed pointers exposes
the following (benign) bug in localealias.  A successful call to realloc
renders its argument indeterminate, even when it doesn't result in moving the
object.  The affected code uses the indeterminate pointer to detect whether the
call resulted in moving the object.  Converting the pointers to intptr_t and
performing the equality test on those avoids the warning.

                      char *new_pool = (char *) realloc (string_space,
new_size);
                      if (new_pool == NULL)
                        goto out;

                      if (__builtin_expect (string_space != new_pool, 0))

and the warning is:

localealias.c: In function ‘read_alias_file’:
localealias.c:329:58: warning: statement uses a freed pointer
[-Wuse-after-free=]
  329 |                       if (__builtin_expect (string_space != new_pool,
0))
      |                                             ~~~~~~~~~~~~~^~~~~~~~~~~
localealias.c:325:49: note: freed by ‘realloc’ here
  325 |                       char *new_pool = (char *) realloc (string_space,
new_size);
      |                                                
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
localealias.c:329:26: warning: statement uses a freed pointer
[-Wuse-after-free=]
  329 |                       if (__builtin_expect (string_space != new_pool,
0))
      |                          ^
localealias.c:325:49: note: freed by ‘realloc’ here
  325 |                       char *new_pool = (char *) realloc (string_space,
new_size);
      |                                                
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-01-11  9:33 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-23 17:12 [Bug build/26779] New: benign use after realloc at localealias.c:329 msebor at gmail dot com
2020-10-23 21:14 ` [Bug build/26779] " msebor at gmail dot com
2020-10-27 21:21 ` 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

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).