File missing-__stack_chk_fail.patch of Package nodejs-vscode-oniguruma

From d38cc5272659c3c69930c2d9e4a1bd3213e503c7 Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc@chromium.org>
Date: Fri, 12 Jul 2024 15:36:51 -0700
Subject: [PATCH] Add support for -fstack-protector (#22229)

Fixes: #9780
---
 system/lib/libc/musl/src/env/__stack_chk_fail.c |  5 +++++
 test/core/test_dlfcn_self.exports               |  1 +
 test/other/test_stack_protector.c               | 14 ++++++++++++++
 test/other/test_stack_protector.out             |  2 ++
 test/test_other.py                              |  3 +++
 tools/system_libs.py                            |  2 +-
 6 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 test/other/test_stack_protector.c
 create mode 100644 test/other/test_stack_protector.out

diff --git a/system/lib/libc/musl/src/env/__stack_chk_fail.c b/system/lib/libc/musl/src/env/__stack_chk_fail.c
index e53526020f75..94d8e1d4c960 100644
--- a/system/lib/libc/musl/src/env/__stack_chk_fail.c
+++ b/system/lib/libc/musl/src/env/__stack_chk_fail.c
@@ -23,6 +23,11 @@ void __init_ssp(void *entropy)
 
 void __stack_chk_fail(void)
 {
+#if defined(__EMSCRIPTEN__) && !defined(NDEBUG)
+	// Report the reason for the crash, at least in debug builds.
+	// This is the same message that glibc outputs (even in release builds).
+	_emscripten_err("*** stack smashing detected ***");
+#endif
 	a_crash();
 }
 
diff --git a/test/core/test_dlfcn_self.exports b/test/core/test_dlfcn_self.exports
index 3f3fc60c99d1..778003379ab0 100644
--- a/test/core/test_dlfcn_self.exports
+++ b/test/core/test_dlfcn_self.exports
@@ -9,6 +9,7 @@ __progname_full
 __sig_actions
 __sig_pending
 __signgam
+__stack_chk_guard
 __threwValue
 __timezone
 __tzname
diff --git a/test/other/test_stack_protector.c b/test/other/test_stack_protector.c
new file mode 100644
index 000000000000..90fefcdb88ba
--- /dev/null
+++ b/test/other/test_stack_protector.c
@@ -0,0 +1,14 @@
+#include <alloca.h>
+#include <memory.h>
+#include <string.h>
+#include <stdio.h>
+
+char mystring[] = "Hello world";
+
+int main() {
+  char buf[10];
+  // This is not valid since mystring is larger than `buf`
+  strcpy(buf, mystring);
+  printf("buf: %s\n", buf);
+  return 0;
+}
diff --git a/test/other/test_stack_protector.out b/test/other/test_stack_protector.out
new file mode 100644
index 000000000000..92b0f3ee629d
--- /dev/null
+++ b/test/other/test_stack_protector.out
@@ -0,0 +1,2 @@
+buf: Hello world
+*** stack smashing detected ***
diff --git a/tools/system_libs.py b/tools/system_libs.py
index ba9e3b36135b..28439c4238dc 100644
--- a/tools/system_libs.py
+++ b/tools/system_libs.py
@@ -1103,7 +1103,7 @@ def get_files(self):
         'fork.c', 'vfork.c', 'posix_spawn.c', 'posix_spawnp.c', 'execve.c', 'waitid.c', 'system.c',
         '_Fork.c',
         # 'env' exclusion
-        '__reset_tls.c', '__init_tls.c', '__libc_start_main.c', '__stack_chk_fail.c',
+        '__reset_tls.c', '__init_tls.c', '__libc_start_main.c',
     ]
 
     ignore += LIBC_SOCKETS
openSUSE Build Service is sponsored by