]> source.dussan.org Git - gitea.git/commitdiff
Fix potential bugs (#10513) (#10518)
author6543 <6543@obermui.de>
Fri, 28 Feb 2020 03:12:23 +0000 (04:12 +0100)
committerGitHub <noreply@github.com>
Fri, 28 Feb 2020 03:12:23 +0000 (00:12 -0300)
* use e if it is an option
* potential nil so check err first
* check err first
* m == nil already checked

models/action.go
models/attachment.go
models/issue_comment.go
modules/markup/common/linkify.go
routers/repo/attachment.go
routers/repo/commit.go

index cd722cbe7ce2dc21509f857b4c5b88e45006188f..161a7220c0005ee1e8cb2b9e915a9035af60ab4a 100644 (file)
@@ -215,7 +215,7 @@ func (a *Action) getCommentLink(e Engine) string {
                return "#"
        }
        if a.Comment == nil && a.CommentID != 0 {
-               a.Comment, _ = GetCommentByID(a.CommentID)
+               a.Comment, _ = getCommentByID(e, a.CommentID)
        }
        if a.Comment != nil {
                return a.Comment.HTMLURL()
index 81f2e15dad80fe86da965bb1fc32d2d32ac2542e..7e59c7eef4d3467f2f11b8e1ea14d1c68bb4b8ac 100644 (file)
@@ -199,7 +199,7 @@ func GetAttachmentsByCommentID(commentID int64) ([]*Attachment, error) {
 
 func getAttachmentsByCommentID(e Engine, commentID int64) ([]*Attachment, error) {
        attachments := make([]*Attachment, 0, 10)
-       return attachments, x.Where("comment_id=?", commentID).Find(&attachments)
+       return attachments, e.Where("comment_id=?", commentID).Find(&attachments)
 }
 
 // getAttachmentByReleaseIDFileName return a file based on the the following infos:
index 3ba6790216bd5365ba9952c15b208e51b81cef6d..2494467bf285337333461b0593f80155fe9d5f1b 100644 (file)
@@ -749,8 +749,12 @@ func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commi
 
 // GetCommentByID returns the comment by given ID.
 func GetCommentByID(id int64) (*Comment, error) {
+       return getCommentByID(x, id)
+}
+
+func getCommentByID(e Engine, id int64) (*Comment, error) {
        c := new(Comment)
-       has, err := x.ID(id).Get(c)
+       has, err := e.ID(id).Get(c)
        if err != nil {
                return nil, err
        } else if !has {
index 6ae70fba3403a859dab10d3c43dec3dac9c73c2f..25621bf8019e01452ae519070d766db0383ab981 100644 (file)
@@ -108,7 +108,7 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont
                }
                at := bytes.IndexByte(line, '@')
                m = []int{0, stop, at, stop - 1}
-               if m == nil || bytes.IndexByte(line[m[2]:m[3]], '.') < 0 {
+               if bytes.IndexByte(line[m[2]:m[3]], '.') < 0 {
                        return nil
                }
                lastChar := line[m[1]-1]
index 96dc28a23a9d970e3f0597220caa4fb8ebf788db..f938c230ed321f21f5bda5e0702a9fafd1f397cc 100644 (file)
@@ -70,14 +70,14 @@ func UploadAttachment(ctx *context.Context) {
 func DeleteAttachment(ctx *context.Context) {
        file := ctx.Query("file")
        attach, err := models.GetAttachmentByUUID(file)
-       if !ctx.IsSigned || (ctx.User.ID != attach.UploaderID) {
-               ctx.Error(403)
-               return
-       }
        if err != nil {
                ctx.Error(400, err.Error())
                return
        }
+       if !ctx.IsSigned || (ctx.User.ID != attach.UploaderID) {
+               ctx.Error(403)
+               return
+       }
        err = models.DeleteAttachment(attach, true)
        if err != nil {
                ctx.Error(500, fmt.Sprintf("DeleteAttachment: %v", err))
index e581d39526c5c9cc78e5cc7c4522de21f3b36325..6a4b405e0e8d561b11d1e88813fece5f9564056a 100644 (file)
@@ -237,11 +237,11 @@ func Diff(ctx *context.Context) {
        parents := make([]string, commit.ParentCount())
        for i := 0; i < commit.ParentCount(); i++ {
                sha, err := commit.ParentID(i)
-               parents[i] = sha.String()
                if err != nil {
                        ctx.NotFound("repo.Diff", err)
                        return
                }
+               parents[i] = sha.String()
        }
 
        ctx.Data["CommitID"] = commitID