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
Junio C Hamano <gitster@pobox.com>
Date
Jan 5, 2013, 04:38 UTC
Message-ID
<7vk3rsqm6u.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CACsJy8BeuV8esGTWsQiT_G9pZE28s5KJxH6+dzdhioLgmSiNVg@mail.gmail.com>
Duy Nguyen <pclouds@gmail.com> writes:
> Maybe we could all this into a wrapper? If getenv() here has a
> problem, many other places may have the same problem too. This
> simplifies the change. But one has to check that getenv() must not be
> used in threaded code.

That needs to be done regardless, if we care; POSIX explicitly says getenv() need not be thread-safe.

I personally do not think a wrapper with limited slots is a healthy direction to go. Most places we use getenv() do not let the return value live across their scope, and those that do should explicitly copy the value away. It's between validating that there is _no_ *env() calls in the codepath between a getenv() call and the use of its return value, and validating that there is at most 4 such calls there. The former is much easier to verify and maintain, I think.

Previous: Duy NguyenNext: Duy Nguyen
Message 6 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.