https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79524

--- Comment #18 from Christopher Albert <albert at tugraz dot at> ---
Created attachment 64103
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64103&action=edit
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.

Reply via email to