From ff27656533e47a4d062100f8b6c0c3ff1ede5097 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 30 May 2020 14:23:29 +0200 Subject: [PATCH] Backport some fixes from libbacktrace upstream repo. --- libbacktrace/elf.cpp | 3 +++ libbacktrace/posix.cpp | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libbacktrace/elf.cpp b/libbacktrace/elf.cpp index 700be542..459e13d7 100644 --- a/libbacktrace/elf.cpp +++ b/libbacktrace/elf.cpp @@ -2789,6 +2789,9 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor, backtrace_release_view (state, &shdr_view, error_callback, data); } + if (shnum == 0 || shstrndx == 0) + goto fail; + /* To translate PC to file/line when using DWARF, we need to find the .debug_info and .debug_line sections. */ diff --git a/libbacktrace/posix.cpp b/libbacktrace/posix.cpp index fd364b89..da6e56be 100644 --- a/libbacktrace/posix.cpp +++ b/libbacktrace/posix.cpp @@ -70,7 +70,11 @@ backtrace_open (const char *filename, backtrace_error_callback error_callback, descriptor = open (filename, (int) (O_RDONLY | O_BINARY | O_CLOEXEC)); if (descriptor < 0) { - if (does_not_exist != NULL && errno == ENOENT) + /* If DOES_NOT_EXIST is not NULL, then don't call ERROR_CALLBACK + if the file does not exist. We treat lacking permission to + open the file as the file not existing; this case arises when + running the libgo syscall package tests as root. */ + if (does_not_exist != NULL && (errno == ENOENT || errno == EACCES)) *does_not_exist = 1; else error_callback (data, filename, errno);