From 0343e0753a977f913c0a5d20a73da0eebce7bdac Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 25 Mar 2008 03:46:08 +0000 Subject: [PATCH] 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 --- src/system/libroot/posix/unistd/exec.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/system/libroot/posix/unistd/exec.cpp b/src/system/libroot/posix/unistd/exec.cpp index c0bfaa8481..6477c6d822 100644 --- a/src/system/libroot/posix/unistd/exec.cpp +++ b/src/system/libroot/posix/unistd/exec.cpp @@ -1,4 +1,5 @@ /* + * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -141,7 +142,9 @@ execvp(const char *file, char* const* argv) int fileNameLen = strlen(file); // iterate through the paths - while (true) { + const char* pathEnd = paths - 1; + while (pathEnd != NULL) { + paths = pathEnd + 1; const char* pathEnd = strchr(paths, ':'); int pathLen = (pathEnd ? pathEnd - paths : strlen(paths)); @@ -164,12 +167,6 @@ execvp(const char *file, char* const* argv) // if executable, execute it if (access(path, X_OK) == 0) 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;