{"thread":{"id":"28952","subject":"[PATCH] mailmap: xcalloc mailmap_info","startedAt":"2011-11-16T23:51:13Z","lastAt":"2011-11-17T01:25:06Z","messageCount":3,"participants":["Marc-André Lureau","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"179603","messageId":"1321487473-29194-1-git-send-email-marcandre.lureau@gmail.com","threadId":"28952","inReplyTo":null,"subject":"[PATCH] mailmap: xcalloc mailmap_info","fromName":"Marc-André Lureau","fromEmail":"marcandre.lureau@gmail.com","sentAt":"2011-11-16T23:51:13Z","receivedAt":"2011-11-16T23:51:13Z","isPatch":true,"sender":{"key":"marcandre.lureau@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9381?v=4"},"body":"This is to avoid reaching free of uninitialized members.\n\nWith an invalid .mailmap (and perhaps in other cases), it can reach\nfree(mi->name) with garbage for example.\n---\n mailmap.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/mailmap.c b/mailmap.c\nindex 02fcfde..fbf7764 100644\n--- a/mailmap.c\n+++ b/mailmap.c\n@@ -88,7 +88,7 @@ static void add_mapping(struct string_list *map,\n \t\t\tme->email = xstrdup(new_email);\n \t\t}\n \t} else {\n-\t\tstruct mailmap_info *mi = xmalloc(sizeof(struct mailmap_info));\n+\t\tstruct mailmap_info *mi = xcalloc(1, sizeof(struct mailmap_info));\n \t\tdebug_mm(\"mailmap: adding (complex) entry for %s at index %d\\n\", old_email, index);\n \t\tif (new_name)\n \t\t\tmi->name = xstrdup(new_name);\n-- \n1.7.7\n"},{"id":"179606","messageId":"7v8vnfpn9v.fsf@alter.siamese.dyndns.org","threadId":"28952","inReplyTo":"1321487473-29194-1-git-send-email-marcandre.lureau@gmail.com","subject":"Re: [PATCH] mailmap: xcalloc mailmap_info","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-11-17T01:10:04Z","receivedAt":"2011-11-17T01:10:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Marc-André Lureau <marcandre.lureau@gmail.com> writes:\n\n> This is to avoid reaching free of uninitialized members.\n>\n> With an invalid .mailmap (and perhaps in other cases), it can reach\n> free(mi->name) with garbage for example.\n> ---\n\nSign-off?\n\nThanks. We might want to turn xmalloc() followed by memset(,0,) for the\nallocation of the mailmap entry itself in the same function, but that is a\nminor issue.\n\n>  mailmap.c |    2 +-\n>  1 files changed, 1 insertions(+), 1 deletions(-)\n>\n> diff --git a/mailmap.c b/mailmap.c\n> index 02fcfde..fbf7764 100644\n> --- a/mailmap.c\n> +++ b/mailmap.c\n> @@ -88,7 +88,7 @@ static void add_mapping(struct string_list *map,\n>  \t\t\tme->email = xstrdup(new_email);\n>  \t\t}\n>  \t} else {\n> -\t\tstruct mailmap_info *mi = xmalloc(sizeof(struct mailmap_info));\n> +\t\tstruct mailmap_info *mi = xcalloc(1, sizeof(struct mailmap_info));\n>  \t\tdebug_mm(\"mailmap: adding (complex) entry for %s at index %d\\n\", old_email, index);\n>  \t\tif (new_name)\n>  \t\t\tmi->name = xstrdup(new_name);\n"},{"id":"179609","messageId":"1321493106-6533-1-git-send-email-marcandre.lureau@gmail.com","threadId":"28952","inReplyTo":"7v8vnfpn9v.fsf@alter.siamese.dyndns.org","subject":"[PATCH] mailmap: xcalloc mailmap_info","fromName":"Marc-André Lureau","fromEmail":"marcandre.lureau@gmail.com","sentAt":"2011-11-17T01:25:06Z","receivedAt":"2011-11-17T01:25:06Z","isPatch":true,"sender":{"key":"marcandre.lureau@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9381?v=4"},"body":"This is to avoid reaching free of uninitialized members.\n\nWith an invalid .mailmap (and perhaps in other cases), it can reach\nfree(mi->name) with garbage for example.\n\nSigned-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>\n---\n mailmap.c |    5 ++---\n 1 files changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/mailmap.c b/mailmap.c\nindex 02fcfde..8c3196c 100644\n--- a/mailmap.c\n+++ b/mailmap.c\n@@ -70,8 +70,7 @@ static void add_mapping(struct string_list *map,\n \t} else {\n \t\t/* create mailmap entry */\n \t\tstruct string_list_item *item = string_list_insert_at_index(map, index, old_email);\n-\t\titem->util = xmalloc(sizeof(struct mailmap_entry));\n-\t\tmemset(item->util, 0, sizeof(struct mailmap_entry));\n+\t\titem->util = xcalloc(1, sizeof(struct mailmap_entry));\n \t\t((struct mailmap_entry *)item->util)->namemap.strdup_strings = 1;\n \t}\n \tme = (struct mailmap_entry *)map->items[index].util;\n@@ -88,7 +87,7 @@ static void add_mapping(struct string_list *map,\n \t\t\tme->email = xstrdup(new_email);\n \t\t}\n \t} else {\n-\t\tstruct mailmap_info *mi = xmalloc(sizeof(struct mailmap_info));\n+\t\tstruct mailmap_info *mi = xcalloc(1, sizeof(struct mailmap_info));\n \t\tdebug_mm(\"mailmap: adding (complex) entry for %s at index %d\\n\", old_email, index);\n \t\tif (new_name)\n \t\t\tmi->name = xstrdup(new_name);\n-- \n1.7.7\n"}]}