[Wien] crash in tetra -enefile
Pavel Ondračka
pavel.ondracka at email.cz
Mon Nov 12 13:09:58 CET 2018
Dear Wien2k mailing list,
there is a small bug in tetra -enefile which could occasionally result
in a crash like this:
x tetra -enefile
Program received signal SIGSEGV: Segmentation fault - invalid memory
reference.
Backtrace for this error:
Segmentation fault (core dumped)
0.023u 0.389s 0:00.56 71.4% 0+0k 0+216io 0pf+0w
This is an uninitialized variable problem (here reproducible with
gfortran 8.2.1 and with the right star alignment due to the dependence
on random uninitialized memory)
The crash happens at tetra.f:464
tetra.f:462 if(nnsum_dos.gt.0) then
tetra.f:463 do i=1,nnsum_dos
tetra.f:464 WRITE(6,1176)
i,(isumdos(i,i1),i1=1,nnsum_dos_max)
with out of bound read of isumdos, (I don't have any SUM in my int
file) hence the "if(nnsum_dos.gt.0)" should be false, but nnsum_dos is
unitialized at this point.
valgrind:
==30563== Conditional jump or move depends on uninitialised value(s)
==30563== at 0x40A38E: MAIN__ (tetra.f:462)
==30563== by 0x40B3B3: main (tetra.f:6)
(gdb) print nnsum_dos
$1 = 528
The variable is supposed to be set here:
tetra.f:256 nnsum_dos=0
tetra.f:257 read(5,'(a)',end=91) system
tetra.f:258 if(system(1:3).ne.'SUM') goto 91
tetra.f:259 read(system(5:70),*,ERR=91,END=91)
nnsum_dos,nnsum_dos_max
however the entire block is skipped with -enefile due to
tetra.f:216 if(enefile) goto 200
which jumps to
tetra.f:343 200 CONTINUE
The solution is to zero-initialize the nnsum_dos variable earlier
(before the goto 200 jump or at the file beginning).
While the crash looks scary, it is likely harmless since it crashes
almost at the end where all important data should be written anyway,
reporting nevertheless.
Best regards
Pavel
More information about the Wien
mailing list