Skip to content

Commit 82682e2

Browse files
committed
Merge branch 'rs/sha1-file-plug-fallback-base-leak'
A leak in a codepath to read from a packed object in (rare) cases has been plugged. * rs/sha1-file-plug-fallback-base-leak: sha1_file: release fallback base's memory in unpack_entry()
2 parents 98c96f8 + 886ddf4 commit 82682e2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

sha1_file.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,6 +2606,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
26062606
while (delta_stack_nr) {
26072607
void *delta_data;
26082608
void *base = data;
2609+
void *external_base = NULL;
26092610
unsigned long delta_size, base_size = size;
26102611
int i;
26112612

@@ -2632,6 +2633,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
26322633
p->pack_name);
26332634
mark_bad_packed_object(p, base_sha1);
26342635
base = read_object(base_sha1, &type, &base_size);
2636+
external_base = base;
26352637
}
26362638
}
26372639

@@ -2650,6 +2652,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
26502652
"at offset %"PRIuMAX" from %s",
26512653
(uintmax_t)curpos, p->pack_name);
26522654
data = NULL;
2655+
free(external_base);
26532656
continue;
26542657
}
26552658

@@ -2669,6 +2672,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
26692672
error("failed to apply delta");
26702673

26712674
free(delta_data);
2675+
free(external_base);
26722676
}
26732677

26742678
*final_type = type;

0 commit comments

Comments
 (0)