Commit f9213015 by Vicent Marti

filebuf: Fix printf buffer overflows

The filebuf was not being properly written after a flush. This should
cut it now.

Fixes #228
parent 2b397327
...@@ -363,14 +363,19 @@ int git_filebuf_printf(git_filebuf *file, const char *format, ...) ...@@ -363,14 +363,19 @@ int git_filebuf_printf(git_filebuf *file, const char *format, ...)
int len, error; int len, error;
va_start(arglist, format); va_start(arglist, format);
len = vsnprintf((char *)file->buffer + file->buf_pos, space_left, format, arglist); len = vsnprintf((char *)file->buffer + file->buf_pos, space_left, format, arglist);
va_end(arglist);
if (len < 0 || (size_t)len >= space_left) { if (len < 0 || (size_t)len >= space_left) {
if ((error = flush_buffer(file)) < GIT_SUCCESS) if ((error = flush_buffer(file)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to output to buffer"); 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); len = vsnprintf((char *)file->buffer + file->buf_pos, space_left, format, arglist);
va_end(arglist);
if (len < 0 || (size_t)len > file->buf_size) if (len < 0 || (size_t)len > file->buf_size)
return GIT_ENOMEM; return GIT_ENOMEM;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment