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

[PATCH] test get_git_work_tree() return value for NULL

From
Clemens Buchacher <drizzd@aon.at>
Date
May 22, 2010, 12:21 UTC
Message-ID
<20100522122127.GA13372@localhost>

If we are in a git directory, get_git_work_tree() can return NULL. While trying to determine whether or not the given paths are outside the work tree, the following command would read from it anyways and trigger a segmentation fault.

 git diff / /
Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---
 diff-no-index.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/diff-no-index.c b/diff-no-index.c
index aae8e7a..4cd9dac 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -150,16 +150,14 @@ static int queue_diff(struct diff_options *o,
 
 static int path_outside_repo(const char *path)
 {
-	/*
-	 * We have already done setup_git_directory_gently() so we
-	 * know we are inside a git work tree already.
-	 */
 	const char *work_tree;
 	size_t len;
 
 	if (!is_absolute_path(path))
 		return 0;
 	work_tree = get_git_work_tree();
+	if (!work_tree)
+		return 1;
 	len = strlen(work_tree);
 	if (strncmp(path, work_tree, len) ||
 	    (path[len] != '\0' && path[len] != '/'))
-- 
1.7.0.5.3.ga76e
Next: Junio C Hamano
Message 1 of 2 in “test get_git_work_tree() return value for NULL”
  1. test get_git_work_tree() return value for NULLClemens Buchacher, May 22, 2010
  2. Junio C HamanoMay 26, 2010

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.