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

Bug in Term::Complete Module with $_ Usage #7616

Closed
p5pRT opened this issue Nov 26, 2004 · 9 comments
Closed

Bug in Term::Complete Module with $_ Usage #7616

p5pRT opened this issue Nov 26, 2004 · 9 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 26, 2004

Migrated from rt.perl.org#32639 (status was 'resolved')

Searchable as RT32639$

@p5pRT
Copy link
Author

p5pRT commented Nov 26, 2004

From adalbert.perbandt@infineon.com

Created by adalbert.perbandt@infineon.com

The sub "Complete" in the file "Complete.pm" assigns data
to the $_ variable without having done a "local $_;" in
advance. This way it produces a side effect at the
caller.

Perl Info

Flags:
    category=core
    severity=medium

This perlbug was built using Perl v5.8.5 - Fri Jul 30 15:38:45 MEST 2004
It is being executed now by  Perl v5.8.5 - Fri Jul 30 08:29:00 MEST 2004.

Site configuration information for perl v5.8.5:

Configured by hwadm at Fri Jul 30 08:29:00 MEST 2004.

Summary of my perl5 (revision 5 version 8 subversion 5) configuration:
  Platform:
    osname=solaris, osvers=2.8, archname=sun4-solaris-thread-multi
    uname='sunos oslo05 5.8 generic_117350-02 sun4us sparc fjsv,gpuzc-m '
    config_args='-Dprefix=/opt/perl_5.8.5 -Dmydomain=.muc.infineon.com -Dcf_email=perl@muc.infineon.com -Dinstallusrbinperl=undef -Dperl5=/opt/perl_5.8.5/bin/perl -Dsitebin=/opt/perl_5.8.5/bin -Dman1dir=/opt/perl_5.8.5/share/man/man1 -Dman3dir=/opt/perl_5.8.5/share/man/man3 -Dperladmin=perl@muc.infineon.com -Dprivlib=/opt/perl_5.8.5/share/lib -Dscriptdir=/opt/perl_5.8.5/share/bin -Dsitescript=/opt/perl_5.8.5/share/bin -Dsitelib=/opt/perl_5.8.5/share/lib -Ubincompat5005 -Dlibperl=libperlifx.so -Dcc=gcc -Doptimize=-O2 -Dldflags=-static-libgcc -Dlddlflags=-G -static-libgcc -Darchlib=/opt/perl_5.8.5/lib/sun4-solaris-thread-multi -Dsitearch=/opt/perl_5.8.5/lib/sun4-solaris-thread-multi -Dlocincpth=/home/hwadm/TWW/SOL/include -Dloclibpth=/home/hwadm/TWW/SOL/lib -Dglibpth=/usr/lib -Duseshrplib -Dusethreads -Dpager=/usr/local/bin/less -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define 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='gcc', ccflags ='-D_REENTRANT -fno-strict-aliasing -pipe -I/home/hwadm/TWW/SOL/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-D_REENTRANT -fno-strict-aliasing -pipe -I/home/hwadm/TWW/SOL/include'
    ccversion='', gccversion='3.2.3', gccosandvers='solaris2.8'
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags ='-static-libgcc -L/home/hwadm/TWW/SOL/lib '
    libpth=/home/hwadm/TWW/SOL/lib /usr/lib
    libs=-lsocket -lnsl -lgdbm -ldb -ldl -lm -lpthread
    perllibs=-lsocket -lnsl -ldl -lm -lpthread
    libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperlifx.so
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='  -R /opt/perl_5.8.5/lib/sun4-solaris-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-G -static-libgcc -L/home/hwadm/TWW/SOL/lib'

Locally applied patches:
    


@INC for perl v5.8.5:
    /opt/perl_5.8.5/lib/sun4-solaris-thread-multi
    /opt/perl_5.8.5/share/lib
    /opt/perl_5.8.5/lib/sun4-solaris-thread-multi
    /opt/perl_5.8.5/share/lib
    /opt/perl_5.8.5/share/lib
    .


Environment for perl v5.8.5:
    HOME=/home/perbandt
    LANG=en_US
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/usr/dt/lib:/usr/lib
    LOGDIR (unset)
    PATH=/opt/perl_5.8.5/bin:/var/vob/relman/admin/vob/devenv/bin:/usr/atria/bin:/opt/OpenOffice_1.1.3/program:/usr/dt/bin:/usr/bin:.:/usr/openwin/bin:/bin:/home/hwadm/bin:/home/bondtool/bin:.:/home/perbandt/bin:/usr/sbin:/home/relman/bin:/opt/ica_7.21:/opt/TWWfsw/bin:/usr/local/bin:/usr/ucb
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented Nov 26, 2004

From @smpeters

Do you have an example that may demonstrate this problem? It would be
helpful for testing and fixing the problem.

Thanks!

@p5pRT
Copy link
Author

p5pRT commented Nov 26, 2004

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

@p5pRT
Copy link
Author

p5pRT commented Nov 26, 2004

From @smpeters

Actually, the bug can be demonstrated with the following script​:

#!/usr/bin/perl -w

use strict;
use lib ".";
use Term​::Complete;

$_ = "Foo";
my @​completion_list;
my $input = Complete('Hit Enter', \@​completion_list);

print "$_\n";

Now, here's the patch that fixes the problem.

