git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFH] pp_header(): work around possible memory corruption

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 15, 2007, 12:19 UTC
Message-ID
<Pine.LNX.4.64.0706151318210.4059@racer.site>

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>
---
	I have no idea if 80 is a good value, and if other places
	need an equivalent fix up, too.
	But I needed this patch in a hurry...
 commit.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/commit.c b/commit.c
index f778bf4..03436b1 100644
--- a/commit.c
+++ b/commit.c
@@ -997,7 +997,7 @@ static void pp_header(enum cmit_fmt fmt,
 			len = linelen;
 			if (fmt == CMIT_FMT_EMAIL)
 				len = bound_rfc2047(linelen, encoding);
-			ALLOC_GROW(*buf_p, *ofs_p + len, *space_p);
+			ALLOC_GROW(*buf_p, *ofs_p + len + 80, *space_p);
 			dst = *buf_p + *ofs_p;
 			*ofs_p += add_user_info("Author", fmt, dst,
 						line + 7, dmode, encoding);
@@ -1008,7 +1008,7 @@ static void pp_header(enum cmit_fmt fmt,
 			len = linelen;
 			if (fmt == CMIT_FMT_EMAIL)
 				len = bound_rfc2047(linelen, encoding);
-			ALLOC_GROW(*buf_p, *ofs_p + len, *space_p);
+			ALLOC_GROW(*buf_p, *ofs_p + len + 80, *space_p);
 			dst = *buf_p + *ofs_p;
 			*ofs_p += add_user_info("Commit", fmt, dst,
 						line + 10, dmode, encoding);
Next: Junio C Hamano
Message 1 of 4 in “pp_header(): work around possible memory corruption”
  1. pp_header(): work around possible memory corruptionJohannes Schindelin, Jun 15, 2007
  2. Junio C HamanoJun 16, 2007
  3. Johannes SchindelinJun 19, 2007
  4. Johannes SchindelinJun 23, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.