commit: allocate array using object_id size
authorPatryk Obara <patryk.obara@gmail.com>
Fri, 18 Aug 2017 18:33:13 +0000 (20:33 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 18 Aug 2017 19:18:10 +0000 (12:18 -0700)
struct commit_graft aggregates an array of object_id's, which have
size >= GIT_MAX_RAWSZ bytes. This change prevents memory allocation
error when size of object_id is larger than GIT_SHA1_RAWSZ.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit.c
index 1a0a9f23e9b4c99c0346e28de7fe58cb67fa0229..c2d2de2d74857dd43d052b0ee4cc18309b95f43b 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -147,7 +147,8 @@ struct commit_graft *read_graft_line(struct strbuf *line)
        if ((line->len + 1) % entry_size)
                goto bad_graft_data;
        i = (line->len + 1) / entry_size - 1;
-       graft = xmalloc(st_add(sizeof(*graft), st_mult(GIT_SHA1_RAWSZ, i)));
+       graft = xmalloc(st_add(sizeof(*graft),
+                              st_mult(sizeof(struct object_id), i)));
        graft->nr_parent = i;
        if (get_oid_hex(line->buf, &graft->oid))
                goto bad_graft_data;