mcexec: readlink and use full path for reexec
This fixes comm on linux side, showing mcexec instead of 'exe' Change-Id: I9345d7a23dccb36b3a1e17fd3e7491eaeca54e5b
This commit is contained in:
committed by
Masamichi Takagi
parent
b70d470e20
commit
9b77630c8b
@ -1325,6 +1325,7 @@ static int reduce_stack(struct rlimit *orig_rlim, char *argv[])
|
||||
{
|
||||
int n;
|
||||
char newval[40];
|
||||
char path[1024];
|
||||
int error;
|
||||
struct rlimit new_rlim;
|
||||
|
||||
@ -1356,7 +1357,17 @@ static int reduce_stack(struct rlimit *orig_rlim, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
execv("/proc/self/exe", argv);
|
||||
error = readlink("/proc/self/exe", path, sizeof(path));
|
||||
if (error < 0) {
|
||||
__eprintf("Could not readlink /proc/self/exe? %m\n");
|
||||
return 1;
|
||||
} else if (error >= sizeof(path)) {
|
||||
strcpy(path, "/proc/self/exe");
|
||||
} else {
|
||||
path[error] = '\0';
|
||||
}
|
||||
|
||||
execv(path, argv);
|
||||
|
||||
__eprintf("failed to execv(myself)\n");
|
||||
return 1;
|
||||
@ -2053,7 +2064,15 @@ int main(int argc, char **argv)
|
||||
error = setenv("MCEXEC_ADDR_NO_RANDOMIZE", "1", 1);
|
||||
CHKANDJUMP(error == -1, 1, "setenv failed\n");
|
||||
|
||||
error = execv("/proc/self/exe", argv);
|
||||
error = readlink("/proc/self/exe", path, sizeof(path));
|
||||
CHKANDJUMP(error == -1, 1, "readlink failed: %m\n");
|
||||
if (error >= sizeof(path)) {
|
||||
strcpy(path, "/proc/self/exe");
|
||||
} else {
|
||||
path[error] = '\0';
|
||||
}
|
||||
|
||||
error = execv(path, argv);
|
||||
CHKANDJUMPF(error == -1, 1, "execv failed, error=%d,strerror=%s\n", error, strerror(errno));
|
||||
}
|
||||
if (getenv("MCEXEC_ADDR_NO_RANDOMIZE")) {
|
||||
|
||||
Reference in New Issue
Block a user