|
28 | 28 | #include "zend_exceptions.h" |
29 | 29 | #include "sqlite_driver_arginfo.h" |
30 | 30 |
|
31 | | - |
32 | 31 | int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line) /* {{{ */ |
33 | 32 | { |
34 | 33 | pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data; |
@@ -74,6 +73,7 @@ int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int li |
74 | 73 | strncpy(*pdo_err, "HY000", sizeof(*pdo_err)); |
75 | 74 | break; |
76 | 75 | } |
| 76 | + |
77 | 77 | if (!dbh->methods) { |
78 | 78 | pdo_throw_exception(einfo->errcode, einfo->errmsg, pdo_err); |
79 | 79 | } |
@@ -226,15 +226,19 @@ static zend_string* sqlite_handle_quoter(pdo_dbh_t *dbh, const zend_string *unqu |
226 | 226 | if (ZSTR_LEN(unquoted) > (INT_MAX - 3) / 2) { |
227 | 227 | return NULL; |
228 | 228 | } |
229 | | - if(memchr(ZSTR_VAL(unquoted), '\0', ZSTR_LEN(unquoted)) != NULL) { |
230 | | - if (dbh->error_mode == PDO_ERRMODE_EXCEPTION) { |
231 | | - zend_throw_exception_ex(php_pdo_get_exception(), 0, |
232 | | - "SQLite PDO::quote does not support NULL bytes"); |
233 | | - } else if (dbh->error_mode == PDO_ERRMODE_WARNING) { |
234 | | - php_error_docref(NULL, E_WARNING, "SQLite PDO::quote does not support NULL bytes"); |
235 | | - } |
236 | | - return NULL; |
| 229 | + |
| 230 | + if (UNEXPECTED(zend_str_has_nul_byte(unquoted))) { |
| 231 | + if (dbh->error_mode == PDO_ERRMODE_EXCEPTION) { |
| 232 | + zend_throw_exception_ex( |
| 233 | + php_pdo_get_exception(), 0, |
| 234 | + "SQLite PDO::quote does not support null bytes"); |
| 235 | + } else if (dbh->error_mode == PDO_ERRMODE_WARNING) { |
| 236 | + php_error_docref(NULL, E_WARNING, |
| 237 | + "SQLite PDO::quote does not support null bytes"); |
| 238 | + } |
| 239 | + return NULL; |
237 | 240 | } |
| 241 | + |
238 | 242 | quoted = safe_emalloc(2, ZSTR_LEN(unquoted), 3); |
239 | 243 | /* TODO use %Q format? */ |
240 | 244 | sqlite3_snprintf(2*ZSTR_LEN(unquoted) + 3, quoted, "'%q'", ZSTR_VAL(unquoted)); |
@@ -750,7 +754,7 @@ static const struct pdo_dbh_methods sqlite_methods = { |
750 | 754 | pdo_sqlite_request_shutdown, |
751 | 755 | pdo_sqlite_in_transaction, |
752 | 756 | pdo_sqlite_get_gc, |
753 | | - pdo_sqlite_scanner |
| 757 | + pdo_sqlite_scanner |
754 | 758 | }; |
755 | 759 |
|
756 | 760 | static char *make_filename_safe(const char *filename) |
@@ -846,8 +850,6 @@ static int pdo_sqlite_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{ |
846 | 850 | if (driver_options) { |
847 | 851 | timeout = pdo_attr_lval(driver_options, PDO_ATTR_TIMEOUT, timeout); |
848 | 852 | } |
849 | | - |
850 | | - |
851 | 853 | sqlite3_busy_timeout(H->db, timeout * 1000); |
852 | 854 |
|
853 | 855 | dbh->alloc_own_columns = 1; |
|
0 commit comments