Skip to content

Commit 3aee68a

Browse files
Ilari Liusvaaragitster
authored andcommitted
Fix integer overflow in unpack_sha1_rest()
[jc: later NUL termination by the caller becomes unnecessary] Signed-off-by: Ilari Liusvaara <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 222083a commit 3aee68a

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

sha1_file.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ static int unpack_sha1_header(z_stream *stream, unsigned char *map, unsigned lon
12321232
static void *unpack_sha1_rest(z_stream *stream, void *buffer, unsigned long size, const unsigned char *sha1)
12331233
{
12341234
int bytes = strlen(buffer) + 1;
1235-
unsigned char *buf = xmalloc(1+size);
1235+
unsigned char *buf = xmallocz(size);
12361236
unsigned long n;
12371237
int status = Z_OK;
12381238

@@ -1260,7 +1260,6 @@ static void *unpack_sha1_rest(z_stream *stream, void *buffer, unsigned long size
12601260
while (status == Z_OK)
12611261
status = git_inflate(stream, Z_FINISH);
12621262
}
1263-
buf[size] = 0;
12641263
if (status == Z_STREAM_END && !stream->avail_in) {
12651264
git_inflate_end(stream);
12661265
return buf;

0 commit comments

Comments
 (0)