On Thu Aug 20 11:06:15 2009, tbusch@cpan.org wrote:
Show quoted text>
> do you have a test case where this systematically happens ?
> I don't know Catalyst at all. Maybe you can help.
I can reproduce this crash with B::PP::EWP 1.02, Perl 5.10.1 on FreeBSD
7.2 using OpenSSL 0.8.9e (the base system's openssl) with this script:
use Test::More tests => 1;
eval "use Business::PayPal::EWP";
my $e = Business::PayPal::EWP::SignAndEncrypt(
"Hello World!", "test.key", "test.crt", "paypal.pem"
);
isnt $e, "";
Removing Test::More or the eval seems to make the problem go away, but
since I think this is a memory corruption bug this is expected.
The following patch fixes the problem, at least for me:
--- EWP.xs.orig 2010-02-14 20:49:15.000000000 +0000
+++ EWP.xs 2010-02-14 20:49:53.000000000 +0000
@@ -99,6 +99,9 @@
goto end;
}
+ /* p7bio now owns memBio, so don't try to free it */
+ memBio = NULL;
+
//Pump data to special PKCS7 BIO. This encrypts and signs it.
BIO_write(p7bio, data, strlen(data));
BIO_flush(p7bio);
The issue is that PKCS7_dataInit calls BIO_push(p7bio, memBio) which
means that when BIO_free_all(p7bio) is called it tries to free an
already-freed BIO.
Since none of this stuff is documented, I'm afraid I have no idea how
portable this fix is across OpenSSL versions. It also appears from the
OpenSSL source that using
p7bio = PKCS7_dataInit(p7, NULL);
would internally allocate a BIO_s_mem if needed and avoid memBio
altogether, but I again I don't know if this is portable across OpenSSL
versions.
Ben