[PATCH v4 3/4] commit: allocate array using object_id size
- From
Patryk Obara <patryk.obara@gmail.com>
- Date
- Aug 18, 2017, 18:33 UTC
- Message-ID
- <d3003634866f18fee7c05f78b6e170a87f62f041.1503079879.git.patryk.obara@gmail.com>
- In-Reply-To
- <cover.1503079879.git.patryk.obara@gmail.com>
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> --- commit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/commit.c b/commit.c index 1a0a9f2..436eb34 100644 --- 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;
-- 2.9.5