Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ PHP NEWS
certificates with CRLs). (Alexander Danilov)

- PDO:
. Fixed use-after-free when a destructor of an old PDO::ATTR_STATEMENT_CLASS
constructor argument reads the attribute. (Roman Ondráček)
. Fixed invalid ATTR_ORACLE_NULLS values being accepted and truncated.
(Ilia Alshanetsky)
. Fixed a duplicate warning when ATTR_STATEMENT_CLASS is rejected on a
Expand Down
11 changes: 7 additions & 4 deletions ext/pdo/pdo_dbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,14 +937,17 @@ static bool pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /
zend_zval_value_name(item));
return false;
}
/* Store the new arguments before releasing the old ones, so that
* destructors of the old arguments do not observe them being destroyed. */
zval old_ctor_args;
ZVAL_COPY_VALUE(&old_ctor_args, &dbh->def_stmt_ctor_args);
dbh->def_stmt_ce = pce;
if (!Z_ISUNDEF(dbh->def_stmt_ctor_args)) {
zval_ptr_dtor(&dbh->def_stmt_ctor_args);
ZVAL_UNDEF(&dbh->def_stmt_ctor_args);
}
if (item != NULL) {
ZVAL_COPY(&dbh->def_stmt_ctor_args, item);
} else {
ZVAL_UNDEF(&dbh->def_stmt_ctor_args);
}
zval_ptr_dtor(&old_ctor_args);
return true;
}
/* Don't throw a ValueError as the attribute might be a driver specific one */
Expand Down
30 changes: 30 additions & 0 deletions ext/pdo_sqlite/tests/pdo_statement_class_ctor_args_release.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
PDO::ATTR_STATEMENT_CLASS: destructors of old constructor arguments do not observe them being released
--EXTENSIONS--
pdo_sqlite
--FILE--
<?php
class St extends PDOStatement {
protected function __construct(...$args) {}
}
class D {
public function __destruct() {
global $db;
$GLOBALS['keep'] = $db->getAttribute(PDO::ATTR_STATEMENT_CLASS);
}
}
$db = new PDO('sqlite::memory:');
$db->setAttribute(PDO::ATTR_STATEMENT_CLASS, ['St', [str_repeat('A', 64), new D, str_repeat('B', 64)]]);
$db->setAttribute(PDO::ATTR_STATEMENT_CLASS, ['St', [1]]);
var_dump($keep);
?>
--EXPECT--
array(2) {
[0]=>
string(2) "St"
[1]=>
array(1) {
[0]=>
int(1)
}
}
Loading