com php-src: Fixed Bug #66034 (Segmentation Fault when constructor of PDO statement throws an exception): NEWS ext/pdo/pdo_dbh.c ex
t/pdo_sqlite/tests/bug66033.phpt

From: Date: Tue, 05 Nov 2013 03:04:55 +0000
Subject: com php-src: Fixed Bug #66034 (Segmentation Fault when constructor of PDO statement throws an exception): NEWS ext/pdo/pdo_dbh.c ex
t/pdo_sqlite/tests/bug66033.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-73857@lists.php.net to get a copy of this message
Commit: e3d9e18e7b24ba2d5c9e420510e804330c94f955 Author: Xinchen Hui <laruence@php.net> Tue, 5 Nov 2013 11:04:55 +0800 Parents: 2b7e89e20a4ab23a50ac2c29884d7d1928560635 Branches: PHP-5.4 PHP-5.5 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e3d9e18e7b24ba2d5c9e420510e804330c94f955 Log: Fixed Bug #66034 (Segmentation Fault when constructor of PDO statement throws an exception) I know zend_call_function will initilize retval_ptr_ptr, but still set it to NULL explict is more readable Bugs: https://bugs.php.net/66034 Changed paths: M NEWS M ext/pdo/pdo_dbh.c A ext/pdo_sqlite/tests/bug66033.phpt Diff: diff --git a/NEWS b/NEWS index e5b79ec..c3e70d9 100644 --- a/NEWS +++ b/NEWS @@ -18,10 +18,14 @@ PHP NEWS - FTP: . Fixed bug #65667 (ftp_nb_continue produces segfault). (Philip Hofstetter) -- ODBC +- ODBC: . Fixed bug #65950 (Field name truncation if the field name is bigger than 32 characters). (patch submitted by: michael dot y at zend dot com, Yasuo) +- PDO: + . Fixed bug #66033 (Segmentation Fault when constructor of PDO statement + throws an exception). (Laruence) + - Sockets: . Fixed bug #65808 (the socket_connect() won't work with IPv6 address). (Mike) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index d5860b1..ac8d29a 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -460,7 +460,7 @@ static void pdo_stmt_construct(pdo_stmt_t *stmt, zval *object, zend_class_entry if (dbstmt_ce->constructor) { zend_fcall_info fci; zend_fcall_info_cache fcc; - zval *retval; + zval *retval = NULL; fci.size = sizeof(zend_fcall_info); fci.function_table = &dbstmt_ce->function_table; @@ -495,7 +495,7 @@ static void pdo_stmt_construct(pdo_stmt_t *stmt, zval *object, zend_class_entry zval_dtor(object); ZVAL_NULL(object); object = NULL; /* marks failure */ - } else { + } else if (retval) { zval_ptr_dtor(&retval); } diff --git a/ext/pdo_sqlite/tests/bug66033.phpt b/ext/pdo_sqlite/tests/bug66033.phpt new file mode 100644 index 0000000..28da3b5 --- /dev/null +++ b/ext/pdo_sqlite/tests/bug66033.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #66033 (Segmentation Fault when constructor of PDO statement throws an exception) +--SKIPIF-- +<?php +if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; +?> +--FILE-- +<?php +class DBStatement extends PDOStatement { + public $dbh; + protected function __construct($dbh) { + $this->dbh = $dbh; + throw new Exception("Blah"); + } +} + +$pdo = new PDO('sqlite::memory:', null, null); +$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('DBStatement', + array($pdo))); +$pdo->exec("CREATE TABLE IF NOT EXISTS messages ( + id INTEGER PRIMARY KEY, + title TEXT, + message TEXT, + time INTEGER)"); + +try { + $pdoStatement = $pdo->query("select * from messages"); +} catch (Exception $e) { + var_dump($e->getMessage()); +} +?> +--EXPECTF-- +string(4) "Blah"

« previous php.cvs (#73857) next »