Skip to content

Commit 92fda79

Browse files
jrngitster
authored andcommitted
unpack-trees: handle lstat failure for existing directory
When check_leading_path notices no file in the way of the new entry to be checked out, verify_absent checks whether there is a directory there or nothing at all. If that lstat call fails (for example due to ENOMEM), it assumes ENOENT, meaning a directory with untracked files would be clobbered in that case. Check errno after calling lstat, and for conditions other than ENOENT, just error out. This is a theoretical race condition. lstat has to succeed moments before it fails for there to be trouble. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3f14246 commit 92fda79

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

unpack-trees.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,12 +1197,16 @@ static int verify_absent_1(struct cache_entry *ce,
11971197

11981198
return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
11991199
error_type, o);
1200-
} else if (!lstat(ce->name, &st))
1200+
} else if (lstat(ce->name, &st)) {
1201+
if (errno != ENOENT)
1202+
return error("cannot stat '%s': %s", ce->name,
1203+
strerror(errno));
1204+
return 0;
1205+
} else {
12011206
return check_ok_to_remove(ce->name, ce_namelen(ce),
1202-
ce_to_dtype(ce), ce, &st,
1203-
error_type, o);
1204-
1205-
return 0;
1207+
ce_to_dtype(ce), ce, &st,
1208+
error_type, o);
1209+
}
12061210
}
12071211

12081212
static int verify_absent(struct cache_entry *ce,

0 commit comments

Comments
 (0)