[Bug tree-optimization/110501] Invalid use-after-free / realloc with a store/load happening

2023-10-31 Thread jhb at FreeBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110501

John Baldwin  changed:

   What|Removed |Added

 CC||jhb at FreeBSD dot org

--- Comment #7 from John Baldwin  ---
I believe I am hitting this same issue using GCC 13 to compile FreeBSD's
userland. (I looked through several of the other bugs for the Wuse-after-free
metabug and this one seems the closest to what I'm encountering).  The code in
question does not trigger the -Wuse-after-free warning when using GCC 12, but
now triggers the warning with GCC 13.  It is just calling free on the old value
after realloc fails which should be safe.  The simplest version I've
encountered so far in FreeBSD's tree is this:

static int
group_resize(void)
{
char *buf;

if (gbufsize == 0)
gbufsize = 1024;
else
gbufsize *= 2;

buf = gbuffer;
gbuffer = realloc(buf, gbufsize);
if (gbuffer == NULL) {
free(buf);
gbufsize = 0;
return (ENOMEM);
}
memset(gbuffer, 0, gbufsize);

return (0);
}

The warning triggers on the call to free:

lib/libcasper/services/cap_grp/cap_grp.c: In function 'group_resize':
lib/libcasper/services/cap_grp/cap_grp.c:65:17: error: pointer 'buf' may be
used after 'realloc' [-Werror=use-after-free]
   65 | free(buf);
  | ^
lib/libcasper/services/cap_grp/cap_grp.c:63:19: note: call to 'realloc'
here
   63 | gbuffer = realloc(buf, gbufsize);
  |   ^~

[Bug tree-optimization/110501] Invalid use-after-free / realloc with a store/load happening

2023-07-06 Thread cheyenne.wills at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110501

--- Comment #6 from Cheyenne Wills  ---
Just another bit of information.

Specifying just -Werror=use-after-free appears to be not not enough to trigger
the problem.  Using -Wall however does trigger the problem.

(tried on gcc-12 and gcc-13)

[Bug tree-optimization/110501] Invalid use-after-free / realloc with a store/load happening

2023-07-03 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110501

Richard Biener  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2023-07-03
 Ever confirmed|0   |1

--- Comment #5 from Richard Biener  ---
So confirmed.

[Bug tree-optimization/110501] Invalid use-after-free / realloc with a store/load happening

2023-06-30 Thread cheyenne.wills at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110501

--- Comment #4 from Cheyenne Wills  ---
(In reply to Andrew Pinski from comment #3)
> Oh GCC warns even with optimizations turned on ...

Correct.  For gcc-12 the failure only occurs with -O0.  With gcc-13 (and
later), the problem occurs with or without optimization.

[Bug tree-optimization/110501] Invalid use-after-free / realloc with a store/load happening

2023-06-30 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110501

--- Comment #3 from Andrew Pinski  ---
Oh GCC warns even with optimizations turned on ...