From owner-svn-src-head@freebsd.org Tue Sep 3 14:06:19 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 78E40DC4E9; Tue, 3 Sep 2019 14:06:11 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [96.47.72.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46N7z709Xlz4PHX; Tue, 3 Sep 2019 14:06:11 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1452) id 2454D1A29A; Tue, 3 Sep 2019 14:06:01 +0000 (UTC) X-Original-To: yuripv@localmail.freebsd.org Delivered-To: yuripv@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 1A56716890; Thu, 4 Apr 2019 16:32:32 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 585428141A; Thu, 4 Apr 2019 16:32:31 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 538) id 236C216849; Thu, 4 Apr 2019 16:32:31 +0000 (UTC) Delivered-To: src-committers@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 82B3D16847 for ; Thu, 4 Apr 2019 16:32:28 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3664781412; Thu, 4 Apr 2019 16:32:28 +0000 (UTC) (envelope-from oshogbo@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 086BF3B; Thu, 4 Apr 2019 16:32:28 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x34GWRbl006166; Thu, 4 Apr 2019 16:32:27 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x34GWR4Z006164; Thu, 4 Apr 2019 16:32:27 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201904041632.x34GWR4Z006164@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r345875 - in head: contrib/elftoolchain/strings usr.bin/strings X-SVN-Group: head X-SVN-Commit-Author: oshogbo X-SVN-Commit-Paths: in head: contrib/elftoolchain/strings usr.bin/strings X-SVN-Commit-Revision: 345875 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk X-Loop: FreeBSD.org Sender: owner-src-committers@freebsd.org X-Rspamd-Queue-Id: 585428141A X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.95)[-0.949,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] Status: O X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Tue, 03 Sep 2019 14:06:19 -0000 X-Original-Date: Thu, 4 Apr 2019 16:32:27 +0000 (UTC) X-List-Received-Date: Tue, 03 Sep 2019 14:06:19 -0000 Author: oshogbo Date: Thu Apr 4 16:32:27 2019 New Revision: 345875 URL: https://svnweb.freebsd.org/changeset/base/345875 Log: strings: capsicumize it Reviewed by: cem Discussed with: emaste Differential Revision: https://reviews.freebsd.org/D18038 Modified: head/contrib/elftoolchain/strings/strings.c head/usr.bin/strings/Makefile Modified: head/contrib/elftoolchain/strings/strings.c ============================================================================== --- head/contrib/elftoolchain/strings/strings.c Thu Apr 4 12:02:48 2019 (r345874) +++ head/contrib/elftoolchain/strings/strings.c Thu Apr 4 16:32:27 2019 (r345875) @@ -25,8 +25,10 @@ */ #include +#include #include +#include #include #include #include @@ -44,6 +46,9 @@ #include #include +#include +#include + #include "_elftc.h" ELFTC_VCSID("$Id: strings.c 3648 2018-11-22 23:26:43Z emaste $"); @@ -85,7 +90,7 @@ static struct option strings_longopts[] = { }; int getcharacter(FILE *, long *); -int handle_file(const char *); +int handle_file(fileargs_t *fa, const char *); int handle_elf(const char *, FILE *); int handle_binary(const char *, FILE *, size_t); int find_strings(const char *, FILE *, off_t, off_t); @@ -99,6 +104,8 @@ void usage(void); int main(int argc, char **argv) { + fileargs_t *fa; + cap_rights_t rights; int ch, rc; rc = 0; @@ -187,27 +194,41 @@ main(int argc, char **argv) argc -= optind; argv += optind; + cap_rights_init(&rights, CAP_READ, CAP_SEEK, CAP_FSTAT, CAP_FCNTL); + fa = fileargs_init(argc, argv, O_RDONLY, 0, &rights); + if (fa == NULL) + err(1, "Unable to initialize casper fileargs"); + + caph_cache_catpages(); + if (caph_limit_stdio() < 0 && caph_enter_casper() < 0) { + fileargs_free(fa); + err(1, "Unable to enter capability mode"); + } + if (min_len == 0) min_len = 4; if (*argv == NULL) rc = find_strings("{standard input}", stdin, 0, 0); else while (*argv != NULL) { - if (handle_file(*argv) != 0) + if (handle_file(fa, *argv) != 0) rc = 1; argv++; } + + fileargs_free(fa); + return (rc); } int -handle_file(const char *name) +handle_file(fileargs_t *fa, const char *name) { FILE *pfile; int rt; if (name == NULL) return (1); - pfile = fopen(name, "rb"); + pfile = fileargs_fopen(fa, name, "rb"); if (pfile == NULL) { warnx("'%s': %s", name, strerror(errno)); return (1); Modified: head/usr.bin/strings/Makefile ============================================================================== --- head/usr.bin/strings/Makefile Thu Apr 4 12:02:48 2019 (r345874) +++ head/usr.bin/strings/Makefile Thu Apr 4 16:32:27 2019 (r345875) @@ -10,6 +10,12 @@ PROG= strings LIBADD= elftc elf +.if ${MK_CASPER} != "no" && !defined(BOOTSTRAPPING) +LIBADD+= casper +LIBADD+= cap_fileargs +CFLAGS+= -DWITH_CASPER +.endif + CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common .include