[LTP] [PATCH] setrlimit01.c: use a more reliable segfault

Edward Liaw edliaw@google.com
Thu Feb 27 19:04:28 CET 2025


When compiled for Android, strcpying to the null pointer was being
optimized away as unreachable, so the segfault wasn't being thrown.  Use
raise to throw the segfault instead of ub, since the test just needs the
signal.

Signed-off-by: Edward Liaw <edliaw@google.com>
---
 testcases/kernel/syscalls/setrlimit/setrlimit01.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit01.c b/testcases/kernel/syscalls/setrlimit/setrlimit01.c
index 188d310b2..d00153533 100644
--- a/testcases/kernel/syscalls/setrlimit/setrlimit01.c
+++ b/testcases/kernel/syscalls/setrlimit/setrlimit01.c
@@ -33,6 +33,7 @@
 #include <sys/wait.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <signal.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include "test.h"
@@ -256,8 +257,7 @@ static void test4(void)
 		tst_brkm(TBROK, cleanup, "fork() failed");
 
 	if (pid == 0) {		/* child */
-		char *testbuf = NULL;
-		strcpy(testbuf, "abcd");
+		raise(SIGSEGV);
 		exit(0);
 	}
 	wait(&status);
-- 
2.48.1.711.g2feabab25a-goog



More information about the ltp mailing list