pp_header(): work around possible memory corruption
add_user_info() possibly adds way more than just the commit header line. In fact, it sometimes needs so much more space that there is a buffer overrun, leading to an ugly crash. For example, the date is printed in its own line, and usually takes up more space than the equivalent Unix epoch. So, for good measure, add 80 characters (a full line) to the allocated space, in addition to the header line length. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jun 15, 2007 at 13:19 UTC
4cd008a925f3c7c0064d86a4cb4b06278e79e9e7
1 file changed
+2
-2
commit.c
+2
-2
@@ -997,7 +997,7 @@ static void pp_header(enum cmit_fmt fmt,
997
len = linelen;
998
if (fmt == CMIT_FMT_EMAIL)
999
len = bound_rfc2047(linelen, encoding);
1000
- ALLOC_GROW(*buf_p, *ofs_p + len, *space_p);
1000
+ ALLOC_GROW(*buf_p, *ofs_p + len + 80, *space_p);
1001
dst = *buf_p + *ofs_p;
1002
*ofs_p += add_user_info("Author", fmt, dst,
1003
line + 7, dmode, encoding);
@@ -1008,7 +1008,7 @@ static void pp_header(enum cmit_fmt fmt,
1008
len = linelen;
1009
if (fmt == CMIT_FMT_EMAIL)
1010
len = bound_rfc2047(linelen, encoding);
1011
- ALLOC_GROW(*buf_p, *ofs_p + len, *space_p);
1011
+ ALLOC_GROW(*buf_p, *ofs_p + len + 80, *space_p);
1012
dst = *buf_p + *ofs_p;
1013
*ofs_p += add_user_info("Commit", fmt, dst,
1014
line + 10, dmode, encoding);