]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_objectstore_tool: read_fd() doesn't handle ^D from tty stdin, don't allow
authorDavid Zafman <dzafman@redhat.com>
Thu, 20 Nov 2014 21:00:10 +0000 (13:00 -0800)
committerDavid Zafman <dzafman@redhat.com>
Tue, 3 Mar 2015 19:20:59 +0000 (11:20 -0800)
Signed-off-by: David Zafman <dzafman@redhat.com>
(cherry picked from commit 5cb692528e3ac0ebea3f1714b3ac43f69d176888)

src/tools/ceph_objectstore_tool.cc

index 0fb9ebcfca1add4e4abf94730c92a23eb920492c..74c0fcb242b17e243c4d8b8fb5074f688131ff94 100644 (file)
@@ -2645,6 +2645,12 @@ int main(int argc, char **argv)
         } else {
           int fd;
           if (vm.count("arg1") == 0 || arg1 == "-") {
+            // Since read_fd() doesn't handle ^D from a tty stdin, don't allow it.
+            if (isatty(STDIN_FILENO)) {
+                cerr << "stdin is a tty and no file specified" << std::endl;
+                ret = 1;
+                goto out;
+            }
             fd = STDIN_FILENO;
          } else {
             fd = open(arg1.c_str(), O_RDONLY|O_LARGEFILE, 0666);
@@ -2674,6 +2680,12 @@ int main(int argc, char **argv)
 
        int fd;
        if (vm.count("arg2") == 0 || arg2 == "-") {
+          // Since read_fd() doesn't handle ^D from a tty stdin, don't allow it.
+          if (isatty(STDIN_FILENO)) {
+            cerr << "stdin is a tty and no file specified" << std::endl;
+            ret = 1;
+            goto out;
+          }
          fd = STDIN_FILENO;
        } else {
          fd = open(arg2.c_str(), O_RDONLY|O_LARGEFILE, 0666);
@@ -2709,6 +2721,12 @@ int main(int argc, char **argv)
 
        int fd;
        if (vm.count("arg2") == 0 || arg2 == "-") {
+          // Since read_fd() doesn't handle ^D from a tty stdin, don't allow it.
+          if (isatty(STDIN_FILENO)) {
+            cerr << "stdin is a tty and no file specified" << std::endl;
+            ret = 1;
+            goto out;
+          }
          fd = STDIN_FILENO;
        } else {
          fd = open(arg2.c_str(), O_RDONLY|O_LARGEFILE, 0666);
@@ -2744,6 +2762,12 @@ int main(int argc, char **argv)
          usage(desc);
        int fd;
        if (vm.count("arg1") == 0 || arg1 == "-") {
+          // Since read_fd() doesn't handle ^D from a tty stdin, don't allow it.
+          if (isatty(STDIN_FILENO)) {
+            cerr << "stdin is a tty and no file specified" << std::endl;
+            ret = 1;
+            goto out;
+          }
          fd = STDIN_FILENO;
        } else {
          fd = open(arg1.c_str(), O_RDONLY|O_LARGEFILE, 0666);