From 262c656bcb5403cd5f8058902c5346e64909cfb9 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 31 Oct 2019 18:39:45 +0100 Subject: [PATCH] Fix overflow in backtrace --- libsrc/core/exception.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libsrc/core/exception.cpp b/libsrc/core/exception.cpp index 93e0e7e9..49594bd1 100644 --- a/libsrc/core/exception.cpp +++ b/libsrc/core/exception.cpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace ngcore { @@ -104,11 +105,11 @@ namespace ngcore if(!funcname.empty()) { - std::array buffer; + std::vector buffer(10240); int status; size_t size = buffer.size(); - abi::__cxa_demangle(funcname.c_str(), buffer.data(), &size, &status); - out << "in " << yellow << buffer.data() << reset_shell << '\n'; + abi::__cxa_demangle(funcname.c_str(), &buffer[0], &size, &status); + out << "in " << yellow << &buffer[0] << reset_shell << '\n'; std::string nm_command = "nm " + libname + " | grep " + funcname + " | cut -f 1 -d ' '"; std::string output; @@ -145,12 +146,12 @@ namespace ngcore { std::cerr << "Collecting backtrace..." << std::endl; std::stringstream result; - void *bt[1024]; + void *bt[100]; int bt_size; char **bt_syms; int i; - bt_size = backtrace(bt, 1024); + bt_size = backtrace(bt, 100); bt_syms = backtrace_symbols(bt, bt_size); Dl_info info; for (i = 1; i < bt_size-1; i++)