svn commit: r343205 - stable/12/usr.bin/cmp
Mark Johnston
markj at FreeBSD.org
Sun Jan 20 00:58:55 UTC 2019
Author: markj
Date: Sun Jan 20 00:58:54 2019
New Revision: 343205
URL: https://svnweb.freebsd.org/changeset/base/343205
Log:
MFC r343117:
Fix handling of rights on stdio streams.
PR: 234885
Modified:
stable/12/usr.bin/cmp/cmp.c
Directory Properties:
stable/12/ (props changed)
Modified: stable/12/usr.bin/cmp/cmp.c
==============================================================================
--- stable/12/usr.bin/cmp/cmp.c Sun Jan 20 00:45:44 2019 (r343204)
+++ stable/12/usr.bin/cmp/cmp.c Sun Jan 20 00:58:54 2019 (r343205)
@@ -116,14 +116,16 @@ main(int argc, char *argv[])
if (argc < 2 || argc > 4)
usage();
+ if (caph_limit_stdio() == -1)
+ err(ERR_EXIT, "failed to limit stdio");
+
/* Backward compatibility -- handle "-" meaning stdin. */
special = 0;
if (strcmp(file1 = argv[0], "-") == 0) {
special = 1;
- fd1 = 0;
+ fd1 = STDIN_FILENO;
file1 = "stdin";
- }
- else if ((fd1 = open(file1, oflag, 0)) < 0 && errno != EMLINK) {
+ } else if ((fd1 = open(file1, oflag, 0)) < 0 && errno != EMLINK) {
if (!sflag)
err(ERR_EXIT, "%s", file1);
else
@@ -134,10 +136,9 @@ main(int argc, char *argv[])
errx(ERR_EXIT,
"standard input may only be specified once");
special = 1;
- fd2 = 0;
+ fd2 = STDIN_FILENO;
file2 = "stdin";
- }
- else if ((fd2 = open(file2, oflag, 0)) < 0 && errno != EMLINK) {
+ } else if ((fd2 = open(file2, oflag, 0)) < 0 && errno != EMLINK) {
if (!sflag)
err(ERR_EXIT, "%s", file2);
else
@@ -174,17 +175,6 @@ main(int argc, char *argv[])
err(ERR_EXIT, "unable to limit fcntls for %s", file1);
if (cap_fcntls_limit(fd2, fcntls) < 0 && errno != ENOSYS)
err(ERR_EXIT, "unable to limit fcntls for %s", file2);
-
- if (!special) {
- cap_rights_init(&rights);
- if (cap_rights_limit(STDIN_FILENO, &rights) < 0 &&
- errno != ENOSYS) {
- err(ERR_EXIT, "unable to limit stdio");
- }
- }
-
- if (caph_limit_stdout() == -1 || caph_limit_stderr() == -1)
- err(ERR_EXIT, "unable to limit stdio");
caph_cache_catpages();
More information about the svn-src-stable
mailing list