
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
|