[PATCH] PR fortran/99147 - Sanitizer detects heap-use-after-free in gfc_add_flavor

Paul Richard Thomas paul.richard.thomas@gmail.com
Fri Feb 19 08:34:40 GMT 2021


Hi Harald,

It looks 'obvious' to me too and is certainly OK for master.

Thanks

Paul


On Thu, 18 Feb 2021 at 21:30, Harald Anlauf via Fortran <fortran@gcc.gnu.org>
wrote:

> Dear all,
>
> the PR reports an issue detected with an ASAN instrumented compiler,
> which can also be verified with valgrind.  It appears that the state
> of gfc_new_block could be such that it should not be dereferenced.
> Reversing the order of condition evaluation helped.
>
> I failed to find out why this should happen, but then other places
> in the code put dereferences of gfc_new_block behind other checks.
> Simple things like initializing gfc_new_block with NULL in decl.c
> did not help.
>
> Regtested on x86_64-pc-linux-gnu.  No testcase added since the issue
> can be found only with an instrumented compiler or valgrind.
>
> I consider the patch to be obvious and trivial, but post it here
> in case somebody wants to dig deeper.
>
> OK for master?
>
> Thanks,
> Harald
>
>
> PR fortran/99147 - Sanitizer detects heap-use-after-free in gfc_add_flavor
>
> Reverse order of conditions to avoid invalid read.
>
> gcc/fortran/ChangeLog:
>
>         * symbol.c (gfc_add_flavor): Reverse order of conditions.
>
>

-- 
"If you can't explain it simply, you don't understand it well enough" -
Albert Einstein


More information about the Gcc-patches mailing list