Skip to content

Commit 5b1be74

Browse files
forsaken628GiteaBot
authored andcommitted
Fix missing error check of bufio.Scanner (go-gitea#29882)
maybe more
1 parent 440be51 commit 5b1be74

File tree

7 files changed

+30
-0
lines changed

7 files changed

+30
-0
lines changed

models/asymkey/ssh_key_authorized_keys.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
206206
return err
207207
}
208208
}
209+
err = scanner.Err()
210+
if err != nil {
211+
return fmt.Errorf("scan: %w", err)
212+
}
209213
f.Close()
210214
}
211215
return nil

models/asymkey/ssh_key_authorized_principals.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ func regeneratePrincipalKeys(ctx context.Context, t io.StringWriter) error {
128128
return err
129129
}
130130
}
131+
err = scanner.Err()
132+
if err != nil {
133+
return fmt.Errorf("scan: %w", err)
134+
}
131135
f.Close()
132136
}
133137
return nil

modules/doctor/authorizedkeys.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func checkAuthorizedKeys(ctx context.Context, logger log.Logger, autofix bool) e
5050
}
5151
linesInAuthorizedKeys.Add(line)
5252
}
53+
err = scanner.Err()
54+
if err != nil {
55+
return fmt.Errorf("scan: %w", err)
56+
}
5357
f.Close()
5458

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

modules/git/commit.go

Lines changed: 5 additions & 0 deletions
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"
@@ -391,6 +392,10 @@ func (c *Commit) GetSubModules() (*ObjectCache, error) {
391392
}
392393
}
393394
}
395+
err = scanner.Err()
396+
if err != nil {
397+
return nil, fmt.Errorf("scan: %w", err)
398+
}
394399

395400
return c.submoduleCache, nil
396401
}

modules/git/repo_stats.go

Lines changed: 4 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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"
@@ -98,6 +99,10 @@ func (Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.Wri
9899
}
99100
return tmpBlock.Flush()
100101
}
102+
err = scan.Err()
103+
if err != nil {
104+
return fmt.Errorf("scan: %w", err)
105+
}
101106

102107
rd, err := csv.CreateReaderAndDetermineDelimiter(ctx, bytes.NewReader(rawBytes))
103108
if err != nil {

routers/web/repo/compare.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,5 +977,9 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu
977977
}
978978
diffLines = append(diffLines, diffLine)
979979
}
980+
err = scanner.Err()
981+
if err != nil {
982+
return nil, fmt.Errorf("scan: %w", err)
983+
}
980984
return diffLines, nil
981985
}

0 commit comments

Comments
 (0)