Skip to content

Commit 99cfd57

Browse files
committed
mountinfo: move s.Err() out of scanner loop
The previous code would actually ignore IO errors during scanning, becuase s.Scan() returns false if there was an error (leaving the loop and never being detected). Indeed the correct way[1] of using the builtin bufio.Scanner is actually more like: s := bufio.NewScanner(...) for s.Scan() { // use s.Text() } if err := s.Err(); err != nil { return err } [1]: https://blog.golang.org/errors-are-values Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
1 parent 95f2efb commit 99cfd57

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

mountinfo/mountinfo_linux.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ import (
1818
func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) {
1919
s := bufio.NewScanner(r)
2020
out := []*Info{}
21-
var err error
2221
for s.Scan() {
23-
if err = s.Err(); err != nil {
24-
return nil, err
25-
}
22+
var err error
23+
2624
/*
2725
See http://man7.org/linux/man-pages/man5/proc.5.html
2826
@@ -133,6 +131,9 @@ func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) {
133131
break
134132
}
135133
}
134+
if err := s.Err(); err != nil {
135+
return nil, err
136+
}
136137
return out, nil
137138
}
138139

0 commit comments

Comments
 (0)