Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ PHP NEWS

- Sqlite3:
. Fix NUL byte truncation in sqlite3 TEXT column handling. (ndossche)
. Fixed bug GH-22051 (Inconsistent error reporting in SQLite3Result::reset()
and SQLite3Result::finalize()). (iliaal)

- Standard:
. Fixed bug GH-19926 (reset internal pointer earlier while splicing array
Expand Down
5 changes: 4 additions & 1 deletion ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,7 @@ PHP_METHOD(SQLite3Result, reset)
sqlite3result_clear_column_names_cache(result_obj);

if (sqlite3_reset(result_obj->stmt_obj->stmt) != SQLITE_OK) {
php_sqlite3_error(result_obj->db_obj, sqlite3_errcode(sqlite3_db_handle(result_obj->stmt_obj->stmt)), "Unable to reset statement: %s", sqlite3_errmsg(sqlite3_db_handle(result_obj->stmt_obj->stmt)));
RETURN_FALSE;
}

Expand All @@ -2150,7 +2151,9 @@ PHP_METHOD(SQLite3Result, finalize)
zend_llist_del_element(&(result_obj->db_obj->free_list), result_obj->stmt_obj,
(int (*)(void *, void *)) php_sqlite3_compare_stmt_free);
} else {
sqlite3_reset(result_obj->stmt_obj->stmt);
if (sqlite3_reset(result_obj->stmt_obj->stmt) != SQLITE_OK) {
php_sqlite3_error(result_obj->db_obj, sqlite3_errcode(sqlite3_db_handle(result_obj->stmt_obj->stmt)), "Unable to reset statement: %s", sqlite3_errmsg(sqlite3_db_handle(result_obj->stmt_obj->stmt)));
}
}

RETURN_TRUE;
Expand Down
43 changes: 43 additions & 0 deletions ext/sqlite3/tests/gh22051.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--TEST--
GH-22051 (SQLite3Result::reset()/finalize() report the error on failure)
--EXTENSIONS--
sqlite3
--FILE--
<?php
$db = new SQLite3(':memory:');

// A query whose second step overflows leaves the statement in an error state.
$sql = "SELECT abs(x) FROM (SELECT 1 AS x UNION ALL SELECT -9223372036854775807 - 1)";

echo "--- SQLite3Result::reset() ---\n";
$result = $db->query($sql);
var_dump($result->fetchArray(SQLITE3_NUM));
var_dump(@$result->fetchArray(SQLITE3_NUM));
var_dump($result->reset());

echo "--- SQLite3Result::finalize() ---\n";
$stmt = $db->prepare($sql);
$result = $stmt->execute();
var_dump($result->fetchArray(SQLITE3_NUM));
var_dump(@$result->fetchArray(SQLITE3_NUM));
var_dump($result->finalize());
?>
--EXPECTF--
--- SQLite3Result::reset() ---
array(1) {
[0]=>
int(1)
}
bool(false)

Warning: SQLite3Result::reset(): Unable to reset statement: integer overflow in %s on line %d
bool(false)
--- SQLite3Result::finalize() ---
array(1) {
[0]=>
int(1)
}
bool(false)

Warning: SQLite3Result::finalize(): Unable to reset statement: integer overflow in %s on line %d
bool(true)
Loading