mailmap: avoid out-of-bounds memory access
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> Signed-off-by: Jeff King <peff@peff.net>
Romain Francoise committed
Oct 28, 2012 at 00:49 UTC
3174bc5ccfea34717a8dac2175c1951239a4985d
1 file changed
+1
-1
mailmap.c
+1
-1
@@ -118,7 +118,7 @@ static char *parse_name_and_email(char *buffer, char **name,
118
while (isspace(*nstart) && nstart < left)
119
++nstart;
120
nend = left-1;
121
- while (isspace(*nend) && nend > nstart)
121
+ while (nend > nstart && isspace(*nend))
122
--nend;
123
124
*name = (nstart < nend ? nstart : NULL);