From 1d665d86612ae63c45c54cf799d5059ff2e6ed2c Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Wed, 21 Mar 2018 15:04:09 +0900 Subject: [PATCH] fetching attributes from a statement handle whose database handle is disabled should return an error, instead of coredump under perl with -fsanitize=address - reported by Peter Rabbitson --- dbdimp.c | 5 +++++ t/32_inactive_error.t | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/dbdimp.c b/dbdimp.c index fcc2161..4ef2805 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -1312,6 +1312,11 @@ sqlite_st_FETCH_attrib(SV *sth, imp_sth_t *imp_sth, SV *keysv) croak_if_db_is_null(); croak_if_stmt_is_null(); + if (!DBIc_ACTIVE(imp_dbh)) { + sqlite_error(sth, -2, "attempt to fetch on inactive database handle"); + return FALSE; + } + if (strEQ(key, "sqlite_unprepared_statements")) { return sv_2mortal(newSVpv(imp_sth->unprepared_statements, 0)); } diff --git a/t/32_inactive_error.t b/t/32_inactive_error.t index 58f4034..a8fecc7 100644 --- a/t/32_inactive_error.t +++ b/t/32_inactive_error.t @@ -6,7 +6,7 @@ BEGIN { $^W = 1; } -use Test::More tests => 4; +use Test::More tests => 7; use lib "t/lib"; use SQLiteTest; @@ -33,3 +33,18 @@ like( qr/attempt to execute on inactive database handle/, 'Got the expected warning', ); + +@warning = (); +SCOPE: { + local $SIG{__WARN__} = sub { push @warning, @_; return }; + my $ret = eval { $sth->{NUM_OF_PARAMS}; }; + # we need PrintError => 1, or warn $@ if $@; + ok !$ret; +} + +is( scalar(@warning), 1, 'Got 1 warning' ); +like( + $warning[0], + qr/attempt to fetch on inactive database handle/, + 'Got the expected warning', +);