Skip to content

Commit 888bd38

Browse files
committed
use bufio.NewReader instead of bufio.NewScanner
Signed-off-by: Andrew LeFevre <andrew.lefevre@goteleport.com>
1 parent 32b9945 commit 888bd38

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

go-selinux/selinux_linux.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,13 +1312,18 @@ func getSeUserFromReader(username string, gids []string, r io.Reader, lookupGrou
13121312
var groupSeUser, groupLevel string
13131313

13141314
lineNum := -1
1315-
scanner := bufio.NewScanner(r)
1316-
for scanner.Scan() {
1317-
line := scanner.Text()
1315+
reader := bufio.NewReader(r)
1316+
for {
1317+
lineBytes, readErr := reader.ReadBytes('\n')
1318+
if readErr != nil {
1319+
if !errors.Is(readErr, io.EOF) {
1320+
return "", "", fmt.Errorf("failed to read seusers file: %w", readErr)
1321+
}
1322+
}
13181323
lineNum++
13191324

13201325
// remove any trailing comments, then extra whitespace
1321-
line, _, _ = strings.Cut(line, "#")
1326+
line, _, _ := strings.Cut(string(lineBytes), "#")
13221327
line = strings.TrimSpace(line)
13231328
if line == "" {
13241329
continue
@@ -1358,9 +1363,10 @@ func getSeUserFromReader(username string, gids []string, r io.Reader, lookupGrou
13581363
defaultSeUser = seUserField
13591364
defaultLevel = levelField
13601365
}
1361-
}
1362-
if err := scanner.Err(); err != nil {
1363-
return "", "", fmt.Errorf("failed to read seusers file: %w", err)
1366+
1367+
if errors.Is(readErr, io.EOF) {
1368+
break
1369+
}
13641370
}
13651371

13661372
if groupSeUser != "" {

0 commit comments

Comments
 (0)