Skip Menu |

This queue is for tickets about the Convert-BER CPAN distribution.

Report information
The Basics
Id: 78587
Status: open
Priority: 0/
Queue: Convert-BER

People
Owner: Nobody in particular
Requestors: asjo [...] koldfront.dk
Cc:
AdminCc:

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



Subject: encode() clobbers $@
When Convert::BER->encode() is called from a DESTROY method inside an eval { }, $@ is overwritten. I have encountered this with DBD::JDBC (0.70) - please see the attached minimal test case, and attached patch that fixes the problem for me. Thanks!
Subject: convert_ber_eval_clobber_fix.patch
--- BER.pm.orig 2012-07-26 16:33:01.934316033 +0200 +++ BER.pm 2012-07-26 16:34:12.074124931 +0200 @@ -662,6 +662,7 @@ sub encode { my $ber = shift; local($SIG{'__DIE__'}); + local($@); $ber->[ Convert::BER::_INDEX() ] = [];
Subject: convert_ber_eval_clobber_example.pl
#!/usr/bin/perl use strict; use warnings; use Test::More; eval { my $some_thing=Some::Thing->new; die "CAUGHT\n"; }; my $error=$@; isnt($error, '', '$@ is not empty'); is($error, "CAUGHT\n", '$@ is CAUGHT'); done_testing; package Some::Thing; use Convert::BER; sub new { my ($class)=@_; return bless {}, $class; } sub DESTROY { my $ber=Convert::BER->new; $ber->encode(INTEGER=>1); # This clobbers $@ }
Subject: Re: [rt.cpan.org #78587] encode() clobbers $@
Date: Thu, 26 Jul 2012 10:02:41 -0500
To: bug-Convert-BER [...] rt.cpan.org
From: Graham Barr <gbarr [...] pobox.com>
I do not see this as a problem specific to Convert::BER *any* code which calls eval during DESTROY will clobber $@ Graham.
From: asjo [...] koldfront.dk
On Thu Jul 26 11:03:03 2012, gbarr@pobox.com wrote: Show quoted text
> I do not see this as a problem specific to Convert::BER
Show quoted text
> *any* code which calls eval during DESTROY will clobber $@
Yeah, you're right - I just happened to encounter this when inside an eval a DBD::JDBC object was created and destroyed, and its DESTROY method called Convert::BER (while closing connections), which then called eval - which I guess was a surprise to the DBD::JDBC author. I took the handling of $SIG{__DIE__} in encode() as an indicator of Convert::BER "trying to be nice" to callers, but I readily admit that I am no expert. Maybe the correct fix is for DBD::JDBC's DESTROY to local'ize $@ instead? The code in question is disconnect()[1] which calls _send_request()[2] which then calls Convert::BER::encode(). Best regards, Adam [1] https://www.metacpan.org/source/VIZDOM/DBD-JDBC-0.71/JDBC.pm#L514 [2] https://www.metacpan.org/source/VIZDOM/DBD-JDBC-0.71/JDBC.pm#L103