aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-06-26 21:47:36 -0700
committerGravatar Kurtis Rader <krader@skepticism.us>2016-06-26 21:51:00 -0700
commitd7bc20c93311fcda1e8548a121db1bdf769dec87 (patch)
tree3f88ea07f60eb4e0052a13d0717ef83976475e20 /src
parente5011fbcdf3237da3483dcd59c4904fe06c88233 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/fish_key_reader.cpp5
1 files changed, 5 insertions, 0 deletions
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;
}