Browse Source

[PAL/{Linux/FreeBSD}] Handle failure on child process creation in DkProcessCreate()

Gary 6 years ago
parent
commit
bc0ddb282b
2 changed files with 6 additions and 14 deletions
  1. 3 4
      Pal/src/host/FreeBSD/db_process.c
  2. 3 10
      Pal/src/host/Linux/db_process.c

+ 3 - 4
Pal/src/host/FreeBSD/db_process.c

@@ -152,8 +152,7 @@ static int child_process (void * param)
 
 failed:
     /* fail is it gets here */
-    _DkThreadExit();
-    return 0;
+    return -PAL_ERROR_DENIED;
 }
 
 int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args)
@@ -267,8 +266,8 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args)
     }
 
     if (!ret) {
-        child_process(&param);
-        return 0;
+        ret = child_process(&param);
+        goto out; /* if child_process returned, there was a failure */
     }
 
     child_handle->process.pid = ret;

+ 3 - 10
Pal/src/host/Linux/db_process.c

@@ -157,11 +157,10 @@ static int child_process (void * param)
 
     INLINE_SYSCALL(execve, 3, PAL_LOADER, proc_param->argv,
                    linux_state.environ);
-    ret = -PAL_ERROR_DENIED;
 
 failed:
     /* fail is it gets here */
-    return ret;
+    return -PAL_ERROR_DENIED;
 }
 
 int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args)
@@ -291,7 +290,6 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args)
 #endif
 
     ret = ARCH_VFORK();
-    int child_ret = 0;
 
     if (IS_ERR(ret)) {
         ret = -PAL_ERROR_DENIED;
@@ -299,13 +297,8 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args)
     }
 
     if (!ret) {
-        child_ret = child_process(&param);
-        return 0;
-    }
-
-    if (child_ret < 0) {
-        ret = child_ret;
-        goto out;
+        ret = child_process(&param);
+        goto out; /* if child_process returned, there was a failure */
     }
 
     proc_args->pal_sec.process_id = ret;