Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActivePerl splits arguments passed to exec() on whitespace #8026

Open
p5pRT opened this issue Jul 19, 2005 · 8 comments
Open

ActivePerl splits arguments passed to exec() on whitespace #8026

p5pRT opened this issue Jul 19, 2005 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Jul 19, 2005

Migrated from rt.perl.org#36594 (status was 'open')

Searchable as RT36594$

@p5pRT
Copy link
Author

p5pRT commented Jul 19, 2005

From pfusik@op.pl

This is a bug report for perl from pfusik@​op.pl,
generated with the help of perlbug 1.34 running under perl v5.8.0.


The problem is that the arguments passed to exec() are not passed
as they are to the called program, but instead are split on whitespace.

Example​:
perl -e "exec$^X,'-e','print+join+q{,},@​ARGV','foo boo bar'"
prints​:
foo,boo,bar

system() works fine​:
perl -e "system$^X,'-e','print+join+q{,},@​ARGV','foo boo bar'"
prints​:
foo boo bar



Flags​:
  category=core
  severity=low


Site configuration information for perl v5.8.0​:

Configured by ActiveState at Mon Mar 31 00​:45​:28 2003.

Summary of my perl5 (revision 5 version 8 subversion 0) configuration​:
  Platform​:
  osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
  uname=''
  config_args='undef'
  hint=recommended, useposix=true, d_sigaction=undef
  usethreads=undef use5005threads=undef 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='cl', ccflags
='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -D
HAVE_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLI
O -DPERL_MSVCRT_READFIX',
  optimize='-MD -Zi -DNDEBUG -O1',
  cppflags='-DWIN32'
  ccversion='', gccversion='', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64',
lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='link', ldflags
'-nologo -nodefaultlib -debug -opt​:ref,icf -libpath​:"C​:\j\Perl\lib\CORE
" -machine​:x86'
  libpth="D​:\Program Files\Microsoft.NET\FrameworkSDK\Lib\"
"D​:\Program Files\Microsoft.Net\Odbc.Net\" "C​:\j\Perl\lib\CORE"
  libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib version.lib
odbc32.lib odbccp32.lib msvcrt.lib
  perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib
version.lib odbc32.lib odbccp32.lib msvcrt.lib
  libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
  gnulibc_version='undef'
  Dynamic Linking​:
  dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ',
lddlflags='-dll -nologo -nodefaultlib -debug -opt​:ref,icf -libpath​:"C​:\
j\Perl\lib\CORE" -machine​:x86'

Locally applied patches​:
  ACTIVEPERL_LOCAL_PATCHES_ENTRY


@​INC for perl v5.8.0​:
  C​:/j/Perl/lib
  C​:/j/Perl/site/lib
  .


Environment for perl v5.8.0​:
  HOME (unset)
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)

PATH=C​:\WINDOWS;C​:\WINDOWS\COMMAND;C​:\U;C​:\JAVA\JDK\BIN;C​:\C\DJGPP\BIN;C
:\J\PERL\BIN;C​:\J\MYSQL\BIN;C​:\U\TEXMF\MAIN\MIKTEX\BIN;C​:\U\GS\GS8.11\BI
N;C​:\C\CYGWIN\BIN;C​:\WINDOWS;C​:\WINDOWS\COMMAND;C​:\U\ANT\BIN
  PERL_BADLANG (unset)
  SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Jul 20, 2005

From @schwern

On Tue, Jul 19, 2005 at 10​:45​:34AM -0700, Piotr Fusik wrote​:

The problem is that the arguments passed to exec() are not passed
as they are to the called program, but instead are split on whitespace.

Example​:
perl -e "exec$^X,'-e','print+join+q{,},@​ARGV','foo boo bar'"
prints​:
foo,boo,bar

system() works fine​:
perl -e "system$^X,'-e','print+join+q{,},@​ARGV','foo boo bar'"
prints​:
foo boo bar

<snip>

Configured by ActiveState at Mon Mar 31 00​:45​:28 2003.

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

Thank you for your report.

That's an old version of Perl. Try upgrading and see if the bug is still
present.

--
Michael G Schwern schwern@​pobox.com http​://www.pobox.com/~schwern
Insulting our readers is part of our business model.
  http​://somethingpositive.net/sp07122005.shtml

@p5pRT
Copy link
Author

