From 2c865d9aa7b9c3511f901b2544b667c5188f510e Mon Sep 17 00:00:00 2001 From: Qingning Huo Date: Sun, 11 Sep 2005 14:27:47 +0100 Subject: [PATCH] [PATCH] Fix buffer overflow in ce_flush(). Add a check before appending SHA1 signature to write_buffer, flush it first if necessary. Signed-off-by: Junio C Hamano --- read-cache.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/read-cache.c b/read-cache.c index ced59731..6eff4c84 100644 --- a/read-cache.c +++ b/read-cache.c @@ -462,6 +462,13 @@ static int ce_flush(SHA_CTX *context, int fd) 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; -- 2.11.0