@matheusbsbs / matheus-bagliano / commits / 2c865d9aa7
Fork 0

[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 <junkio@cox.net>

Qingning Huo committed Sep 11, 2005 at 14:27 UTC 2c865d9aa7b9c3511f901b2544b667c5188f510e
1 file changed +7
read-cache.c
+7
@@ -462,6 +462,13 @@ static int ce_flush(SHA_CTX *context, int fd)
462 SHA1_Update(context, write_buffer, left);
463 }
464
465 + /* Flush first if not enough space for SHA1 signature */
466 + if (left + 20 > WRITE_BUFFER_SIZE) {
467 + if (write(fd, write_buffer, left) != left)
468 + return -1;
469 + left = 0;
470 + }
471 +
472 /* Append the SHA1 signature at the end */
473 SHA1_Final(write_buffer + left, context);
474 left += 20;