git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] unpack-trees: handle lstat failure for existing directory

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jan 13, 2011, 02:26 UTC
Message-ID
<20110113022636.GB8635@burratino>
In-Reply-To
<20110113022415.GA8635@burratino>

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 <jrnieder@gmail.com>
---
Does this need an o->gently check?
 unpack-trees.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index 1ca41b1..a795db5 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1382,7 +1382,9 @@ static int verify_absent_1(struct cache_entry *ce,
 		return check_ok_to_remove(ce->name, ce_namelen(ce),
 				ce_to_dtype(ce), ce, &st,
 				error_type, o);
-
+	if (errno != ENOENT)
+		return error("cannot stat '%s': %s", ce->name,
+				strerror(errno));
 	return 0;
 }
 
-- 
1.7.4.rc1
Previous: Jonathan NiederNext: Miles Bader
Message 15 of 20 in “unpack-trees: fix D/F conflict bugs in verify_absent”
  1. Clemens BuchacherJan 1, 2009
  2. 1/3 unpack-trees: handle failure in verify_absentClemens Buchacher, Jan 1, 2009
  3. 2/3 unpack-trees: fix path search bug in verify_absentClemens Buchacher, Jan 1, 2009
  4. 3/3 unpack-trees: remove redundant path search in verify_absentClemens Buchacher, Jan 1, 2009
  5. Junio C HamanoJan 6, 2009
  6. Johannes SchindelinJan 2, 2009
  7. Miklos VajnaJan 3, 2009
  8. Johannes SchindelinJan 2, 2009
  9. Clemens BuchacherJan 3, 2009
  10. Johannes SchindelinJan 3, 2009
  11. Junio C HamanoJan 4, 2009
  12. Clemens BuchacherJan 4, 2009
  13. Johannes SchindelinJan 6, 2009
  14. 0/2 unpack-trees: handle lstat failures in verify_absentJonathan Nieder, Jan 13, 2011
  15. 1/2 unpack-trees: handle lstat failure for existing directoryJonathan Nieder, Jan 13, 2011
  16. Miles BaderJan 13, 2011
  17. Jonathan NiederJan 13, 2011
  18. 2/2 unpack-trees: handle lstat failure for existing fileJonathan Nieder, Jan 13, 2011
  19. Clemens BuchacherJan 13, 2011
  20. Junio C HamanoJan 1, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.