Properly support running programs using relative pathnames.

Previously, relative pathnames other than those starting with "." or ".." wouldn't be recognized.
This commit is contained in:
Stephen Heumann 2015-02-03 21:24:10 -06:00
parent ad96f52394
commit 0d0ec552b5
1 changed files with 20 additions and 15 deletions

View File

@ -181,7 +181,6 @@ int execve(const char *path, char *const *argv, char *const *envp)
fileInfoRec.pCount = 4; fileInfoRec.pCount = 4;
fileInfoRec.pathname = path_gs; fileInfoRec.pathname = path_gs;
GetFileInfoGS(&fileInfoRec); GetFileInfoGS(&fileInfoRec);
/* If it's not an EXEC file, error out. */
if (toolerror()) { if (toolerror()) {
errno = ENOENT; errno = ENOENT;
goto error_ret; goto error_ret;
@ -200,7 +199,7 @@ int execve(const char *path, char *const *argv, char *const *envp)
args = NULL; args = NULL;
/* If _execve kernel call failed, consider trying to execute /* If _execve kernel call failed, consider trying to execute
* the file as a script. */ * the file as a script. If it's not an EXEC file, error out. */
if (fileInfoRec.fileType != 0xB0 || fileInfoRec.auxType != 0x0006) { if (fileInfoRec.fileType != 0xB0 || fileInfoRec.auxType != 0x0006) {
errno = EACCES; errno = EACCES;
goto error_ret; goto error_ret;
@ -295,26 +294,32 @@ int execvp(const char *file, char *const *argv)
int result; int result;
char *path, *path2; char *path, *path2;
path = buildPath(file); if (!strpbrk(file, "/:")) {
if (path == NULL) { path = buildPath(file);
errno = ENOENT; if (path == NULL) {
return -1; errno = ENOENT;
} return -1;
}
/* Move path to memory that will be freed following _execve */ /* Move path to memory that will be freed following _execve */
path2 = alloc_for_current_process(strlen(path) + 1); path2 = alloc_for_current_process(strlen(path) + 1);
if (path2 == NULL) { if (path2 == NULL) {
free(path);
errno = ENOMEM;
return -1;
}
strcpy(path2, path);
free(path); free(path);
errno = ENOMEM; } else {
return -1; path2 = (char *)file;
} }
strcpy(path2, path);
free(path);
result = execve(path2, argv, environ); result = execve(path2, argv, environ);
/* error case */ /* error case */
dealloc_for_current_process(path2); if (path2 != file) {
dealloc_for_current_process(path2);
}
return result; return result;
} }
#endif #endif