Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a81733

Browse files
committed
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: Fix bug #66550 (SQLite prepared statement use-after-free)
2 parents c167029 + 66b853d commit 2a81733

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ PHP NEWS
66
. Fixed bug #69354 (Incorrect use of SQLColAttributes with ODBC 3.0).
77
(Anatol)
88

9+
- Sqlite3:
10+
. Fixed bug #66550 (SQLite prepared statement use-after-free). (Sean Heelan)
11+
912
16 Apr 2015, PHP 5.6.8
1013

1114
- Core:

ext/sqlite3/sqlite3.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,8 @@ PHP_METHOD(sqlite3stmt, paramCount)
12871287
php_sqlite3_stmt *stmt_obj;
12881288
zval *object = getThis();
12891289
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
1290+
1291+
SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
12901292

12911293
if (zend_parse_parameters_none() == FAILURE) {
12921294
return;
@@ -1305,6 +1307,8 @@ PHP_METHOD(sqlite3stmt, close)
13051307
php_sqlite3_stmt *stmt_obj;
13061308
zval *object = getThis();
13071309
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
1310+
1311+
SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
13081312

13091313
if (zend_parse_parameters_none() == FAILURE) {
13101314
return;
@@ -1325,6 +1329,8 @@ PHP_METHOD(sqlite3stmt, reset)
13251329
php_sqlite3_stmt *stmt_obj;
13261330
zval *object = getThis();
13271331
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
1332+
1333+
SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
13281334

13291335
if (zend_parse_parameters_none() == FAILURE) {
13301336
return;
@@ -1347,6 +1353,8 @@ PHP_METHOD(sqlite3stmt, clear)
13471353
php_sqlite3_stmt *stmt_obj;
13481354
zval *object = getThis();
13491355
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
1356+
1357+
SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
13501358

13511359
if (zend_parse_parameters_none() == FAILURE) {
13521360
return;
@@ -1370,6 +1378,8 @@ PHP_METHOD(sqlite3stmt, readOnly)
13701378
php_sqlite3_stmt *stmt_obj;
13711379
zval *object = getThis();
13721380
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
1381+
1382+
SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
13731383

13741384
if (zend_parse_parameters_none() == FAILURE) {
13751385
return;
@@ -1439,6 +1449,8 @@ PHP_METHOD(sqlite3stmt, bindParam)
14391449
zval *object = getThis();
14401450
struct php_sqlite3_bound_param param = {0};
14411451
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
1452+
1453+
SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
14421454

14431455
param.param_number = -1;
14441456
param.type = SQLITE3_TEXT;
@@ -1472,6 +1484,8 @@ PHP_METHOD(sqlite3stmt, bindValue)
14721484
zval *object = getThis();
14731485
struct php_sqlite3_bound_param param = {0};
14741486
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
1487+
1488+
SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
14751489

14761490
param.param_number = -1;
14771491
param.type = SQLITE3_TEXT;
@@ -1509,6 +1523,8 @@ PHP_METHOD(sqlite3stmt, execute)
15091523

15101524
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
15111525

1526+
SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
1527+
15121528
if (zend_parse_parameters_none() == FAILURE) {
15131529
return;
15141530
}

ext/sqlite3/tests/bug66550.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Bug #66550 (SQLite prepared statement use-after-free)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('sqlite3')) die('skip');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
$db = new SQLite3(':memory:');
11+
12+
$db->exec('CREATE TABLE foo (id INTEGER, bar STRING)');
13+
14+
$stmt = $db->prepare('SELECT bar FROM foo WHERE id=:id');
15+
// Close the database connection and free the internal sqlite3_stmt object
16+
$db->close();
17+
// Access the sqlite3_stmt object via the php_sqlite3_stmt container
18+
$stmt->reset();
19+
?>
20+
==DONE==
21+
--EXPECTF--
22+
Warning: SQLite3Stmt::reset(): The SQLite3 object has not been correctly initialised in %s
23+
==DONE==

0 commit comments

Comments
 (0)