diff --git a/src/system/libroot/os/image.cpp b/src/system/libroot/os/image.cpp index 9f76a4a47f..b59a6d4117 100644 --- a/src/system/libroot/os/image.cpp +++ b/src/system/libroot/os/image.cpp @@ -412,6 +412,7 @@ __test_executable(const char *path, char *invoker) into it. The buffer starts with a char* array which contains pointers to the strings of the arguments and environment, followed by the strings. Both arguments and environment arrays are NULL-terminated. + If executablePath is non-NULL, it should refer to the executable to be executed. If the executable file specifies changes to environment variable values, those will be performed. @@ -421,7 +422,7 @@ __flatten_process_args(const char* const* args, int32 argCount, const char* const* env, int32* _envCount, const char* executablePath, char*** _flatArgs, size_t* _flatSize) { - if (args == NULL || env == NULL || _envCount == NULL) + if (args == NULL || _envCount == NULL || (env == NULL && *_envCount != 0)) return B_BAD_VALUE; int32 envCount = *_envCount; diff --git a/src/system/libroot/posix/unistd/exec.cpp b/src/system/libroot/posix/unistd/exec.cpp index 4f3b2a3b06..39cf3e6784 100644 --- a/src/system/libroot/posix/unistd/exec.cpp +++ b/src/system/libroot/posix/unistd/exec.cpp @@ -56,21 +56,24 @@ static int do_exec(const char *path, char * const args[], char * const environment[], bool useDefaultInterpreter) { - int32 argCount = 0, envCount = 0; - char invoker[B_FILE_NAME_LENGTH]; - char **newArgs = NULL; - - if (path == NULL) { + if (path == NULL || args == NULL) { __set_errno(B_BAD_VALUE); return -1; } - // count argument/environment list entries here, we don't want + // Count argument/environment list entries here, we don't want // to do this in the kernel - while (args[argCount] != NULL) + int32 argCount = 0; + while (args[argCount] != NULL) { argCount++; - while (environment[envCount] != NULL) - envCount++; + } + + int32 envCount = 0; + if (environment != NULL) { + while (environment[envCount] != NULL) { + envCount++; + } + } if (argCount == 0) { // we need some more info on what to do... @@ -78,7 +81,8 @@ do_exec(const char *path, char * const args[], char * const environment[], return -1; } - // test validity of executable + support for scripts + // Test validity of executable + support for scripts + char invoker[B_FILE_NAME_LENGTH]; status_t status = __test_executable(path, invoker); if (status < B_OK) { if (status == B_NOT_AN_EXECUTABLE && useDefaultInterpreter) { @@ -90,6 +94,7 @@ do_exec(const char *path, char * const args[], char * const environment[], } } + char **newArgs = NULL; if (invoker[0] != '\0') { status = __parse_invoke_line(invoker, &newArgs, &args, &argCount, path); if (status < B_OK) {