From 876d92b91ed62742eae8d85db0b2e35db8c29636 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Fri, 11 Sep 2020 18:12:59 +0200 Subject: [PATCH 1/3] Fix SKIPIF section for SQLite3 test Test is borked if the posix_geteui() function is unavailable. --- ext/sqlite3/tests/sqlite3_15_open_error.phpt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/sqlite3/tests/sqlite3_15_open_error.phpt b/ext/sqlite3/tests/sqlite3_15_open_error.phpt index 0c3e9537db2da..817affa78461a 100644 --- a/ext/sqlite3/tests/sqlite3_15_open_error.phpt +++ b/ext/sqlite3/tests/sqlite3_15_open_error.phpt @@ -6,6 +6,9 @@ if(substr(PHP_OS, 0, 3) == 'WIN' ) { die('skip non windows test'); } require_once(__DIR__ . '/skipif.inc'); +if (!function_exists('posix_geteui')) { + die('SKIP posix_geteuid() not defined so cannot check if run as root'); +} if (posix_geteuid() == 0) { die('SKIP Cannot run test as root.'); } From 0fd9afc125f7d0fd9551c42eaf2c1225e22620be Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Fri, 11 Sep 2020 18:10:38 +0200 Subject: [PATCH 2/3] Use Error for uninitialized SQLite object --- ext/sqlite3/sqlite3.c | 8 ++++---- ext/sqlite3/tests/bug66550.phpt | 10 +++++++--- .../tests/sqlite3_12_unfinalized_stmt_cleanup.phpt | 10 ++++++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index b06f723b4caf6..bf201015dc15f 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -63,14 +63,14 @@ static void php_sqlite3_error(php_sqlite3_db_object *db_obj, char *format, ...) #define SQLITE3_CHECK_INITIALIZED(db_obj, member, class_name) \ if (!(db_obj) || !(member)) { \ - php_sqlite3_error(db_obj, "The " #class_name " object has not been correctly initialised"); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised"); \ + RETURN_THROWS(); \ } #define SQLITE3_CHECK_INITIALIZED_STMT(member, class_name) \ if (!(member)) { \ - php_error_docref(NULL, E_WARNING, "The " #class_name " object has not been correctly initialised"); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised"); \ + RETURN_THROWS(); \ } /* {{{ PHP_INI */ diff --git a/ext/sqlite3/tests/bug66550.phpt b/ext/sqlite3/tests/bug66550.phpt index de7aae1493943..a380b84db07f8 100644 --- a/ext/sqlite3/tests/bug66550.phpt +++ b/ext/sqlite3/tests/bug66550.phpt @@ -15,7 +15,11 @@ $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(); +try { + $stmt->reset(); +} catch (\Error $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> ---EXPECTF-- -Warning: SQLite3Stmt::reset(): The SQLite3 object has not been correctly initialised in %s +--EXPECT-- +The SQLite3 object has not been correctly initialised diff --git a/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt b/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt index e3e67f1ff453d..4f10a2b7c4f01 100644 --- a/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt +++ b/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt @@ -27,7 +27,11 @@ while ($result = $results->fetchArray(SQLITE3_NUM)) echo "Closing database\n"; var_dump($db->close()); echo "Check db was closed\n"; -var_dump($results->numColumns()); +try { + var_dump($results->numColumns()); +} catch (\Error $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> --EXPECTF-- @@ -46,7 +50,5 @@ array(2) { Closing database bool(true) Check db was closed - -Warning: SQLite3Result::numColumns(): The SQLite3Result object has not been correctly initialised in %s on line %d -bool(false) +The SQLite3Result object has not been correctly initialised Done From 1d7b0f391986b410abce3a8a9c7dcdbafcf99b1a Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sat, 12 Sep 2020 04:13:20 +0200 Subject: [PATCH 3/3] Amend uninitialized error text --- ext/sqlite3/sqlite3.c | 4 ++-- ext/sqlite3/tests/bug66550.phpt | 2 +- ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index bf201015dc15f..464df5ae21aa5 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -63,13 +63,13 @@ static void php_sqlite3_error(php_sqlite3_db_object *db_obj, char *format, ...) #define SQLITE3_CHECK_INITIALIZED(db_obj, member, class_name) \ if (!(db_obj) || !(member)) { \ - zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised"); \ + zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised or is already closed"); \ RETURN_THROWS(); \ } #define SQLITE3_CHECK_INITIALIZED_STMT(member, class_name) \ if (!(member)) { \ - zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised"); \ + zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised or is already closed"); \ RETURN_THROWS(); \ } diff --git a/ext/sqlite3/tests/bug66550.phpt b/ext/sqlite3/tests/bug66550.phpt index a380b84db07f8..244f358a5f094 100644 --- a/ext/sqlite3/tests/bug66550.phpt +++ b/ext/sqlite3/tests/bug66550.phpt @@ -22,4 +22,4 @@ try { } ?> --EXPECT-- -The SQLite3 object has not been correctly initialised +The SQLite3 object has not been correctly initialised or is already closed diff --git a/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt b/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt index 4f10a2b7c4f01..34af57128ab56 100644 --- a/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt +++ b/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt @@ -50,5 +50,5 @@ array(2) { Closing database bool(true) Check db was closed -The SQLite3Result object has not been correctly initialised +The SQLite3Result object has not been correctly initialised or is already closed Done