Skip to content

Commit

Permalink
mailmap: xcalloc mailmap_info
Browse files Browse the repository at this point in the history
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 <marcandre.lureau@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
elmarco authored and gitster committed Nov 17, 2011
1 parent 0925ce4 commit 74b531f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions mailmap.c
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 74b531f

Please sign in to comment.