https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79524
Mikael Morin <mikael at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mikael at gcc dot gnu.org
--- Comment #20 from Mikael Morin <mikael at gcc dot gnu.org> ---
(In reply to Christopher Albert from comment #18)
> Created attachment 64103 [details]
> Proposed patch: fix heap-use-after-free in resolve_charlen
>
> Patch to fix the heap-use-after-free / segfault in resolve_charlen (PR79524).
>
> When a rejected declaration leaves a charlen on the namespace cl_list whose
> length expression references a freed symtree, resolve_charlen crashes
> dereferencing the dangling pointer.
>
> The fix adds a recursive walk of the charlen expression to detect any
> sub-expression whose symtree is no longer in the namespace BBT. This
> covers both simple cases (character(n)) and compound expressions
> (character(n+1), character(2*n), etc.).
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu, no regressions.
> Also verified clean under valgrind.
I'm a bit afraid of the performance of this.
For every namespace, and for every charlen in the namespace, and for every
symbol appearing in the charlen expr, we are going to walk the full symbol tree
of the namespace, right?
There shouldn't be any dangling charlen in the first place.
The list of charlen used to be cleaned up on statement rejection, but that was
removed in r7-5263-gd0803c0cf815ee for reasons that I don't remember.