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