Skip Menu |

This queue is for tickets about the Hash-Merge CPAN distribution.

Report information
The Basics
Id: 2252
Status: resolved
Priority: 0/
Queue: Hash-Merge

People
Owner: Nobody in particular
Requestors: mark.clements [...] tuskerdirect.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: (no value)
Fixed in: (no value)



Subject: undef value in hash causes perl segfault
under perl 5.6.1 and perl 5.8.0 on debian 3.0r1 and redhat 8.0 respectively, and also on Solaris 8.0 and 5.6.1. the following code segfaults Perl. perl -MHash::Merge=merge -le '%a=(a=>undef);%b=(c=>1);$c=merge(\%a,\%b)' but perl -MHash::Merge=merge -le '%a=(a=>undef);%b=(c=>1);$c=merge(\%a,\%b); undef $c' does not. Storable is 1.014 and 2.06 respectively. a gdb backtrace indicates that the crash is in do_clean_objs. cheers, Mark
Subject: empty hash causes perl segfault
From: patrick.mulvany [...] tuskerdirect.com
We have refined things down to an even more simple test case that still segfaults :- perl -MHash::Merge=merge -le '$a={};$c=merge($a)' and even perl -MHash::Merge=merge -le 'merge({})' Clone::VERSION 0.13 however when clone is replaced with dclone the same code does not segfault Hope this helps Paddy
Subject: use of Clone causes perl segfault
From: patrick.mulvany [...] tuskerdirect.com
Further to my last post a more in depth investigation has proven the problem lies in the Clone module. I hope this Helps Paddy ----- Forwarded message from Nicholas Clark <nick#unfortu.net> ----- Envelope-to: chris#nodnol.org Delivery-date: Wed, 19 Mar 2003 21:39:38 +0000 Date: Wed, 19 Mar 2003 21:36:24 +0000 To: chris#nodnol.org Subject: Re: Perl segfaulting bug From: Nicholas Clark <nick#unfortu.net> On Wed, Mar 19, 2003 at 03:08:52PM +0000, chris#nodnol.org wrote: Show quoted text
> > Nick, > > MBM suggested you might like to take a look at this problem we found: > (we've added it to rt.cpan.org under Hash::Merge.) > > Under perl 5.6.1 and perl 5.8.0 on debian 3.0r1 and redhat 8.0 > respectively, and also on Solaris 8 and 5.6.1, the following code > segfaults Perl: > > perl -MHash::Merge=merge -le '%a=(a=>undef);%b=(c=>1);$c=merge(\%a,\%b)' > > but > > perl -MHash::Merge=merge -le
'%a=(a=>undef);%b=(c=>1);$c=merge(\%a,\%b); undef $c' Show quoted text
> > does not. > > More worryingly: > > perl -MHash::Merge=merge -le '%a=(a=>undef);$c=merge(\%a)' > perl -MHash::Merge=merge -le '@a=(undef);$c=merge(\@a)' > perl -MHash::Merge=merge -le '$a={};$c=merge($a)' > also segfault...
So does perl -e 'use Clone qw(clone); $a = \$b; undef $a; $c = clone $a;' It's a bug in Clone: $ perl -e 'use Clone qw(clone); $a = \$b; undef $a; $c = clone $a; use Devel::Peek; Dump $c' SV = RV(0x813a864) at 0x812e2ac REFCNT = 1 FLAGS = (ROK) RV = 0x0 SV = 0 ROK shouldn't be set when RV doesn't point to a reference. (Clearly here it's a NULL pointer) The error seems to be in this bit of code in Clone.xs case SVt_RV: /* 3 */ TRACEME(("ref scalar\n")); clone = NEWSV(1002, 0); sv_upgrade(clone, SVt_RV); SvROK_on(clone); break; I'm not quite sure what it ought to be doing - I think a straight clone = newSVsv (ref); ought to work, but that causes it to fail its tests. I'm not convinced I like Clone in preference to Storable's dclone, given that Storable is now in core and some effort has been put into trying to keep it up-to-date on subtleties of the internal representations of things, such as Unicode in hash keys: $ perl5.8.0-32-g -MClone=clone -le '%a=(chr 256 =>1);$c=clone \%a; print ord foreach keys %$c' 196 $ perl5.8.0-32-g -MStorable=dclone -le '%a=(chr 256 =>1);$c=dclone \%a; print ord foreach keys %$c' 256 I'm biased, as I fixed Storable for Unicode hash keys before 5.8.0 was released. Also OK, it isn't strictly fair complaining that clone can't do this, as 5.7.something did extend the hash API to cope with Unicode in hash keys. Hash::Merge is innocent. Free the Hash::Merge 1 :-) Nicholas Clark Show quoted text
----- End forwarded message -----
From: patrick.mulvany [...] tuskerdirect.com
Following this up I have generated a Patch that appears to fix the problem by avoiding the bug in Clone. We have also logged this bug against Clone. Thanks Paddy
--- lib-vanilla/Hash/Merge.pm 2003-03-20 09:40:44.618025000 +0000 +++ lib/Hash/Merge.pm 2003-03-20 09:41:27.308033000 +0000 @@ -290,10 +290,14 @@ my $var = $arg; # Forced clone return $var; } else { - if ($depth ) { - return clone( $arg, $depth ); + if (defined $arg) { + if ($depth) { + return clone( $arg, $depth ); + } else { + return clone( $arg ); + } } else { - return clone( $arg ); + return undef; } } }
Hi, I've uploaded a new version, Clone-0.15 which fixes both problems. I apologize for the delay in getting the fixes out, they were both fairly trivial once I devoted a little time to the problem. As far as using Clone vs Storable, the one advantage clone has over dclone is speed. [guest - Thu Mar 20 06:41:38 2003]: Show quoted text
> Following this up I have generated a Patch that appears to fix the > problem by avoiding the bug in Clone. > > We have also logged this bug against Clone. > > Thanks > > Paddy > >
Hello, Since the functionality was added to Clone I'll go ahead and close this here. Thanks for the excellent details! It would have been even simpler to just return if !defeind $arg; right after that =@_ asignment but the point is moot because clone shoudl be able to handle clone an undef value, which it does now so we're all set :) Thanks! On Sun Sep 07 18:42:29 2003, RDF wrote: Show quoted text
> > Hi, I've uploaded a new version, Clone-0.15 which fixes both problems. I > apologize for the delay in getting the fixes out, they were both fairly > trivial once I devoted a little time to the problem. > > As far as using Clone vs Storable, the one advantage clone has over > dclone is speed. > > [guest - Thu Mar 20 06:41:38 2003]: >
> > Following this up I have generated a Patch that appears to fix the > > problem by avoiding the bug in Clone. > > > > We have also logged this bug against Clone. > > > > Thanks > > > > Paddy > > > >
> >