Inline Patch
--- /usr/libdata/perl5/Term/Complete.pm Fri Sep 17 13:09:30 2004
+++ ./Term/Complete.pm  Fri Nov 26 11:13:08 2004
@@ -5,7 +5,7 @@
 use strict;
 our @ISA = qw(Exporter);
 our @EXPORT = qw(Complete);
-our $VERSION = '1.401';
+our $VERSION = '1.402';

 #      @(#)complete.pl,v1.2            (me@anywhere.EBay.Sun.COM) 09/23/91

@@ -113,6 +113,7 @@
     }
     system $tty_raw_noecho if defined $tty_raw_noecho;
     LOOP: {
+        local $_;
         print($prompt, $return);
         while (($_ = getc(STDIN)) ne "\r") {
             CASE: {

@p5pRT
Copy link
Author

p5pRT commented Nov 26, 2004

From @rgs

Steve Peters via RT wrote​:

Now, here's the patch that fixes the problem.

Thanks, applied as #23548 to bleadperl.

--- /usr/libdata/perl5/Term/Complete.pm Fri Sep 17 13​:09​:30 2004
+++ ./Term/Complete.pm Fri Nov 26 11​:13​:08 2004

@p5pRT
Copy link
Author

p5pRT commented Nov 26, 2004

From adalbert.perbandt@infineon.com

"Steve" == Steve Peters via <RT" <perlbug-followup@​perl.org>> writes​:

  Steve> Do you have an example that may demonstrate this problem?
  Steve> It would be helpful for testing and fixing the problem.

I didn't spend the effort to generate a minimal example but I think
the information given below should help​:

1. This is a code snippet from inside a script​:

[...]
use Class​::Autouse qw(
  IFXClearCase​::Project
  IFXClearCase​::Component
  IFXClearCase​::Baseline
  IFXClearCase​::EnvHandler
  IFXClearCase​::ProjectManager
  IFXClearCase​::WorkspaceManager
);

my $env = IFXClearCase​::EnvHandler->instance();
my $projMgr = IFXClearCase​::ProjectManager->new(ENVHANDLER => $env);
my $project = IFXClearCase​::Project->lookup(NAME => "InwayDev-5.0",
  PVOB => $env->getPVOBTag());

my $devenv =
  IFXClearCase​::Component->lookup(NAME =>"devenv@​/var/vob/relman/p/vob");

my @​roComps = ($devenv);

my %roCompBls;
foreach (@​roComps) {
  print("\n\$\_​: `$_'\n");
  my $bl = $_->prompt4Baseline();
  print("\n\$\_​: `$_'\n");
  if (!defined $bl) {
  print("BLOED!\n");
  exit(1);
  }
  $roCompBls{$_} = $bl;
}
[...]

See the foreach loop. I have inserted print() statements immediately
before and after the call of the prompt4Baseline() method. In this
method I have isolated the location where the $_ variable gets
overwritten. It's in this code snippet​:

sub prompt4Baseline
{
[...]
print("\nprompt4Baseline​: \$\_​: `$_'\n");
  my $blName;
  if (-t STDIN) {
  $blName = Complete("Choose one​: ", @​baselineIds);
  } else {
  $blName = <STDIN>;
  chomp $blName;
  }
  $blName =~ s/^\s+|\s+$//g; # Remove leading and trailing whitespace.
print("\nprompt4Baseline​: \$\_​: `$_'\n");

We then inspected the source code of the Complete.pm. In the code of
the sub Complete we found this​:

[...]
  LOOP​: {
  print($prompt, $return);
  while (($_ = getc(STDIN)) ne "\r") {
[...]

In the while statements condition part $_ gets overwritten. We did not
find a place before this location where $_ would have been made local.

Regards,

Adalbert.

@p5pRT
Copy link
Author

p5pRT commented Nov 26, 2004

From adalbert.perbandt@infineon.com

"Steve" == Steve Peters via <RT" <perlbug-followup@​perl.org>> writes​:

  Steve> Actually, the bug can be demonstrated with the following
  Steve> script​:

Thanks a lot.

Regards

Adalbert.

@p5pRT
Copy link
Author

p5pRT commented Nov 28, 2004

From @ysth

On Fri, Nov 26, 2004 at 05​:14​:33PM -0000, Steve Peters wrote​:

--- /usr/libdata/perl5/Term/Complete.pm Fri Sep 17 13​:09​:30 2004
+++ ./Term/Complete.pm Fri Nov 26 11​:13​:08 2004
@​@​ -5,7 +5,7 @​@​
use strict;
our @​ISA = qw(Exporter);
our @​EXPORT = qw(Complete);
-our $VERSION = '1.401';
+our $VERSION = '1.402';

# @​(#)complete.pl,v1.2 (me@​anywhere.EBay.Sun.COM) 09/23/91

@​@​ -113,6 +113,7 @​@​
}
system $tty_raw_noecho if defined $tty_raw_noecho;
LOOP​: {
+ local $_;
print($prompt, $return);
while (($_ = getc(STDIN)) ne "\r") {
CASE​: {

I thought the preferred way to do this was "local *_;" in maint or
"my $_;" in blead. Or, better yet, use a lexical $char instead of $_
throughout the block.

@p5pRT
Copy link
Author

p5pRT commented Dec 9, 2004

@rgs - Status changed from 'open' to 'resolved'

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

No branches or pull requests

1 participant