p5pRT commented Jul 20, 2005

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jul 20, 2005

From @steve-m-hay

Michael G Schwern wrote​:

On Tue, Jul 19, 2005 at 10​:45​:34AM -0700, Piotr Fusik wrote​:

The problem is that the arguments passed to exec() are not passed
as they are to the called program, but instead are split on whitespace.

Example​:
perl -e "exec$^X,'-e','print+join+q{,},@​ARGV','foo boo bar'"
prints​:
foo,boo,bar

system() works fine​:
perl -e "system$^X,'-e','print+join+q{,},@​ARGV','foo boo bar'"
prints​:
foo boo bar

<snip>

Configured by ActiveState at Mon Mar 31 00​:45​:28 2003.

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

Thank you for your report.

That's an old version of Perl. Try upgrading and see if the bug is still
present.

I see the same behaviour using current perls.

It appears that you need to add some double quotes into the string that
becomes the exec'd programs @​ARGV​:

perl -e "exec$^X,'-e','print+join+q{,},@​ARGV',q{\"foo boo bar\"}"

prints

foo boo bar

as expected.

(You can also use the same idea to avoid the need for the ugly + signs
in your -e one-liner​:

perl -e "exec $^X, '-e', q{\"print join ',', @​ARGV\"}, q{\"foo boo bar\"}"

also works fine.)


Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only. If you have received this message in error or there are any problems, please notify the sender immediately. The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden. Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd. The recipient(s) of this message should check it and any attached files for viruses​: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.

@p5pRT
Copy link
Author

p5pRT commented Jul 20, 2005

From @gisle

Steve Hay <steve.hay@​uk.radan.com> writes​:

It appears that you need to add some double quotes into the string that
becomes the exec'd programs @​ARGV

Shouldn't perl do this automatically?

The behaviour of exec and system should anyway be consistent so this
appear to be a real/verified bug then.

--Gisle

@p5pRT
Copy link
Author

p5pRT commented Oct 21, 2012

From @jkeenan

On Wed Jul 20 02​:41​:11 2005, gisle@​ActiveState.com wrote​:

Steve Hay <steve.hay@​uk.radan.com> writes​:

It appears that you need to add some double quotes into the string that
becomes the exec'd programs @​ARGV

Shouldn't perl do this automatically?

The behaviour of exec and system should anyway be consistent so this
appear to be a real/verified bug then.

--Gisle

Discussion in this ticket petered out seven years ago. Is there anyone,
particularly on Win32, who could review the ticket and make a
recommendation?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Oct 22, 2012

From @bulk88

On Sun Oct 21 16​:05​:46 2012, jkeenan wrote​:

Discussion in this ticket petered out seven years ago. Is there anyone,
particularly on Win32, who could review the ticket and make a
recommendation?

Thank you very much.
Jim Keenan

I'm not sure, but Win32 specific shell interpretation might be involved
in this ticket. I always pass single quote single strings to system()
with double quotes to control splitting of whitespace.

@p5pRT
Copy link
Author

p5pRT commented Oct 22, 2012

From @jandubois

On Sun, 21 Oct 2012, James E Keenan via RT wrote​:

On Wed Jul 20 02​:41​:11 2005, gisle@​ActiveState.com wrote​:

Steve Hay <steve.hay@​uk.radan.com> writes​:

It appears that you need to add some double quotes into the string that
becomes the exec'd programs @​ARGV

Shouldn't perl do this automatically?

The behaviour of exec and system should anyway be consistent so this
appear to be a real/verified bug then.

Discussion in this ticket petered out seven years ago. Is there anyone,
particularly on Win32, who could review the ticket and make a
recommendation?

The difference in behavior is due to win32_spawnvp() using a special
helper function create_command_line() that knows about the
idiosyncrasies of Windows commandline parsing and adds the required quoting etc.
win32_execvp() however will just pass the arguments on to execvp() from
the C RTL, so the special treatment is missing there (same also for
win32_execv). It should be possible to fix this, but I won't have the
time to do this​: build up the commandline yourself, and then call
execlp(cmd, args) instead of execvp().

If somebody tackles this, please check out the t/win32/system_tests file
for all the weird combinations of commandlines covered by the system()
implementation and try to apply the same set of test cases to exec().

Bonus points for fixing this for the list form of readpipe() as well. :)

Cheers,
-Jan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants