xref: /openbsd-src/regress/sys/kern/pledge/sigabrt/sigabrt.c (revision fbc2f996c792e4c85e8bdedfd02d928d379ead21)
1*fbc2f996Ssemarie /*	$OpenBSD: sigabrt.c,v 1.2 2016/01/09 06:13:43 semarie Exp $ */
270bd4cc8Ssemarie /*
370bd4cc8Ssemarie  * Copyright (c) 2015 Sebastien Marie <semarie@openbsd.org>
470bd4cc8Ssemarie  *
570bd4cc8Ssemarie  * Permission to use, copy, modify, and distribute this software for any
670bd4cc8Ssemarie  * purpose with or without fee is hereby granted, provided that the above
770bd4cc8Ssemarie  * copyright notice and this permission notice appear in all copies.
870bd4cc8Ssemarie  *
970bd4cc8Ssemarie  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1070bd4cc8Ssemarie  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1170bd4cc8Ssemarie  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1270bd4cc8Ssemarie  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1370bd4cc8Ssemarie  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1470bd4cc8Ssemarie  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1570bd4cc8Ssemarie  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1670bd4cc8Ssemarie  */
1770bd4cc8Ssemarie 
1870bd4cc8Ssemarie #include <err.h>
1970bd4cc8Ssemarie #include <stdio.h>
2070bd4cc8Ssemarie #include <stdlib.h>
2170bd4cc8Ssemarie #include <signal.h>
2270bd4cc8Ssemarie #include <unistd.h>
2370bd4cc8Ssemarie 
2470bd4cc8Ssemarie void
handler(int sigraised)2570bd4cc8Ssemarie handler(int sigraised)
2670bd4cc8Ssemarie {
2770bd4cc8Ssemarie 	/* this handler shouldn't not be called */
2870bd4cc8Ssemarie 	printf("forbidden STDIO in SIGABRT handler\n");
2970bd4cc8Ssemarie }
3070bd4cc8Ssemarie 
3170bd4cc8Ssemarie int
main(int argc,char * argv[])3270bd4cc8Ssemarie main(int argc, char *argv[])
3370bd4cc8Ssemarie {
3470bd4cc8Ssemarie 	/* install SIGABRT handler */
3570bd4cc8Ssemarie 	signal(SIGABRT, &handler);
3670bd4cc8Ssemarie 
3770bd4cc8Ssemarie 	printf("permitted STDIO\n");
3870bd4cc8Ssemarie 	fflush(stdout);
3970bd4cc8Ssemarie 
40*fbc2f996Ssemarie 	if (pledge("", NULL) == -1)
4170bd4cc8Ssemarie 		err(EXIT_FAILURE, "pledge");
4270bd4cc8Ssemarie 
4370bd4cc8Ssemarie 	/* this will triggered pledge_fail() */
4470bd4cc8Ssemarie 	printf("forbidden STDIO 1\n");
4570bd4cc8Ssemarie 
4670bd4cc8Ssemarie 	/* shouldn't continue */
4770bd4cc8Ssemarie 	printf("forbidden STDIO 2\n");
4870bd4cc8Ssemarie 	return (EXIT_SUCCESS);
4970bd4cc8Ssemarie }
50