aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2026-01-27 21:08:35 +0000
committerMark Johnston <markj@FreeBSD.org>2026-01-27 21:08:35 +0000
commit938915a22c84af88afa587694e8d63ce9dd202f4 (patch)
tree798412db9aab80b39fe27e85d1e2568dff3b147b
parent37d86e9487754b8541cd4418a4c42999bbb2761f (diff)
netbsd-tests: Fix regcomp_too_big flakiness
The test sometimes crashes with ASLR enabled. This seems to happen when regcomp() grows the process stack and happens to run into the virtual memory limit set at the beginning of the test. ASLR triggers the problem since it introduces a bit of fragmentation and thus introduces cases where stack allocation can be the trigger of virtual memory exhaustion, rather than dynamic memory allocation in regcomp(). Make the test stable by priming the stack before doing anything else. This effectively reserves 16MB of virtual memory for the stack, which in practice is enough to make the test stable on amd64. PR: 259971 Reviewed by: ngie, emaste MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D54880
-rw-r--r--contrib/netbsd-tests/lib/libc/regex/t_exhaust.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/contrib/netbsd-tests/lib/libc/regex/t_exhaust.c b/contrib/netbsd-tests/lib/libc/regex/t_exhaust.c
index 2f3d1025536b..9741f3311ae0 100644
--- a/contrib/netbsd-tests/lib/libc/regex/t_exhaust.c
+++ b/contrib/netbsd-tests/lib/libc/regex/t_exhaust.c
@@ -168,6 +168,14 @@ static const struct {
{ p6, REG_BASIC },
};
+static void __noinline
+prime_stack(void)
+{
+ char buf[16 * 1024 * 1024];
+
+ explicit_bzero(buf, sizeof(buf));
+}
+
ATF_TC(regcomp_too_big);
ATF_TC_HEAD(regcomp_too_big, tc)
@@ -186,12 +194,15 @@ ATF_TC_BODY(regcomp_too_big, tc)
int e;
struct rlimit limit;
- if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
- atf_tc_skip("https://bugs.freebsd.org/259971");
-
limit.rlim_cur = limit.rlim_max = 256 * 1024 * 1024;
ATF_REQUIRE(setrlimit(RLIMIT_VMEM, &limit) != -1);
+ /*
+ * Pre-fault the stack to avoid crashes caused by growing the stack
+ * beyond the limit.
+ */
+ prime_stack();
+
for (size_t i = 0; i < __arraycount(tests); i++) {
char *d = (*tests[i].pattern)(REGEX_MAXSIZE);
e = regcomp(&re, d, tests[i].type);