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 <art27@cantab.net>

* Also ensure the repo is loaded

Signed-off-by: Andrew Thornton <art27@cantab.net>
release/v1.7
zeripath 5 years ago committed by GitHub
parent 4fe1a3050e
commit 0190d3c243
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -39,11 +39,11 @@ func mailIssueCommentToParticipants(e Engine, issue *Issue, doer *User, content
// In case the issue poster is not watching the repository and is active,
// even if we have duplicated in watchers, can be safely filtered out.
poster, err := getUserByID(e, issue.PosterID)
err = issue.loadPoster(e)
if err != nil {
return fmt.Errorf("GetUserByID [%d]: %v", issue.PosterID, err)
}
if issue.PosterID != doer.ID && poster.IsActive && !poster.ProhibitLogin {
if issue.PosterID != doer.ID && issue.Poster.IsActive && !issue.Poster.ProhibitLogin {
participants = append(participants, issue.Poster)
}
@ -88,6 +88,10 @@ func mailIssueCommentToParticipants(e Engine, issue *Issue, doer *User, content
names = append(names, participants[i].Name)
}
if err := issue.loadRepo(e); err != nil {
return err
}
for _, to := range tos {
SendIssueCommentMail(issue, doer, content, comment, []string{to})
}

Loading…
Cancel
Save