From 8db36c382855b09eeee6a0be783a946a4b855f66 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 25 Aug 2018 03:42:09 +0900 Subject: [PATCH] mcexec: do not resolve links in lookup_exec_path This would incorrectly make "mcexec sh -c './script.sh'" run with /bin/bash instead of /bin/sh (which is important, because bash behaviour changes depending on how it is invoked) Change-Id: I80610cf442c6c3ecacfa23e8ed15652bc8d4e3f7 --- executer/user/mcexec.c | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index 5412c783..0069a8e0 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -492,7 +492,6 @@ int lookup_exec_path(char *filename, char *path, int max_len, int execvp) struct stat sb; char *link_path = NULL; -retry: found = 0; /* Is file not absolute path? */ @@ -608,38 +607,6 @@ retry: return error; } - if ((sb.st_mode & S_IFMT) == S_IFLNK) { - link_path = malloc(max_len); - if (!link_path) { - fprintf(stderr, "lookup_exec_path(): error allocating\n"); - return ENOMEM; - } -#ifdef POSTK_DEBUG_TEMP_FIX_6 /* dynamic allocate area initialize clear */ - memset(link_path, '\0', max_len); -#endif /* POSTK_DEBUG_TEMP_FIX_6 */ - - error = readlink(path, link_path, max_len); - if (error == -1 || error == max_len) { - fprintf(stderr, "lookup_exec_path(): error readlink\n"); - free(link_path); - return EINVAL; - } - link_path[error] = '\0'; - - __dprintf("lookup_exec_path(): %s is link -> %s\n", path, link_path); - - if(link_path[0] != '/'){ - char *t = strrchr(path, '/'); - if(t){ - t++; - strcpy(t, link_path); - strcpy(link_path, path); - } - } - filename = link_path; - goto retry; - } - if (!found) { fprintf(stderr, "lookup_exec_path(): error finding file %s\n", filename);