execvp() was looping endlessly if PATH contained empty entries.
Reorganized the loop so that this won't happen anymore. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24568 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright 2008, Ingo Weinhold, [email protected].
|
||||||
* Copyright 2004-2005, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2004-2005, Axel Dörfler, [email protected]. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
@@ -141,7 +142,9 @@ execvp(const char *file, char* const* argv)
|
|||||||
int fileNameLen = strlen(file);
|
int fileNameLen = strlen(file);
|
||||||
|
|
||||||
// iterate through the paths
|
// iterate through the paths
|
||||||
while (true) {
|
const char* pathEnd = paths - 1;
|
||||||
|
while (pathEnd != NULL) {
|
||||||
|
paths = pathEnd + 1;
|
||||||
const char* pathEnd = strchr(paths, ':');
|
const char* pathEnd = strchr(paths, ':');
|
||||||
int pathLen = (pathEnd ? pathEnd - paths : strlen(paths));
|
int pathLen = (pathEnd ? pathEnd - paths : strlen(paths));
|
||||||
|
|
||||||
@@ -164,12 +167,6 @@ execvp(const char *file, char* const* argv)
|
|||||||
// if executable, execute it
|
// if executable, execute it
|
||||||
if (access(path, X_OK) == 0)
|
if (access(path, X_OK) == 0)
|
||||||
return do_exec(path, argv, environ, true);
|
return do_exec(path, argv, environ, true);
|
||||||
|
|
||||||
// not found yet -- get the next path, if any
|
|
||||||
if (pathEnd == NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
paths = pathEnd + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
errno = B_ENTRY_NOT_FOUND;
|
errno = B_ENTRY_NOT_FOUND;
|
||||||
|
|||||||
Reference in New Issue
Block a user