Skip to content

Commit ace8fba

Browse files
pilifnikic
authored andcommitted
Fix bug #81343: inconsistent type conversion after closeCursor
S->cols is already freed in the statement destructor and since caa7100 the column data is only populated on the first execute() which means that on subsequent execute()s after closeCursor was called, all meta-data for column types was removed and never restored Closes GH-7355.
1 parent 865b096 commit ace8fba

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ PHP NEWS
2323
. Fixed bug #81349 (mb_detect_encoding misdetcts ASCII in some cases).
2424
(Nikita)
2525

26+
- PDO PgSQL:
27+
. Fixed bug #81343 (pdo_pgsql: Inconsitent boolean conversion after calling
28+
closeCursor()). (Philip Hofstetter)
29+
2630
- Phar:
2731
. Use SHA256 by default for signature. (remi)
2832
. Add support for OpenSSL_SHA256 and OpenSSL_SHA512 signature. (remi)

ext/pdo_pgsql/pgsql_statement.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ static int pgsql_stmt_execute(pdo_stmt_t *stmt)
240240
return 0;
241241
}
242242

243-
if (!stmt->executed && (!stmt->column_count || S->cols == NULL)) {
244-
stmt->column_count = (int) PQnfields(S->result);
243+
stmt->column_count = (int) PQnfields(S->result);
244+
if (S->cols == NULL) {
245245
S->cols = ecalloc(stmt->column_count, sizeof(pdo_pgsql_column));
246246
}
247247

@@ -674,12 +674,6 @@ static int pgsql_stmt_get_column_meta(pdo_stmt_t *stmt, zend_long colno, zval *r
674674

675675
static int pdo_pgsql_stmt_cursor_closer(pdo_stmt_t *stmt)
676676
{
677-
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
678-
679-
if (S->cols != NULL){
680-
efree(S->cols);
681-
S->cols = NULL;
682-
}
683677
return 1;
684678
}
685679

ext/pdo_pgsql/tests/bug81343.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #81343 pdo_pgsql: Inconsitent boolean conversion after calling closeCursor()
3+
--EXTENSIONS--
4+
pdo
5+
pdo_pgsql
6+
--SKIPIF--
7+
<?php
8+
require __DIR__ . '/config.inc';
9+
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
10+
PDOTest::skip();
11+
?>
12+
--FILE--
13+
<?php
14+
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
15+
$pdo = PDOTest::test_factory(__DIR__ . '/common.phpt');
16+
$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
17+
$sth = $pdo->prepare("select false where 2=?");
18+
19+
for ($i = 0; $i < 2; $i++) {
20+
$sth->execute([2]);
21+
var_dump($sth->fetchColumn(0));
22+
$sth->closeCursor();
23+
}
24+
?>
25+
--EXPECT--
26+
bool(false)
27+
bool(false)

0 commit comments

Comments
 (0)