Skip to content
Open
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 @@ -176,6 +176,10 @@ PHP NEWS
. Fixed a duplicate warning when ATTR_STATEMENT_CLASS is rejected on a
persistent connection. (Ilia Alshanetsky)

- PDO_Firebird:
. Fixed bug GH-25006 (getColumnMeta() reads out of bounds for an
out-of-range column index). (Ilia Alshanetsky)

- Phar:
. Fixed bug GH-24740 (Oversized tar metadata exhausts the memory limit).
(Lazizbek Ergashev)
Expand Down
10 changes: 8 additions & 2 deletions ext/pdo_firebird/firebird_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,15 @@ static int pdo_firebird_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
static int pdo_firebird_stmt_get_column_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_value)
{
pdo_firebird_stmt *S = (pdo_firebird_stmt *) stmt->driver_data;
XSQLVAR *var = &S->out_sqlda.sqlvar[colno];

XSQLVAR *var;
enum pdo_param_type param_type;

if (colno >= stmt->column_count) {
array_init(return_value);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZVAL_EMPTY_RETURN_VALUE()

return 1;
}

var = &S->out_sqlda.sqlvar[colno];
if (var->sqlscale < 0) {
param_type = PDO_PARAM_STR;
} else {
Expand Down
73 changes: 73 additions & 0 deletions ext/pdo_firebird/tests/gh25006.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
--TEST--
GH-25006 (PDO_Firebird::getColumnMeta() reads out of bounds for an out-of-range column index)
--EXTENSIONS--
pdo_firebird
--SKIPIF--
<?php
require 'skipif.inc';
?>
--XLEAK--
A bug in firebird causes a memory leak when calling `isc_attach_database()`.
See https://github.com/FirebirdSQL/firebird/issues/7849
--FILE--
<?php
require 'testdb.inc';

$dbh = getDbConnection();
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $dbh->prepare('SELECT 1 AS one, 2 AS two FROM RDB$DATABASE');

echo "before execute: ";
try {
var_dump($stmt->getColumnMeta(2));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

$stmt->execute();

echo "column 0: ";
$meta = $stmt->getColumnMeta(0);
echo $meta['name'], ' ', $meta['pdo_type'], "\n";

echo "column 1: ";
$meta = $stmt->getColumnMeta(1);
echo $meta['name'], ' ', $meta['pdo_type'], "\n";

foreach ([2, 1000000] as $col) {
echo "column $col: ";
try {
var_dump($stmt->getColumnMeta($col));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
}

echo "no output columns: ";
$empty = $dbh->prepare('EXECUTE BLOCK AS BEGIN END');
echo $empty->columnCount(), ' ';
try {
var_dump($empty->getColumnMeta(0));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

echo "negative: ";
try {
var_dump($stmt->getColumnMeta(-1));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

echo "done\n";
?>
--EXPECT--
before execute: PDOException: SQLSTATE[07009]: Invalid descriptor index: invalid column index
column 0: ONE 1
column 1: TWO 1
column 2: PDOException: SQLSTATE[07009]: Invalid descriptor index: invalid column index
column 1000000: PDOException: SQLSTATE[07009]: Invalid descriptor index: invalid column index
no output columns: 0 PDOException: SQLSTATE[07009]: Invalid descriptor index: invalid column index
negative: ValueError: PDOStatement::getColumnMeta(): Argument #1 ($column) must be greater than or equal to 0
done
Loading