ssh/terminal: consume data before checking for an error.

According to the io.Reader docs, Alex had it right the first time. (See
discussion on https://golang.org/cl/25355.)

Change-Id: Ib6fb9dfb99009e034263574e82d7e9d4828df38f
Reviewed-on: https://go-review.googlesource.com/35242
TryBot-Result: Gobot Gobot <gobot@golang.org>
Run-TryBot: Adam Langley <agl@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Adam Langley <agl@golang.org>
This commit is contained in:
Adam Langley 2017-01-16 16:40:45 -08:00
Родитель 038bd0bb6d
Коммит efcab1a52e
1 изменённых файлов: 7 добавлений и 6 удалений

Просмотреть файл

@ -930,12 +930,6 @@ func readPasswordLine(reader io.Reader) ([]byte, error) {
for {
n, err := reader.Read(buf[:])
if err != nil {
if err == io.EOF && len(ret) > 0 {
return ret, nil
}
return ret, err
}
if n > 0 {
switch buf[0] {
case '\n':
@ -945,6 +939,13 @@ func readPasswordLine(reader io.Reader) ([]byte, error) {
default:
ret = append(ret, buf[0])
}
continue
}
if err != nil {
if err == io.EOF && len(ret) > 0 {
return ret, nil
}
return ret, err
}
}
}