From eb3370ceec169988a2cf286ad3f10aac35f30b9d Mon Sep 17 00:00:00 2001 From: hanshenrik Date: Mon, 12 May 2025 15:57:43 +0200 Subject: [PATCH 1/4] returning NULL with no explanation is not cool --- ext/pdo_sqlite/sqlite_driver.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ext/pdo_sqlite/sqlite_driver.c b/ext/pdo_sqlite/sqlite_driver.c index ddf25d4965f06..231f8d09428a1 100644 --- a/ext/pdo_sqlite/sqlite_driver.c +++ b/ext/pdo_sqlite/sqlite_driver.c @@ -227,7 +227,17 @@ static zend_string *pdo_sqlite_last_insert_id(pdo_dbh_t *dbh, const zend_string static zend_string* sqlite_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquoted, enum pdo_param_type paramtype) { char *quoted; - if (ZSTR_LEN(unquoted) > (INT_MAX - 3) / 2) { + + if (UNEXPECTED(ZSTR_LEN(unquoted) > (INT_MAX - 3) / 2)) { + if (dbh->error_mode == PDO_ERRMODE_EXCEPTION) { + zend_throw_exception_ex( + php_pdo_get_exception(), 0, + "SQLite PDO::quote: string is too long to quote"); + } else if (dbh->error_mode == PDO_ERRMODE_WARNING) { + php_error_docref( + NULL, E_WARNING, + "SQLite PDO::quote: string is too long to quote"); + } return NULL; } From 183911cd4d145ca223a9068c7d64caa00445841c Mon Sep 17 00:00:00 2001 From: hanshenrik Date: Mon, 12 May 2025 17:04:13 +0200 Subject: [PATCH 2/4] update test --- ext/pdo_sqlite/tests/bug81740.phpt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ext/pdo_sqlite/tests/bug81740.phpt b/ext/pdo_sqlite/tests/bug81740.phpt index 2b8b9447f0fed..231faac9a64b7 100644 --- a/ext/pdo_sqlite/tests/bug81740.phpt +++ b/ext/pdo_sqlite/tests/bug81740.phpt @@ -16,5 +16,9 @@ $pdo = new PDO("sqlite::memory:"); $string = str_repeat("a", 0x80000000); var_dump($pdo->quote($string)); ?> ---EXPECT-- -bool(false) +--EXPECTF-- +Fatal error: Uncaught PDOException: SQLite PDO::quote: string is too long to quote in %s:%d +Stack trace: +#0 %s(%d): PDO->quote('aaaaaaaaaaaaaaa...') +#1 {main} + thrown in %s on line %d From d742ce265fb57b47c44c1443cde36a7f8a2d56a8 Mon Sep 17 00:00:00 2001 From: hanshenrik Date: Mon, 12 May 2025 17:06:05 +0200 Subject: [PATCH 3/4] update test --- ext/pdo_sqlite/tests/bug81740.phpt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ext/pdo_sqlite/tests/bug81740.phpt b/ext/pdo_sqlite/tests/bug81740.phpt index 231faac9a64b7..ab01c81b3325c 100644 --- a/ext/pdo_sqlite/tests/bug81740.phpt +++ b/ext/pdo_sqlite/tests/bug81740.phpt @@ -14,9 +14,17 @@ memory_limit=-1 quote($string)); +try{ + var_dump($pdo->quote($string)); +} finally { + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); + var_dump($pdo->quote($string)); +} ?> --EXPECTF-- +Warning: PDO::quote(): SQLite PDO::quote: string is too long to quote in %s on line %d +bool(false) + Fatal error: Uncaught PDOException: SQLite PDO::quote: string is too long to quote in %s:%d Stack trace: #0 %s(%d): PDO->quote('aaaaaaaaaaaaaaa...') From bff6e293d407ab48deffd6524fa2c89833f85b1f Mon Sep 17 00:00:00 2001 From: hanshenrik Date: Mon, 12 May 2025 17:08:29 +0200 Subject: [PATCH 4/4] update error message --- ext/pdo_sqlite/sqlite_driver.c | 2 +- ext/pdo_sqlite/tests/bug81740.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/pdo_sqlite/sqlite_driver.c b/ext/pdo_sqlite/sqlite_driver.c index 231f8d09428a1..224bd3ab09de4 100644 --- a/ext/pdo_sqlite/sqlite_driver.c +++ b/ext/pdo_sqlite/sqlite_driver.c @@ -236,7 +236,7 @@ static zend_string* sqlite_handle_quoter(pdo_dbh_t *dbh, const zend_string *unqu } else if (dbh->error_mode == PDO_ERRMODE_WARNING) { php_error_docref( NULL, E_WARNING, - "SQLite PDO::quote: string is too long to quote"); + "string is too long to quote"); } return NULL; } diff --git a/ext/pdo_sqlite/tests/bug81740.phpt b/ext/pdo_sqlite/tests/bug81740.phpt index ab01c81b3325c..4bf97b1203740 100644 --- a/ext/pdo_sqlite/tests/bug81740.phpt +++ b/ext/pdo_sqlite/tests/bug81740.phpt @@ -22,7 +22,7 @@ try{ } ?> --EXPECTF-- -Warning: PDO::quote(): SQLite PDO::quote: string is too long to quote in %s on line %d +Warning: PDO::quote(): string is too long to quote in %s on line %d bool(false) Fatal error: Uncaught PDOException: SQLite PDO::quote: string is too long to quote in %s:%d