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 /services/gitdiff | |
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 'services/gitdiff')
-rw-r--r-- | services/gitdiff/gitdiff.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index f42686bb71..f046e59678 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -1136,7 +1136,10 @@ func GetDiff(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, fi } else { actualBeforeCommitID := opts.BeforeCommitID if len(actualBeforeCommitID) == 0 { - parentCommit, _ := commit.Parent(0) + parentCommit, err := commit.Parent(0) + if err != nil { + return nil, err + } actualBeforeCommitID = parentCommit.ID.String() } @@ -1145,7 +1148,6 @@ func GetDiff(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, fi AddDynamicArguments(actualBeforeCommitID, opts.AfterCommitID) opts.BeforeCommitID = actualBeforeCommitID - var err error beforeCommit, err = gitRepo.GetCommit(opts.BeforeCommitID) if err != nil { return nil, err |