bug-autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Portability issue with `putenv'


From: James Youngman
Subject: Re: Portability issue with `putenv'
Date: Mon, 21 Feb 2005 14:34:17 +0000
User-agent: Mutt/1.3.28i

On Sun, Feb 20, 2005 at 10:45:37PM +0100, Sam Lauber wrote:

> A good replacement for a broken putenv() is (assuming that `putenv'
> is defined as `rpl_putenv'):
> 
> #undef putenv
> int 
> rpl_putenv(s)
>   char *s;
> {
>   char *t;
>   strcpy(t, s);
>   return putenv(t);
> }

The strcpy() call has an undefined effect as it dereferences an
uninitialised pointer.  Perhaps you meant to put a call to xmalloc()
or strdup() in there.

If so, what about those callers who already carefully did this: -

   /* Assume no other thread will modify var or val; also assume
    * we already hold a mutex controlling access to putenv().
    */
   size_t len = strlen(var) + 1u + strlen(val);
   char *s = xmalloc(len + 1u);
   snprintf(s, len+1u, "%s=%s", var, val);
   rpl_putenv(s);

... because then you would have a memory leak.

James.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]