aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/commit.go
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2018-08-17 18:52:18 +0200
committerJavi Fontan <jfontan@gmail.com>2018-08-17 18:52:18 +0200
commit166623633e285e17b0582443c9d03b842b6370fa (patch)
tree9ccd4a33da8ea9b8a569f3ba261511a5e594667b /plumbing/object/commit.go
parent7b6c1266556f59ac436fada3fa6106d4a84f9b56 (diff)
downloadgo-git-166623633e285e17b0582443c9d03b842b6370fa.tar.gz
object: fix panic when reading object header
When the first line of the pgp signature is an empty line or some header is malformed it crashes as there's no data for the header element. For example, if author name is "\n". Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'plumbing/object/commit.go')
-rw-r--r--plumbing/object/commit.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/plumbing/object/commit.go b/plumbing/object/commit.go
index 00ae3f1..e254342 100644
--- a/plumbing/object/commit.go
+++ b/plumbing/object/commit.go
@@ -199,17 +199,23 @@ func (c *Commit) Decode(o plumbing.EncodedObject) (err error) {
}
split := bytes.SplitN(line, []byte{' '}, 2)
+
+ var data []byte
+ if len(split) == 2 {
+ data = split[1]
+ }
+
switch string(split[0]) {
case "tree":
- c.TreeHash = plumbing.NewHash(string(split[1]))
+ c.TreeHash = plumbing.NewHash(string(data))
case "parent":
- c.ParentHashes = append(c.ParentHashes, plumbing.NewHash(string(split[1])))
+ c.ParentHashes = append(c.ParentHashes, plumbing.NewHash(string(data)))
case "author":
- c.Author.Decode(split[1])
+ c.Author.Decode(data)
case "committer":
- c.Committer.Decode(split[1])
+ c.Committer.Decode(data)
case headerpgp:
- c.PGPSignature += string(split[1]) + "\n"
+ c.PGPSignature += string(data) + "\n"
pgpsig = true
}
} else {