Skip to content

Commit 63c38c9

Browse files
Metabolixnikic
authored andcommitted
Fixed bug #77289
Use mysqlnd_restart_psession and mysqlnd_end_psession in PDO MySQL. This makes sure we free last_message while ZMM is still live.
1 parent bf4dab0 commit 63c38c9

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ PHP NEWS
5454
. Fixed bug #77273 (array_walk_recursive corrupts value types leading to PDO
5555
failure). (Nikita)
5656

57+
- PDO MySQL:
58+
. Fixed bug #77289 (PDO MySQL segfaults with persistent connection).
59+
(Lauri Kenttä)
60+
5761
- Phar:
5862
. Fixed bug #77247 (heap buffer overflow in phar_detect_phar_fname_ext). (Stas)
5963

ext/pdo_mysql/mysql_driver.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,21 @@ static int pdo_mysql_check_liveness(pdo_dbh_t *dbh)
509509
}
510510
/* }}} */
511511

512+
/* {{{ pdo_mysql_request_shutdown */
513+
static void pdo_mysql_request_shutdown(pdo_dbh_t *dbh)
514+
{
515+
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
516+
517+
PDO_DBG_ENTER("pdo_mysql_request_shutdown");
518+
PDO_DBG_INF_FMT("dbh=%p", dbh);
519+
#ifdef PDO_USE_MYSQLND
520+
if (H->server) {
521+
mysqlnd_end_psession(H->server);
522+
}
523+
#endif
524+
}
525+
/* }}} */
526+
512527
/* {{{ mysql_methods */
513528
static const struct pdo_dbh_methods mysql_methods = {
514529
mysql_handle_closer,
@@ -524,7 +539,7 @@ static const struct pdo_dbh_methods mysql_methods = {
524539
pdo_mysql_get_attribute,
525540
pdo_mysql_check_liveness,
526541
NULL,
527-
NULL,
542+
pdo_mysql_request_shutdown,
528543
NULL
529544
};
530545
/* }}} */
@@ -589,6 +604,11 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
589604
pdo_mysql_error(dbh);
590605
goto cleanup;
591606
}
607+
#if defined(PDO_USE_MYSQLND)
608+
if (dbh->is_persistent) {
609+
mysqlnd_restart_psession(H->server);
610+
}
611+
#endif
592612

593613
dbh->driver_data = H;
594614

ext/pdo_mysql/tests/bug77289.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #77289: PDO MySQL segfaults with persistent connection
3+
--SKIPIF--
4+
<?php
5+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7+
MySQLPDOTest::skip();
8+
?>
9+
--FILE--
10+
<?php
11+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
12+
13+
$dsn = MySQLPDOTest::getDSN();
14+
$user = PDO_MYSQL_TEST_USER;
15+
$pass = PDO_MYSQL_TEST_PASS;
16+
$pdo = new PDO($dsn, $user, $pass, [PDO::ATTR_PERSISTENT => true]);
17+
$pdo->exec("DROP TABLE IF EXISTS bug77289");
18+
$pdo->exec("CREATE TEMPORARY TABLE bug77289 (x INT)");
19+
$pdo->exec("UPDATE bug77289 SET x = x");
20+
21+
?>
22+
===DONE===
23+
--EXPECT--
24+
===DONE===

0 commit comments

Comments
 (0)