{"thread":{"id":"33599","subject":"[PATCH] Fix segfault for insane ident line","startedAt":"2013-04-25T10:32:25Z","lastAt":"2013-04-25T10:52:13Z","messageCount":3,"participants":["Jiang Xin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"215422","messageId":"cover.1366885748.git.worldhello.net@gmail.com","threadId":"33599","inReplyTo":null,"subject":"[PATCH] Fix segfault for insane ident line","fromName":"Jiang Xin","fromEmail":"worldhello.net@gmail.com","sentAt":"2013-04-25T10:32:25Z","receivedAt":"2013-04-25T10:32:25Z","isPatch":true,"sender":{"key":"worldhello.net@gmail.com","avatar":"https://avatars.githubusercontent.com/u/183860?v=4"},"body":"Today when I push a long run repository, git complains:\n\n    $ git push -u github master:doc-tech\n    Counting objects: 5575, done.\n    Delta compression using up to 8 threads.\n    Compressing objects: 100% (2560/2560), done.\n    remote: error: object b798e3ffca56af58c2a7728d75027212a558b6d3:invalid author/committer line - missing space before email\n    remote: fatal: Error in object\n    error: pack-objects died of signal 13\n    error: failed to push some refs to ...\n\nWhen I check the commit, git will segfault:\n\n    $ git show b798e3ffca56af58c2a7728d75027212a558b6d3\n    Segmentation fault: 11\n\nBut git v1.8.1 works without difficulty, only with a suspect datetime.\n\n    $ gitv1.8.1 log -1 b798e3ffca56af58c2a7728d75027212a558b6d3\n    commit b798e3ffca56af58c2a7728d75027212a558b6d3\n    Author: leiweiwei<leiww@bj.ossxp.com>\n    Date:   Thu Jan 1 00:00:00 1970 +0000\n    \n        add blog/typo.mm.\n\nDetail of this commit. (Note that username and email is insane.)\n\n    $ gitv1.8.1 cat-file commit b798e3ffca56af58c2a7728d75027212a558b6d3\n    tree a1fcf9257bfbcd75f8c9aa931d1e89dbc60ae308\n    parent 566f0a6489316db9c9dd12bfda51ffc75a24a9b0\n    author leiweiwei<leiww@bj.ossxp.com> <leiweiwei<leiww@bj.ossxp.com>> 1261964093 +0800\n    committer leiweiwei<leiww@bj.ossxp.com> <leiweiwei<leiww@bj.ossxp.com>> 1261964093 +0800\n    \n    add blog/typo.mm.\n\nBecause git v1.8.1 is good and v1.8.2 is bad, so I run a `git bisect` on it,\nthen I find this issue was was introduced in v1.8.1-rc1-7-g3c020bd.\n\n    commit 3c020bd528d5dc320b82bd787670edfe6695f097\n    Author: Antoine Pelisse <apelisse@gmail.com>\n    Date:   Sat Jan 5 22:26:38 2013 +0100\n    \n        Use split_ident_line to parse author and committer\n        \n        Currently blame.c::get_acline(), pretty.c::pp_user_info() and\n        shortlog.c::insert_one_record() are parsing author name, email, time\n        and tz themselves.\n        \n        Use ident.c::split_ident_line() for better code reuse.\n        \n        Signed-off-by: Antoine Pelisse <apelisse@gmail.com>\n        Signed-off-by: Junio C Hamano <gitster@pobox.com>\n\nBacktrace for this segfault:\n\n    (gdb) bt\n    #0  0x00007fff8d8959ae in strtoul_l ()\n    #1  0x000000010012da4a in pp_user_info ()\n    #2  0x000000010012f811 in pp_header ()\n    #3  0x000000010012f546 in pretty_print_commit ()\n    #4  0x000000010010dd1f in show_log ()\n    #5  0x000000010010e601 in log_tree_commit ()\n    #6  0x00000001000565f1 in cmd_log_walk ()\n    #7  0x0000000100056c5c in cmd_show ()\n    #8  0x0000000100002710 in run_builtin ()\n    #9  0x0000000100001717 in handle_internal_command ()\n    #10 0x0000000100001f39 in run_argv ()\n    #11 0x000000010000155d in main ()\n\nThis patch can fix it.\n\nJiang Xin (1):\n  Fix segfault for insane ident line\n\n builtin/blame.c | 14 +++++++++++---\n pretty.c        |  9 +++++++--\n 2 files changed, 18 insertions(+), 5 deletions(-)\n\n-- \n1.8.2.1.348.gb94490b\n"},{"id":"215423","messageId":"e7453e2b99517ebed045d82be4d5f2c9388bb002.1366885748.git.worldhello.net@gmail.com","threadId":"33599","inReplyTo":"cover.1366885748.git.worldhello.net@gmail.com","subject":"[PATCH] Fix segfault for insane ident line","fromName":"Jiang Xin","fromEmail":"worldhello.net@gmail.com","sentAt":"2013-04-25T10:32:26Z","receivedAt":"2013-04-25T10:32:26Z","isPatch":true,"sender":{"key":"worldhello.net@gmail.com","avatar":"https://avatars.githubusercontent.com/u/183860?v=4"},"body":"An insane ident line (generated by old version of git or by hands such\nas git-hash-object) may cause segfault for `git log` and others commands.\n\nThis is because the `split_ident_line` function save the result in\nident_split, and the returned ident_split.date_begin, ident_split.date_end,\nident_split.tz_begin, and ident_split.tz_end maybe NULL pointers for an\ninsame ident line.\n\nThis issue was was introduced in v1.8.1-rc1-7-g3c020bd (Use split_ident_line\nto parse author and committer).\n\nSigned-off-by: Jiang Xin <worldhello.net@gmail.com>\n---\n builtin/blame.c | 14 +++++++++++---\n pretty.c        |  9 +++++++--\n 2 files changed, 18 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 86100..4b94e 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -1375,10 +1375,18 @@ static void get_ac_line(const char *inbuf, const char *what,\n \tmaillen = ident.mail_end - ident.mail_begin;\n \tmailbuf = ident.mail_begin;\n \n-\t*time = strtoul(ident.date_begin, NULL, 10);\n+\tif (ident.date_begin != NULL) {\n+\t\t*time = strtoul(ident.date_begin, NULL, 10);\n+\t} else {\n+\t\t*time = 0;\n+\t}\n \n-\tlen = ident.tz_end - ident.tz_begin;\n-\tstrbuf_add(tz, ident.tz_begin, len);\n+\tif (ident.tz_begin != NULL && ident.tz_end !=NULL) {\n+\t\tlen = ident.tz_end - ident.tz_begin;\n+\t\tstrbuf_add(tz, ident.tz_begin, len);\n+\t} else {\n+\t\tstrbuf_addstr(tz, \"(unknown)\");\n+\t}\n \n \t/*\n \t * Now, convert both name and e-mail using mailmap\ndiff --git a/pretty.c b/pretty.c\nindex d3a82..2402f 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -438,8 +438,13 @@ void pp_user_info(const struct pretty_print_context *pp,\n \tstrbuf_add(&name, namebuf, namelen);\n \n \tnamelen = name.len + mail.len + 3; /* ' ' + '<' + '>' */\n-\ttime = strtoul(ident.date_begin, &date, 10);\n-\ttz = strtol(date, NULL, 10);\n+\tif (ident.date_begin != NULL) {\n+\t\ttime = strtoul(ident.date_begin, &date, 10);\n+\t\ttz = strtol(date, NULL, 10);\n+\t} else {\n+\t\ttime = 0;\n+\t\ttz = 0;\n+\t}\n \n \tif (pp->fmt == CMIT_FMT_EMAIL) {\n \t\tstrbuf_addstr(sb, \"From: \");\n-- \n1.8.2.1.348.gb94490b\n"},{"id":"215424","messageId":"CANYiYbGC0VqtsPH8H4wmarJC-Y480+zE7irf1Y1RNLR2jA=EjA@mail.gmail.com","threadId":"33599","inReplyTo":"e7453e2b99517ebed045d82be4d5f2c9388bb002.1366885748.git.worldhello.net@gmail.com","subject":"Re: [PATCH] Fix segfault for insane ident line","fromName":"Jiang Xin","fromEmail":"worldhello.net@gmail.com","sentAt":"2013-04-25T10:52:13Z","receivedAt":"2013-04-25T10:52:13Z","isPatch":true,"sender":{"key":"worldhello.net@gmail.com","avatar":"https://avatars.githubusercontent.com/u/183860?v=4"},"body":"Oops, Ignore this patch please, I found they were already fixed by the\nfollowing commits\nof next branch. Maybe next time I should patch something in next branch.\n\ncommit 9dbe7c3d7f4424cf0c27c2d4efabf72e58fa76b9\nAuthor: René Scharfe <rene.scharfe@lsrfire.ath.cx>\nDate:   Wed Apr 17 20:33:35 2013 +0200\n\n    pretty: handle broken commit headers gracefully\n\n    Centralize the parsing of the date and time zone strings in the new\n    helper function show_ident_date() and make sure it checks the pointers\n    provided by split_ident_line() for NULL before use.\n\n    Reported-by: Ivan Lyapunov <dront78@gmail.com>\n    Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n    Signed-off-by: Junio C Hamano <gitster@pobox.com>\n\n\ncommit de5abe9fe91a496d019d62abefe23df9d72fad30\nAuthor: René Scharfe <rene.scharfe@lsrfire.ath.cx>\nDate:   Wed Apr 17 20:33:54 2013 +0200\n\n    blame: handle broken commit headers gracefully\n\n    split_ident_line() can leave us with the pointers date_begin, date_end,\n    tz_begin and tz_end all set to NULL.  Check them before use and supply\n    the same fallback values as in the case of a negative return code from\n    split_ident_line().\n\n    The \"(unknown)\" is not actually shown in the output, though, because it\n    will be converted to a number (zero) eventually.\n\n    Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n\n\n--\n蒋鑫\n\n北京群英汇信息技术有限公司\n邮件: worldhello.net@gmail.com\n网址: http://www.ossxp.com/\n博客: http://www.worldhello.net/\n微博: http://weibo.com/gotgit/\n电话: 18601196889\n"}]}