Commit 66b8eddf authored by yonghong-song's avatar yonghong-song Committed by GitHub

Merge pull request #1377 from palmtenor/ksym_segfault

Avoid potential SEGFAULT when resolving Kernel symbols
parents 2e20494f 9c38f480
...@@ -61,21 +61,25 @@ void KSyms::refresh() { ...@@ -61,21 +61,25 @@ void KSyms::refresh() {
bool KSyms::resolve_addr(uint64_t addr, struct bcc_symbol *sym, bool demangle) { bool KSyms::resolve_addr(uint64_t addr, struct bcc_symbol *sym, bool demangle) {
refresh(); refresh();
if (syms_.empty()) { std::vector<Symbol>::iterator it;
sym->name = nullptr;
sym->demangle_name = nullptr; if (syms_.empty())
sym->module = nullptr; goto unknown_symbol;
sym->offset = 0x0;
return false; it = std::upper_bound(syms_.begin(), syms_.end(), Symbol("", addr));
if (it != syms_.begin()) {
it--;
sym->name = (*it).name.c_str();
if (demangle)
sym->demangle_name = sym->name;
sym->module = "kernel";
sym->offset = addr - (*it).addr;
return true;
} }
auto it = std::upper_bound(syms_.begin(), syms_.end(), Symbol("", addr)) - 1; unknown_symbol:
sym->name = (*it).name.c_str(); memset(sym, 0, sizeof(struct bcc_symbol));
if (demangle) return false;
sym->demangle_name = sym->name;
sym->module = "kernel";
sym->offset = addr - (*it).addr;
return true;
} }
bool KSyms::resolve_name(const char *_unused, const char *name, bool KSyms::resolve_name(const char *_unused, const char *name,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment