Commit e7d0ced2192c5efeea6d9f5667d366891010b86a

Russell Belfer 2013-09-11T12:38:06

Fix longstanding valgrind warning There was a possible circumstance that could result in reading past the end of a buffer. This check fixes that.

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/src/buf_text.c b/src/buf_text.c
index eda86ad..631feb3 100644
--- a/src/buf_text.c
+++ b/src/buf_text.c
@@ -87,7 +87,7 @@ int git_buf_text_crlf_to_lf(git_buf *tgt, const git_buf *src)
 		}
 
 		/* Do not drop \r unless it is followed by \n */
-		if (next[1] != '\n')
+		if (next + 1 == scan_end || next[1] != '\n')
 			*out++ = '\r';
 	}