diff --git a/ext/pdo_sqlite/sqlite_driver.c b/ext/pdo_sqlite/sqlite_driver.c index ddf25d4965f06..224bd3ab09de4 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, + "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 2b8b9447f0fed..4bf97b1203740 100644 --- a/ext/pdo_sqlite/tests/bug81740.phpt +++ b/ext/pdo_sqlite/tests/bug81740.phpt @@ -14,7 +14,19 @@ 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)); +} ?> ---EXPECT-- +--EXPECTF-- +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 +Stack trace: +#0 %s(%d): PDO->quote('aaaaaaaaaaaaaaa...') +#1 {main} + thrown in %s on line %d