Bug #25251 libmysql.c:4322: setup_one_fetch_function: Assertion `param->buffer_length != 0'

Submitted: 22 Dec 2006 18:16 Modified: 18 Feb 2008 18:54
Reporter: Philip Stoev Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.0.27 OS:Linux (Linux; FreeBsd )
Assigned to: Andrey Hristov CPU Architecture:Any
Tags: qc

[22 Dec 2006 18:16] Philip Stoev
Description:
Hello,

The following statements will not execute properly from DBI:

SELECT '';
SELECT SUBSTR('a', 2);
SELECT CONCAT_WS('','');
SELECT REPEAT(-1,'a');

DBI fails with:
perl: libmysql.c:4322: setup_one_fetch_function: Assertion `param->buffer_length != 0' failed.

How to repeat:
my $sth = $dbh->prepare("SELECT ''");
$sth->execute();

$dbh->do() does not trigger this behavoir (possibly because the new-style MySQL binary protocol does not kick in).

Suggested fix:
What happens is that DBD's dbd_describe() calls mysql_fetch_fields() which returns a  fields[0].length of 0. This is then passed to mysql_stmt_bind_result which calls setup_one_fetch_function() which causes the assertion since buffer_length can not be zero if type is MYSQL_TYPE_STRING.

It appears that the length is zero because all those functions in those special cases return &my_empty_string which probably has a length of zero which gets propagated all the way up to the caller.

IF it is OK to have a buffer MYSQL_BIND structure with buffer_length == 0 (that is, if it is trailing \0 safe), then the assertion should be removed.
[22 Dec 2006 21:03] Philip Stoev
server_side_prepare must be enabled and working for this bug to manifest itself via DBI (though it does not look like a bug of DBD::mysql). Please make sure you have the latest DBD::mysql and that DBI tracing shows that dbd_describe() was called indeede.
[26 Dec 2006 21:38] Sveta Smirnova
Thank you for the report.

Verified as described using DBD-4.00 and last BK MySQL server.

With simple C test program error is not repeatable.
[18 Feb 2008 18:54] Andrey Hristov
This bug can't be reproduced anymore. In the libmysql sources the assert is missing.
[18 Feb 2008 18:54] Andrey Hristov
The test cases work as expected.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.042 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.