cpan-authors / IPC-Run

https://metacpan.org/pod/IPC::Run
Other
21 stars 38 forks source link

Modification of a read-only value attempted at /usr/share/perl5/IPC/Run.pm line 1686, <STDIN> line 1 #139

Open ken-i opened 4 years ago

ken-i commented 4 years ago

The above error is being returned from the harness function of IPC::Run.

The trip for the error is passing in undef for a variable during a call to run, but would also of happened if calling start or harness:

run $cmd, undef, \$out, \$err;

The above is passing undef for \$in.

I have not located any documentation indicating \$in is mandatory, and can not be undef.

The error did not occur on stretch IPC::Run version 0.94, with the code:

   my @args;
   if ( @_ == 1 && ! ref $_[0] ) {
      if ( Win32_MODE ) {
         my $command = $ENV{ComSpec} || 'cmd';
         @args = ( [ $command, '/c', win32_parse_cmd_line $_[0] ] );
      }
      else {
         @args = ( [ qw( sh -c ), @_ ] );
      }
   }
   elsif ( @_ > 1 && ! grep ref $_, @_ ) {
      @args = ( [ @_ ] );
   }
   else {
==>      @args = @_;
   }

The error does occur on buster IPC::Run version 20180523.0, with the code:

    my @args;
    if ( @_ == 1 && !ref $_[0] ) {
        if (Win32_MODE) {
            my $command = $ENV{ComSpec} || 'cmd';
            @args = ( [ $command, '/c', win32_parse_cmd_line $_[0] ] );
        }
        else {
            @args = ( [ qw( sh -c ), @_ ] );
        }
    }
    elsif ( @_ > 1 && !grep ref $_, @_ ) {
        @args = ( [@_] );
    }
    else {
==>        @args = map { !defined $_ ? bless(\$_, 'IPC::Run::Undef') : $_ } @_;
    }

Change indicated by ==> above.

I believe the issue here is the introduction of the map or more specifically the bless call trying to modify the read only constant $_.

Please advise if further details required.

A search of open tickets yielded no existing ticket for the above.

Workaround

A workaround for the error is to always pass in the STDIN variable \$in.

Environment

Debian GNU/Linux 10 (buster)

Package: libipc-run-perl
Version: 20180523.0-1
Priority: optional
Section: perl
Maintainer: Debian Perl Group <pkg-perl-maintainers@lists.alioth.debian.org>
Installed-Size: 268 kB
Depends: perl, libio-pty-perl
Homepage: https://metacpan.org/release/IPC-Run
Tag: devel::lang:perl, devel::library, implemented-in::perl, role::program,
 works-with::software:running
Download-Size: 101 kB
APT-Manual-Installed: no
APT-Sources: https://friskrepo/debian buster/main amd64 Packages
Description: Perl module for running processes