Skip to content

Commit

Permalink
Fix bug #81343: inconsistent type conversion after closeCursor
Browse files Browse the repository at this point in the history
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 phpGH-7355.
  • Loading branch information
pilif authored and nikic committed Aug 11, 2021
1 parent 865b096 commit ace8fba
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ PHP NEWS
. Fixed bug #81349 (mb_detect_encoding misdetcts ASCII in some cases).
(Nikita)

- PDO PgSQL:
. Fixed bug #81343 (pdo_pgsql: Inconsitent boolean conversion after calling
closeCursor()). (Philip Hofstetter)

- Phar:
. Use SHA256 by default for signature. (remi)
. Add support for OpenSSL_SHA256 and OpenSSL_SHA512 signature. (remi)
Expand Down
10 changes: 2 additions & 8 deletions ext/pdo_pgsql/pgsql_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ static int pgsql_stmt_execute(pdo_stmt_t *stmt)
return 0;
}

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

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

static int pdo_pgsql_stmt_cursor_closer(pdo_stmt_t *stmt)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;

if (S->cols != NULL){
efree(S->cols);
S->cols = NULL;
}
return 1;
}

Expand Down
27 changes: 27 additions & 0 deletions ext/pdo_pgsql/tests/bug81343.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Bug #81343 pdo_pgsql: Inconsitent boolean conversion after calling closeCursor()
--EXTENSIONS--
pdo
pdo_pgsql
--SKIPIF--
<?php
require __DIR__ . '/config.inc';
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
$pdo = PDOTest::test_factory(__DIR__ . '/common.phpt');
$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
$sth = $pdo->prepare("select false where 2=?");

for ($i = 0; $i < 2; $i++) {
$sth->execute([2]);
var_dump($sth->fetchColumn(0));
$sth->closeCursor();
}
?>
--EXPECT--
bool(false)
bool(false)

0 comments on commit ace8fba

Please sign in to comment.