Skip to content

Commit 6a267a1

Browse files
committed
Merge pull request #120
Fix breakage of Net::SSLeay / OpenSSL library after DBI disconnect
2 parents f510d42 + f1f4824 commit 6a267a1

File tree

6 files changed

+64
-1
lines changed

6 files changed

+64
-1
lines changed

Changes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
1.11 2019-01-02
2+
- Fix breakage of Net::SSLeay / OpenSSL library after DBI disconnect
3+
(https://github.com/gooddata/DBD-MariaDB/issues/119)
4+
15
1.10 2018-12-05
26
- Fix spelling error (https://github.com/gooddata/DBD-MariaDB/issues/82)
37
- Fix MinGW build (https://github.com/gooddata/DBD-MariaDB/issues/91)

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ t/92ssl_connection.t
8484
t/92ssl_optional.t
8585
t/92ssl_backronym_vulnerability.t
8686
t/92ssl_riddle_vulnerability.t
87+
t/93net_ssleay.t
8788
t/99_bug_server_prepare_blob_null.t
8889
t/cve-2017-3302.t
8990
t/lib.pl

Makefile.PL

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,14 @@ my $have_get_option = check_lib(
270270
function => 'MYSQL mysql; char buf[1024]; mysql_server_init(-1, 0, 0); mysql_init(&mysql); mysql_get_option(&mysql, 0, &buf); return 0;',
271271
);
272272

273+
my $have_deinitialize_ssl = check_lib(
274+
LIBS => (join ' ', @libdirs, $main_lib),
275+
ccflags => $opt->{cflags},
276+
ldflags => (join ' ', @libdirs, @libs, @ldflags),
277+
header => 'mysql.h',
278+
function => 'mariadb_deinitialize_ssl = 0; return 0;',
279+
);
280+
273281
my $fileName = File::Spec->catfile("t", "MariaDB.mtest");
274282
(open(FILE, ">$fileName") &&
275283
(print FILE ("{ local " . Data::Dumper->Dump([$opt], ["opt"]) .
@@ -298,6 +306,7 @@ $cflags .= " -DHAVE_DBI_1_642" if eval { DBI->VERSION(1.642) };
298306
$cflags .= " -DHAVE_EMBEDDED" if $have_embedded;
299307
$cflags .= " -DHAVE_GET_CHARSET_NUMBER" if $have_get_charset_number;
300308
$cflags .= " -DHAVE_GET_OPTION" if $have_get_option;
309+
$cflags .= " -DHAVE_DEINITIALIZE_SSL" if $have_deinitialize_ssl;
301310
my %o = ( 'NAME' => 'DBD::MariaDB',
302311
'INC' => $cflags,
303312
'dist' => { 'SUFFIX' => ".gz",
@@ -407,6 +416,7 @@ if (eval { ExtUtils::MakeMaker->VERSION(5.43) }) {
407416
prereqs => {
408417
test => {
409418
recommends => {
419+
'Net::SSLeay' => 0,
410420
'Proc::ProcessTable' => 0,
411421
'TAP::Harness' => '3.31',
412422
'CPAN::Meta::YAML' => 0,

MariaDB.xs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ BOOT:
6363
newTypeSub(stash, MYSQL_TYPE_VAR_STRING);
6464
newTypeSub(stash, MYSQL_TYPE_STRING);
6565
#undef newTypeSub
66+
#ifdef HAVE_DEINITIALIZE_SSL
67+
/* Do not deinitialize OpenSSL library after mysql_server_end()
68+
* See: https://github.com/gooddata/DBD-MariaDB/issues/119 */
69+
mariadb_deinitialize_ssl = 0;
70+
#endif
6671
mysql_thread_init();
6772
}
6873

lib/DBD/MariaDB.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use DBI;
1010
use DynaLoader();
1111
our @ISA = qw(DynaLoader);
1212

13-
our $VERSION = '1.10';
13+
our $VERSION = '1.11';
1414

1515
bootstrap DBD::MariaDB $VERSION;
1616

t/93net_ssleay.t

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use strict;
2+
use warnings;
3+
4+
use Test::More;
5+
6+
use DBI;
7+
use DBD::MariaDB;
8+
9+
BEGIN {
10+
plan skip_all => 'Net::SSLeay is required for this test' unless eval { require Net::SSLeay };
11+
Net::SSLeay->import();
12+
}
13+
14+
sub diag_ssl {
15+
my $error = Net::SSLeay::ERR_get_error();
16+
my $error_string = Net::SSLeay::ERR_error_string($error);
17+
diag($error_string);
18+
Net::SSLeay::load_error_strings();
19+
my $error_string2 = Net::SSLeay::ERR_error_string($error);
20+
diag($error_string2);
21+
}
22+
23+
Net::SSLeay::initialize();
24+
25+
my $ctx_new_sub = Net::SSLeay->can('CTX_tlsv1_2_new') || Net::SSLeay->can('CTX_tlsv1_1_new') || Net::SSLeay->can('CTX_tlsv1_new');
26+
plan skip_all => 'Net::SSLeay does not provide TLS context' unless defined $ctx_new_sub;
27+
28+
plan tests => 4;
29+
30+
my $ctx1 = $ctx_new_sub->();
31+
ok($ctx1, 'Net::SSLeay TLS context was created before MariaDB connection') or diag_ssl();
32+
33+
my $dbh = DBI->connect('DBI:MariaDB:', undef, undef, { RaiseError => 0, PrintError => 0 });
34+
$dbh->disconnect() if defined $dbh;
35+
$dbh = undef;
36+
pass('MariaDB connection was successfully created and destroyed');
37+
38+
my $ctx2 = $ctx_new_sub->();
39+
ok($ctx2, 'Net::SSLeay TLS context was created after MariaDB connection') or diag_ssl();
40+
41+
Net::SSLeay::CTX_free($ctx1);
42+
Net::SSLeay::CTX_free($ctx2);
43+
pass('Net::SSLeay TLS contexts were destroyed');

0 commit comments

Comments
 (0)