Skip to content

Commit

Permalink
stacktrace: Remove dangerous value access
Browse files Browse the repository at this point in the history
dlip.dli_fname could be NULL.
So add null check before use this value.

Signed-off-by: Bojun Seo <bojun.seo.0@gmail.com>
  • Loading branch information
Bojun-Seo committed Mar 17, 2023
1 parent 9cc0413 commit f97b9b0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/stacktrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,14 @@ static void print_backtrace_symbol(int count, void *addr)
}
offset = static_cast<int>(static_cast<int *>(addr) -
static_cast<int *>(dlip.dli_saddr));
pr_out("%s +%#x ", symbol, offset);
pr_out("%s +%#x", symbol, offset);
free(symbol);
}
offset = (int)((char *)addr - (char *)(dlip.dli_fbase));
pr_out("(%s +%#x)\n", dlip.dli_fname, offset);
if (dlip.dli_fname) {
offset = (int)((char *)addr - (char *)(dlip.dli_fbase));
pr_out(" (%s +%#x)", dlip.dli_fname, offset);
}
pr_out("\n");
}

static void print_backtrace_symbol_flamegraph(void *addr, const char *semicolon)
Expand Down

0 comments on commit f97b9b0

Please sign in to comment.