From e6bf8463d98e0aba5580a662552909042ed97f84 Mon Sep 17 00:00:00 2001 From: Joan Bruguera Date: Wed, 7 Apr 2021 18:50:31 +0200 Subject: [PATCH] Fix unlocking multiple databases with pw-stdin when input is a pipe This works: ``` $ keepassxc test1.kdbx test2.kdbx --pw-stdin Database password: Database password: ``` But this doesn't (only `test1.kdbx` is unlocked): ``` $ printf '%s\n' 1234 4321 | keepassxc test1.kdbx test2.kdbx --pw-stdin Database password: Database password: ``` The problem is that `Utils::setDefaultTextStreams()` is called multiple times when unlocking multiple databases with `--pw-stdin`, which appears to break the pipe. Simply call it once to avoid the problem. Fixes: #5012 (as far as I can tell by simulating the script in Linux) Signed-off-by: Joan Bruguera --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f6f68769c..24d891a06 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -166,6 +166,9 @@ int main(int argc, char** argv) #endif const bool pwstdin = parser.isSet(pwstdinOption); + if (!fileNames.isEmpty() && pwstdin) { + Utils::setDefaultTextStreams(); + } for (const QString& filename : fileNames) { QString password; if (pwstdin) { @@ -173,7 +176,6 @@ int main(int argc, char** argv) // buffer for native messaging, even if the specified file does not exist QTextStream out(stdout, QIODevice::WriteOnly); out << QObject::tr("Database password: ") << flush; - Utils::setDefaultTextStreams(); password = Utils::getPassword(); }