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

Andrea Cervesato andrea.cervesato@suse.com
Fri Feb 28 10:06:05 CET 2025


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.

Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>

Best regards,
Andrea Cervesato

On 2/27/25 19:04, Edward Liaw via ltp wrote:
> 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);


More information about the ltp mailing list