Changeset 326 in code for trunk/cmd


Ignore:
Timestamp:
Jun 8, 2020, 8:30:09 PM (5 years ago)
Author:
delthas
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cmd/sojuctl/main.go

    r324 r326  
    121121                fmt.Fprintf(os.Stderr, "Warning: Reading password from stdin.\n")
    122122                scanner := bufio.NewScanner(os.Stdin)
    123                 scanner.Scan()
     123                if !scanner.Scan() {
     124                        if err := scanner.Err(); err != nil {
     125                                log.Fatalf("failed to read password from stdin: %v", err)
     126                        }
     127                        log.Fatalf("failed to read password from stdin: stdin is empty")
     128                }
    124129                password = scanner.Bytes()
    125130
Note: See TracChangeset for help on using the changeset viewer.