From: Qingning Huo Date: Sun, 11 Sep 2005 13:27:47 GMT Subject: [PATCH] Fix buffer overflow in ce_flush(). 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;