]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-127146: Report uid in Emscripten + node as native uid (GH-136509) (#136699)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 16 Jul 2025 04:50:51 +0000 (06:50 +0200)
committerGitHub <noreply@github.com>
Wed, 16 Jul 2025 04:50:51 +0000 (06:50 +0200)
Corrects the handling of getuid on emscripten, which was consistently reporting as 0.
(cherry picked from commit e81c4e84b3a8688a367099e3adf9b2fcf914447f)

Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
Python/emscripten_syscalls.c [new file with mode: 0644]
Tools/c-analyzer/cpython/_parser.py
configure
configure.ac

diff --git a/Python/emscripten_syscalls.c b/Python/emscripten_syscalls.c
new file mode 100644 (file)
index 0000000..7875bfc
--- /dev/null
@@ -0,0 +1,19 @@
+#include "emscripten.h"
+
+// If we're running in node, report the UID of the user in the native system as
+// the UID of the user. Since the nodefs will report the uid correctly, if we
+// don't make getuid report it correctly too we'll see some permission errors.
+// Normally __syscall_getuid32 is a stub that always returns 0 but it is
+// defined with weak linkage so we can override it.
+EM_JS(int, __syscall_getuid32_js, (void), {
+    // If we're in node and we can, report the native uid
+    if (typeof process !== "undefined" && typeof process.getuid === "function") {
+        return process.getuid();
+    }
+    // Fall back to the stub case of returning 0.
+    return 0;
+})
+
+int __syscall_getuid32(void) {
+    return __syscall_getuid32_js();
+}
index 037fe11ea223c793e68749bc0d87085d6fbf2618..cfbf0d143484993a43e6f742ec9522bd7844039d 100644 (file)
@@ -66,6 +66,7 @@ Python/dynload_aix.c            # sys/ldr.h
 Python/dynload_dl.c             # dl.h
 Python/dynload_hpux.c           # dl.h
 Python/emscripten_signal.c
+Python/emscripten_syscalls.c
 Python/thread_pthread.h
 Python/thread_pthread_stubs.h
 
index 67a40b841aa5068021862189f6b803319a32616b..2242865313e57c75cc6255bf7e68007a9de840a9 100755 (executable)
--- a/configure
+++ b/configure
@@ -19077,7 +19077,7 @@ PLATFORM_OBJS=
 case $ac_sys_system in #(
   Emscripten) :
 
-    as_fn_append PLATFORM_OBJS ' Python/emscripten_signal.o Python/emscripten_trampoline.o'
+    as_fn_append PLATFORM_OBJS ' Python/emscripten_signal.o Python/emscripten_trampoline.o Python/emscripten_syscalls.o'
     as_fn_append PLATFORM_HEADERS ' $(srcdir)/Include/internal/pycore_emscripten_signal.h $(srcdir)/Include/internal/pycore_emscripten_trampoline.h'
    ;; #(
   *) :
index bbd0fa8c1ae8f6d3d739f4d52e2b61992bca90e0..a05b3b18efec36cfc5cecaad61b66140d58b0a7e 100644 (file)
@@ -5131,7 +5131,7 @@ PLATFORM_OBJS=
 
 AS_CASE([$ac_sys_system],
   [Emscripten], [
-    AS_VAR_APPEND([PLATFORM_OBJS], [' Python/emscripten_signal.o Python/emscripten_trampoline.o'])
+    AS_VAR_APPEND([PLATFORM_OBJS], [' Python/emscripten_signal.o Python/emscripten_trampoline.o Python/emscripten_syscalls.o'])
     AS_VAR_APPEND([PLATFORM_HEADERS], [' $(srcdir)/Include/internal/pycore_emscripten_signal.h $(srcdir)/Include/internal/pycore_emscripten_trampoline.h'])
   ],
 )