From 5cb692528e3ac0ebea3f1714b3ac43f69d176888 Mon Sep 17 00:00:00 2001 From: David Zafman Date: Thu, 20 Nov 2014 13:00:10 -0800 Subject: [PATCH] ceph_objectstore_tool: read_fd() doesn't handle ^D from tty stdin, don't allow Signed-off-by: David Zafman --- src/tools/ceph_objectstore_tool.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index a7dc61c0f28..6531ff88584 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -2694,6 +2694,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); @@ -2723,6 +2729,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); @@ -2758,6 +2770,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); @@ -2793,6 +2811,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);