Bug #68768 [NEW]: Mysqli segfaults on get_result call to stored procedure using cursors
| From: | yicheng at heroengine dot com | Date: | Wed, 07 Jan 2015 18:32:03 +0000 |
| Subject: | Bug #68768 [NEW]: Mysqli segfaults on get_result call to stored procedure using cursors | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-189705@lists.php.net to get a copy of this message | ||
From: yicheng at heroengine dot com
Operating system: Linux Fedora 20
PHP version: 5.5Git-2015-01-07 (Git)
Package: MySQLi related
Bug Type: Bug
Bug description:Mysqli segfaults on get_result call to stored procedure using cursors
Description:
------------
Given this sample stored procedure:
DELIMITER //
drop procedure IF EXISTS
testProcedure;
CREATE DEFINER=root@% PROCEDURE testProcedure(IN
v_username
VARCHAR(255))
MAIN:BEGIN
DECLARE done INT DEFAULT 0;
DECLARE p_username VARCHAR(255) DEFAULT 'default';
DECLARE sub CURSOR FOR SELECT 'Jon Jones' AS Acct_Username;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN sub;
read_loop: LOOP
FETCH sub INTO p_username;
IF done=1 THEN
LEAVE read_loop;
END IF;
END LOOP read_loop;
CLOSE sub;
SELECT 'Some kind of message' AS Msg, '200000' AS Num,CURDATE()
AS current;
END;
//
Executing the above procedure from the mysql command line retrieves the
following results:
MySQL [AMS]> CALL testProcedure('yicheng');//
+----------------------+--------+------------+
| Msg | Num | current |
+----------------------+--------+------------+
| Some kind of message | 200000 | 2015-01-07 |
+----------------------+--------+------------+
1 row in set (0.00 sec)
Calling the same procedure from mysqli (e.g. the test script) will
result in a segmentation fault, as shown in the following line from
apache error_log:
[Wed Jan 07 13:09:50.161212 2015] [core:notice] [pid 4653:tid
140193375778624] AH00052: child pid 22786 exit signal Segmentation fault
(11)
Curiously, taking out the select statement from the procedure will
remove the segfault but will still cause a php error due to attempting
to call fetch_array on a non-object.
Also, if I insert another select statement before the call to OPEN sub,
this will also avert the segfault although it will now cause two result
sets to be returned.
Test script:
---------------
$mysqli = new mysqli("host", "user", "pass", "DBNAME");
$sql = "CALL testProcedure(?)";
$username = "yicheng";
$statement = $mysqli->prepare($sql);
$statement->bind_param("s", $username);
$statement->execute();
$result = $statement->get_result();
echo "Get Results<br/>\n";
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
echo var_export($row, TRUE)."<br/>\n";
}
i
echo "Closing Mysqli<br/>\n";
$mysqli->close();
--
Edit bug report at https://bugs.php.net/bug.php?id=68768&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68768&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68768&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68768&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68768&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68768&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68768&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68768&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68768&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68768&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68768&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68768&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68768&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68768&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68768&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68768&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68768&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68768&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68768&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68768&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68768&r=mysqlcfg