develooper Front page | perl.perl5.porters | Postings from November 1999

Re: [ID 19991116.002] perl5.005_02: my_setenv() and Term::ReadLine::Gnu

Thread Previous | Thread Next
From:
Joerg Schumacher
Date:
November 18, 1999 16:37
Subject:
Re: [ID 19991116.002] perl5.005_02: my_setenv() and Term::ReadLine::Gnu
Message ID:
199911190037.BAA04832@aunt.gaertner.de
Hi!

> [...]
> > Nope.  All I say is that you MUST NOT free() memory which hasn't been
> > malloc()ed before.  The memory block which perl tries to free() in
> > Safefree() is the original block passed via exec(2).  This block
> > hasn't been malloc()ed and therefore perl must not free() it.
> 
> Let me restate things to syncronize our understanding:
> 
> a) Perl uses PL_origenviron variable to understand when environ is malloc()ed.
> 
>    You do not claim that this scheme is broken (though AFAICS, it will
>    work correct only if perl_parse is called only once).

On the contrary: I do believe that the check 

	(environ == PL_origenviron) /* need we copy environment? */

is broken.  This test would only be OK if perl itself could guarantee
that no extension module modifies environ behind the scene.

> b) Perl thinks that if environ is malloc()ed, then environ[i] is malloc()ed;
> 
>    You claim that this assumption is unwarranted.  This claim looks correct.

See above.

> However, in view of the above two statements your patch is still
> broken, since AFAICS it does not address existence of two different
> questions.

My patch is definitely broken since mg.c:magic_clear_all_env() has to
be fixed also.  Since there are two different functions preformig the
"need we copy environment?" check, the IMHO correct fix would need 
a global variable which indicates wether perl has already copied
the environment.

The following two testcases show the bug on my Solaris 5.5.1 box with 
perl5.00503, Term-ReadLine-Gnu-1.07 and readline-4.0:

-----------------------------------------------------------------
#!/tmp/perl/bin/perl 
# dumps core if LINES and COLUMNS aren't defined in the env:
#0  0xef5cc5a0 in _free_unlocked ()
#1  0xef5cc560 in free ()
#2  0x507b8 in Perl_safefree (where=0xeffffa79) at util.c:173
#3  0x550f4 in Perl_magic_clear_all_env (sv=0x0, mg=0xc98e0) at mg.c:785
#....
use Term::ReadLine;
$RL = new Term::ReadLine 'foo';
undef %ENV;
-----------------------------------------------------------------
#!/tmp/perl/bin/perl 
# dumps core if LINES and COLUMNS aren't defined in the env:
#0  0xef5cc5a0 in _free_unlocked ()
#1  0xef5cc560 in free ()
#2  0x507b8 in Perl_safefree (where=0xeffffcff) at util.c:173
#3  0x52af8 in Perl_my_setenv (nam=0xd0128 "PATH", val=0xd1890 "/foobar")
#   at util.c:1443
#....
use Term::ReadLine;
$RL = new Term::ReadLine 'foo';
$ENV{PATH} = "/foobar";
-----------------------------------------------------------------


I'm not familiar with the perl source so I leave it up to you to
invent a correct patch.

Regards,
Joerg 

-- 
 Gaertner Datensysteme                         38114 Braunschweig 
 Joerg Schumacher                              Hamburger Str. 273a
 Tel: 0531-2335555          		       Fax: 0531-2335556

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About