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
This commit is contained in:
Dominique Martinet
2018-08-25 03:42:09 +09:00
committed by Dominique Martinet
parent 06dd71a7e0
commit 8db36c3828

View File

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