Re: [BUG/PATCH] setup: Copy an environment variable to avoid overwrites
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Jan 5, 2013, 02:45 UTC
- Message-ID
- <CACsJy8BeuV8esGTWsQiT_G9pZE28s5KJxH6+dzdhioLgmSiNVg@mail.gmail.com>
- In-Reply-To
- <CAEvUa7niTJVfp8_kuWs50kvhfZ59F-yAuAmeOXEduHXOq-tRFA@mail.gmail.com>
On Sat, Jan 5, 2013 at 7:35 AM, David Michael <fedora.dm0@gmail.com> wrote:
Show 8 quoted lines
> - 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;
> + }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.
char *git_getenv(const char *env)
{
static int bufno;
static char *buf[4];
bufno = (bufno + 1) % 4;
free(buf[bufno]);
buf[bufno] = xstrdup(getenv(env));
return buf[bufno];
}
#define getenv(x) git_getenv(x)-- Duy