Skip to content

Commit 26d7aaf

Browse files
committed
- Fixed bug #53463 (sqlite3 columnName() segfaults on bad column_number)
1 parent 17d1b13 commit 26d7aaf

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,15 +1529,21 @@ PHP_METHOD(sqlite3result, columnName)
15291529
php_sqlite3_result *result_obj;
15301530
zval *object = getThis();
15311531
long column = 0;
1532+
char *column_name;
15321533
result_obj = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC);
15331534

15341535
SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result)
15351536

15361537
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &column) == FAILURE) {
15371538
return;
15381539
}
1540+
column_name = (char*) sqlite3_column_name(result_obj->stmt_obj->stmt, column);
15391541

1540-
RETVAL_STRING((char*)sqlite3_column_name(result_obj->stmt_obj->stmt, column), 1);
1542+
if (column_name == NULL) {
1543+
RETURN_FALSE;
1544+
}
1545+
1546+
RETVAL_STRING(column_name, 1);
15411547
}
15421548
/* }}} */
15431549

ext/sqlite3/tests/bug53463.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Bug #53463 (sqlite3 columnName() segfaults on bad column_number)
3+
--FILE--
4+
<?php
5+
6+
$db = new SQLite3(':memory:');
7+
8+
$db->exec('CREATE TABLE test (whatever INTEGER)');
9+
$db->exec('INSERT INTO test (whatever) VALUES (1)');
10+
11+
$result = $db->query('SELECT * FROM test');
12+
while ($row = $result->fetchArray(SQLITE3_NUM)) {
13+
var_dump($result->columnName(0)); // string(8) "whatever"
14+
15+
// Seems returning false will be most appropriate.
16+
var_dump($result->columnName(3)); // Segmentation fault
17+
}
18+
19+
$result->finalize();
20+
$db->close();
21+
22+
echo "Done\n";
23+
24+
?>
25+
--EXPECT--
26+
string(8) "whatever"
27+
bool(false)
28+
Done

0 commit comments

Comments
 (0)