From owner-svn-src-stable-11@freebsd.org Fri Apr 13 03:30:11 2018 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A648EF86176; Fri, 13 Apr 2018 03:30:11 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5A40983F07; Fri, 13 Apr 2018 03:30:11 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 55110145B1; Fri, 13 Apr 2018 03:30:11 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w3D3UB1s040691; Fri, 13 Apr 2018 03:30:11 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3D3UAdv040682; Fri, 13 Apr 2018 03:30:10 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201804130330.w3D3UAdv040682@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Fri, 13 Apr 2018 03:30:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r332463 - in stable/11: bin/echo bin/sleep usr.bin/basename usr.bin/dc usr.bin/dirname usr.bin/getopt usr.bin/locate/bigram usr.bin/logname usr.bin/printenv usr.bin/yes X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable/11: bin/echo bin/sleep usr.bin/basename usr.bin/dc usr.bin/dirname usr.bin/getopt usr.bin/locate/bigram usr.bin/logname usr.bin/printenv usr.bin/yes X-SVN-Commit-Revision: 332463 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Apr 2018 03:30:12 -0000 Author: kevans Date: Fri Apr 13 03:30:10 2018 New Revision: 332463 URL: https://svnweb.freebsd.org/changeset/base/332463 Log: MFC r308432, r308657: Capsicumize some trivial stdio programs r308432: Capsicumize some trivial stdio programs Trivially capsicumize some simple programs that just interact with stdio. This list of programs uses 'pledge("stdio")' in OpenBSD. r308657: fold(1): Revert incorrect r308432 As Jean-Sébastien notes, fold(1) requires handling argv-supplied files. That will require a slightly more sophisticated approach. Modified: stable/11/bin/echo/echo.c stable/11/bin/sleep/sleep.c stable/11/usr.bin/basename/basename.c stable/11/usr.bin/dc/dc.c stable/11/usr.bin/dirname/dirname.c stable/11/usr.bin/getopt/getopt.c stable/11/usr.bin/locate/bigram/locate.bigram.c stable/11/usr.bin/logname/logname.c stable/11/usr.bin/printenv/printenv.c stable/11/usr.bin/yes/yes.c Directory Properties: stable/11/ (props changed) Modified: stable/11/bin/echo/echo.c ============================================================================== --- stable/11/bin/echo/echo.c Fri Apr 13 02:40:10 2018 (r332462) +++ stable/11/bin/echo/echo.c Fri Apr 13 03:30:10 2018 (r332463) @@ -45,6 +45,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include #include #include #include @@ -77,6 +79,9 @@ main(int argc, char *argv[]) char space[] = " "; char newline[] = "\n"; char *progname = argv[0]; + + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); /* This utility may NOT do getopt(3) option parsing. */ if (*++argv && !strcmp(*argv, "-n")) { Modified: stable/11/bin/sleep/sleep.c ============================================================================== --- stable/11/bin/sleep/sleep.c Fri Apr 13 02:40:10 2018 (r332462) +++ stable/11/bin/sleep/sleep.c Fri Apr 13 03:30:10 2018 (r332463) @@ -41,6 +41,7 @@ static char sccsid[] = "@(#)sleep.c 8.3 (Berkeley) 4/2 #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -68,6 +69,9 @@ main(int argc, char *argv[]) double d; time_t original; char buf[2]; + + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); if (argc != 2) usage(); Modified: stable/11/usr.bin/basename/basename.c ============================================================================== --- stable/11/usr.bin/basename/basename.c Fri Apr 13 02:40:10 2018 (r332462) +++ stable/11/usr.bin/basename/basename.c Fri Apr 13 03:30:10 2018 (r332463) @@ -42,6 +42,7 @@ static char sccsid[] = "@(#)basename.c 8.4 (Berkeley) #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -63,6 +64,9 @@ main(int argc, char **argv) int aflag, ch; setlocale(LC_ALL, ""); + + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); aflag = 0; suffix = NULL; Modified: stable/11/usr.bin/dc/dc.c ============================================================================== --- stable/11/usr.bin/dc/dc.c Fri Apr 13 02:40:10 2018 (r332462) +++ stable/11/usr.bin/dc/dc.c Fri Apr 13 03:30:10 2018 (r332463) @@ -22,9 +22,11 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include #include +#include #include #include #include @@ -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(); Modified: stable/11/usr.bin/dirname/dirname.c ============================================================================== --- stable/11/usr.bin/dirname/dirname.c Fri Apr 13 02:40:10 2018 (r332462) +++ stable/11/usr.bin/dirname/dirname.c Fri Apr 13 03:30:10 2018 (r332463) @@ -39,6 +39,7 @@ static const char sccsid[] = "@(#)dirname.c 8.4 (Berke #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -52,6 +53,9 @@ main(int argc, char **argv) { char *p; int ch; + + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); while ((ch = getopt(argc, argv, "")) != -1) switch(ch) { Modified: stable/11/usr.bin/getopt/getopt.c ============================================================================== --- stable/11/usr.bin/getopt/getopt.c Fri Apr 13 02:40:10 2018 (r332462) +++ stable/11/usr.bin/getopt/getopt.c Fri Apr 13 03:30:10 2018 (r332463) @@ -6,6 +6,9 @@ __FBSDID("$FreeBSD$"); * into the public domain and is thus not subject to any copyright. */ +#include +#include +#include #include #include #include @@ -15,6 +18,9 @@ main(int argc, char *argv[]) { int c; int status = 0; + + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); optind = 2; /* Past the program name and the option letters. */ while ((c = getopt(argc, argv, argv[1])) != -1) Modified: stable/11/usr.bin/locate/bigram/locate.bigram.c ============================================================================== --- stable/11/usr.bin/locate/bigram/locate.bigram.c Fri Apr 13 02:40:10 2018 (r332462) +++ stable/11/usr.bin/locate/bigram/locate.bigram.c Fri Apr 13 03:30:10 2018 (r332463) @@ -57,6 +57,9 @@ static char sccsid[] = "@(#)locate.bigram.c 8.1 (Berke * Use 'code' to encode a file using this output. */ +#include +#include +#include #include #include #include /* for MAXPATHLEN */ @@ -72,6 +75,9 @@ main(void) u_char *cp; u_char *oldpath = buf1, *path = buf2; u_int i, j; + + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); while (fgets(path, sizeof(buf2), stdin) != NULL) { Modified: stable/11/usr.bin/logname/logname.c ============================================================================== --- stable/11/usr.bin/logname/logname.c Fri Apr 13 02:40:10 2018 (r332462) +++ stable/11/usr.bin/logname/logname.c Fri Apr 13 03:30:10 2018 (r332463) @@ -39,6 +39,7 @@ static const char sccsid[] = "@(#)logname.c 8.2 (Berke #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -50,6 +51,9 @@ int main(int argc, char *argv[] __unused) { char *p; + + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); if (argc != 1) usage(); Modified: stable/11/usr.bin/printenv/printenv.c ============================================================================== --- stable/11/usr.bin/printenv/printenv.c Fri Apr 13 02:40:10 2018 (r332462) +++ stable/11/usr.bin/printenv/printenv.c Fri Apr 13 03:30:10 2018 (r332463) @@ -44,6 +44,8 @@ __FBSDID("$FreeBSD$"); #include +#include +#include #include #include #include @@ -64,6 +66,9 @@ main(int argc, char *argv[]) char *cp, **ep; size_t len; int ch; + + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); while ((ch = getopt(argc, argv, "")) != -1) switch(ch) { Modified: stable/11/usr.bin/yes/yes.c ============================================================================== --- stable/11/usr.bin/yes/yes.c Fri Apr 13 02:40:10 2018 (r332462) +++ stable/11/usr.bin/yes/yes.c Fri Apr 13 03:30:10 2018 (r332463) @@ -41,12 +41,17 @@ static const char rcsid[] = "$FreeBSD$"; #endif #endif /* not lint */ +#include #include #include int main(int argc, char **argv) { + + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); + if (argc > 1) while (puts(argv[1]) != EOF) ;