Module Name:    src
Committed By:   riastradh
Date:           Thu Dec  7 16:54:44 UTC 2023

Modified Files:
        src/tests/lib/libc/sys: Makefile t_setrlimit.c

Log Message:
t_setrlimit: Narrow the scope of stack-protector warning suppression.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libc/sys/t_setrlimit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.75 src/tests/lib/libc/sys/Makefile:1.76
--- src/tests/lib/libc/sys/Makefile:1.75	Fri Nov 24 17:19:55 2023
+++ src/tests/lib/libc/sys/Makefile	Thu Dec  7 16:54:44 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.75 2023/11/24 17:19:55 christos Exp $
+# $NetBSD: Makefile,v 1.76 2023/12/07 16:54:44 riastradh Exp $
 
 MKMAN=	no
 
@@ -158,6 +158,5 @@ CWARNFLAGS.gcc+=	${CC_WNO_ADDRESS_OF_PAC
 
 # Explicitly breaks this
 COPTS.t_wait.c+=	${CC_WNO_ARRAY_BOUNDS} ${CC_WNO_STRINGOP_OVERFLOW}
-COPTS.t_setrlimit.c+=	-Wno-error=stack-protector
 
 .include <bsd.test.mk>

Index: src/tests/lib/libc/sys/t_setrlimit.c
diff -u src/tests/lib/libc/sys/t_setrlimit.c:1.10 src/tests/lib/libc/sys/t_setrlimit.c:1.11
--- src/tests/lib/libc/sys/t_setrlimit.c:1.10	Wed Nov 22 02:20:34 2023
+++ src/tests/lib/libc/sys/t_setrlimit.c	Thu Dec  7 16:54:44 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: t_setrlimit.c,v 1.10 2023/11/22 02:20:34 riastradh Exp $ */
+/* $NetBSD: t_setrlimit.c,v 1.11 2023/12/07 16:54:44 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_setrlimit.c,v 1.10 2023/11/22 02:20:34 riastradh Exp $");
+__RCSID("$NetBSD: t_setrlimit.c,v 1.11 2023/12/07 16:54:44 riastradh Exp $");
 
 #include <sys/resource.h>
 #include <sys/mman.h>
@@ -534,6 +534,26 @@ ATF_TC_HEAD(setrlimit_stack_growshrink, 
 }
 
 /*
+ * checkstackchild(n)
+ *
+ *	Allocate an array of size n on the stack, and verify it can be
+ *	used.  If it can't be used, this will crash with SIGSEGV,
+ *	deliberately.
+ */
+_Pragma("GCC diagnostic push")
+_Pragma("GCC diagnostic ignored \"-Wstack-protector\"")
+static void
+checkstackchild(size_t n)
+{
+	volatile char *const x = alloca(n);
+	size_t i;
+
+	for (i = 0; i < n; i++)
+		x[i] = 0x1a;
+}
+_Pragma("GCC diagnostic pop")
+
+/*
  * checkstack(n, expectsegv)
  *
  *	Check whether we can allocate an array of size n on the stack.
@@ -555,14 +575,11 @@ static void
 checkstack(size_t n, int expectsegv)
 {
 	pid_t forked, waited;
-	size_t i;
 	int status;
 
 	RL(forked = fork());
 	if (forked == 0) {	/* child */
-		volatile char *const x = alloca(n);
-		for (i = 0; i < n; i++)
-			x[i] = 0x1a;
+		checkstackchild(n);
 		_exit(expectsegv);
 	}
 

Reply via email to