diff options
author | Conrad Meyer <cem@FreeBSD.org> | 2016-11-08 05:31:01 +0000 |
---|---|---|
committer | Conrad Meyer <cem@FreeBSD.org> | 2016-11-08 05:31:01 +0000 |
commit | cd1693d3f953314178bc9c1ad75283ed29dc26ba (patch) | |
tree | efe9556fcb7bf108db23dd38c51ce08841c2826d /usr.bin/dc | |
parent | a965389b5a77dc64dd8ddc3c4340eed16698f4fd (diff) | |
download | src-cd1693d3f953314178bc9c1ad75283ed29dc26ba.tar.gz src-cd1693d3f953314178bc9c1ad75283ed29dc26ba.zip |
Notes
Diffstat (limited to 'usr.bin/dc')
-rw-r--r-- | usr.bin/dc/dc.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/usr.bin/dc/dc.c b/usr.bin/dc/dc.c index 546b24706eee..8f2cf51fb3bd 100644 --- a/usr.bin/dc/dc.c +++ b/usr.bin/dc/dc.c @@ -22,9 +22,11 @@ __FBSDID("$FreeBSD$"); #include <sys/stat.h> +#include <capsicum_helpers.h> #include <ctype.h> #include <err.h> #include <errno.h> +#include <fcntl.h> #include <getopt.h> #include <stdio.h> #include <stdlib.h> @@ -58,11 +60,11 @@ usage(void) } static void -procfile(char *fname) { +procfd(int fd, char *fname) { struct stat st; FILE *file; - file = fopen(fname, "r"); + file = fdopen(fd, "r"); if (file == NULL) err(1, "cannot open file %s", fname); if (fstat(fileno(file), &st) == -1) @@ -80,7 +82,7 @@ procfile(char *fname) { int main(int argc, char *argv[]) { - int ch; + int ch, fd; bool extended_regs = false, preproc_done = false; /* accept and ignore a single dash to be 4.4BSD dc(1) compatible */ @@ -97,7 +99,10 @@ main(int argc, char *argv[]) case 'f': if (!preproc_done) init_bmachine(extended_regs); - procfile(optarg); + fd = open(optarg, O_RDONLY); + if (fd < 0) + err(1, "cannot open file %s", optarg); + procfd(fd, optarg); preproc_done = true; break; case 'x': @@ -126,12 +131,23 @@ main(int argc, char *argv[]) if (argc > 1) usage(); if (argc == 1) { - procfile(argv[0]); + fd = open(argv[0], O_RDONLY); + if (fd < 0) + err(1, "cannot open file %s", argv[0]); + + if (caph_limit_stream(fd, CAPH_READ) < 0 || + caph_limit_stdio() < 0 || + (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); + + procfd(fd, argv[0]); preproc_done = true; } if (preproc_done) return (0); + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); src_setstream(&src, stdin); reset_bmachine(&src); eval(); |