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

[PATCH] unpack-trees.c: check return value of lstat()

From
Torsten Bögershausen <tboegi@web.de>
Date
Mar 6, 2011, 19:13 UTC
Message-ID
<201103062013.52793.tboegi@web.de>

Since commit f66caa "do not overwrite files in leading path" at one place lstat() was called but the result was not checked.

Signed-off-by: Torsten Bögershausen <tboegi@web.de>
---
(While I was experimenting with something different, 
this was found by valgrind)
Please review the patch, comments wellcome.
 unpack-trees.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index 1ca41b1..42f7aad 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1374,10 +1374,9 @@ static int verify_absent_1(struct cache_entry *ce,
 		char path[PATH_MAX + 1];
 		memcpy(path, ce->name, len);
 		path[len] = 0;
-		lstat(path, &st);
-
-		return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
-				error_type, o);
+		if (!lstat(path, &st))
+			return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
+			                          error_type, o);
 	} else if (!lstat(ce->name, &st))
 		return check_ok_to_remove(ce->name, ce_namelen(ce),
 				ce_to_dtype(ce), ce, &st,
-- 
1.7.4
Next: Matthieu Moy
Message 1 of 5 in “unpack-trees.c: check return value of lstat()”
  1. unpack-trees.c: check return value of lstat()Torsten Bögershausen, Mar 6, 2011
  2. Matthieu MoyMar 6, 2011
  3. Torsten BögershausenMar 6, 2011
  4. Matthieu MoyMar 6, 2011
  5. Torsten BögershausenMar 7, 2011

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.