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

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

Thread Next
Jeremy Madea
May 25, 2012 00:45
[perl #113046] Code embeddable in argument to -i switch
Message ID:
# New Ticket Created by  Jeremy Madea 
# Please include the string:  [perl #113046]
# in the subject line of all future correspondence about this issue. 
# <URL: >

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

$ 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

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]
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:

    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 '
    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
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE
-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include
    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',
    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/, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib

Locally applied patches:

@INC for perl 5.16.0:

Environment for perl 5.16.0:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About