Skip to content

Commit

Permalink
[PATCH] Fix buffer overflow in ce_flush().
Browse files Browse the repository at this point in the history
Add a check before appending SHA1 signature to write_buffer,
flush it first if necessary.

Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Qingning Huo authored and Junio C Hamano committed Sep 11, 2005
1 parent 720d150 commit 2c865d9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2c865d9

Please sign in to comment.