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

In-memory read from undefined variable can return junk #7510

Closed
p5pRT opened this issue Sep 23, 2004 · 4 comments
Closed

In-memory read from undefined variable can return junk #7510

p5pRT opened this issue Sep 23, 2004 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Sep 23, 2004

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

Searchable as RT31692$

@p5pRT
Copy link
Author

p5pRT commented Sep 23, 2004

From perl@pythontech.co.uk

This is a bug report for perl from perl@​pythontech.co.uk,
generated with the help of perlbug 1.34 running under perl v5.8.3.

# 13 characters of junk are printed.
# I expect nothing to be printed.

$data = "13 characters";
$data = undef;

open(MEM,'<',\$data) or die "Fail​: $!\n";
while (<MEM>) {
  print;
}


Flags​:
  category=core
  severity=medium


Site configuration information for perl v5.8.3​:

Configured by bhcompile at Thu Apr 15 13​:08​:28 EDT 2004.

Summary of my perl5 (revision 5.0 version 8 subversion 3) configuration​:
  Platform​:
  osname=linux, osvers=2.4.21-4.elsmp, archname=i386-linux-thread-multi
  uname='linux tweety.devel.redhat.com 2.4.21-4.elsmp #1 smp fri oct 3 17​:52​:56 edt 2003 i686 i686 i386 gnulinux '
  config_args='-des -Doptimize=-O2 -g -pipe -march=i386 -mcpu=i686 -Dversion=5.8.3 -Dmyhostname=localhost -Dperladmin=root@​localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dinc_version_list=5.8.2 5.8.1 5.8.0'
  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 -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
  optimize='-O2 -g -pipe -march=i386 -mcpu=i686',
  cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
  ccversion='', gccversion='3.3.3 20040412 (Red Hat Linux 3.3.3-7)', 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 =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib
  libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
  perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
  libc=/lib/libc-2.3.3.so, so=so, useshrplib=true, libperl=libperl.so
  gnulibc_version='2.3.3'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.8.3/i386-linux-thread-multi/CORE'
  cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches​:
 


@​INC for perl v5.8.3​:
  /usr/lib/perl5/site_perl/jac_perl/5.8.3/i386-linux-thread-multi
  /usr/lib/perl5/site_perl/jac_perl/5.8.3
  /usr/lib/perl5/site_perl/jac_perl/i386-linux-thread-multi
  /usr/lib/perl5/site_perl/jac_perl/5.8.2
  /usr/lib/perl5/site_perl/jac_perl/5.8.1
  /usr/lib/perl5/site_perl/jac_perl/5.8.0
  /usr/lib/perl5/site_perl/jac_perl
  /usr/lib/perl5/5.8.3/i386-linux-thread-multi
  /usr/lib/perl5/5.8.3
  /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi
  /usr/lib/perl5/site_perl/5.8.2/i386-linux-thread-multi
  /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi
  /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
  /usr/lib/perl5/site_perl/5.8.3
  /usr/lib/perl5/site_perl/5.8.2
  /usr/lib/perl5/site_perl/5.8.1
  /usr/lib/perl5/site_perl/5.8.0
  /usr/lib/perl5/site_perl
  /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi
  /usr/lib/perl5/vendor_perl/5.8.2/i386-linux-thread-multi
  /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi
  /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
  /usr/lib/perl5/vendor_perl/5.8.3
  /usr/lib/perl5/vendor_perl/5.8.2
  /usr/lib/perl5/vendor_perl/5.8.1
  /usr/lib/perl5/vendor_perl/5.8.0
  /usr/lib/perl5/vendor_perl
  .


Environment for perl v5.8.3​:
  HOME=/home/chah
  LANG=en_GB.iso88591
  LANGUAGE (unset)
  LD_LIBRARY_PATH=/jet/share/lib​:/usr/local/lib​:/usr/local/matlab/extern/lib/glnx86
  LOGDIR (unset)
  PATH=/usr/kerberos/bin​:/usr/bin​:/bin​:/usr/X11R6/bin​:/usr/local/bin​:/jet/share/root/bin​:/jet/share/bin​:/usr/lib/openoffice/program​:.​:/home/chah/bin
  PERL5LIB=​:/usr/lib/perl5/site_perl/jac_perl
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2004

From @rgs

perl@​pythontech.co.uk (via RT) wrote​:

# 13 characters of junk are printed.
# I expect nothing to be printed.

$data = "13 characters";
$data = undef;

open(MEM,'<',\$data) or die "Fail​: $!\n";
while (<MEM>) {
print;
}

I committed the following fix to the development branch of perl. It's
not perfectly clean but it's conservative.

Change 23340 by rgs@​valis on 2004/09/30 15​:12​:29

  A fix for [perl #31692] : as PerlIO​::scalar accesses directly the
  PV of the scalar it reads from, avoid to read it when it's an
  undefined PV.

Affected files ...

... //depot/perl/ext/PerlIO/scalar/scalar.xs#10 edit
... //depot/perl/ext/PerlIO/t/scalar.t#10 edit

Differences ...

==== //depot/perl/ext/PerlIO/scalar/scalar.xs#10 (text) ====

@​@​ -39,7 +39,7 @​@​
  }
  SvUPGRADE(s->var, SVt_PV);
  code = PerlIOBase_pushed(aTHX_ f, mode, Nullsv, tab);
- if ((PerlIOBase(f)->flags) & PERLIO_F_TRUNCATE)
+ if (!SvOK(s->var) || (PerlIOBase(f)->flags) & PERLIO_F_TRUNCATE)
  SvCUR(s->var) = 0;
  if ((PerlIOBase(f)->flags) & PERLIO_F_APPEND)
  s->posn = SvCUR(s->var);

==== //depot/perl/ext/PerlIO/t/scalar.t#10 (text) ====

@​@​ -15,7 +15,7 @​@​
}

$| = 1;
-print "1..25\n";
+print "1..26\n";

my $fh;
my $var = "ok 2\n";
@​@​ -143,3 +143,9 @​@​
  close $fh;
  print $ok ? "ok 25\n" : "not ok 25\n";
}
+
+my $data = "a non-empty PV";
+$data = undef;
+open(MEM, '<', \$data) or die "Fail​: $!\n";
+my $x = join '', <MEM>;
+print $x eq '' ? "ok 26\n" : "not ok 26\n";

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2004

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

@p5pRT p5pRT closed this as completed Sep 30, 2004
@p5pRT
Copy link
Author

p5pRT commented Sep 30, 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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant