From: Steffen Prohaska <prohaska@zib.de>
To: Git Mailing List <git@vger.kernel.org>
Cc: Johannes Sixt <j.sixt@viscovery.net>,
Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Dmitry Kakurin <Dmitry.Kakurin@gmail.com>
Subject: Re: [PATCH 3/3] Replace setenv(GIT_DIR_ENVIRONMENT, ...) with set_git_dir()
Date: Tue, 1 Jan 2008 19:52:30 +0100 [thread overview]
Message-ID: <0FFA1D0A-DB70-446C-9C43-A6FBAEFE7CA4@zib.de> (raw)
In-Reply-To: <3B6B19E6-255F-4D8F-B6A3-255A9E8E0AB0@zib.de>
Eventually I found some time to investigate this issue ...
On Nov 22, 2007, at 6:56 PM, Steffen Prohaska wrote:
>
> On Nov 22, 2007, at 10:58 AM, Johannes Sixt wrote:
>
>> Steffen Prohaska schrieb:
>>> On Nov 22, 2007, at 8:52 AM, Junio C Hamano wrote:
>>>> I suspect that if there are even earlier callers than these
>>>> early parts in the codepaths (handle_options, enter_repo, and
>>>> setup_git_directory_gently), maybe these earlier callers are
>>>> doing something wrong. Logically, if you are somewhere very
>>>> early in the codepath that you can still change the value of
>>>> GIT_DIR, you shouldn't have assumed the unknown value of GIT_DIR
>>>> and cached locations relative to that directory, no? What are
>>>> the problematic callers? What values do they access and why?
>>> I thought about these questions, too. But only very briefly.
>>> I did not analyze the code path that lead to calls of getenv().
>>> I'm not sure if it's really necessary. Calling set_git_dir()
>>> looks more sensible too me than the old code. I believe using
>>> set_git_dir() is the safer choice, and should not do any harm.
>>> So I stopped analyzing too much, and instead proposed to use
>>> set_git_dir().
>>
>> Junio's point is this: If we stumble over a dangling pointer that
>> getenv() produced, then this has obviously happened before setenv
>> (GIT_DIR), and caching that pointer is probably the wrong thing to
>> do anyway (because it refers to the wrong GIT_DIR) and needs to be
>> fixed.
>
> I see your point. It is probably more important to investigate
> this than I recognized at a first glance.
I instrumented the code to verify if setenv(GIT_DIR) is called after
setup_git_env(). This is not the case for all tests.
I also searched for problematic code paths.
setup_git_directory_gently() looks correct. It explicitly calls
getenv(GIT_DIR_ENVIRONMENT); but uses the value returned in a
safe manner. It does not cache the result and the only code path
that calls set_git_dir() does not access the return value of the
getenv() call after the call to set_git_dir().
setup_work_tree() looks correct, too. Here, get_git_dir() is
called, which implicitly results in caching the pointer returned
from getenv(GIT_DIR_ENVIRONMENT). But the result of get_git_dir() is
neither cached nor used after a subsequent call to set_git_dir().
So, I don't find any obvious problems.
>>> Interesting, though, is to find out if we have other potentially
>>> dangerous calls to getenv() that are not removed by this patch.
>>
>> Side note for other readers: This is a Windows specific problem
>> for the moment because its getenv() does not behave well.
>
> Yes, and apparently even nobody knows how to trigger the problem
> on Windows. At this point, we only know that caching getenv()
> calls is unsafe, while on Unix it is safe (at least for BSD
> it's documented to be safe).
In conclusion, using setenv() as in the original code instead of
set_git_dir() should be safe and this patch is not needed.
I tend to revert the changes in msysgit and see if we hit any
problems. But I'll wait until 1.5.4 is released.
Steffen
next prev parent reply other threads:[~2008-01-01 18:52 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-21 20:27 [PATCH 0/3] msysgit fallout Steffen Prohaska
2007-11-21 20:27 ` [PATCH 1/3] sha1_file.c: Fix size_t related printf format warnings Steffen Prohaska
2007-11-21 20:27 ` [PATCH 2/3] builtin-init-db: use get_git_dir() instead of getenv() Steffen Prohaska
2007-11-21 20:27 ` [PATCH 3/3] Replace setenv(GIT_DIR_ENVIRONMENT, ...) with set_git_dir() Steffen Prohaska
2007-11-22 1:22 ` Johannes Schindelin
2007-11-22 2:34 ` Junio C Hamano
2007-11-22 6:13 ` Steffen Prohaska
2007-11-22 7:52 ` Junio C Hamano
2007-11-22 8:31 ` Steffen Prohaska
2007-11-22 9:58 ` Johannes Sixt
2007-11-22 17:56 ` Steffen Prohaska
2007-11-22 22:09 ` Johannes Schindelin
2008-01-01 18:52 ` Steffen Prohaska [this message]
2008-01-03 4:07 ` Dmitry Kakurin
2008-01-03 6:02 ` Steffen Prohaska
2008-01-03 6:26 ` Dmitry Kakurin
2008-01-03 7:53 ` Steffen Prohaska
2007-11-22 7:29 ` Johannes Sixt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0FFA1D0A-DB70-446C-9C43-A6FBAEFE7CA4@zib.de \
--to=prohaska@zib.de \
--cc=Dmitry.Kakurin@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j.sixt@viscovery.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).