Fix: Check the stdin scanner for errors when reading the password
Reading from stdin with Scanner.Scan() can either fail because of a read error, or return no bytes because the EOF was reached. This adds support for checking these cases before actually reading the password.
This commit is contained in:
parent
17fe033adc
commit
ed943f5451
@ -120,7 +120,12 @@ func readPassword() ([]byte, error) {
|
|||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(os.Stderr, "Warning: Reading password from stdin.\n")
|
fmt.Fprintf(os.Stderr, "Warning: Reading password from stdin.\n")
|
||||||
scanner := bufio.NewScanner(os.Stdin)
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
scanner.Scan()
|
if !scanner.Scan() {
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
log.Fatalf("failed to read password from stdin: %v", err)
|
||||||
|
}
|
||||||
|
log.Fatalf("failed to read password from stdin: stdin is empty")
|
||||||
|
}
|
||||||
password = scanner.Bytes()
|
password = scanner.Bytes()
|
||||||
|
|
||||||
if len(password) == 0 {
|
if len(password) == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user