[gcc r17-3389] fortran: [PR126816] Fix use-after-free of charlen from rejected trial
Jerry DeLisle via Gcc-cvs <[email protected]>
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:0a59650d1ec84d0e155670ef5ae226e4c59ba748 commit r17-3389-g0a59650d1ec84d0e155670ef5ae226e4c59ba748 Author: Jerry DeLisle <[email protected]> Date: Tue Aug 18 09:46:21 2026 -0700 fortran: [PR126816] Fix use-after-free of charlen from rejected trial restore_old_symbol reverted only ts.type/ts.kind when undoing a tentative symbol change, leaving ts.u.cl pointing at whatever charlen the rejected trial had allocated via gfc_set_default_type. Restore the whole typespec instead. PR fortran/126816 gcc/fortran/ChangeLog: * symbol.cc (restore_old_symbol): Restore the whole typespec instead of just type and kind. Diff: --- gcc/fortran/symbol.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc index dde3e92a33d3..57e3daa5767a 100644 --- a/gcc/fortran/symbol.cc +++ b/gcc/fortran/symbol.cc @@ -3817,8 +3817,9 @@ restore_old_symbol (gfc_symbol *p) p->mark = 0; old = p->old_symbol; - p->ts.type = old->ts.type; - p->ts.kind = old->ts.kind; + /* Restore the whole typespec, not just type/kind, so ts.u.cl doesn't + dangle. */ + p->ts = old->ts; p->attr = old->attr;