Skip to contentSkip to conversation

setrlimit01.c: use a more reliable segfault

PATCH In review Edward Liaw via ltp 1 participant 2 messages Feb 27, 2025 – Feb 28, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 setrlimit01.c: use a more reliable segfault

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.

---
 testcases/kernel/syscalls/setrlimit/setrlimit01.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/setrlimit/setrlimit01.c +2 -2
index 188d310b2..d00153533 100644
@@ -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);
Signature · 5 lines
2.48.1.711.g2feabab25a-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author Reviewed-by Andrea Cervesato on v1 1/1
#1 lore raw

Hi!

obviously correct and merged. It would be nice to rewrite this test with new API because it looks pretty ancient and there's a big margin of improvement.

Best regards,
Andrea Cervesato

Quoted 32 lines · Edward Liaw via ltp

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.

---
  testcases/kernel/syscalls/setrlimit/setrlimit01.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/setrlimit/setrlimit01.c +2 -2
index 188d310b2..d00153533 100644
@@ -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);
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp