Skip to content

Commit e3d9e18

Browse files
committed
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
1 parent 2b7e89e commit e3d9e18

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

NEWS

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ PHP NEWS
1818
- FTP:
1919
. Fixed bug #65667 (ftp_nb_continue produces segfault). (Philip Hofstetter)
2020

21-
- ODBC
21+
- ODBC:
2222
. Fixed bug #65950 (Field name truncation if the field name is bigger than
2323
32 characters). (patch submitted by: michael dot y at zend dot com, Yasuo)
2424

25+
- PDO:
26+
. Fixed bug #66033 (Segmentation Fault when constructor of PDO statement
27+
throws an exception). (Laruence)
28+
2529
- Sockets:
2630
. Fixed bug #65808 (the socket_connect() won't work with IPv6 address).
2731
(Mike)

ext/pdo/pdo_dbh.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ static void pdo_stmt_construct(pdo_stmt_t *stmt, zval *object, zend_class_entry
460460
if (dbstmt_ce->constructor) {
461461
zend_fcall_info fci;
462462
zend_fcall_info_cache fcc;
463-
zval *retval;
463+
zval *retval = NULL;
464464

465465
fci.size = sizeof(zend_fcall_info);
466466
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
495495
zval_dtor(object);
496496
ZVAL_NULL(object);
497497
object = NULL; /* marks failure */
498-
} else {
498+
} else if (retval) {
499499
zval_ptr_dtor(&retval);
500500
}
501501

ext/pdo_sqlite/tests/bug66033.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #66033 (Segmentation Fault when constructor of PDO statement throws an exception)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo_sqlite')) print 'skip not loaded';
6+
?>
7+
--FILE--
8+
<?php
9+
class DBStatement extends PDOStatement {
10+
public $dbh;
11+
protected function __construct($dbh) {
12+
$this->dbh = $dbh;
13+
throw new Exception("Blah");
14+
}
15+
}
16+
17+
$pdo = new PDO('sqlite::memory:', null, null);
18+
$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('DBStatement',
19+
array($pdo)));
20+
$pdo->exec("CREATE TABLE IF NOT EXISTS messages (
21+
id INTEGER PRIMARY KEY,
22+
title TEXT,
23+
message TEXT,
24+
time INTEGER)");
25+
26+
try {
27+
$pdoStatement = $pdo->query("select * from messages");
28+
} catch (Exception $e) {
29+
var_dump($e->getMessage());
30+
}
31+
?>
32+
--EXPECTF--
33+
string(4) "Blah"

0 commit comments

Comments
 (0)