diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2002-02-21 21:07:12 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2002-02-21 21:07:12 +0000 |
commit | 2243aef466f63d751addec83f9434f6902d756c0 (patch) | |
tree | 34b3cb5611719ec15d1970cc0cbc3e3f20cbbfe9 /regress/sys/kern | |
parent | 2f058413cfe2577ff949673b79467acaae6f84c1 (diff) |
Make sure that the stack is not shared.
Diffstat (limited to 'regress/sys/kern')
-rw-r--r-- | regress/sys/kern/rfork/rfmem-stack/Makefile | 5 | ||||
-rw-r--r-- | regress/sys/kern/rfork/rfmem-stack/rfmem-stack.c | 49 |
2 files changed, 54 insertions, 0 deletions
diff --git a/regress/sys/kern/rfork/rfmem-stack/Makefile b/regress/sys/kern/rfork/rfmem-stack/Makefile new file mode 100644 index 00000000000..491df13bda7 --- /dev/null +++ b/regress/sys/kern/rfork/rfmem-stack/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2002/02/21 21:07:11 art Exp $ + +PROG=rfmem-stack + +.include <bsd.regress.mk> diff --git a/regress/sys/kern/rfork/rfmem-stack/rfmem-stack.c b/regress/sys/kern/rfork/rfmem-stack/rfmem-stack.c new file mode 100644 index 00000000000..a75b1be6bd1 --- /dev/null +++ b/regress/sys/kern/rfork/rfmem-stack/rfmem-stack.c @@ -0,0 +1,49 @@ +/* $OpenBSD: rfmem-stack.c,v 1.1 2002/02/21 21:07:11 art Exp $ */ +/* + * Written by Artur Grabowski <art@openbsd.org>, 2002 Public Domain. + */ +#include <sys/param.h> +#include <sys/wait.h> +#include <sys/mman.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <err.h> + +#define MAGIC "inherited" + +int +main() +{ + char *map, *map2; + int status; + + map = alloca(sizeof(MAGIC)); + memset(map, 0, sizeof(MAGIC)); + + map2 = alloca(sizeof(MAGIC)); + memset(map2, 0, sizeof(MAGIC)); + + switch(rfork(RFFDG|RFPROC|RFMEM)) { + case -1: + err(1, "fork"); + case 0: + memcpy(map, MAGIC, sizeof(MAGIC)); + sleep(1); + if (memcmp(map2, MAGIC, sizeof(MAGIC)) == 0); + fprintf(stderr, "child stack polluted\n"); + _exit(0); + } + + if (wait(&status) < 0) + err(1, "wait"); + + if (!WIFEXITED(status)) + err(1, "child error"); + + if (memcmp(map, MAGIC, sizeof(MAGIC)) == 0) + return 1; + + return WEXITSTATUS(status) != 0; +}
\ No newline at end of file |