Skip to content

Commit

Permalink
Fix main program resolution.
Browse files Browse the repository at this point in the history
It seems with ASLR main program get a nonzero l_addr, but an empty
l_name.
  • Loading branch information
jrfonseca committed Mar 27, 2018
1 parent e3728fd commit fcb1153
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion memtrail.cpp
Expand Up @@ -163,6 +163,7 @@ _dladdr (const void *address, Dl_info *info) {

if (0) fprintf(stderr, "0x%lx:\n", addr);

assert(lm->l_prev == 0);
while (lm->l_prev) {
lm = lm->l_prev;
}
Expand All @@ -184,7 +185,11 @@ _dladdr (const void *address, Dl_info *info) {
#else
#error
#endif
l_name = lm->l_name;
}

assert(l_name != nullptr);
if (l_name[0] == 0 && lm == _r_debug.r_map) {
// Determine the absolute path to progname
if (progname[0] == 0) {
size_t len = readlink("/proc/self/exe", progname, sizeof progname - 1);
Expand All @@ -194,7 +199,6 @@ _dladdr (const void *address, Dl_info *info) {
}
progname[len] = 0;
}

l_name = progname;
}

Expand Down

0 comments on commit fcb1153

Please sign in to comment.