Fixed exec*(), and __flatten_process_args() with NULL env.
* Not sure if it's following any standard, but environ can be NULL (either by manually setting it to NULL, or by calling clearenv()).
This commit is contained in:
parent
ea19a80ed6
commit
463d38e40b
@ -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;
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user