diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2002-02-08 17:33:33 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2002-02-08 17:33:33 +0000 |
commit | 1a2ccb20a6d72354d742cc1452ce9bd0e16149c0 (patch) | |
tree | 3962fca5ea475459ba1392d41f8db46fb6e52b12 | |
parent | fc54576be033828908c98695b5126448220b34ab (diff) |
Try to confuse /dev/fd (might crash the kernel on other systems or if someone screws up in the kernel).
-rw-r--r-- | regress/sys/fdescfs/confuse/Makefile | 5 | ||||
-rw-r--r-- | regress/sys/fdescfs/confuse/confuse.c | 41 |
2 files changed, 46 insertions, 0 deletions
diff --git a/regress/sys/fdescfs/confuse/Makefile b/regress/sys/fdescfs/confuse/Makefile new file mode 100644 index 00000000000..40401cd70c7 --- /dev/null +++ b/regress/sys/fdescfs/confuse/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2002/02/08 17:33:32 art Exp $ + +PROG= confuse + +.include <bsd.regress.mk> diff --git a/regress/sys/fdescfs/confuse/confuse.c b/regress/sys/fdescfs/confuse/confuse.c new file mode 100644 index 00000000000..4fb68d94e32 --- /dev/null +++ b/regress/sys/fdescfs/confuse/confuse.c @@ -0,0 +1,41 @@ +/* $OpenBSD: confuse.c,v 1.1 2002/02/08 17:33:32 art Exp $ */ +/* + * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain. + */ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <err.h> +#include <fcntl.h> +#include <errno.h> + +int +main() +{ + char fname[64]; + int fd, newfd; + + if ((fd = open("/dev/null", O_RDONLY)) < 0) + err(1, "open(/dev/null)"); + + /* Try to confuse fdescfs by making it open into itself. */ + close(fd); + + snprintf(fname, sizeof(fname), "/dev/fd/%d", fd); + + if ((newfd = open(fname, O_RDONLY)) == fd) + errx(1, "open of %s to %d succeeded, beware.", fname, fd); + + if (newfd >= 0) + errx(1, "open(%s) gave us the unexpected %d", fname, fd); + + if (errno == ENOENT) + err(1, "open(%s)", fname); + + if (errno == ENXIO) + errx(1, "no support for fdesc in kernel"); + + warn("errno was (%d)", errno); + + return 0; +} |