mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Skip entries with zero inode when parsing /proc/PID/maps
This also skips all entries that point to deleted files. PiperOrigin-RevId: 344244273 Change-Id: Ic47c6ab0dff4eaf4b4dea2779c45685922adc608
This commit is contained in:
parent
5001778443
commit
6587e571f1
|
@ -24,6 +24,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/match.h"
|
||||||
#include "absl/strings/str_cat.h"
|
#include "absl/strings/str_cat.h"
|
||||||
#include "libunwind-ptrace.h"
|
#include "libunwind-ptrace.h"
|
||||||
#include "sandboxed_api/sandbox2/comms.h"
|
#include "sandboxed_api/sandbox2/comms.h"
|
||||||
|
@ -185,20 +186,23 @@ std::vector<std::string> RunLibUnwindAndSymbolizer(pid_t pid,
|
||||||
addr_to_symbol[entry.end] = "";
|
addr_to_symbol[entry.end] = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool should_parse = entry.is_executable && !entry.path.empty() &&
|
if (!entry.is_executable ||
|
||||||
entry.path != "[vdso]" &&
|
entry.inode == 0 || // Only parse file-backed entries
|
||||||
entry.path != "[vsyscall]";
|
entry.path.empty() ||
|
||||||
if (should_parse) {
|
absl::EndsWith(entry.path, " (deleted)") // Skip deleted files
|
||||||
auto elf_or = ElfFile::ParseFromFile(entry.path, ElfFile::kLoadSymbols);
|
) {
|
||||||
if (!elf_or.ok()) {
|
|
||||||
SAPI_RAW_LOG(WARNING, "Could not load symbols for %s: %s", entry.path,
|
|
||||||
elf_or.status().message());
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto elf = std::move(elf_or).value();
|
|
||||||
|
|
||||||
for (const auto& symbol : elf.symbols()) {
|
auto elf = ElfFile::ParseFromFile(entry.path, ElfFile::kLoadSymbols);
|
||||||
if (elf.position_independent()) {
|
if (!elf.ok()) {
|
||||||
|
SAPI_RAW_LOG(WARNING, "Could not load symbols for %s: %s", entry.path,
|
||||||
|
elf.status().message());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& symbol : elf->symbols()) {
|
||||||
|
if (elf->position_independent()) {
|
||||||
if (symbol.address < entry.end - entry.start) {
|
if (symbol.address < entry.end - entry.start) {
|
||||||
addr_to_symbol[symbol.address + entry.start] = symbol.name;
|
addr_to_symbol[symbol.address + entry.start] = symbol.name;
|
||||||
}
|
}
|
||||||
|
@ -209,11 +213,10 @@ std::vector<std::string> RunLibUnwindAndSymbolizer(pid_t pid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::string> stack_trace;
|
std::vector<std::string> stack_trace;
|
||||||
stack_trace.reserve(ips->size());
|
stack_trace.reserve(ips->size());
|
||||||
// Symbolize stacktrace.
|
// Symbolize stacktrace
|
||||||
for (const auto& ip : *ips) {
|
for (const auto& ip : *ips) {
|
||||||
const std::string symbol =
|
const std::string symbol =
|
||||||
GetSymbolAt(addr_to_symbol, static_cast<uint64_t>(ip));
|
GetSymbolAt(addr_to_symbol, static_cast<uint64_t>(ip));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user