Skip to content

Commit a93e530

Browse files
jrngitster
authored andcommitted
unpack-trees: handle lstat failure for existing file
When check_leading_path notices a file in the way of a new entry to be checked out, verify_absent uses (1) the mode to determine whether it is a directory (2) the rest of the stat information to check if this is actually an old entry, disguised by a change in filename (e.g., README -> Readme) that is significant to git but insignificant to the underlying filesystem. If lstat fails, these checks are performed with an uninitialied stat structure, producing essentially random results. Better to just error out when lstat fails. The easiest way to reproduce this is to remove a file after the check_leading_path call and before the lstat in verify_absent. An lstat failure other than ENOENT in check_leading_path would also trigger the same code path. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 92fda79 commit a93e530

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

unpack-trees.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,9 @@ static int verify_absent_1(struct cache_entry *ce,
11931193
char path[PATH_MAX + 1];
11941194
memcpy(path, ce->name, len);
11951195
path[len] = 0;
1196-
lstat(path, &st);
1196+
if (lstat(path, &st))
1197+
return error("cannot stat '%s': %s", path,
1198+
strerror(errno));
11971199

11981200
return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
11991201
error_type, o);

0 commit comments

Comments
 (0)