Fix error message allocation of PDO PgSQL

Closes GH-7723.
This commit is contained in:
SATO Kentaro 2021-12-06 06:59:52 +09:00 committed by Christoph M. Becker
parent 2c2b0abd4a
commit 778513f605
No known key found for this signature in database
GPG Key ID: D66C9593118BCCB6
3 changed files with 34 additions and 1 deletions

3
NEWS
View File

@ -7,6 +7,9 @@ PHP NEWS
. Fixed bug #81585 (cached_chunks are not counted to real_size on shutdown).
(cmb)
- PDO_PGSQL:
. Fixed error message allocation of PDO PgSQL. (SATO Kentaro)
- Spl:
. Fixed bug #75917 (SplFileObject::seek broken with CSV flags). (Aliaksandr
Bystry)

View File

@ -87,7 +87,7 @@ int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, const char *
}
if (msg) {
einfo->errmsg = estrdup(msg);
einfo->errmsg = pestrdup(msg, dbh->is_persistent);
}
else if (errmsg) {
einfo->errmsg = _pdo_pgsql_trim_message(errmsg, dbh->is_persistent);

View File

@ -0,0 +1,30 @@
--TEST--
GitHub #7723 (Fix error message allocation of PDO PgSQL)
--SKIPIF--
<?php
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
require __DIR__ . '/config.inc';
PDOTest::skip();
?>
--FILE--
<?php
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
require __DIR__ . '/config.inc';
$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
$db->setAttribute(PDO::ATTR_PERSISTENT, true);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$st = $db->prepare('select 1');
for ($i = 0; ++$i <= 2;) {
try {
$st->bindValue(':invalid', $i);
} catch (PDOException $e) {
echo $e->getMessage() . "\n";
}
}
?>
--EXPECT--
SQLSTATE[HY093]: Invalid parameter number: :invalid
SQLSTATE[HY093]: Invalid parameter number: :invalid