Skip to content

Commit eb57029

Browse files
committed
Fix #73530: Unsetting result set may reset other result set
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.
1 parent ecba563 commit eb57029

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ PHP NEWS
1111
. Fixed bug #72776 (Invalid parameter in memcpy function trough
1212
openssl_pbkdf2). (Jakub Zelenka)
1313

14+
- SQLite3:
15+
. Fixed bug #73530 (Unsetting result set may reset other result set). (cmb)
16+
1417
10 Nov 2016, PHP 5.6.28
1518

1619
- Core:

ext/sqlite3/sqlite3.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,10 +2184,6 @@ static void php_sqlite3_result_object_free_storage(void *object TSRMLS_DC) /* {{
21842184
}
21852185

21862186
if (intern->stmt_obj_zval) {
2187-
if (intern->stmt_obj->initialised) {
2188-
sqlite3_reset(intern->stmt_obj->stmt);
2189-
}
2190-
21912187
if (intern->is_prepared_statement == 0) {
21922188
zval_dtor(intern->stmt_obj_zval);
21932189
FREE_ZVAL(intern->stmt_obj_zval);

ext/sqlite3/tests/bug73530.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Bug #73530 (Unsetting result set may reset other result set)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('sqlite3')) die('skip sqlite3 extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$db = new SQLite3(':memory:');
10+
$db->exec("CREATE TABLE foo (num int)");
11+
$db->exec("INSERT INTO foo VALUES (0)");
12+
$db->exec("INSERT INTO foo VALUES (1)");
13+
$stmt = $db->prepare("SELECT * FROM foo WHERE NUM = ?");
14+
$stmt->bindValue(1, 0, SQLITE3_INTEGER);
15+
$res1 = $stmt->execute();
16+
$res1->finalize();
17+
$stmt->clear();
18+
$stmt->reset();
19+
$stmt->bindValue(1, 1, SQLITE3_INTEGER);
20+
$res2 = $stmt->execute();
21+
while ($row = $res2->fetchArray(SQLITE3_ASSOC)) {
22+
var_dump($row);
23+
unset($res1);
24+
}
25+
?>
26+
===DONE===
27+
--EXPECT--
28+
array(1) {
29+
["num"]=>
30+
int(1)
31+
}
32+
===DONE===

0 commit comments

Comments
 (0)