Skip to content

Commit 11300ee

Browse files
authored
Fix potential bugs (#10513) (#10518)
* use e if it is an option * potential nil so check err first * check err first * m == nil already checked
1 parent c6b78c3 commit 11300ee

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

models/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (a *Action) getCommentLink(e Engine) string {
215215
return "#"
216216
}
217217
if a.Comment == nil && a.CommentID != 0 {
218-
a.Comment, _ = GetCommentByID(a.CommentID)
218+
a.Comment, _ = getCommentByID(e, a.CommentID)
219219
}
220220
if a.Comment != nil {
221221
return a.Comment.HTMLURL()

models/attachment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func GetAttachmentsByCommentID(commentID int64) ([]*Attachment, error) {
199199

200200
func getAttachmentsByCommentID(e Engine, commentID int64) ([]*Attachment, error) {
201201
attachments := make([]*Attachment, 0, 10)
202-
return attachments, x.Where("comment_id=?", commentID).Find(&attachments)
202+
return attachments, e.Where("comment_id=?", commentID).Find(&attachments)
203203
}
204204

205205
// getAttachmentByReleaseIDFileName return a file based on the the following infos:

models/issue_comment.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,12 @@ func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commi
749749

750750
// GetCommentByID returns the comment by given ID.
751751
func GetCommentByID(id int64) (*Comment, error) {
752+
return getCommentByID(x, id)
753+
}
754+
755+
func getCommentByID(e Engine, id int64) (*Comment, error) {
752756
c := new(Comment)
753-
has, err := x.ID(id).Get(c)
757+
has, err := e.ID(id).Get(c)
754758
if err != nil {
755759
return nil, err
756760
} else if !has {

modules/markup/common/linkify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont
108108
}
109109
at := bytes.IndexByte(line, '@')
110110
m = []int{0, stop, at, stop - 1}
111-
if m == nil || bytes.IndexByte(line[m[2]:m[3]], '.') < 0 {
111+
if bytes.IndexByte(line[m[2]:m[3]], '.') < 0 {
112112
return nil
113113
}
114114
lastChar := line[m[1]-1]

routers/repo/attachment.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ func UploadAttachment(ctx *context.Context) {
7070
func DeleteAttachment(ctx *context.Context) {
7171
file := ctx.Query("file")
7272
attach, err := models.GetAttachmentByUUID(file)
73-
if !ctx.IsSigned || (ctx.User.ID != attach.UploaderID) {
74-
ctx.Error(403)
75-
return
76-
}
7773
if err != nil {
7874
ctx.Error(400, err.Error())
7975
return
8076
}
77+
if !ctx.IsSigned || (ctx.User.ID != attach.UploaderID) {
78+
ctx.Error(403)
79+
return
80+
}
8181
err = models.DeleteAttachment(attach, true)
8282
if err != nil {
8383
ctx.Error(500, fmt.Sprintf("DeleteAttachment: %v", err))

routers/repo/commit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ func Diff(ctx *context.Context) {
237237
parents := make([]string, commit.ParentCount())
238238
for i := 0; i < commit.ParentCount(); i++ {
239239
sha, err := commit.ParentID(i)
240-
parents[i] = sha.String()
241240
if err != nil {
242241
ctx.NotFound("repo.Diff", err)
243242
return
244243
}
244+
parents[i] = sha.String()
245245
}
246246

247247
ctx.Data["CommitID"] = commitID

0 commit comments

Comments
 (0)