git: 05492ff6f636 - main - pdwait(2) tests: do not rely on (int *)-1 being invalid address
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 17 Feb 2026 00:29:03 UTC
The branch main has been updated by asomers:
URL: https://cgit.FreeBSD.org/src/commit/?id=05492ff6f636108c4fac40c259defe9b2eac7833
commit 05492ff6f636108c4fac40c259defe9b2eac7833
Author: Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2026-02-17 00:25:58 +0000
Commit: Alan Somers <asomers@FreeBSD.org>
CommitDate: 2026-02-17 00:27:38 +0000
pdwait(2) tests: do not rely on (int *)-1 being invalid address
Explicitly mmap guard and use it as the invalid address instead.
MFC after: 1 week
---
tests/sys/kern/pdwait.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/tests/sys/kern/pdwait.c b/tests/sys/kern/pdwait.c
index 513b07cae87e..c7b2c40a87ba 100644
--- a/tests/sys/kern/pdwait.c
+++ b/tests/sys/kern/pdwait.c
@@ -27,6 +27,7 @@
#include <sys/types.h>
#include <sys/capsicum.h>
+#include <sys/mman.h>
#include <sys/procdesc.h>
#include <sys/resource.h>
#include <sys/time.h>
@@ -37,6 +38,16 @@
#include <signal.h>
#include <string.h>
+static void*
+unmapped(void) {
+ void *unmapped;
+
+ unmapped = mmap(NULL, PAGE_SIZE, PROT_NONE, MAP_GUARD, -1, 0);
+ ATF_REQUIRE(unmapped != MAP_FAILED);
+
+ return(unmapped);
+}
+
/* basic usage */
ATF_TC_WITHOUT_HEAD(basic);
ATF_TC_BODY(basic, tc)
@@ -108,7 +119,8 @@ ATF_TC_BODY(efault1, tc)
ATF_REQUIRE_MSG(pid >= 0, "pdfork failed: %s", strerror(errno));
ATF_REQUIRE_MSG(fdp >= 0, "pdfork didn't return a process descriptor");
- ATF_CHECK_ERRNO(EFAULT, pdwait(fdp, (int*)-1, WEXITED, NULL, NULL) < 0);
+ ATF_CHECK_ERRNO(EFAULT,
+ pdwait(fdp, (int*)unmapped(), WEXITED, NULL, NULL) < 0);
close(fdp);
}
@@ -127,7 +139,8 @@ ATF_TC_BODY(efault2, tc)
ATF_REQUIRE_MSG(fdp >= 0, "pdfork didn't return a process descriptor");
ATF_CHECK_ERRNO(EFAULT,
- pdwait(fdp, NULL, WEXITED, (struct __wrusage*)-1, NULL) < 0);
+ pdwait(fdp, NULL, WEXITED, (struct __wrusage*)unmapped(), NULL) < 0
+ );
close(fdp);
}
@@ -146,7 +159,8 @@ ATF_TC_BODY(efault3, tc)
ATF_REQUIRE_MSG(fdp >= 0, "pdfork didn't return a process descriptor");
ATF_CHECK_ERRNO(EFAULT,
- pdwait(fdp, NULL, WEXITED, NULL, (struct __siginfo*)-1) < 0);
+ pdwait(fdp, NULL, WEXITED, NULL, (struct __siginfo*)unmapped()) < 0
+ );
close(fdp);
}