summaryrefslogtreecommitdiff
path: root/math/moo/files/patch-moo.y
blob: 646bcef4ff14445874cf14f65da88542cf334366 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
--- moo.y.orig	2016-06-04 10:05:27 UTC
+++ moo.y
@@ -4,6 +4,11 @@
  * Public domain.
  */
 
+#ifdef HAVE_CAPSICUM
+#include <sys/capsicum.h>
+#include <capsicum_helpers.h>
+#endif
+
 #include <ctype.h>
 #include <err.h>
 #include <errno.h>
@@ -34,7 +39,7 @@ static int used_oct;
 
 static void		divbyzero(void);
 static void		printnum(int64_t);
-__dead static void	usage(void);
+__dead2 static void	usage(void);
 void			yyerror(char *);
 int			yylex(void);
 int			yyparse(void);
@@ -315,10 +320,16 @@ getnum(const char *nptr)
 int
 main(int argc, char *argv[])
 {
-	int ch;
+#ifdef HAVE_CAPSICUM
+    if (caph_limit_stdio() < 0)
+        err(1, "unable to limit capabilities for stdio");
 
-	if (pledge("stdio tmppath", NULL) == -1)
-		err(1, "pledge");
+    caph_cache_catpages();
+    if (cap_enter() < 0 && errno != ENOSYS)
+        err(1, "unable to enter capability mode");
+#endif
+
+	int ch;
 
 	while ((ch = getopt(argc, argv, "0123456789b:lsuw:")) != -1)
 		switch (ch) {
@@ -403,9 +414,6 @@ DONEPARSING:
 		yyin = sfp;
 	}
 
-	if (pledge("stdio", NULL) == -1)
-		err(1, "pledge");
-
 	yyparse();
 
 	return (0);