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

Re: [BUG/PATCH] setup: Copy an environment variable to avoid overwrites

From
Erik Faye-Lund <kusmabite@gmail.com>
Date
Jan 7, 2013, 15:28 UTC
Message-ID
<CABPQNSbpyO5k8TauFi4+Yan_SiXgULn5F2SMJ_VkL-XX_vDB8w@mail.gmail.com>
In-Reply-To
<CAEvUa7niTJVfp8_kuWs50kvhfZ59F-yAuAmeOXEduHXOq-tRFA@mail.gmail.com>
On Sat, Jan 5, 2013 at 1:35 AM, David Michael <fedora.dm0@gmail.com> wrote:
Show 29 quoted lines
> 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.
I have some patches of a similar nature here:
https://github.com/kusma/git/commits/work/getenv-safety

These were written for an earlier version of the UTF-8 patches for Git for Windows, where we were looking into allowing getenv to use a static buffer to convert the environment variables from UTF-16 (which is what Windows maintains) to UTF-8. We ended converting the environment on start-up instead, so these weren't needed for us. But perhaps they can be of use to someone else?

Previous: David Michael
Message 14 of 14 in “setup: Copy an environment variable to avoid overwrites”
  1. setup: Copy an environment variable to avoid overwritesDavid Michael, Jan 5, 2013
  2. Junio C HamanoJan 5, 2013
  3. David MichaelJan 5, 2013
  4. Junio C HamanoJan 5, 2013
  5. Duy NguyenJan 5, 2013
  6. Junio C HamanoJan 5, 2013
  7. Duy NguyenJan 5, 2013
  8. Junio C HamanoJan 5, 2013
  9. Add getenv.so for catching invalid getenv() use via LD_PRELOADNguyễn Thái Ngọc Duy, Jan 5, 2013
  10. Matt KraaiJan 5, 2013
  11. Duy NguyenJan 5, 2013
  12. Jonathan NiederJan 5, 2013
  13. David MichaelJan 7, 2013
  14. Erik Faye-LundJan 7, 2013

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.