From 74b531f65feaa09b5c3963f788b437a368933730 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 17 Nov 2011 02:25:06 +0100 Subject: [PATCH] mailmap: xcalloc mailmap_info MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is to avoid reaching free of uninitialized members. With an invalid .mailmap (and perhaps in other cases), it can reach free(mi->name) with garbage for example. Signed-off-by: Marc-André Lureau Signed-off-by: Junio C Hamano --- mailmap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mailmap.c b/mailmap.c index f12bb45a3..4892d4973 100644 --- a/mailmap.c +++ b/mailmap.c @@ -61,8 +61,7 @@ static void add_mapping(struct string_list *map, } else { /* create mailmap entry */ struct string_list_item *item = string_list_insert_at_index(index, old_email, map); - item->util = xmalloc(sizeof(struct mailmap_entry)); - memset(item->util, 0, sizeof(struct mailmap_entry)); + item->util = xcalloc(1, sizeof(struct mailmap_entry)); ((struct mailmap_entry *)item->util)->namemap.strdup_strings = 1; } me = (struct mailmap_entry *)map->items[index].util; @@ -77,7 +76,7 @@ static void add_mapping(struct string_list *map, if (new_email) me->email = xstrdup(new_email); } else { - struct mailmap_info *mi = xmalloc(sizeof(struct mailmap_info)); + struct mailmap_info *mi = xcalloc(1, sizeof(struct mailmap_info)); debug_mm("mailmap: adding (complex) entry for %s at index %d\n", old_email, index); if (new_name) mi->name = xstrdup(new_name); -- 2.30.2