Skip to content

Commit 4d677ae

Browse files
committed
Fixed bug #72570 Segmentation fault when binding parameters on a query without placeholders
1 parent 11d74b5 commit 4d677ae

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ PHP NEWS
1313

1414
- PDO_pgsql:
1515
. Fixed bug #70313 (PDO statement fails to throw exception). (Matteo)
16+
. Fixed bug #72570 (Segmentation fault when binding parameters on a query
17+
without placeholders). (Matteo)
1618

1719
- SPL:
1820
. Fixed bug #55701 (GlobIterator throws LogicException). (Valentin VĂLCIU)

ext/pdo_pgsql/pgsql_statement.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
292292
break;
293293

294294
case PDO_PARAM_EVT_ALLOC:
295+
if (!stmt->bound_param_map) {
296+
return 1;
297+
}
295298
if (!zend_hash_index_exists(stmt->bound_param_map, param->paramno)) {
296299
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined");
297300
return 0;

ext/pdo_pgsql/tests/bug72570.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
PDO PgSQL Bug #72570 (Segmentation fault when binding parameters on a query without placeholders)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
6+
require dirname(__FILE__) . '/config.inc';
7+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
8+
PDOTest::skip();
9+
?>
10+
--FILE--
11+
<?php
12+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
13+
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
14+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
15+
16+
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
17+
18+
$stmt = $db->prepare("SELECT 1");
19+
20+
try {
21+
$stmt->execute([1]);
22+
} catch (PDOException $e) {
23+
var_dump($e->getCode());
24+
}
25+
26+
?>
27+
--EXPECT--
28+
string(5) "08P01"

0 commit comments

Comments
 (0)