xref: /openbsd-src/regress/sys/kern/fchown/fchown.c (revision b6b913c5b60ca0a52d882c7ee2b27441a95cef23)
1*b6b913c5Santon /*	$OpenBSD: fchown.c,v 1.1 2018/07/22 06:37:46 anton Exp $	*/
2*b6b913c5Santon /*
3*b6b913c5Santon  * Copyright (c) 2018 Anton Lindqvist <anton@openbsd.org>
4*b6b913c5Santon  *
5*b6b913c5Santon  * Permission to use, copy, modify, and distribute this software for any
6*b6b913c5Santon  * purpose with or without fee is hereby granted, provided that the above
7*b6b913c5Santon  * copyright notice and this permission notice appear in all copies.
8*b6b913c5Santon  *
9*b6b913c5Santon  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*b6b913c5Santon  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*b6b913c5Santon  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*b6b913c5Santon  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*b6b913c5Santon  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*b6b913c5Santon  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*b6b913c5Santon  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*b6b913c5Santon  */
17*b6b913c5Santon 
18*b6b913c5Santon /*
19*b6b913c5Santon  * Regression test for NULL-deref inside sys_fchown().
20*b6b913c5Santon  */
21*b6b913c5Santon 
22*b6b913c5Santon #include <err.h>
23*b6b913c5Santon #include <fcntl.h>
24*b6b913c5Santon #include <unistd.h>
25*b6b913c5Santon 
26*b6b913c5Santon int
main(void)27*b6b913c5Santon main(void)
28*b6b913c5Santon {
29*b6b913c5Santon 	const char *path = "/dev/bpf";
30*b6b913c5Santon 	int fd;
31*b6b913c5Santon 
32*b6b913c5Santon 	fd = open(path, O_WRONLY);
33*b6b913c5Santon 	if (fd == -1)
34*b6b913c5Santon 		err(1, "open: %s", path);
35*b6b913c5Santon 	if (fchown(fd, 0, -1) == -1)
36*b6b913c5Santon 		err(1, "fchown");
37*b6b913c5Santon 	close(fd);
38*b6b913c5Santon 
39*b6b913c5Santon 	return 0;
40*b6b913c5Santon }
41