develooper Front page | perl.perl5.porters | Postings from May 2012

[perl #113046] Code embeddable in argument to -i switch

Thread Next
From:
Jeremy Madea
Date:
May 25, 2012 00:45
Subject:
[perl #113046] Code embeddable in argument to -i switch
Message ID:
rt-3.6.HEAD-7788-1337733344-1824.113046-75-0@perl.org
# New Ticket Created by  Jeremy Madea 
# Please include the string:  [perl #113046]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=113046 >


This is a bug report for perl from jeremy@cpan.org,
generated with the help of perlbug 1.39 running under perl 5.16.0.


-----------------------------------------------------------------
Example:
$ perl -i'.bak -e warn 1;' -e'warn 2'
1 at -e line 1.
2 at -e line 2.

Showing that code can be embedded in the argument to the -i
command line switch. Other switches can be embedded as well.
This is only possible when the switch is preceded by exactly
one space. The extension can be empty and the switch does not
require the dash.

$ perl -i' e warn 1'
1 at -e line 1.

And this shows that, with two spaces, the bug is not exercised:

$ perl -MO=Deparse -i'  e warn 1' -e'warn 2'
BEGIN { $^I = ""; }
warn 2;
-e syntax OK

The bug was first reported by EvanCarroll on perlmonks.org

http://www.perlmonks.org/?node_id=971866



Here is a patch.


--- orig-perl.c 2012-05-22 15:43:39.000000000 -0400
+++ perl.c      2012-05-22 15:45:45.000000000 -0400
@@ -3187,11 +3187,8 @@

            PL_inplace = savepvn(start, s - start);
        }
-       if (*s) {
-           ++s;
-           if (*s == '-')      /* Additional switches on #! line. */
-               s++;
-       }
+       if (*s == '-')  /* Additional switches on #! line. */
+           s++;
        return s;
     case 'I':  /* -I handled both here and in parse_body() */
        forbid_setid('I', FALSE);




[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl 5.16.0:

Configured by jmadea at Tue May 22 13:17:52 EDT 2012.

Summary of my perl5 (revision 5 version 16 subversion 0) configuration:

  Platform:
    osname=linux, osvers=2.6.32-5-686, archname=i686-linux-thread-multi
    uname='linux kermit 2.6.32-5-686 #1 smp mon jan 16 16:04:25 utc
2012 i686 gnulinux '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE
-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.4.5', gccosandvers=''
    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='gcc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib/../lib /usr/lib/../lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.11.3.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.11.3'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib
-fstack-protector'

Locally applied patches:


---
@INC for perl 5.16.0:
    /home/jmadea/lib/perl5/site_perl/5.16.0/i686-linux-thread-multi
    /home/jmadea/lib/perl5/site_perl/5.16.0
    /home/jmadea/lib/perl5/5.16.0/i686-linux-thread-multi
    /home/jmadea/lib/perl5/5.16.0
    .

---
Environment for perl 5.16.0:
    HOME=/home/jmadea
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/jmadea/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
    PERL_BADLANG (unset)
    SHELL=/bin/bash


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