Skip to content

Commit 7fe8b2a

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: ext/pdo: Bound-check column index in getColumnMeta()
2 parents 5f9eb6d + 6a2023c commit 7fe8b2a

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

‎NEWS‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ PHP NEWS
3333
. Fixed bug GH-23106 (mb_strpos() reads past the end of a haystack ending in
3434
a truncated UTF-8 sequence). (Lazizbek Ergashev)
3535

36+
- PDO:
37+
. Fixed PDOStatement::getColumnMeta() reading out of bounds for an invalid
38+
column index. (Ilia Alshanetsky)
39+
3640
- PGSQL:
3741
. Fixed pg_lo_write() rejecting data containing null bytes. (Ilia Alshanetsky)
3842

‎ext/pdo/pdo_stmt.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,13 @@ PHP_METHOD(PDOStatement, getColumnMeta)
15861586
RETURN_FALSE;
15871587
}
15881588

1589+
if (stmt->columns == NULL || colno >= stmt->column_count) {
1590+
zval_ptr_dtor(return_value);
1591+
ZVAL_UNDEF(return_value);
1592+
pdo_raise_impl_error(stmt->dbh, stmt, "07009", "invalid column index");
1593+
RETURN_FALSE;
1594+
}
1595+
15891596
/* add stock items */
15901597
col = &stmt->columns[colno];
15911598
add_assoc_str(return_value, "name", zend_string_copy(col->name));
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
PDO_odbc getColumnMeta() bounds checking on unexecuted statements and invalid indexes
3+
--EXTENSIONS--
4+
pdo_odbc
5+
--SKIPIF--
6+
<?php
7+
try {
8+
new Pdo\Odbc('odbc:Driver={SQLite3};Database=:memory:');
9+
} catch (Throwable $e) {
10+
die('skip SQLite3 ODBC driver not available');
11+
}
12+
?>
13+
--FILE--
14+
<?php
15+
$pdo = new Pdo\Odbc('odbc:Driver={SQLite3};Database=:memory:',
16+
null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
17+
$stmt = $pdo->prepare('SELECT 1 AS one');
18+
19+
try {
20+
var_dump($stmt->getColumnMeta(0));
21+
} catch (Throwable $e) {
22+
echo $e::class, ': ', $e->getMessage(), "\n";
23+
}
24+
25+
$stmt->execute();
26+
var_dump($stmt->getColumnMeta(0));
27+
28+
try {
29+
var_dump($stmt->getColumnMeta(5));
30+
} catch (Throwable $e) {
31+
echo $e::class, ': ', $e->getMessage(), "\n";
32+
}
33+
34+
echo "done\n";
35+
?>
36+
--EXPECTF--
37+
PDOException: SQLSTATE[07009]: Invalid descriptor index: invalid column index
38+
array(4) {
39+
["pdo_type"]=>
40+
int(2)
41+
["name"]=>
42+
string(3) "one"
43+
["len"]=>
44+
int(%d)
45+
["precision"]=>
46+
int(%d)
47+
}
48+
PDOException: SQLSTATE[07009]: Invalid descriptor index: invalid column index
49+
done

0 commit comments

Comments
 (0)