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

[PATCH] setup_git_directory: fix segfault if repository is found in cwd

From
MLMatthias Lederhofer <matled@gmx.net>
Date
Jun 6, 2007, 21:29 UTC
Message-ID
<20070606212959.GA8800@moooo.ath.cx>
In-Reply-To
<20070603144401.GA9518@moooo.ath.cx>

Additionally there was a similar part calling setenv and getenv in the same way which missed a check if getenv succeeded.

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
There seems to be no easy way to test this case.  We'd have to run the
test in a directory which never has a .git directory in any parent.
---
 setup.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/setup.c b/setup.c
index 14a4d95..dba8012 100644
--- a/setup.c
+++ b/setup.c
@@ -251,6 +251,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
 			die("Not a git repository");
 		}
 		setenv(GIT_DIR_ENVIRONMENT, cwd, 1);
+		gitdirenv = getenv(GIT_DIR_ENVIRONMENT);
+		if (!gitdirenv)
+			die("getenv after setenv failed");
 	}
 
 	if (PATH_MAX - 40 < strlen(gitdirenv)) {
@@ -290,6 +293,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
 	if (gitdirenv[0] != '/') {
 		setenv(GIT_DIR_ENVIRONMENT, gitdir, 1);
 		gitdirenv = getenv(GIT_DIR_ENVIRONMENT);
+		if (!gitdirenv)
+			die("getenv after setenv failed");
 		if (PATH_MAX - 40 < strlen(gitdirenv)) {
 			if (nongit_ok) {
 				*nongit_ok = 1;
-- 
1.5.2.1.887.ge344-dirty
Previous: Sergio
Message 22 of 22 in “[RFC] GIT_WORK_TREE”
  1. Matthias LederhoferJun 3, 2007
  2. 1/7 rev-parse: document --is-inside-git-dirMatthias Lederhofer, Jun 3, 2007
  3. 2/7 rev-parse: introduce --is-bare-repositoryMatthias Lederhofer, Jun 3, 2007
  4. 3/7 test git rev-parseMatthias Lederhofer, Jun 3, 2007
  5. 3/7 test git rev-parseMatthias Lederhofer, Jun 6, 2007
  6. 4/7 introduce GIT_WORK_TREE to specify the work treeMatthias Lederhofer, Jun 3, 2007
  7. Junio C HamanoJun 5, 2007
  8. filter-branch: always export GIT_DIR if it is setMatthias Lederhofer, Jun 5, 2007
  9. Johannes SchindelinJun 5, 2007
  10. Junio C HamanoJun 5, 2007
  11. filter-branch: always export GIT_DIR if it is setMatthias Lederhofer, Jun 6, 2007
  12. 4/7 introduce GIT_WORK_TREE to specify the work treeMatthias Lederhofer, Jun 6, 2007
  13. Matthias LederhoferJun 3, 2007
  14. Matthias LederhoferJun 3, 2007
  15. 6/7 extend rev-parse test for --is-inside-work-treeMatthias Lederhofer, Jun 3, 2007
  16. 6/7 extend rev-parse test for --is-inside-work-treeMatthias Lederhofer, Jun 6, 2007
  17. 7/7 test GIT_WORK_TREEMatthias Lederhofer, Jun 3, 2007
  18. 7/7 test GIT_WORK_TREEMatthias Lederhofer, Jun 6, 2007
  19. SergioJun 3, 2007
  20. Matthias LederhoferJun 3, 2007
  21. SergioJun 3, 2007
  22. setup_git_directory: fix segfault if repository is found in cwdMatthias Lederhofer, Jun 6, 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.