Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4: Check if handle is active when calling prepare #400

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ MYMETA.*
*.old
INSTALL.html
/DBD-mysql-*
socket.o
5 changes: 5 additions & 0 deletions dbdimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2977,6 +2977,11 @@ dbd_st_prepare(
D_imp_xxh(sth);
D_imp_dbh_from_sth;

if (!DBIc_ACTIVE(imp_dbh)) {
do_error(sth, JW_ERR_NOT_ACTIVE, "Statement not active" ,NULL);
return FALSE;
}

if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
PerlIO_printf(DBIc_LOGPIO(imp_xxh),
"\t-> dbd_st_prepare MYSQL_VERSION_ID %d, SQL statement: %s\n",
Expand Down
29 changes: 29 additions & 0 deletions t/gh352.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use strict;
use warnings;

use Test::More;
use DBI;
use lib 't', '.';
require 'lib.pl';

use vars qw($test_dsn $test_user $test_password);

my $dbh;
eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password,
{ RaiseError => 1, PrintError => 1, AutoCommit => 0 });};

if ($@) {
diag $@;
plan skip_all => "no database connection";
}
plan tests => 2;

# https://github.com/perl5-dbi/DBD-mysql/issues/352
# Calling prepare on a disconnected handle causes the call to mysql_real_escape_string to segfault

my $sth;
ok $dbh->disconnect;
my $result = eval {
$dbh->prepare('SELECT ?');
};
ok !$result