Skip to content

Commit 0190d3c

Browse files
authored
Prevent nil dereference in mailIssueCommentToParticipants (#5891, #5895) (#5894)
* Ensure issue.Poster is loaded in mailIssueCommentToParticipants (#5891) Previous code could potentially dereference nil - this PR ensures that the poster is loaded before dereferencing it. Signed-off-by: Andrew Thornton <[email protected]> * Also ensure the repo is loaded Signed-off-by: Andrew Thornton <[email protected]>
1 parent 4fe1a30 commit 0190d3c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

models/issue_mail.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ func mailIssueCommentToParticipants(e Engine, issue *Issue, doer *User, content
3939

4040
// In case the issue poster is not watching the repository and is active,
4141
// even if we have duplicated in watchers, can be safely filtered out.
42-
poster, err := getUserByID(e, issue.PosterID)
42+
err = issue.loadPoster(e)
4343
if err != nil {
4444
return fmt.Errorf("GetUserByID [%d]: %v", issue.PosterID, err)
4545
}
46-
if issue.PosterID != doer.ID && poster.IsActive && !poster.ProhibitLogin {
46+
if issue.PosterID != doer.ID && issue.Poster.IsActive && !issue.Poster.ProhibitLogin {
4747
participants = append(participants, issue.Poster)
4848
}
4949

@@ -88,6 +88,10 @@ func mailIssueCommentToParticipants(e Engine, issue *Issue, doer *User, content
8888
names = append(names, participants[i].Name)
8989
}
9090

91+
if err := issue.loadRepo(e); err != nil {
92+
return err
93+
}
94+
9195
for _, to := range tos {
9296
SendIssueCommentMail(issue, doer, content, comment, []string{to})
9397
}

0 commit comments

Comments
 (0)