[php-src] Issue #16131: It is possible to mix PDO sub-classes with different dsn and crash PHP

From: Date: Mon, 30 Sep 2024 11:48:18 +0000
Subject: [php-src] Issue #16131: It is possible to mix PDO sub-classes with different dsn and crash PHP
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-247941@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/16131 Author: evaikene ### Description PHP 8.4 added PDO driver specific sub-classes and it is now possible to write the following code, which crashes the PHP process: ```php $db = new Pdo\Mysql('sqlite:test.db'); $db->getWarningCount(); <?php ``` ``` * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x94048479aa1403e0) * frame #0: 0x00000479aa1403e0 frame #1: 0x00000001002e2694 php`zim_Pdo_Mysql_getWarningCount(execute_data=0x0000000101215140, return_value=0x0000000101215120) at pdo_mysql.c:99:2 frame #2: 0x00000001007a926c php`ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER(execute_data=0x0000000101215020) at zend_vm_execute.h:2025:4 frame #3: 0x000000010075c248 php`execute_ex(ex=0x0000000101215020) at zend_vm_execute.h:58486:7 ... ``` The dsn requested a sqlite driver, but the PDO sub-class is Pdo\Mysql, which assumes that it has a mysql driver and can use it causing a crash. pdo_mysql.c line 99: ```c H = (pdo_mysql_db_handle *)dbh->driver_data; RETURN_LONG(mysql_warning_count(H->server)); ``` **Expected result** Either an exception throw when the PDO sub-class and dsn don't match or not possible to create sub-class objects directly (only with PDO::connect). ### PHP Version PHP 8.4.0RC1 ### Operating System _No response_

« previous php.bugs (#247941) next »