git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [BUG/PATCH] setup: Copy an environment variable to avoid overwrites
@ 2013-01-05  0:35 David Michael
  2013-01-05  1:17 ` Junio C Hamano
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: David Michael @ 2013-01-05  0:35 UTC (permalink / raw)
  To: git@vger.kernel.org, Junio C Hamano

It is possible for this pointer of the GIT_DIR environment variable to
survive unduplicated until further getenv calls are made.  The standards
allow for subsequent calls of getenv to overwrite the string located at
its returned pointer, and this can result in broken git operations on
certain platforms.

Signed-off-by: David Michael <fedora.dm0@gmail.com>
---

I have encountered an issue with consecutive calls to getenv
overwriting earlier values.  Most notably, it prevents a plain "git
clone" from working.

Long story short: This value of GIT_DIR gets passed around setup.c
until it reaches check_repository_format_gently.  This function calls
git_config_early, which eventually runs getenv("HOME").  When it
returns back to check_repository_format_gently, the gitdir variable
contains my home directory path.  The end result is that I wind up
with ~/objects/ etc. and a failed repository clone.  (Simply adding a
bare getenv("GIT_DIR") afterwards to reset the pointer also corrects
the problem.)

Since other platforms are apparently working, yet this getenv behavior
is supported by the standards, I am left wondering if this could be a
symptom of something else being broken on my platform (z/OS).  Can
anyone more familiar with this part of git identify any condition that
obviously should not be occurring?

Thanks.

 setup.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/setup.c b/setup.c
index f108c4b..64fb160 100644
--- a/setup.c
+++ b/setup.c
@@ -675,8 +675,12 @@ static const char
*setup_git_directory_gently_1(int *nongit_ok)
      * validation.
      */
     gitdirenv = getenv(GIT_DIR_ENVIRONMENT);
-    if (gitdirenv)
-        return setup_explicit_git_dir(gitdirenv, cwd, len, nongit_ok);
+    if (gitdirenv) {
+        gitdirenv = xstrdup(gitdirenv);
+        ret = setup_explicit_git_dir(gitdirenv, cwd, len, nongit_ok);
+        free(gitdirenv);
+        return ret;
+    }

     if (env_ceiling_dirs) {
         string_list_split(&ceiling_dirs, env_ceiling_dirs, PATH_SEP, -1);
--
1.7.11.7

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-01-07 15:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-05  0:35 [BUG/PATCH] setup: Copy an environment variable to avoid overwrites David Michael
2013-01-05  1:17 ` Junio C Hamano
2013-01-05  2:15   ` David Michael
2013-01-05  4:32   ` Junio C Hamano
2013-01-05  2:45 ` Duy Nguyen
2013-01-05  4:38   ` Junio C Hamano
2013-01-05  6:24     ` Duy Nguyen
2013-01-05  6:47       ` Junio C Hamano
2013-01-05  8:55 ` [PATCH] Add getenv.so for catching invalid getenv() use via LD_PRELOAD Nguyễn Thái Ngọc Duy
2013-01-05 10:39   ` Matt Kraai
2013-01-05 11:37     ` Duy Nguyen
2013-01-05 22:53   ` Jonathan Nieder
2013-01-07 15:45   ` David Michael
2013-01-07 15:28 ` [BUG/PATCH] setup: Copy an environment variable to avoid overwrites Erik Faye-Lund

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).