trig2disk segmentation fault and out-of-bound array indexes in sacputaway.c
Recently we are detecting that trig2disk dies due to segmentation fault.
Investigating in depth I discovered that this mainly depends on 2 causes:
- the triggers message exceeds the number of SCNLs allowed in
DB_MAX_PHS_PER_EQ, equal to 1000 at moment [earthworm_defs.h]. (Our production Earthworm configuration currently handles 3200 channels.) - the handling of exceeding the maximum possible index of the
FileListarray insacputaway.cis incorrect
Details below.
trig2disk version:
trig2disk: version 1.0.8 2023-09-18
gdb backtrace:
b443d20ae789-hew:/opt/ew_env/params $ gdb /opt/earthworm/bin/trig2disk $EW_PARAMS/core
GNU gdb (Debian 10.1-1.7) 10.1.90.20210103-git
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /opt/earthworm/bin/trig2disk...
warning: Can't open file /SYSV00000410 (deleted) during file-backed mapping note processing
warning: Can't open file /SYSV000007cf (deleted) during file-backed mapping note processing
[New LWP 8620]
[New LWP 8618]
[New LWP 8619]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `trig2disk out/trig2disk.d'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x000056109407e4a0 in SACPABase_end_scnl () at sacputaway.c:1258
1258 FileList[FileIndex].sort_param = SAC_starttime;
[Current thread is 1 (Thread 0x7f05a1ed1700 (LWP 8620))]
(gdb) bt
#0 0x000056109407e4a0 in SACPABase_end_scnl () at sacputaway.c:1258
#1 0x000056109407c308 in SACPA_next (getThis=0x7f05a39f7230, GapThresh=1.5, OutBufferLen=262776, debug=0) at sacputaway.c:375
#2 0x0000561094078005 in PA_next (getThis=0x7f05a39f7230, FormatInd=1, GapThresh=1.5, OutBufferLen=262776, debug=0) at putaway.c:438
#3 0x000056109406c371 in SnippetMaker (dummy=0x0) at trig2disk.c:1534
#4 0x00007f05a3e82ea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
#5 0x00007f05a3d72a2f in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#6 0x0000000000000000 in ?? ()
quit)
sacputaway source line where segmentation fault occurs:
/* Update SAC file list with file name and arrival time */
sprintf (FileList[FileIndex].filename, "%s.%s.%s.%s", SAC_szSta, SAC_szChan,
SAC_szNet, SAC_szLoc);
FileList[FileIndex].sort_param = SAC_starttime;
if ((FileIndex = FileIndex + 1) > DB_MAX_PHS_PER_EQ)
{
logit ("e", "SACPABase_end_scnl: WARNING: Maximum number of phases per "
"event (%d) exceeded.\n", DB_MAX_PHS_PER_EQ);
FileIndex = FileIndex - 1;
}