linker: stat /proc/self/exe instead of executable_path
The absolute path to an executable may no longer be valid for
example when the file is unlinked immediately after exec.
Using /proc/self/exe instead of absolute path solves this problem.
Bug: http://b/31084669
Test: Run the app from http://b/31084669 make sure executable starts
Test: by checking ps and /proc/<pid>/exe
Change-Id: I5c819f39ef0fc4fc71b05de71e8af9ede611f04c
(cherry picked from commit 7da4bbbe87
)
This commit is contained in:
parent
0e99e40892
commit
f4e3ebe1e3
|
@ -3394,12 +3394,15 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
|
|||
}
|
||||
}
|
||||
|
||||
const char* executable_path = get_executable_path();
|
||||
struct stat file_stat;
|
||||
if (TEMP_FAILURE_RETRY(stat(executable_path, &file_stat)) != 0) {
|
||||
__libc_fatal("unable to stat file for the executable \"%s\": %s", executable_path, strerror(errno));
|
||||
// Stat "/proc/self/exe" instead of executable_path because
|
||||
// the executable could be unlinked by this point and it should
|
||||
// not cause a crash (see http://b/31084669)
|
||||
if (TEMP_FAILURE_RETRY(stat("/proc/self/exe", &file_stat)) != 0) {
|
||||
__libc_fatal("unable to stat \"/proc/self/exe\": %s", strerror(errno));
|
||||
}
|
||||
|
||||
const char* executable_path = get_executable_path();
|
||||
soinfo* si = soinfo_alloc(&g_default_namespace, executable_path, &file_stat, 0, RTLD_GLOBAL);
|
||||
if (si == nullptr) {
|
||||
__libc_fatal("Couldn't allocate soinfo: out of memory?");
|
||||
|
|
Loading…
Reference in New Issue