]> git.apps.os.sepia.ceph.com Git - fscrypt.git/commitdiff
cmd/fscrypt: fix race condition in getPassphraseKey()
authorEric Biggers <ebiggers@google.com>
Sun, 8 Nov 2020 04:30:51 +0000 (20:30 -0800)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 8 Nov 2020 04:46:57 +0000 (20:46 -0800)
Set the terminal to raw mode *before* printing the prompt.
Otherwise the user (or the automated test) might enter the
passphrase before the terminal gets put into raw mode.

This is needed for some of the CLI tests to pass reliably in Travis CI.

cmd/fscrypt/keys.go

index 77e3900acff27e57aaf4d8536bc3a176c242d4e5..33461ec68e546dde6055bd5c9ed19d183c415b83 100644 (file)
@@ -86,9 +86,6 @@ func (p passphraseReader) Read(buf []byte) (int, error) {
 // passphrase into a key. If we are not reading from a terminal, just read into
 // the passphrase into the key normally.
 func getPassphraseKey(prompt string) (*crypto.Key, error) {
-       if !quietFlag.Value {
-               fmt.Print(prompt)
-       }
 
        // Only disable echo if stdin is actually a terminal.
        if terminal.IsTerminal(stdinFd) {
@@ -102,6 +99,10 @@ func getPassphraseKey(prompt string) (*crypto.Key, error) {
                }()
        }
 
+       if !quietFlag.Value {
+               fmt.Print(prompt)
+       }
+
        return crypto.NewKeyFromReader(passphraseReader{})
 }