From d7bc20c93311fcda1e8548a121db1bdf769dec87 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sun, 26 Jun 2016 21:47:36 -0700 Subject: don't allow f-k-r to run if stdin/stdout not a tty Another developer noticed that redirecting stdin of `fish_key_reader` results in weird behavior. Which is not at all surprising. So add checks to ensure stdin and stdout are attached to a tty. Add some rudimentary unit tests for this program. --- src/fish_key_reader.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/fish_key_reader.cpp b/src/fish_key_reader.cpp index 0051ebb4..72d550c2 100644 --- a/src/fish_key_reader.cpp +++ b/src/fish_key_reader.cpp @@ -281,6 +281,11 @@ int main(int argc, char **argv) { return 1; } + if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) { + fprintf(stderr, "Stdin and stdout must be attached to a tty, redirection not allowed.\n"); + return 1; + } + setup_and_process_keys(continuous_mode); return 0; } -- cgit v1.2.3