From c1cf630a94b1ab9ae2e021e519a0514b6c3b0091 Mon Sep 17 00:00:00 2001 From: "Balazs Gerofi bgerofi@riken.jp" Date: Wed, 3 Dec 2014 15:14:26 +0900 Subject: [PATCH] mcexec: store full path to executable required so that a forked process can obtain exec reference in the Linux kernel even if executable was specified with relative path and fork was called after changing the current working directory --- executer/user/mcexec.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index 0d727d74..2bc012c3 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -548,9 +548,24 @@ int load_elf_desc(char *filename, struct program_load_desc **desc_p, free(exec_path); } - exec_path = strdup(filename); - if (!exec_path) { - fprintf(stderr, "WARNING: strdup(filename) failed\n"); + if (!strncmp("/", filename, 1)) { + exec_path = strdup(filename); + + if (!exec_path) { + fprintf(stderr, "WARNING: strdup(filename) failed\n"); + return ENOMEM; + } + } + else { + char *cwd = getcwd(NULL, 0); + exec_path = malloc(strlen(cwd) + strlen(filename) + 1); + if (!exec_path) { + fprintf(stderr, "Error: allocating exec_path\n"); + return ENOMEM; + } + + sprintf(exec_path, "%s/%s", cwd, filename); + free(cwd); } desc = load_elf(fp, &interp_path);