delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/06/30/22:01:27

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Sun, 30 Jun 2002 22:00:59 -0400
From: Christopher Faylor <cgf AT redhat DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: problem with inheriting environment
Message-ID: <20020701020059.GA6469@redhat.com>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <012901c22052$3470a5c0$0100a8c0 AT advent02> <20020630170455 DOT GA10399 AT redhat DOT com> <017401c22082$fca36840$0100a8c0 AT advent02> <20020630232515 DOT GA5001 AT redhat DOT com> <007501c22098$e3f49510$0100a8c0 AT advent02>
Mime-Version: 1.0
In-Reply-To: <007501c22098$e3f49510$0100a8c0@advent02>
User-Agent: Mutt/1.3.23.1i

On Mon, Jul 01, 2002 at 01:47:35AM +0100, Chris January wrote:
>To duplicate, add the 'export' flag to your CYGWIN environment variable.

That does duplicate it.

>In _addenv, there is the line:
>    envhere = cur_environ ()[offset] = (char *) (ENVMALLOC ? strdup (name) :
>name);
>ENVMALLOC is not set by default, so the entry in the environment table gets
>set to the value of name. However when name goes out of scope in the calling
>process, it's contents may be overwritten. Now the environment table entry
>will be pointing to random memory.
>Therefore, strdup must be called in all situations. Also, the original entry
>should be free'ed to prevent a memory leak.

If you do a 'cvs annotate', you'll see that this is not new code.  It
was added in November 2000.  I don't recall now but you might even be
able to find some discussion about this.  What I think this means is
that the 'export' option has been broken since then.

For fun, try the following code on linux:

  #include <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>
  #include <time.h>
  #include <string.h>
  #include <sys/wait.h>

  int
  main (int argc, char **argv, char **envirin)
  {
    char buf[80];
    sprintf (buf, "FFFFFFFFFFFF=27");
    putenv (buf);
    sprintf (buf, "GGGGGGGGGGGG=28");
    system ("env");
  }

You'll see that the environment has no hint of FFFFFFFFFFFF=27 but
does have a GGGGGGGGGGGG=28 in it.  To me, this means that the
environment does not get automatically malloced.  Even if putenv
did automatically malloc the things it puts in the environment,
you can't rely on the fact that the user's program didn't manipulate
the environment directly, adding non-malloced strings to it.

So, I've made the CYGWIN export code strdup its options.  I've also
caused the export option to only work when cygwin settings were
retrieved from the registry.

Thanks very much for tracking this down.  I am mystified as to why
this would suddenly show up now, though.  I don't see how it ever
would have worked correctly -- at least not for the last 1.5 years
anyway.

cgf

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019