Skip to content

Commit 6031af3

Browse files
rscharfegitster
authored andcommitted
fetch-pack: disregard invalid pack lockfiles
9da69a6 (fetch-pack: support more than one pack lockfile, 2020-06-10) started to use a string_list for pack lockfile names instead of a single string pointer. It removed a NULL check from transport_unlock_pack() as well, which is the function that eventually deletes these lockfiles and releases their name strings. index_pack_lockfile() can return NULL if it doesn't like the contents it reads from the file descriptor passed to it. unlink(2) is declared to not accept NULL pointers (at least with glibc). Undefined Behavior Sanitizer together with Address Sanitizer detects a case where a NULL lockfile name is passed to unlink(2) by transport_unlock_pack() in t1060 (make SANITIZE=address,undefined; cd t; ./t1060-object-corruption.sh). Reinstate the NULL check to avoid undefined behavior, but put it right at the source, so that the number of items in the string_list reflects the number of valid lockfiles. Signed-off-by: René Scharfe <[email protected]> Reviewed-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 898f807 commit 6031af3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fetch-pack.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,9 @@ static int get_pack(struct fetch_pack_args *args,
915915
if (start_command(&cmd))
916916
die(_("fetch-pack: unable to fork off %s"), cmd_name);
917917
if (do_keep && pack_lockfiles) {
918-
string_list_append_nodup(pack_lockfiles,
919-
index_pack_lockfile(cmd.out));
918+
char *pack_lockfile = index_pack_lockfile(cmd.out);
919+
if (pack_lockfile)
920+
string_list_append_nodup(pack_lockfiles, pack_lockfile);
920921
close(cmd.out);
921922
}
922923

0 commit comments

Comments
 (0)