diff options
author | hiifong <f@ilo.nz> | 2025-01-19 10:51:43 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-19 02:51:43 +0000 |
commit | b7614e2d2f2af246e33b8bd6a38ecfd1babc9ecc (patch) | |
tree | 8dae2bbf32f2a9c100ceb7a40b334668008a0610 /modules/git | |
parent | dc2308a95908091c036011252fbca38980c8846c (diff) | |
download | gitea-b7614e2d2f2af246e33b8bd6a38ecfd1babc9ecc.tar.gz gitea-b7614e2d2f2af246e33b8bd6a38ecfd1babc9ecc.zip |
Fix parentCommit invalid memory address or nil pointer dereference. (#33204)
When the parent Commit does not exist on gitea, an error will be
reported when opening the Commit details page: invalid memory address or
nil pointer dereference.


Diffstat (limited to 'modules/git')
-rw-r--r-- | modules/git/diff.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/modules/git/diff.go b/modules/git/diff.go index 833f6220f9..da0a2f26ba 100644 --- a/modules/git/diff.go +++ b/modules/git/diff.go @@ -64,7 +64,10 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff } else if commit.ParentCount() == 0 { cmd.AddArguments("show").AddDynamicArguments(endCommit).AddDashesAndList(files...) } else { - c, _ := commit.Parent(0) + c, err := commit.Parent(0) + if err != nil { + return err + } cmd.AddArguments("diff", "-M").AddDynamicArguments(c.ID.String(), endCommit).AddDashesAndList(files...) } case RawDiffPatch: @@ -74,7 +77,10 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff } else if commit.ParentCount() == 0 { cmd.AddArguments("format-patch", "--no-signature", "--stdout", "--root").AddDynamicArguments(endCommit).AddDashesAndList(files...) } else { - c, _ := commit.Parent(0) + c, err := commit.Parent(0) + if err != nil { + return err + } query := fmt.Sprintf("%s...%s", endCommit, c.ID.String()) cmd.AddArguments("format-patch", "--no-signature", "--stdout").AddDynamicArguments(query).AddDashesAndList(files...) } |