Skip to content

Commit 260e0e9

Browse files
committed
Fix GH-17837: ::getColumnMeta() on unexecuted statement segfaults
We cannot properly get the column meta data of a statement which has been prepared, but has not yet been executed. As such we bail out early, reporting failure. Closes GH-17850.
1 parent 86f5a31 commit 260e0e9

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ PHP NEWS
4040
JIT crash). (nielsdos)
4141
. Fixed bug GH-17577 (JIT packed type guard crash). (nielsdos, Dmitry)
4242

43+
- PDO_SQLite:
44+
. Fixed GH-17837 ()::getColumnMeta() on unexecuted statement segfaults).
45+
(cmb)
46+
4347
- Phar:
4448
. Fixed bug GH-17808: PharFileInfo refcount bug. (nielsdos)
4549

ext/pdo_sqlite/sqlite_statement.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static int pdo_sqlite_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *ret
305305
const char *str;
306306
zval flags;
307307

308-
if (!S->stmt) {
308+
if (!S->stmt || !stmt->executed) {
309309
return FAILURE;
310310
}
311311
if(colno >= sqlite3_column_count(S->stmt)) {

ext/pdo_sqlite/tests/gh17837.phpt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-17837 (::getColumnMeta() on unexecuted statement segfaults)
3+
--EXTENSIONS--
4+
pdo_sqlite
5+
--CREDITS--
6+
YuanchengJiang
7+
--FILE--
8+
<?php
9+
$db = new PDO('sqlite::memory:');
10+
$stmt = $db->prepare('select :a, :b, ?');
11+
var_dump($stmt->getColumnMeta(0));
12+
?>
13+
--EXPECT--
14+
bool(false)

0 commit comments

Comments
 (0)