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

[PATCH] git-show: only chdir(prefix) when prefix is not NULL, and check for success

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 2, 2007, 01:42 UTC
Message-ID
<Pine.LNX.4.64.0712020141530.27959@racer.site>

We blindly called "chdir(prefix);" and did not even check if it succeeded. Found by valgrind.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin-log.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 21f3b0f..0f38579 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -285,7 +285,8 @@ int cmd_show(int argc, const char **argv, const char *prefix)
 	struct object_array_entry *objects;
 	int i, count, ret = 0;
 
-	chdir(prefix);
+	if (prefix && chdir(prefix))
+		die ("Could not change directory to '%s'", prefix);
 
 	git_config(git_log_config);
 	init_revisions(&rev, prefix);
-- 
1.5.3.6.2112.ge2263
Message 1 of 1 in “git-show: only chdir(prefix) when prefix is not NULL, and check for success”
  1. git-show: only chdir(prefix) when prefix is not NULL, and check for successJohannes Schindelin, Dec 2, 2007

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.