{"thread":{"id":"10820","subject":"[PATCH] for-each-ref: fix off by one read.","startedAt":"2007-11-12T04:37:25Z","lastAt":"2007-11-13T05:15:54Z","messageCount":3,"participants":["Christian Couder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"59422","messageId":"20071112053725.4f0d1940.chriscool@tuxfamily.org","threadId":"10820","inReplyTo":null,"subject":"[PATCH] for-each-ref: fix off by one read.","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2007-11-12T04:37:25Z","receivedAt":"2007-11-12T04:37:25Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin-for-each-ref.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c\nindex 598d4e1..89ea37c 100644\n--- a/builtin-for-each-ref.c\n+++ b/builtin-for-each-ref.c\n@@ -306,7 +306,7 @@ static const char *find_wholine(const char *who, int wholen, const char *buf, un\n \t\tif (!eol)\n \t\t\treturn \"\";\n \t\teol++;\n-\t\tif (eol[1] == '\\n')\n+\t\tif (*eol == '\\n')\n \t\t\treturn \"\"; /* end of header */\n \t\tbuf = eol;\n \t}\n-- \n1.5.3.5.577.g4d1b9-dirty\n"},{"id":"59601","messageId":"7vfxzb1032.fsf@gitster.siamese.dyndns.org","threadId":"10820","inReplyTo":"20071112053725.4f0d1940.chriscool@tuxfamily.org","subject":"Re: [PATCH] for-each-ref: fix off by one read.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-13T00:05:37Z","receivedAt":"2007-11-13T00:05:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c\n> index 598d4e1..89ea37c 100644\n> --- a/builtin-for-each-ref.c\n> +++ b/builtin-for-each-ref.c\n> @@ -306,7 +306,7 @@ static const char *find_wholine(const char *who, int wholen, const char *buf, un\n>  \t\tif (!eol)\n>  \t\t\treturn \"\";\n>  \t\teol++;\n> -\t\tif (eol[1] == '\\n')\n> +\t\tif (*eol == '\\n')\n>  \t\t\treturn \"\"; /* end of header */\n>  \t\tbuf = eol;\n>  \t}\n\nGood eyes.  This would have broken if\n\n (1) we had a header field that consists of a single character\n     and then LF.  We would have mistaken such a line as the end\n     of header; or\n\n (2) we had a commit or a tag that consists solely of header and\n     no body.  We would have read past the terminating NUL.\n\nThanks.\n"},{"id":"59617","messageId":"200711130615.54196.chriscool@tuxfamily.org","threadId":"10820","inReplyTo":"7vfxzb1032.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] for-each-ref: fix off by one read.","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2007-11-13T05:15:54Z","receivedAt":"2007-11-13T05:15:54Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Le mardi 13 novembre 2007, Junio C Hamano a écrit :\n> Christian Couder <chriscool@tuxfamily.org> writes:\n> > diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c\n> > index 598d4e1..89ea37c 100644\n> > --- a/builtin-for-each-ref.c\n> > +++ b/builtin-for-each-ref.c\n> > @@ -306,7 +306,7 @@ static const char *find_wholine(const char *who,\n> > int wholen, const char *buf, un if (!eol)\n> >  \t\t\treturn \"\";\n> >  \t\teol++;\n> > -\t\tif (eol[1] == '\\n')\n> > +\t\tif (*eol == '\\n')\n> >  \t\t\treturn \"\"; /* end of header */\n> >  \t\tbuf = eol;\n> >  \t}\n>\n> Good eyes.  \n\nWell, Valgrind found it when I did:\n\n$ valgrind git for-each-ref --format='%(refname)' \"refs/tags/*\"\n\n> This would have broken if\n\n>  (1) we had a header field that consists of a single character\n>      and then LF.  We would have mistaken such a line as the end\n>      of header; or\n>\n>  (2) we had a commit or a tag that consists solely of header and\n>      no body.  We would have read past the terminating NUL.\n\nI suspect that the end of the header was not properly detected, so that it \nmay have read one byte past a body ending with LF and the terminating NUL.\n\nChristian.\n"}]}