From 9c359356717b8b838c82151832fc3ad7741aab84 Mon Sep 17 00:00:00 2001 From: "bgerofi@riken.jp" Date: Tue, 27 Jan 2015 16:54:03 +0900 Subject: [PATCH] mcexec: fix memory allocation bug that crashes CentOS7 glibc --- executer/user/mcexec.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index 9400286c..3dd8f720 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -546,6 +546,7 @@ int load_elf_desc(char *filename, struct program_load_desc **desc_p, /* Drop old name if exists */ if (exec_path) { free(exec_path); + exec_path = NULL; } if (!strncmp("/", filename, 1)) { @@ -558,7 +559,12 @@ int load_elf_desc(char *filename, struct program_load_desc **desc_p, } else { char *cwd = getcwd(NULL, 0); - exec_path = malloc(strlen(cwd) + strlen(filename) + 1); + if (!cwd) { + fprintf(stderr, "Error: getting current working dir pathname\n"); + return ENOMEM; + } + + exec_path = malloc(strlen(cwd) + strlen(filename) + 2); if (!exec_path) { fprintf(stderr, "Error: allocating exec_path\n"); return ENOMEM;