]> granicus.if.org Git - php/commitdiff
Fix #73530: Unsetting result set may reset other result set
authorChristoph M. Becker <cmbecker69@gmx.de>
Wed, 16 Nov 2016 10:49:04 +0000 (11:49 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Wed, 16 Nov 2016 10:49:04 +0000 (11:49 +0100)
Calling sqlite3_reset() when a result set object is freed can cause
undesired and maybe even hard to track interference with other result
sets. Furthermore, there is no need to call sqlite3_reset(), because
that is implicitly called on SQLite3Stmt::execute(), and users are
encouraged to explicitly call either SQLite3Result::finalize() or
SQLite3Stmt::reset() anyway.

NEWS
ext/sqlite3/sqlite3.c
ext/sqlite3/tests/bug73530.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 9a2f915c1f901fd24dce2f07914a623512f52a84..33a9ae1ba08a91432c581a0944d55aa34608eac8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,9 @@ PHP                                                                        NEWS
   . Fixed bug #72776 (Invalid parameter in memcpy function trough
     openssl_pbkdf2). (Jakub Zelenka)
 
+- SQLite3:
+  . Fixed bug #73530 (Unsetting result set may reset other result set). (cmb)
+
 10 Nov 2016, PHP 5.6.28
 
 - Core:
index 80d6b897f1bc7c6664591ef3b620afedad7730c0..b443657e3cbd0a11b3dd76b19692ac7a099416fa 100644 (file)
@@ -2184,10 +2184,6 @@ static void php_sqlite3_result_object_free_storage(void *object TSRMLS_DC) /* {{
        }
 
        if (intern->stmt_obj_zval) {
-               if (intern->stmt_obj->initialised) {
-                       sqlite3_reset(intern->stmt_obj->stmt);
-               }
-
                if (intern->is_prepared_statement == 0) {
                        zval_dtor(intern->stmt_obj_zval);
                        FREE_ZVAL(intern->stmt_obj_zval);
diff --git a/ext/sqlite3/tests/bug73530.phpt b/ext/sqlite3/tests/bug73530.phpt
new file mode 100644 (file)
index 0000000..7e17dfe
--- /dev/null
@@ -0,0 +1,32 @@
+--TEST--\r
+Bug #73530 (Unsetting result set may reset other result set)\r
+--SKIPIF--\r
+<?php\r
+if (!extension_loaded('sqlite3')) die('skip sqlite3 extension not available');\r
+?>\r
+--FILE--\r
+<?php\r
+$db = new SQLite3(':memory:');\r
+$db->exec("CREATE TABLE foo (num int)");\r
+$db->exec("INSERT INTO foo VALUES (0)");\r
+$db->exec("INSERT INTO foo VALUES (1)");\r
+$stmt = $db->prepare("SELECT * FROM foo WHERE NUM = ?");\r
+$stmt->bindValue(1, 0, SQLITE3_INTEGER);\r
+$res1 = $stmt->execute();\r
+$res1->finalize();\r
+$stmt->clear();\r
+$stmt->reset();\r
+$stmt->bindValue(1, 1, SQLITE3_INTEGER);\r
+$res2 = $stmt->execute();\r
+while ($row = $res2->fetchArray(SQLITE3_ASSOC)) {\r
+    var_dump($row);\r
+    unset($res1);\r
+}\r
+?>\r
+===DONE===\r
+--EXPECT--\r
+array(1) {\r
+  ["num"]=>\r
+  int(1)\r
+}\r
+===DONE===\r