From 987e85f2614a5ca31c0c902546d142e3dcb6bcb1 Mon Sep 17 00:00:00 2001 From: Daniel Oliveira Date: Thu, 23 Apr 2015 13:39:36 -0600 Subject: [PATCH] About this commit: 1. server/builds.go:92 used SetStatus(). Replaced with SetBuildStatus(). 2. Added a index check in SetBuildTask() and return an error in case the tasks number is > than build.tasks size. --- datastore/bolt/build.go | 8 ++++---- datastore/bolt/build_test.go | 4 ---- server/builds.go | 2 -- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/datastore/bolt/build.go b/datastore/bolt/build.go index 78629474..34c06292 100644 --- a/datastore/bolt/build.go +++ b/datastore/bolt/build.go @@ -3,11 +3,10 @@ package bolt import ( //"bytes" "encoding/binary" - "strconv" - "time" - "github.com/boltdb/bolt" "github.com/drone/drone/common" + "strconv" + "time" ) // Build gets the specified build number for the @@ -203,12 +202,13 @@ func (db *DB) SetBuildTask(repo string, build int, task *common.Task) error { if err != nil { return err } + // check index to prevent nil pointer / panic if task.Number > len(build_.Tasks) { return ErrKeyNotFound } build_.Updated = time.Now().UTC().Unix() //assuming task number is 1-based. - build_.Tasks[task.Number-1] = task // TODO check index to prevent nil pointer / panic + build_.Tasks[task.Number-1] = task return update(t, bucketBuild, key, build_) }) } diff --git a/datastore/bolt/build_test.go b/datastore/bolt/build_test.go index 35c6a6cb..969a34cb 100644 --- a/datastore/bolt/build_test.go +++ b/datastore/bolt/build_test.go @@ -107,10 +107,6 @@ func TestBuild(t *testing.T) { db.SetBuild(repo, &common.Build{State: "success"}) err_ := db.SetBuildTask(repo, 1, &common.Task{Number: 1}) g.Assert(err_).Equal(nil) - //err_ = db.SetBuildTask(repo, 1, &common.Task{Number: 2}) - //g.Assert(err_).Equal(nil) - //err_ = db.SetBuildTask(repo, 2, &common.Task{Number: 1}) - //g.Assert(err_).Equal(nil) }) }) } diff --git a/server/builds.go b/server/builds.go index 0586f50a..9dd7bb6c 100644 --- a/server/builds.go +++ b/server/builds.go @@ -89,8 +89,6 @@ func PostBuildStatus(c *gin.Context) { c.AbortWithStatus(400) return } - - //if err := store.SetStatus(repo.Name, num, in); err != nil { if err := store.SetBuildStatus(repo.Name, num, in); err != nil { c.Fail(400, err) } else {