develooper Front page | perl.perl5.porters | Postings from September 2004

[perl #31455] Dup DATA filehandle, lose initial data

From:
Jim Carter
Date:
September 5, 2004 13:30
Subject:
[perl #31455] Dup DATA filehandle, lose initial data
Message ID:
rt-3.0.11-31455-95275.6.53735876320958@perl.org
# New Ticket Created by  Jim Carter 
# Please include the string:  [perl #31455]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=31455 >



This is a bug report for perl from jimc@math.ucla.edu,
generated with the help of perlbug 1.34 running under perl v5.8.3.

#!/usr/bin/perl 
# If the script is not seekable, and if the DATA filehandle is duped, an
# initial segment of the DATA is lost when reading from the duplicate
# handle. With this script the lossage is 4216 bytes from start of
# script or 2959 bytes from start of DATA.  In the production 
# script where this was discovered, the loss from start of DATA is in 
# the range 3500 to 4000 bytes.
#    The production context is, we concatenate a "tripwire" type script
# and the filenames and checksums it should verify (customized per
# host), and do ssh remotehost "perl - -f '<&DATA'" where -f tells the
# script where to find the checksum list.  That way the hackers have
# little to attack -- only by munging perl itself can they defend
# themselves.
print <<EOF;
Compare these three command lines:
    perl datatrunc.pl		# Seekable script, runs perfectly
    perl - < datatrunc.pl	# Seekable script, runs perfectly
    cat datatrunc.pl | perl -	# Not seekable, loses initial DATA
EOF
open(DUPL, "<&DATA") or die "Failed to dup DATA filehandle: $!\n";
while (<DUPL>) {		# Each line is exactly 80 bytes including \n
    print
}
__DATA__
Line 01   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 02   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 03   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 04   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 05   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 06   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 07   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 08   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 09   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 10   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 11   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 12   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 13   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 14   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 15   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 16   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 17   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 18   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 19   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 20   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 21   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 22   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 23   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 24   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 25   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 26   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 27   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 28   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 29   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 30   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 31   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 32   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 33   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 34   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 35   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 36   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 37   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 38   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 39   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
Line 40   b123456789c123456789d123456789e123456789f123456789g123456789h12345678
---
Flags:
    category=core
    severity=medium
---
This perlbug was built using Perl v5.8.3 - Sat Apr  3 00:50:30 UTC 2004
It is being executed now by  Perl v5.8.3 - Sat Apr  3 00:37:21 UTC 2004.

Site configuration information for perl v5.8.3:

Configured by abuild at Sat Apr  3 00:37:21 UTC 2004.

Summary of my perl5 (revision 5.0 version 8 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.6.4, archname=i586-linux-thread-multi
    uname='linux d209 2.6.4 #1 smp thu mar 11 17:56:49 utc 2004 i686 i686 i386 gnulinux '
    config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Duseshrplib=true -Doptimize=-O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -Wall -pipe'
    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='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -Wall -pipe',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing'
    ccversion='', gccversion='3.3.3 (SuSE Linux)', 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='cc', ldflags =''
    libpth=/lib /usr/lib /usr/local/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=, 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/i586-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared'

Locally applied patches:
    

---
@INC for perl v5.8.3:
    /usr/lib/perl5/5.8.3/i586-linux-thread-multi
    /usr/lib/perl5/5.8.3
    /usr/lib/perl5/site_perl/5.8.3/i586-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.3
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.3/i586-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.3
    /usr/lib/perl5/vendor_perl
    .

---
Environment for perl v5.8.3:
    HOME=/home/jimc
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=.:/home/jimc/bin:/usr/diklo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/sbin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/sbin:/usr/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About