From 574a315c4444920e5fe64d429d1d3acf0dd74a84 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Sun, 13 Sep 2015 15:15:21 +0200 Subject: [PATCH] Check that stdin is a tty before reading If stdin isn't a tty, the behaviour of std::getline(std::cin, email) and getpass() is different (the latter always uses /dev/tty). If input is redirected, it's probably best to just fail. --- src/downloader.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/downloader.cpp b/src/downloader.cpp index 8de7a9a..bf53509 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -121,6 +121,10 @@ int Downloader::login() { char *pwd; std::string email; + if (!isatty(STDIN_FILENO)) { + std::cout << "Unable to read email and password" << std::endl; + return 0; + } std::cout << "Email: "; std::getline(std::cin,email); pwd = getpass("Password: ");