Commit f9213015fddb8636daa993080cbbec70a02cba5c

Vicent Marti 2011-06-06T01:54:59

filebuf: Fix printf buffer overflows The filebuf was not being properly written after a flush. This should cut it now. Fixes #228

diff --git a/src/filebuf.c b/src/filebuf.c
index 97dec83..d0579b1 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -363,14 +363,19 @@ int git_filebuf_printf(git_filebuf *file, const char *format, ...)
 	int len, error;
 
 	va_start(arglist, format);
-
 	len = vsnprintf((char *)file->buffer + file->buf_pos, space_left, format, arglist);
+	va_end(arglist);
 
 	if (len < 0 || (size_t)len >= space_left) {
 		if ((error = flush_buffer(file)) < GIT_SUCCESS)
 			return git__rethrow(error, "Failed to output to buffer");
 
+		space_left = file->buf_size - file->buf_pos;
+
+		va_start(arglist, format);
 		len = vsnprintf((char *)file->buffer + file->buf_pos, space_left, format, arglist);
+		va_end(arglist);
+
 		if (len < 0 || (size_t)len > file->buf_size)
 			return GIT_ENOMEM;
 	}