Skip to content

Commit 0e183d8

Browse files
authored
Fix missing error check of bufio.Scanner (#29882)
maybe more
1 parent 1f0d31c commit 0e183d8

File tree

7 files changed

+30
-0
lines changed

7 files changed

+30
-0
lines changed

models/asymkey/ssh_key_authorized_keys.go

+4
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
152152
return err
153153
}
154154
}
155+
err = scanner.Err()
156+
if err != nil {
157+
return fmt.Errorf("scan: %w", err)
158+
}
155159
f.Close()
156160
}
157161
return nil

modules/git/commit.go

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"bytes"
1010
"context"
1111
"errors"
12+
"fmt"
1213
"io"
1314
"os/exec"
1415
"strconv"
@@ -396,6 +397,10 @@ func (c *Commit) GetSubModules() (*ObjectCache, error) {
396397
}
397398
}
398399
}
400+
err = scanner.Err()
401+
if err != nil {
402+
return nil, fmt.Errorf("scan: %w", err)
403+
}
399404

400405
return c.submoduleCache, nil
401406
}

modules/git/repo_stats.go

+4
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
124124
}
125125
}
126126
}
127+
err = scanner.Err()
128+
if err != nil {
129+
return fmt.Errorf("scan: %w", err)
130+
}
127131
a := make([]*CodeActivityAuthor, 0, len(authors))
128132
for _, v := range authors {
129133
a = append(a, v)

modules/markup/csv/csv.go

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package markup
66
import (
77
"bufio"
88
"bytes"
9+
"fmt"
910
"html"
1011
"io"
1112
"regexp"
@@ -123,6 +124,10 @@ func (Renderer) fallbackRender(input io.Reader, tmpBlock *bufio.Writer) error {
123124
return err
124125
}
125126
}
127+
err = scan.Err()
128+
if err != nil {
129+
return fmt.Errorf("scan: %w", err)
130+
}
126131

127132
_, err = tmpBlock.WriteString("</pre>")
128133
if err != nil {

routers/web/repo/compare.go

+4
Original file line numberDiff line numberDiff line change
@@ -980,5 +980,9 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu
980980
}
981981
diffLines = append(diffLines, diffLine)
982982
}
983+
err = scanner.Err()
984+
if err != nil {
985+
return nil, fmt.Errorf("scan: %w", err)
986+
}
983987
return diffLines, nil
984988
}

services/asymkey/ssh_key_authorized_principals.go

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ func regeneratePrincipalKeys(ctx context.Context, t io.StringWriter) error {
122122
return err
123123
}
124124
}
125+
err = scanner.Err()
126+
if err != nil {
127+
return fmt.Errorf("scan: %w", err)
128+
}
125129
f.Close()
126130
}
127131
return nil

services/doctor/authorizedkeys.go

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func checkAuthorizedKeys(ctx context.Context, logger log.Logger, autofix bool) e
5151
}
5252
linesInAuthorizedKeys.Add(line)
5353
}
54+
err = scanner.Err()
55+
if err != nil {
56+
return fmt.Errorf("scan: %w", err)
57+
}
5458
f.Close()
5559

5660
// now we regenerate and check if there are any lines missing

0 commit comments

Comments
 (0)