Subject: | Failure due to use of Clone - no apparent reason |
(This is an entirely inadequate bug report and I _expect_ it to be closed as non-reproducible, but it should serve as a warning, suggestion, and thanks for the clone behavior workaround)
I've spent hours and hours trying to refine the problem scenario and must give up. I finally tried using the set_clone_behavior() to turn off the use of Clone and that appears to avoid the problem. This in spite of apparently using the latest versions of Clone and Hash::Merge.
I'm developing a CGI that uses Template Toolkit. Hash::Merge is exactly what I needed to merge a fairly static hash describing one web page with a dynamic hash populated with form values, notes and error messages. While running as a 'normal' CGI under Apache on Redhat Linux 7.2 everything worked wonderfully.
But when I was forced to use setuid suidperl the CGI would occasionally and mysteriously quit with Apache saying "Premature end of script headers: /var/www/cgi-bin/easyftp/easyftp.pl" Much pain and agony ensued but I was able to track down the failure point to the Hash::Merge::merge call. I could not reproduce with unaltered code when not setuid, nor standalone with 'same' data structures.
When I finally gave up and used set_clone_behavior(0) the problem disappeared and I got the desired data results away.
I had simplified the code and data down to this:
if(0){
my $updates = { form => { adduser => { ftpuserid => { value => 'arf' } } } };
}else{
my $updates;
foreach my $field_name ( @names ) {
foreach my $field_name ( qw( ftpuserid ) ) {
my $formvalue = $rhSES->{adduser}{$field_name};
next unless defined $formvalue;
$updates->{form}{adduser}{$field_name}{value} = $formvalue;
}
}
[ subroutine calls that eventually end up with ... ]
Hash::Merge::set_behavior('RIGHT_PRECEDENT');
Hash::Merge::set_clone_behavior(0);
printf " (I see tt_vars %s)<BR>\n", QVoU($tt_vars);
printf " (I see updates %s)<BR>\n", QVoU($updates);
printf "<PRE>\n";
print ''.Data::Dumper->Dump( [ $tt_vars ], [ qw( *tt_vars ) ] );
print ''.Data::Dumper->Dump( [ $updates ], [ qw( *updates ) ] );
printf "</PRE>\n";
$tt_vars = Hash::Merge::merge( $tt_vars, $updates );
printf "<PRE>\n";
print ''.Data::Dumper->Dump( [ $tt_vars ], [ qw( *tt_vars ) ] );
printf "</PRE>\n";
(I see tt_vars 'HASH(0x8416184)')
(I see updates 'HASH(0x8416028)')
%tt_vars = (
'form' => {
'adduser' => {
'ftpuserid' => {
'value' => 'the_default'
}
}
}
);
%updates = (
'form' => {
'adduser' => {
'ftpuserid' => {
'value' => 'XT2KMR'
}
}
}
);
Would fail at this point with unhelpful Apache message. When working dumped result was:
%tt_vars = (
'form' => {
'adduser' => {
'ftpuserid' => {
'value' => 'XT2KMR'
}
}
}
);
To give the proper "Twilight Zone" feel to it all, if I commented out the loop line
$updates->{form}{adduser}{$field_name}{value} = $formvalue;
the problem would not surface (although of course the data was then wrong). Even when I manually constructed the 'same' data structure in $updates beforehand with
my $updates = { form => { adduser => { ftpuserid => .....
Anyway, I had to give up and use set_clone_behavior(0). This was okay for me as the data structure 'leaves' contain only scalar values. For the curious, version information below.
perl -M"Hash::Merge 99"
Hash::Merge version 99 required--this is only version 0.07.
perl -M"Clone 99"
Clone version 99 required--this is only version 0.15.
cat /etc/redhat-release
Red Hat Linux release 7.2 (Enigma)
uname -a
Linux xxxxxx.budgie.com 2.4.9-31smp #1 SMP Tue Feb 26 06:55:00 EST 2002 i686 unknown
[root@wacs06 easyftp]# perl -V
Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
Platform:
osname=linux, osvers=2.4.17-0.13smp, archname=i386-linux
uname='linux daffy.perf.redhat.com 2.4.17-0.13smp #1 smp fri feb 1 10:30:48 est 2002 i686 unknown '
config_args='-des -Doptimize=-O2 -march=i386 -mcpu=i686 -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dcccdlflags=-fPIC -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Uusethreads -Uuseithreads -Uuselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Di_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Dlocincpth='
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
useperlio=undef d_sfio=undef uselargefiles=undef usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
Compiler:
cc='gcc', ccflags ='-fno-strict-aliasing -I/usr/local/include',
optimize='-O2 -march=i386 -mcpu=i686',
cppflags='-fno-strict-aliasing -I/usr/local/include'
ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.1 2.96-98)', 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=4
alignbytes=4, usemymalloc=n, prototype=define
Linker and Libraries:
ld='gcc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lc -lcrypt -lutil
perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil
libc=/lib/libc-2.2.4.so, so=so, useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options:
Built under linux
Compiled at Feb 20 2002 15:01:16
@INC:
/usr/lib/perl5/5.6.1/i386-linux
/usr/lib/perl5/5.6.1
/usr/lib/perl5/site_perl/5.6.1/i386-linux
/usr/lib/perl5/site_perl/5.6.1
/usr/lib/perl5/site_perl/5.6.0/i386-linux
/usr/lib/perl5/site_perl/5.6.0
/usr/lib/perl5/site_perl
.