git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mailmap: avoid out-of-bounds memory access
@ 2012-10-27 22:49 Romain Francoise
  2012-10-28 11:02 ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: Romain Francoise @ 2012-10-27 22:49 UTC (permalink / raw)
  To: git; +Cc: gitster, peff

AddressSanitizer (http://clang.llvm.org/docs/AddressSanitizer.html)
complains of a one-byte buffer underflow in parse_name_and_email() while
running the test suite. And indeed, if one of the lines in the mailmap
begins with '<', we dereference the address just before the beginning of
the buffer when looking for whitespace to remove, before checking that
we aren't going too far.

So reverse the order of the tests to make sure that we don't read
outside the buffer.

Signed-off-by: Romain Francoise <romain@orebokech.com>
---
 mailmap.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mailmap.c b/mailmap.c
index 47aa419..ea4b471 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -118,7 +118,7 @@ static char *parse_name_and_email(char *buffer, char **name,
 	while (isspace(*nstart) && nstart < left)
 		++nstart;
 	nend = left-1;
-	while (isspace(*nend) && nend > nstart)
+	while (nend > nstart && isspace(*nend))
 		--nend;
 
 	*name = (nstart < nend ? nstart : NULL);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-10-28 13:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-27 22:49 [PATCH] mailmap: avoid out-of-bounds memory access Romain Francoise
2012-10-28 11:02 ` Jeff King
2012-10-28 13:21   ` Romain Francoise

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 NNTP newsgroup(s).