Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

[perl #41008] Setting $0 invalidates environment shown by ps

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


perlbug-followup at perl

Nov 28, 2006, 5:09 AM

Post #1 of 5 (268 views)
Permalink
[perl #41008] Setting $0 invalidates environment shown by ps

# New Ticket Created by alexander_bluhm [at] genua
# Please include the string: [perl #41008]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=41008 >



This is a bug report for perl from bluhm [at] genua,
generated with the help of perlbug 1.35 running under perl v5.8.8.


-----------------------------------------------------------------
[Please enter your report here]

On BSD 'ps -e' shows the environment of each process. If a perl
program sets the $0 variable, the memory where the kernel has stored
the original environment gets overwritten.

Reproduce:
$ perl -e '$0="XXX"; sleep 2' & { sleep 1; ps -eww; } | grep '(perl)'
25082 p4 I 0:00.00 ... 3400 Spaces ... (perl)

Fix:
BSD provides the setproctitle() function to set the program name.
Overwriting existing memory provided by the system should only be
done for operating systems where this is necessary. I tested my
fix with OpenBSD -current but not with HPUX but the same should be
true there.

Patch:
Index: mg.c
===================================================================
RCS file: /mount/p4/cvs/openbsd/src/gnu/usr.bin/perl/mg.c,v
retrieving revision 1.12
diff -p -u -r1.12 mg.c
--- mg.c 28 Mar 2006 19:22:57 -0000 1.12
+++ mg.c 27 Nov 2006 22:17:13 -0000
@@ -2509,15 +2509,14 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
setproctitle("%s", s);
# endif
}
-#endif
-#if defined(__hpux) && defined(PSTAT_SETCMD)
+#elif defined(__hpux) && defined(PSTAT_SETCMD)
{
union pstun un;
s = SvPV_const(sv, len);
un.pst_command = (char *)s;
pstat(PSTAT_SETCMD, un, len, 0, 0);
}
-#endif
+#else
/* PL_origalen is set in perl_parse(). */
s = SvPV_force(sv,len);
if (len >= (STRLEN)PL_origalen) {
@@ -2539,6 +2538,7 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
for (i = 1; i < PL_origargc; i++)
PL_origargv[i] = 0;
}
+#endif
UNLOCK_DOLLARZERO_MUTEX;
break;
#endif
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=low
---
Site configuration information for perl v5.8.8:

Configured by root at Thu Jan 1 0:00:00 UTC 1970.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
Platform:
osname=openbsd, osvers=4.0, archname=i386-openbsd
uname='openbsd'
config_args='-dsE -Dopenbsd_distribution=defined'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-fno-strict-aliasing -fno-delete-null-pointer-checks -pipe -I/usr/local/include',
optimize='-O2',
cppflags='-fno-strict-aliasing -fno-delete-null-pointer-checks -pipe -I/usr/local/include'
ccversion='', gccversion='3.3.5 (propolice)', gccosandvers='openbsd4.0'
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags ='-Wl,-E '
libpth=/usr/lib
libs=-lm -lutil -lc
perllibs=-lm -lutil -lc
libc=/usr/lib/libc.so.40.2, so=so, useshrplib=true, libperl=libperl.so.10.1
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-R/usr/libdata/perl5/i386-openbsd/5.8.8/CORE'
cccdlflags='-DPIC -fPIC ', lddlflags='-shared -fPIC '

Locally applied patches:


---
@INC for perl v5.8.8:
/usr/libdata/perl5/i386-openbsd/5.8.8
/usr/local/libdata/perl5/i386-openbsd/5.8.8
/usr/libdata/perl5
/usr/local/libdata/perl5
/usr/local/libdata/perl5/site_perl/i386-openbsd
/usr/libdata/perl5/site_perl/i386-openbsd
/usr/local/libdata/perl5/site_perl
/usr/libdata/perl5/site_perl
/usr/local/lib/perl5/site_perl
.

---
Environment for perl v5.8.8:
HOME=/home/bluhm
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/home/bluhm/bin
PERL_BADLANG (unset)
SHELL=/bin/ksh


h.m.brand at xs4all

Nov 28, 2006, 3:53 PM

Post #2 of 5 (263 views)
Permalink
Re: [perl #41008] Setting $0 invalidates environment shown by ps [In reply to]

On Tue, 28 Nov 2006 05:09:31 -0800, "alexander_bluhm [at] genua (via RT)"
<perlbug-followup [at] perl> wrote:

> On BSD 'ps -e' shows the environment of each process. If a perl
> program sets the $0 variable, the memory where the kernel has stored
> the original environment gets overwritten.
>
> Reproduce:
> $ perl -e '$0="XXX"; sleep 2' & { sleep 1; ps -eww; } | grep '(perl)'
> 25082 p4 I 0:00.00 ... 3400 Spaces ... (perl)
>
> Fix:
> BSD provides the setproctitle() function to set the program name.
> Overwriting existing memory provided by the system should only be
> done for operating systems where this is necessary. I tested my
> fix with OpenBSD -current but not with HPUX but the same should be
> true there.
>
> Patch:
> Index: mg.c
> ===================================================================
> RCS file: /mount/p4/cvs/openbsd/src/gnu/usr.bin/perl/mg.c,v
> retrieving revision 1.12
> diff -p -u -r1.12 mg.c
> --- mg.c 28 Mar 2006 19:22:57 -0000 1.12
> +++ mg.c 27 Nov 2006 22:17:13 -0000
> @@ -2509,15 +2509,14 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
> setproctitle("%s", s);
> # endif
> }
> -#endif
> -#if defined(__hpux) && defined(PSTAT_SETCMD)
> +#elif defined(__hpux) && defined(PSTAT_SETCMD)

#elif is not backward ANSI-C compatible

/me is now not in a position to be able to test on `older' systems

> {
> union pstun un;
> s = SvPV_const(sv, len);
> un.pst_command = (char *)s;
> pstat(PSTAT_SETCMD, un, len, 0, 0);
> }
> -#endif
> +#else
> /* PL_origalen is set in perl_parse(). */
> s = SvPV_force(sv,len);
> if (len >= (STRLEN)PL_origalen) {
> @@ -2539,6 +2538,7 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
> for (i = 1; i < PL_origargc; i++)
> PL_origargv[i] = 0;
> }
> +#endif
> UNLOCK_DOLLARZERO_MUTEX;
> break;
> #endif

--
H.Merijn Brand Amsterdam Perl Mongers (http://amsterdam.pm.org/)
using & porting perl 5.6.2, 5.8.x, 5.9.x on HP-UX 10.20, 11.00, 11.11,
& 11.23, SuSE 10.0 & 10.1, AIX 4.3 & 5.2, and Cygwin. http://qa.perl.org
http://mirrors.develooper.com/hpux/ http://www.test-smoke.org
http://www.goldmark.org/jeff/stupid-disclaimers/


perlbug-followup at perl

Nov 29, 2006, 3:36 AM

Post #3 of 5 (260 views)
Permalink
[perl #41008] Setting $0 invalidates environment shown by ps [In reply to]

Thanks, your patchlooks correct; I've applied it as change #29416 to
bleadperl.


gisle at activestate

Nov 29, 2006, 6:26 AM

Post #4 of 5 (241 views)
Permalink
Re: [perl #41008] Setting $0 invalidates environment shown by ps [In reply to]

"H.Merijn Brand" <h.m.brand [at] xs4all> writes:

> #elif is not backward ANSI-C compatible

#elif is ANSI-C compatible and is already used by the perl sources.
#elif is not K&R-C compatible though.

--
Gisle


h.m.brand at xs4all

Nov 29, 2006, 11:44 PM

Post #5 of 5 (256 views)
Permalink
Re: [perl #41008] Setting $0 invalidates environment shown by ps [In reply to]

On 29 Nov 2006 10:53:33 +0100, Gisle Aas <gisle [at] activestate> wrote:

> "H.Merijn Brand" <h.m.brand [at] xs4all> writes:
>
> > #elif is not backward ANSI-C compatible
>
> #elif is ANSI-C compatible and is already used by the perl sources.
> #elif is not K&R-C compatible though.

/me submits this change to memory. thanks

--
H.Merijn Brand Amsterdam Perl Mongers (http://amsterdam.pm.org/)
using & porting perl 5.6.2, 5.8.x, 5.9.x on HP-UX 10.20, 11.00, 11.11,
& 11.23, SuSE 10.0 & 10.1, AIX 4.3 & 5.2, and Cygwin. http://qa.perl.org
http://mirrors.develooper.com/hpux/ http://www.test-smoke.org
http://www.goldmark.org/jeff/stupid-disclaimers/

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.