Open myrrhlin opened 1 day ago
Only a single test references ParamValues
at all: rt83494-quotes-comments.t
.
If you confirm that we intend to support this attribute, I might try to add some tests, perhaps in some of 4?bindparam.t
, or any test file you suggest.
DBD::mysql version
4.050
MySQL client version
8.0.39
Server version
8.0.39-0ubuntu0.20.04.1
Operating system version
Ubuntu 20.04.6 LTS
What happened?
Started work in an older codebase. I tried using
DBI::Log
module in a test script, and got a segfault.As you can see, the first query, using
$dbh->do()
is fine. The second query is an$sth->execute(42)
on aSELECT
statement with one placeholder, an integer id field, that causes the segfault. (Note: nowhere did we use$sth->bind_param
.)I used perl debugger to find the offending statement, and it's this one:
So this module uses the statement handle attribute
ParamValues
to find out what the bound parameter values were. This is a sometimes supported interface from DBI. It's expected to return a hashref, whereHowever, it should be noted that:
So, it's clear to me that
DBI::Log
should not be trying to read this data before execution, because for some drivers (including obviously mysql), the data won't be there yet. Regardless, if the attribute value wasundef
, as DBI docs suggest, the line causing the segfault would not have been executed. To have entered theif
block, the attribute must have had some true value.In the debugger again, I find what it is:
So the
ParamValues
attribute had the true value{ 0 => undef }
.However, that data structure was not a "pure-perl" clean hashref, as dereferencing it in list context caused the segfault. Alternative code to copy the hash such as this did not trigger a segfault:
Now, reading statement handle docs for
DBD::mysql
there is no mention ofParamValues
attribute, which raises some question whether it is supported at all. The docs do confirm however that:Testing shows that after execution, the attribute is populated with e.g.,
{ 0 => 42 }
, which is almost useful, but non-compliant with the DBI docs (which required the first argument to be under key1
).So we have these problems:
under no circumstance should accessing the parameter value, regardless of context, cause a segfault.
before execution, if we can't provide the values yet, the attribute value should be
undef
.after execution, it should probably be using integer keys starting with 1, e.g.
{ 1 => 42 }
Other information
Testing performed with system perl on Ubuntu 20.04 LTS :
Apologies I did not have time to try to replicate the failure with a newer version. If I get more time I will try to do that.
Issue #353 also suggests trouble with the xs building the data structures tied behind the statement handle attributes. Perhaps related.