* [PATCH] for-each-ref: fix off by one read.
@ 2007-11-12 4:37 Christian Couder
2007-11-13 0:05 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Christian Couder @ 2007-11-12 4:37 UTC (permalink / raw
To: Junio Hamano; +Cc: git
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin-for-each-ref.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index 598d4e1..89ea37c 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -306,7 +306,7 @@ static const char *find_wholine(const char *who, int wholen, const char *buf, un
if (!eol)
return "";
eol++;
- if (eol[1] == '\n')
+ if (*eol == '\n')
return ""; /* end of header */
buf = eol;
}
--
1.5.3.5.577.g4d1b9-dirty
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] for-each-ref: fix off by one read.
2007-11-12 4:37 [PATCH] for-each-ref: fix off by one read Christian Couder
@ 2007-11-13 0:05 ` Junio C Hamano
2007-11-13 5:15 ` Christian Couder
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2007-11-13 0:05 UTC (permalink / raw
To: Christian Couder; +Cc: git
Christian Couder <chriscool@tuxfamily.org> writes:
> diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
> index 598d4e1..89ea37c 100644
> --- a/builtin-for-each-ref.c
> +++ b/builtin-for-each-ref.c
> @@ -306,7 +306,7 @@ static const char *find_wholine(const char *who, int wholen, const char *buf, un
> if (!eol)
> return "";
> eol++;
> - if (eol[1] == '\n')
> + if (*eol == '\n')
> return ""; /* end of header */
> buf = eol;
> }
Good eyes. This would have broken if
(1) we had a header field that consists of a single character
and then LF. We would have mistaken such a line as the end
of header; or
(2) we had a commit or a tag that consists solely of header and
no body. We would have read past the terminating NUL.
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] for-each-ref: fix off by one read.
2007-11-13 0:05 ` Junio C Hamano
@ 2007-11-13 5:15 ` Christian Couder
0 siblings, 0 replies; 3+ messages in thread
From: Christian Couder @ 2007-11-13 5:15 UTC (permalink / raw
To: Junio C Hamano; +Cc: git
Le mardi 13 novembre 2007, Junio C Hamano a écrit :
> Christian Couder <chriscool@tuxfamily.org> writes:
> > diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
> > index 598d4e1..89ea37c 100644
> > --- a/builtin-for-each-ref.c
> > +++ b/builtin-for-each-ref.c
> > @@ -306,7 +306,7 @@ static const char *find_wholine(const char *who,
> > int wholen, const char *buf, un if (!eol)
> > return "";
> > eol++;
> > - if (eol[1] == '\n')
> > + if (*eol == '\n')
> > return ""; /* end of header */
> > buf = eol;
> > }
>
> Good eyes.
Well, Valgrind found it when I did:
$ valgrind git for-each-ref --format='%(refname)' "refs/tags/*"
> This would have broken if
> (1) we had a header field that consists of a single character
> and then LF. We would have mistaken such a line as the end
> of header; or
>
> (2) we had a commit or a tag that consists solely of header and
> no body. We would have read past the terminating NUL.
I suspect that the end of the header was not properly detected, so that it
may have read one byte past a body ending with LF and the terminating NUL.
Christian.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-11-13 5:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-12 4:37 [PATCH] for-each-ref: fix off by one read Christian Couder
2007-11-13 0:05 ` Junio C Hamano
2007-11-13 5:15 ` Christian Couder
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).