mcexec: fix memory allocation bug that crashes CentOS7 glibc

This commit is contained in:
bgerofi@riken.jp
2015-01-27 16:54:03 +09:00
committed by Balazs Gerofi bgerofi@riken.jp
parent ed33ee65b2
commit 9c35935671

View File

@ -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;