Skip to content
Closed
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
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ PHP NEWS
. Fixed a crash when executing a prepared statement again after a failed
execute() with libmysqlclient. (Ilia Alshanetsky)

- PDO_PGSQL:
. Fixed bug GH-25838 (use-after-free when a lazy statement follows a failed
query). (Yun Dou)

- PDO_SQLite:
. Fixed bug GH-25588 (Use-after-free of a string parameter omitted on a later
execute() or rebound while fetching). (Ilia Alshanetsky)
Expand Down
2 changes: 1 addition & 1 deletion ext/pdo_pgsql/pgsql_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static int pgsql_stmt_dtor(pdo_stmt_t *stmt)

pgsql_stmt_finish(S, FIN_DISCARD|(server_obj_usable ? FIN_CLOSE|FIN_ABORT : 0));

if (server_obj_usable && S->H->running_stmt == S) {
if ((server_obj_usable || stmt->database_object_handle == NULL) && S->H->running_stmt == S) {
S->H->running_stmt = NULL;
}

Expand Down
30 changes: 30 additions & 0 deletions ext/pdo_pgsql/tests/gh25838.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
GH-25838 (pdo_pgsql: use-after-free when a lazy statement follows a failed query)
--EXTENSIONS--
pdo_pgsql
--SKIPIF--
<?php
require __DIR__ . '/config.inc';
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
PDOTest::skip();
?>
--CREDITS--
Yun Dou
--FILE--
<?php
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
$pdo = PDOTest::test_factory(__DIR__ . '/common.phpt');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

try {
$pdo->query('SELECT 1 / 0');
} catch (PDOException $e) {
echo $e->getCode(), PHP_EOL;
}

$pdo->setAttribute(PDO::ATTR_PREFETCH, 0);
echo $pdo->query('SELECT 43')->fetchColumn(), PHP_EOL;
?>
--EXPECT--
22012
43
Loading