{"thread":{"id":"15112","subject":"git for-each-ref crashes for %(body) with tags","startedAt":"2008-08-20T18:28:41Z","lastAt":"2008-08-20T20:41:49Z","messageCount":3,"participants":["Han-Wen Nienhuys","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"87840","messageId":"f329bf540808201128r2d21c40cr37eb63a6706ac0aa@mail.gmail.com","threadId":"15112","inReplyTo":null,"subject":"git for-each-ref crashes for %(body) with tags","fromName":"Han-Wen Nienhuys","fromEmail":"hanwenn@gmail.com","sentAt":"2008-08-20T18:28:41Z","receivedAt":"2008-08-20T18:28:41Z","isPatch":false,"sender":{"key":"hanwenn@gmail.com","avatar":"https://gravatar.com/avatar/058832acb8d613baeb6ce9d21b009d9772424a309b9a521330423daef909a27a?d=mp&s=160"},"body":"Hi,\n\nsee gdb trace below.   Unfortunately, I don't have a repo that I can\nreadily share to demonstrate this.\n\n(gdb) r for-each-ref --format '%(body)' refs/tags\n..\n\nBreakpoint 1, grab_sub_body_contents (val=<value optimized out>,\nderef=0, obj=<value optimized out>, buf=0x8146ad0, sz=161)\n    at builtin-for-each-ref.c:494\n494                             v->s = xstrdup(bodypos);\n(gdb) p bodypos\n$10 = 0x0\n\n(gdb) n\n496                             v->s = xstrdup(subpos);\n(gdb) n\n\nProgram received signal SIGSEGV, Segmentation fault.\n0x4d9ff013 in strlen () from /lib/tls/i686/cmov/libc.so.6\n\n-- \nHan-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen\n"},{"id":"87848","messageId":"7vhc9fqz4a.fsf@gitster.siamese.dyndns.org","threadId":"15112","inReplyTo":"f329bf540808201128r2d21c40cr37eb63a6706ac0aa@mail.gmail.com","subject":"Re: git for-each-ref crashes for %(body) with tags","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-20T19:12:53Z","receivedAt":"2008-08-20T19:12:53Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Han-Wen Nienhuys\" <hanwenn@gmail.com> writes:\n\n> see gdb trace below.   Unfortunately, I don't have a repo that I can\n> readily share to demonstrate this.\n\nYou have a tag that has a single incomplete line as its payload.  The\nattached patch should fix it, but I wonder how you created such an unusual\n(I would not say \"broken\") tag to begin with?\n\n\ndiff --git i/builtin-for-each-ref.c w/builtin-for-each-ref.c\nindex 445039e..4d25ec5 100644\n--- i/builtin-for-each-ref.c\n+++ w/builtin-for-each-ref.c\n@@ -459,8 +459,10 @@ static void find_subpos(const char *buf, unsigned long sz, const char **sub, con\n \t\treturn;\n \t*sub = buf; /* first non-empty line */\n \tbuf = strchr(buf, '\\n');\n-\tif (!buf)\n+\tif (!buf) {\n+\t\t*body = \"\";\n \t\treturn; /* no body */\n+\t}\n \twhile (*buf == '\\n')\n \t\tbuf++; /* skip blank between subject and body */\n \t*body = buf;\n"},{"id":"87874","messageId":"f329bf540808201341m183da990hef93d35c08773b86@mail.gmail.com","threadId":"15112","inReplyTo":"7vhc9fqz4a.fsf@gitster.siamese.dyndns.org","subject":"Re: git for-each-ref crashes for %(body) with tags","fromName":"Han-Wen Nienhuys","fromEmail":"hanwenn@gmail.com","sentAt":"2008-08-20T20:41:49Z","receivedAt":"2008-08-20T20:41:49Z","isPatch":false,"sender":{"key":"hanwenn@gmail.com","avatar":"https://gravatar.com/avatar/058832acb8d613baeb6ce9d21b009d9772424a309b9a521330423daef909a27a?d=mp&s=160"},"body":">From what I can see, the command responsible was\n\n  git tag empty\n\n\nit still works (v1.6.0):\n\n$ git tag this-tag-has-no-body\n\n$ git cat-file tag this-tag-has-no-body\nfatal: git-cat-file this-tag-has-no-body: bad file\n\n$ git cat-file commit this-tag-has-no-body |head -2\ntree b51a1eb73af67d17f12114ed3e1e6f93d5adbaa8\nparent 49e532412bbc84e4fb73f0862df61882dd7dbf89\n\n\n\n\nOn Wed, Aug 20, 2008 at 4:12 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> \"Han-Wen Nienhuys\" <hanwenn@gmail.com> writes:\n>\n>> see gdb trace below.   Unfortunately, I don't have a repo that I can\n>> readily share to demonstrate this.\n>\n> You have a tag that has a single incomplete line as its payload.  The\n> attached patch should fix it, but I wonder how you created such an unusual\n> (I would not say \"broken\") tag to begin with?\n>\n>\n> diff --git i/builtin-for-each-ref.c w/builtin-for-each-ref.c\n> index 445039e..4d25ec5 100644\n> --- i/builtin-for-each-ref.c\n> +++ w/builtin-for-each-ref.c\n> @@ -459,8 +459,10 @@ static void find_subpos(const char *buf, unsigned long sz, const char **sub, con\n>                return;\n>        *sub = buf; /* first non-empty line */\n>        buf = strchr(buf, '\\n');\n> -       if (!buf)\n> +       if (!buf) {\n> +               *body = \"\";\n>                return; /* no body */\n> +       }\n>        while (*buf == '\\n')\n>                buf++; /* skip blank between subject and body */\n>        *body = buf;\n>\n\n\n\n-- \nHan-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen\n"}]}