Skip to content

Commit 74b531f

Browse files
elmarcogitster
authored andcommitted
mailmap: xcalloc mailmap_info
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0925ce4 commit 74b531f

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

mailmap.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ static void add_mapping(struct string_list *map,
6161
} else {
6262
/* create mailmap entry */
6363
struct string_list_item *item = string_list_insert_at_index(index, old_email, map);
64-
item->util = xmalloc(sizeof(struct mailmap_entry));
65-
memset(item->util, 0, sizeof(struct mailmap_entry));
64+
item->util = xcalloc(1, sizeof(struct mailmap_entry));
6665
((struct mailmap_entry *)item->util)->namemap.strdup_strings = 1;
6766
}
6867
me = (struct mailmap_entry *)map->items[index].util;
@@ -77,7 +76,7 @@ static void add_mapping(struct string_list *map,
7776
if (new_email)
7877
me->email = xstrdup(new_email);
7978
} else {
80-
struct mailmap_info *mi = xmalloc(sizeof(struct mailmap_info));
79+
struct mailmap_info *mi = xcalloc(1, sizeof(struct mailmap_info));
8180
debug_mm("mailmap: adding (complex) entry for %s at index %d\n", old_email, index);
8281
if (new_name)
8382
mi->name = xstrdup(new_name);

0 commit comments

Comments
 (0)