From 0e183d81fc5283f9d2047472de580e4f04a046c1 Mon Sep 17 00:00:00 2001 From: coldWater Date: Tue, 19 Mar 2024 10:20:36 +0800 Subject: [PATCH] Fix missing error check of bufio.Scanner (#29882) maybe more --- models/asymkey/ssh_key_authorized_keys.go | 4 ++++ modules/git/commit.go | 5 +++++ modules/git/repo_stats.go | 4 ++++ modules/markup/csv/csv.go | 5 +++++ routers/web/repo/compare.go | 4 ++++ services/asymkey/ssh_key_authorized_principals.go | 4 ++++ services/doctor/authorizedkeys.go | 4 ++++ 7 files changed, 30 insertions(+) diff --git a/models/asymkey/ssh_key_authorized_keys.go b/models/asymkey/ssh_key_authorized_keys.go index 9279db20208..7621994866e 100644 --- a/models/asymkey/ssh_key_authorized_keys.go +++ b/models/asymkey/ssh_key_authorized_keys.go @@ -152,6 +152,10 @@ func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error { return err } } + err = scanner.Err() + if err != nil { + return fmt.Errorf("scan: %w", err) + } f.Close() } return nil diff --git a/modules/git/commit.go b/modules/git/commit.go index facb632bd9b..789a2e8f692 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -9,6 +9,7 @@ import ( "bytes" "context" "errors" + "fmt" "io" "os/exec" "strconv" @@ -396,6 +397,10 @@ func (c *Commit) GetSubModules() (*ObjectCache, error) { } } } + err = scanner.Err() + if err != nil { + return nil, fmt.Errorf("scan: %w", err) + } return c.submoduleCache, nil } diff --git a/modules/git/repo_stats.go b/modules/git/repo_stats.go index 41f94e24f99..ce82946873e 100644 --- a/modules/git/repo_stats.go +++ b/modules/git/repo_stats.go @@ -124,6 +124,10 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string) } } } + err = scanner.Err() + if err != nil { + return fmt.Errorf("scan: %w", err) + } a := make([]*CodeActivityAuthor, 0, len(authors)) for _, v := range authors { a = append(a, v) diff --git a/modules/markup/csv/csv.go b/modules/markup/csv/csv.go index 570c4f47041..50bb9184426 100644 --- a/modules/markup/csv/csv.go +++ b/modules/markup/csv/csv.go @@ -6,6 +6,7 @@ package markup import ( "bufio" "bytes" + "fmt" "html" "io" "regexp" @@ -123,6 +124,10 @@ func (Renderer) fallbackRender(input io.Reader, tmpBlock *bufio.Writer) error { return err } } + err = scan.Err() + if err != nil { + return fmt.Errorf("scan: %w", err) + } _, err = tmpBlock.WriteString("") if err != nil { diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index b0570f97c3b..bf42b77b66a 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -980,5 +980,9 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu } diffLines = append(diffLines, diffLine) } + err = scanner.Err() + if err != nil { + return nil, fmt.Errorf("scan: %w", err) + } return diffLines, nil } diff --git a/services/asymkey/ssh_key_authorized_principals.go b/services/asymkey/ssh_key_authorized_principals.go index 9154db7dbb5..822dd0ffe7a 100644 --- a/services/asymkey/ssh_key_authorized_principals.go +++ b/services/asymkey/ssh_key_authorized_principals.go @@ -122,6 +122,10 @@ func regeneratePrincipalKeys(ctx context.Context, t io.StringWriter) error { return err } } + err = scanner.Err() + if err != nil { + return fmt.Errorf("scan: %w", err) + } f.Close() } return nil diff --git a/services/doctor/authorizedkeys.go b/services/doctor/authorizedkeys.go index d5a96605b9c..bc0266c4bc7 100644 --- a/services/doctor/authorizedkeys.go +++ b/services/doctor/authorizedkeys.go @@ -51,6 +51,10 @@ func checkAuthorizedKeys(ctx context.Context, logger log.Logger, autofix bool) e } linesInAuthorizedKeys.Add(line) } + err = scanner.Err() + if err != nil { + return fmt.Errorf("scan: %w", err) + } f.Close() // now we regenerate and check if there are any lines missing