Author: markj
Date: Mon Jan 21 03:47:20 2019
New Revision: 343245
URL: https://svnweb.freebsd.org/changeset/base/343245

Log:
  Revert r343117.
  
  It breaks the special mode specified by passing "-" as one of the
  input files.  Revert for now while we discuss a fix.
  
  PR:           234885
  Reported by:  delphij
  MFC after:    now

Modified:
  head/usr.bin/cmp/cmp.c

Modified: head/usr.bin/cmp/cmp.c
==============================================================================
--- head/usr.bin/cmp/cmp.c      Mon Jan 21 03:38:37 2019        (r343244)
+++ head/usr.bin/cmp/cmp.c      Mon Jan 21 03:47:20 2019        (r343245)
@@ -116,16 +116,14 @@ 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 = STDIN_FILENO;
+               fd1 = 0;
                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
@@ -136,9 +134,10 @@ main(int argc, char *argv[])
                        errx(ERR_EXIT,
                                "standard input may only be specified once");
                special = 1;
-               fd2 = STDIN_FILENO;
+               fd2 = 0;
                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
@@ -175,6 +174,16 @@ main(int argc, char *argv[])
                err(ERR_EXIT, "unable to limit fcntls for %s", file1);
        if (caph_fcntls_limit(fd2, fcntls) < 0)
                err(ERR_EXIT, "unable to limit fcntls for %s", file2);
+
+       if (!special) {
+               cap_rights_init(&rights);
+               if (caph_rights_limit(STDIN_FILENO, &rights) < 0) {
+                       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();
 
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to