mirror of https://github.com/OISF/suricata
suricata: bound stack trace formatting in signal handler
The crash handler built its stack trace by advancing a pointer with the snprintf return value. That value is the length the output would have had, not what was written, so once the trace filled msg the pointer moved past the end of the buffer. Every size argument after that, SC_LOG_MAX_LOG_MSG_LEN - (temp - msg), was negative and converted to a huge size_t, and snprintf went on writing into the stack past msg. With a deep enough stack the handler faults before it can log the crash it exists to report. The frame name lookup also compared unw_get_proc_name() against UNW_ENOMEM, but libunwind returns the negated code, so the test never fired. A lookup that failed with UNW_ENOINFO fell through to the success branch and printed the name buffer, which libunwind had not written. Track space used with offset and use that on each snprintf call. Advance by MIN(cw, remaining - 1) to prevent overruns. The loop stops when the buffer is full and closes the trace with "..." so a clipped message is not read as a whole stack. Failed symbol lookups now print "[unknown]:". -UNW_ENOMEM is not one of them, since libunwind returns a truncated but usable name with it. name starts as "?" so nothing is printed from it either way. Ticket: 8846pull/16148/head
parent
9b491a131e
commit
cd7f7751d5
Loading…
Reference in New Issue