{"thread":{"id":"62990","subject":"[PATCH v2] mailmap: fix check-mailmap with full mailmap line","startedAt":"2025-02-21T23:48:35Z","lastAt":"2025-02-22T02:26:50Z","messageCount":2,"participants":["Jacob Keller","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"512867","messageId":"20250221-jk-fix-sendemail-mailinfo-v2-1-9aca7dc05dbb@gmail.com","threadId":"62990","inReplyTo":null,"subject":"[PATCH v2] mailmap: fix check-mailmap with full mailmap line","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2025-02-21T23:47:58Z","receivedAt":"2025-02-21T23:48:35Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nI recently had reported to me a crash from a coworker using the recently\nadded sendemail mailmap support:\n\n  3724814 Segmentation fault      (core dumped) git check-mailmap \"bugs@company.xx\"\n\nThis appears to happen because of the NULL pointer name passed into\nmap_user(). Fix this by passing \"\" instead of NULL so that we have a\nvalid pointer.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\nChanges in v2:\n- Just fix the NULL pointer dereference, leave mailmap resolution as-is\n- Link to v1: https://lore.kernel.org/r/20250213-jk-fix-sendemail-mailinfo-v1-1-c0b06c215f21@gmail.com\n---\n builtin/check-mailmap.c |  2 +-\n t/t4203-mailmap.sh      | 12 ++++++++++++\n 2 files changed, 13 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c\nindex df00b5ee13adb87881b8c1e92cac256e6ad319d1..be2cebe12152e38d3bb8cf12948823c8d710bdda 100644\n--- a/builtin/check-mailmap.c\n+++ b/builtin/check-mailmap.c\n@@ -35,7 +35,7 @@ static void check_mailmap(struct string_list *mailmap, const char *contact)\n \t\tmail = ident.mail_begin;\n \t\tmaillen = ident.mail_end - ident.mail_begin;\n \t} else {\n-\t\tname = NULL;\n+\t\tname = \"\";\n \t\tnamelen = 0;\n \t\tmail = contact;\n \t\tmaillen = strlen(contact);\ndiff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh\nindex 24214919312777b76e4d3b2b784bcb953583750a..4a6242ff99b59ea1a46eb14ca812c94e5e620162 100755\n--- a/t/t4203-mailmap.sh\n+++ b/t/t4203-mailmap.sh\n@@ -113,6 +113,18 @@ test_expect_success 'check-mailmap --stdin simple address: no mapping' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'check-mailmap name and address: mapping' '\n+\ttest_when_finished \"rm .mailmap\" &&\n+\tcat >.mailmap <<-EOF &&\n+\tBug Reports <bugs-new@company.xx> Bugs <bugs@company.xx>\n+\tEOF\n+\tcat >expect <<-EOF &&\n+\t<bugs@company.xx>\n+\tEOF\n+\tgit check-mailmap \"bugs@company.xx\" >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'No mailmap' '\n \tcat >expect <<-EOF &&\n \t$GIT_AUTHOR_NAME (1):\n\n---\nbase-commit: b838bf1938926a7a900166136d995d86f8a00e24\nchange-id: 20250213-jk-fix-sendemail-mailinfo-32f027b1b9e7\n\nBest regards,\n-- \nJacob Keller <jacob.keller@gmail.com>\n\n"},{"id":"512870","messageId":"xmqqh64m90k7.fsf@gitster.g","threadId":"62990","inReplyTo":"20250221-jk-fix-sendemail-mailinfo-v2-1-9aca7dc05dbb@gmail.com","subject":"Re: [PATCH v2] mailmap: fix check-mailmap with full mailmap line","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-02-22T02:26:48Z","receivedAt":"2025-02-22T02:26:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.e.keller@intel.com> writes:\n\n> From: Jacob Keller <jacob.keller@gmail.com>\n>\n> I recently had reported to me a crash from a coworker using the recently\n> added sendemail mailmap support:\n>\n>   3724814 Segmentation fault      (core dumped) git check-mailmap \"bugs@company.xx\"\n>\n> This appears to happen because of the NULL pointer name passed into\n> map_user(). Fix this by passing \"\" instead of NULL so that we have a\n> valid pointer.\n>\n> Signed-off-by: Jacob Keller <jacob.keller@gmail.com>\n> ---\n> Changes in v2:\n> - Just fix the NULL pointer dereference, leave mailmap resolution as-is\n> - Link to v1: https://lore.kernel.org/r/20250213-jk-fix-sendemail-mailinfo-v1-1-c0b06c215f21@gmail.com\n> ---\n>  builtin/check-mailmap.c |  2 +-\n>  t/t4203-mailmap.sh      | 12 ++++++++++++\n>  2 files changed, 13 insertions(+), 1 deletion(-)\n>\n> diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c\n> index df00b5ee13adb87881b8c1e92cac256e6ad319d1..be2cebe12152e38d3bb8cf12948823c8d710bdda 100644\n> --- a/builtin/check-mailmap.c\n> +++ b/builtin/check-mailmap.c\n> @@ -35,7 +35,7 @@ static void check_mailmap(struct string_list *mailmap, const char *contact)\n>  \t\tmail = ident.mail_begin;\n>  \t\tmaillen = ident.mail_end - ident.mail_begin;\n>  \t} else {\n> -\t\tname = NULL;\n> +\t\tname = \"\";\n>  \t\tnamelen = 0;\n>  \t\tmail = contact;\n>  \t\tmaillen = strlen(contact);\n\nOK.  I audited all users of map_user(), and everybody else\n(including the other side of the if/else we see here) follows the\npattern to point name and mail into an \"ident\" instance, which would\nnever be NULL.  The way an \"ident\" instance signals that there is no\nname is to have the name_begin and name_end members point at the same\nbyte.\n\nSo this change obviously is a good thing to do.\n\nThe callee, map_user() does assume both email and name pointers\npoint at valid strings, passes them to lookup_prefix(), and have\nthem receive what a mailmap_info instance records.  We may want\nto document the calling convention a bit better, but that is\nobviously outside the scope of this immediate fix.\n\nThanks.  Will queue.\n\n\n> diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh\n> index 24214919312777b76e4d3b2b784bcb953583750a..4a6242ff99b59ea1a46eb14ca812c94e5e620162 100755\n> --- a/t/t4203-mailmap.sh\n> +++ b/t/t4203-mailmap.sh\n> @@ -113,6 +113,18 @@ test_expect_success 'check-mailmap --stdin simple address: no mapping' '\n>  \ttest_cmp expect actual\n>  '\n>  \n> +test_expect_success 'check-mailmap name and address: mapping' '\n> +\ttest_when_finished \"rm .mailmap\" &&\n> +\tcat >.mailmap <<-EOF &&\n> +\tBug Reports <bugs-new@company.xx> Bugs <bugs@company.xx>\n> +\tEOF\n> +\tcat >expect <<-EOF &&\n> +\t<bugs@company.xx>\n> +\tEOF\n> +\tgit check-mailmap \"bugs@company.xx\" >actual &&\n> +\ttest_cmp expect actual\n> +'\n> +\n>  test_expect_success 'No mailmap' '\n>  \tcat >expect <<-EOF &&\n>  \t$GIT_AUTHOR_NAME (1):\n>\n> ---\n> base-commit: b838bf1938926a7a900166136d995d86f8a00e24\n> change-id: 20250213-jk-fix-sendemail-mailinfo-32f027b1b9e7\n>\n> Best regards,\n"}]}