From owner-svn-src-all@freebsd.org Fri Dec 16 02:03:41 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AA351C77139; Fri, 16 Dec 2016 02:03:41 +0000 (UTC) (envelope-from cem@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 mx1.freebsd.org (Postfix) with ESMTPS id 601B01594; Fri, 16 Dec 2016 02:03:41 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uBG23eKN024825; Fri, 16 Dec 2016 02:03:40 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uBG23eLU024823; Fri, 16 Dec 2016 02:03:40 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201612160203.uBG23eLU024823@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: "Conrad E. Meyer" Date: Fri, 16 Dec 2016 02:03:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r310143 - head/usr.bin/hexdump X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Dec 2016 02:03:41 -0000 Author: cem Date: Fri Dec 16 02:03:40 2016 New Revision: 310143 URL: https://svnweb.freebsd.org/changeset/base/310143 Log: hexdump(1): First cut capsicumification For now, only enter the sandbox for the last file processed (including stdin for zero-argument mode). Sandboxing all inputs will require a little restructuring of the program. Feedback by: emaste@ (earlier versions) Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D7915 Modified: head/usr.bin/hexdump/display.c head/usr.bin/hexdump/hexdump.c Modified: head/usr.bin/hexdump/display.c ============================================================================== --- head/usr.bin/hexdump/display.c Fri Dec 16 01:59:28 2016 (r310142) +++ head/usr.bin/hexdump/display.c Fri Dec 16 02:03:40 2016 (r310143) @@ -36,10 +36,13 @@ static char sccsid[] = "@(#)display.c 8. __FBSDID("$FreeBSD$"); #include +#include #include +#include #include #include +#include #include #include #include @@ -355,6 +358,19 @@ next(char **argv) return(0); statok = 0; } + + if (caph_limit_stream(fileno(stdin), CAPH_READ) < 0) + err(1, "unable to restrict %s", + statok ? _argv[-1] : "stdin"); + + /* + * We've opened our last input file; enter capsicum sandbox. + */ + if (*_argv == NULL) { + if (cap_enter() < 0 && errno != ENOSYS) + err(1, "unable to enter capability mode"); + } + if (skip) doskip(statok ? *_argv : "stdin", statok); if (*_argv) Modified: head/usr.bin/hexdump/hexdump.c ============================================================================== --- head/usr.bin/hexdump/hexdump.c Fri Dec 16 01:59:28 2016 (r310142) +++ head/usr.bin/hexdump/hexdump.c Fri Dec 16 02:03:40 2016 (r310143) @@ -42,6 +42,9 @@ static char sccsid[] = "@(#)hexdump.c 8. __FBSDID("$FreeBSD$"); #include +#include +#include +#include #include #include #include @@ -76,6 +79,14 @@ main(int argc, char *argv[]) for (tfs = fshead; tfs; tfs = tfs->nextfs) rewrite(tfs); + /* + * Cache NLS data, for strerror, for err(3), before entering capability + * mode. + */ + caph_cache_catpages(); + if (caph_limit_stdio() < 0) + err(1, "capsicum"); + (void)next(argv); display(); exit(exitval);