1 /* $OpenBSD: sigabrt.c,v 1.2 2016/01/09 06:13:43 semarie Exp $ */
2 /*
3 * Copyright (c) 2015 Sebastien Marie <semarie@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #include <err.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <signal.h>
22 #include <unistd.h>
23
24 void
handler(int sigraised)25 handler(int sigraised)
26 {
27 /* this handler shouldn't not be called */
28 printf("forbidden STDIO in SIGABRT handler\n");
29 }
30
31 int
main(int argc,char * argv[])32 main(int argc, char *argv[])
33 {
34 /* install SIGABRT handler */
35 signal(SIGABRT, &handler);
36
37 printf("permitted STDIO\n");
38 fflush(stdout);
39
40 if (pledge("", NULL) == -1)
41 err(EXIT_FAILURE, "pledge");
42
43 /* this will triggered pledge_fail() */
44 printf("forbidden STDIO 1\n");
45
46 /* shouldn't continue */
47 printf("forbidden STDIO 2\n");
48 return (EXIT_SUCCESS);
49 }
50