1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-09 04:46:12 +02:00

commit: allocate array using object_id size

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>
This commit is contained in:
Patryk Obara 2017-08-18 20:33:13 +02:00 committed by Junio C Hamano
parent 9a9340329a
commit bc65d2262d

View File

@ -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;