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

[PATCH] Fix buffer overflow in ce_flush().

From
QHQingning Huo <qhuo@mayhq.co.uk>
Date
Sep 11, 2005, 13:27 UTC
Message-ID
<20050911132747.GA26401@mayhq.zapto.org>
Fix buffer overflow in ce_flush().

Add a check before appending SHA1 signature to write_buffer, flush it first if necessary.

---
 read-cache.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
ca84fa808ba3a314d3d9ea5cfb7b8c2462249ca3
diff --git a/read-cache.c b/read-cache.c
--- a/read-cache.c
+++ b/read-cache.c
@@ -462,6 +462,13 @@ static int ce_flush(SHA_CTX *context, in
 		SHA1_Update(context, write_buffer, left);
 	}
 
+	/* Flush first if not enough space for SHA1 signature */
+	if (left + 20 > WRITE_BUFFER_SIZE) {
+		if (write(fd, write_buffer, left) != left)
+			return -1;
+		left = 0;
+	}
+
 	/* Append the SHA1 signature at the end */
 	SHA1_Final(write_buffer + left, context);
 	left += 20;
Next: Junio C Hamano
Message 1 of 5 in “Fix buffer overflow in ce_flush().”
  1. Fix buffer overflow in ce_flush().Qingning Huo, Sep 11, 2005
  2. Junio C HamanoSep 11, 2005
  3. Linus TorvaldsSep 11, 2005
  4. Junio C HamanoSep 11, 2005
  5. Linus TorvaldsSep 11, 2005

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.