aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2026-02-15 15:09:48 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2026-02-16 17:57:52 +0000
commitd6bf2d14a941a88e27a82a3f91790353e134b8f6 (patch)
tree7c28577c57534978eda6a3d5b087b85ebc50be80
parent68ba270f4fc7799929a3d59d710f44e5e9087def (diff)
pdrfork(2) tests: do not rely on (int *)-1 being invalid address
Explicitly mmap guard and use it as the invalid address instead. Tested by: pho Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D55306
-rw-r--r--tests/sys/kern/pdrfork.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/tests/sys/kern/pdrfork.c b/tests/sys/kern/pdrfork.c
index 7a560e4fa08d..1003ad9dc746 100644
--- a/tests/sys/kern/pdrfork.c
+++ b/tests/sys/kern/pdrfork.c
@@ -26,8 +26,9 @@
*/
#include <sys/types.h>
-#include <sys/user.h>
+#include <sys/mman.h>
#include <sys/procdesc.h>
+#include <sys/user.h>
#include <sys/wait.h>
#include <atf-c.h>
@@ -93,7 +94,12 @@ ATF_TC_BODY(child_gets_no_pidfd, tc)
ATF_TC_WITHOUT_HEAD(efault);
ATF_TC_BODY(efault, tc)
{
- ATF_REQUIRE_ERRNO(EFAULT, pdrfork((int*)-1, 0, RFPROC | RFPROCDESC) < 0);
+ void *unmapped;
+
+ unmapped = mmap(NULL, PAGE_SIZE, PROT_NONE, MAP_GUARD, -1, 0);
+ ATF_REQUIRE(unmapped != MAP_FAILED);
+ ATF_REQUIRE_ERRNO(EFAULT, pdrfork(unmapped, 0, RFPROC |
+ RFPROCDESC) < 0);
}
/* Invalid combinations of flags should return EINVAL */