Skip to content

Commit 8c72423

Browse files
committedMay 28, 2014
[Sanitizer] Always prefer cached contents of /proc/self/exe if it's available
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@209773 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent dfa76ad commit 8c72423

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed
 

Diff for: ‎lib/sanitizer_common/sanitizer_linux.cc

+12-13
Original file line numberDiff line numberDiff line change
@@ -667,24 +667,23 @@ static char proc_self_exe_cache_str[kMaxPathLength];
667667
static uptr proc_self_exe_cache_len = 0;
668668

669669
uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) {
670+
if (proc_self_exe_cache_len > 0) {
671+
// If available, use the cached module name.
672+
uptr module_name_len =
673+
internal_snprintf(buf, buf_len, "%s", proc_self_exe_cache_str);
674+
CHECK_LT(module_name_len, buf_len);
675+
return module_name_len;
676+
}
670677
uptr module_name_len = internal_readlink(
671678
"/proc/self/exe", buf, buf_len);
672679
int readlink_error;
673680
if (internal_iserror(module_name_len, &readlink_error)) {
674-
if (proc_self_exe_cache_len) {
675-
// If available, use the cached module name.
676-
CHECK_LE(proc_self_exe_cache_len, buf_len);
677-
internal_strncpy(buf, proc_self_exe_cache_str, buf_len);
678-
module_name_len = internal_strlen(proc_self_exe_cache_str);
679-
} else {
680-
// We can't read /proc/self/exe for some reason, assume the name of the
681-
// binary is unknown.
682-
Report("WARNING: readlink(\"/proc/self/exe\") failed with errno %d, "
683-
"some stack frames may not be symbolized\n", readlink_error);
684-
module_name_len = internal_snprintf(buf, buf_len, "/proc/self/exe");
685-
}
681+
// We can't read /proc/self/exe for some reason, assume the name of the
682+
// binary is unknown.
683+
Report("WARNING: readlink(\"/proc/self/exe\") failed with errno %d, "
684+
"some stack frames may not be symbolized\n", readlink_error);
685+
module_name_len = internal_snprintf(buf, buf_len, "/proc/self/exe");
686686
CHECK_LT(module_name_len, buf_len);
687-
buf[module_name_len] = '\0';
688687
}
689688
return module_name_len;
690689
}

0 commit comments

Comments
 (0)