]> git.kaiwu.me - quickjs.git/commitdiff
fixed setuid() / setgid() ordering (#517)
authorFabrice Bellard <fabrice@bellard.org>
Mon, 1 Jun 2026 16:47:42 +0000 (18:47 +0200)
committerFabrice Bellard <fabrice@bellard.org>
Tue, 2 Jun 2026 08:43:18 +0000 (10:43 +0200)
quickjs-libc.c

index de860f769423f36273a6039d1a526826861a8a24..bd671b69a46e3cd93ae34a26fa0fa79c1baead90 100644 (file)
@@ -3305,14 +3305,14 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val,
             if (chdir(cwd) < 0)
                 _exit(127);
         }
-        if (uid != -1) {
-            if (setuid(uid) < 0)
-                _exit(127);
-        }
         if (gid != -1) {
             if (setgid(gid) < 0)
                 _exit(127);
         }
+        if (uid != -1) {
+            if (setuid(uid) < 0)
+                _exit(127);
+        }
 
         if (!file)
             file = exec_argv[0];