summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--ext/sqlite3/sqlite3.c16
-rw-r--r--ext/sqlite3/tests/bug66550.phpt23
3 files changed, 42 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 6de9b29564..2bc4f7c9cd 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,9 @@ PHP NEWS
. Fixed bug #69281 (opcache_is_script_cached no longer works). (danack)
. Fixed bug #68677 (Use After Free). (CVE-2015-1351) (Laruence)
+- Sqlite3:
+ . Fixed bug #66550 (SQLite prepared statement use-after-free). (Sean Heelan)
+
?? ??? 2015, PHP 5.5.24
- Core:
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index 8178d4f3b2..ce3af65fcb 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -1279,6 +1279,8 @@ PHP_METHOD(sqlite3stmt, paramCount)
php_sqlite3_stmt *stmt_obj;
zval *object = getThis();
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
+
+ SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
if (zend_parse_parameters_none() == FAILURE) {
return;
@@ -1295,6 +1297,8 @@ PHP_METHOD(sqlite3stmt, close)
php_sqlite3_stmt *stmt_obj;
zval *object = getThis();
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
+
+ SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
if (zend_parse_parameters_none() == FAILURE) {
return;
@@ -1313,6 +1317,8 @@ PHP_METHOD(sqlite3stmt, reset)
php_sqlite3_stmt *stmt_obj;
zval *object = getThis();
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
+
+ SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
if (zend_parse_parameters_none() == FAILURE) {
return;
@@ -1333,6 +1339,8 @@ PHP_METHOD(sqlite3stmt, clear)
php_sqlite3_stmt *stmt_obj;
zval *object = getThis();
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
+
+ SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
if (zend_parse_parameters_none() == FAILURE) {
return;
@@ -1354,6 +1362,8 @@ PHP_METHOD(sqlite3stmt, readOnly)
php_sqlite3_stmt *stmt_obj;
zval *object = getThis();
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
+
+ SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
if (zend_parse_parameters_none() == FAILURE) {
return;
@@ -1421,6 +1431,8 @@ PHP_METHOD(sqlite3stmt, bindParam)
zval *object = getThis();
struct php_sqlite3_bound_param param = {0};
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
+
+ SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
param.param_number = -1;
param.type = SQLITE3_TEXT;
@@ -1452,6 +1464,8 @@ PHP_METHOD(sqlite3stmt, bindValue)
zval *object = getThis();
struct php_sqlite3_bound_param param = {0};
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
+
+ SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
param.param_number = -1;
param.type = SQLITE3_TEXT;
@@ -1487,6 +1501,8 @@ PHP_METHOD(sqlite3stmt, execute)
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
+ SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
diff --git a/ext/sqlite3/tests/bug66550.phpt b/ext/sqlite3/tests/bug66550.phpt
new file mode 100644
index 0000000000..a44515b0d9
--- /dev/null
+++ b/ext/sqlite3/tests/bug66550.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Bug #66550 (SQLite prepared statement use-after-free)
+--SKIPIF--
+<?php
+if (!extension_loaded('sqlite3')) die('skip');
+?>
+--FILE--
+<?php
+
+$db = new SQLite3(':memory:');
+
+$db->exec('CREATE TABLE foo (id INTEGER, bar STRING)');
+
+$stmt = $db->prepare('SELECT bar FROM foo WHERE id=:id');
+// Close the database connection and free the internal sqlite3_stmt object
+$db->close();
+// Access the sqlite3_stmt object via the php_sqlite3_stmt container
+$stmt->reset();
+?>
+==DONE==
+--EXPECTF--
+Warning: SQLite3Stmt::reset(): The SQLite3 object has not been correctly initialised in %s
+==DONE==