summaryrefslogtreecommitdiff
path: root/ext/sqlite3/sqlite3.c
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2018-11-29 13:19:26 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2018-11-29 13:19:26 +0100
commit525d3ae858ec33a1e9fe72c339d053e65d252430 (patch)
tree6d66960be039949e3c7a6470c3beef34c56b17fd /ext/sqlite3/sqlite3.c
parent0d3799dedcdc8828190b4c63793b9f3cbf724dbb (diff)
downloadphp-git-525d3ae858ec33a1e9fe72c339d053e65d252430.tar.gz
Handle potential sqlite3_bind_*() call failures
Since bug 77051 has been fixed, it is unlikely that any of the `sqlite3_bind_*` calls will ever fail, but we add respective checks nonetheless, and call `php_sqlite3_error()` in case of bind failures.
Diffstat (limited to 'ext/sqlite3/sqlite3.c')
-rw-r--r--ext/sqlite3/sqlite3.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index 7c4987a03c..7f76e55684 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -1575,7 +1575,10 @@ PHP_METHOD(sqlite3stmt, execute)
/* If the ZVAL is null then it should be bound as that */
if (Z_TYPE_P(parameter) == IS_NULL) {
- sqlite3_bind_null(stmt_obj->stmt, param->param_number);
+ return_code = sqlite3_bind_null(stmt_obj->stmt, param->param_number);
+ if (return_code != SQLITE_OK) {
+ php_sqlite3_error(stmt_obj->db_obj, "Unable to bind parameter number " ZEND_LONG_FMT " (%d)", param->param_number, return_code);
+ }
continue;
}
@@ -1583,15 +1586,21 @@ PHP_METHOD(sqlite3stmt, execute)
case SQLITE_INTEGER:
convert_to_long(parameter);
#if ZEND_LONG_MAX > 2147483647
- sqlite3_bind_int64(stmt_obj->stmt, param->param_number, Z_LVAL_P(parameter));
+ return_code = sqlite3_bind_int64(stmt_obj->stmt, param->param_number, Z_LVAL_P(parameter));
#else
- sqlite3_bind_int(stmt_obj->stmt, param->param_number, Z_LVAL_P(parameter));
+ return_code = sqlite3_bind_int(stmt_obj->stmt, param->param_number, Z_LVAL_P(parameter));
#endif
+ if (return_code != SQLITE_OK) {
+ php_sqlite3_error(stmt_obj->db_obj, "Unable to bind parameter number " ZEND_LONG_FMT " (%d)", param->param_number, return_code);
+ }
break;
case SQLITE_FLOAT:
convert_to_double(parameter);
- sqlite3_bind_double(stmt_obj->stmt, param->param_number, Z_DVAL_P(parameter));
+ return_code = sqlite3_bind_double(stmt_obj->stmt, param->param_number, Z_DVAL_P(parameter));
+ if (return_code != SQLITE_OK) {
+ php_sqlite3_error(stmt_obj->db_obj, "Unable to bind parameter number " ZEND_LONG_FMT " (%d)", param->param_number, return_code);
+ }
break;
case SQLITE_BLOB:
@@ -1610,21 +1619,33 @@ PHP_METHOD(sqlite3stmt, execute)
}
if (buffer) {
- sqlite3_bind_blob(stmt_obj->stmt, param->param_number, ZSTR_VAL(buffer), ZSTR_LEN(buffer), SQLITE_TRANSIENT);
+ return_code = sqlite3_bind_blob(stmt_obj->stmt, param->param_number, ZSTR_VAL(buffer), ZSTR_LEN(buffer), SQLITE_TRANSIENT);
zend_string_release_ex(buffer, 0);
+ if (return_code != SQLITE_OK) {
+ php_sqlite3_error(stmt_obj->db_obj, "Unable to bind parameter number " ZEND_LONG_FMT " (%d)", param->param_number, return_code);
+ }
} else {
- sqlite3_bind_null(stmt_obj->stmt, param->param_number);
+ return_code = sqlite3_bind_null(stmt_obj->stmt, param->param_number);
+ if (return_code != SQLITE_OK) {
+ php_sqlite3_error(stmt_obj->db_obj, "Unable to bind parameter number " ZEND_LONG_FMT " (%d)", param->param_number, return_code);
+ }
}
break;
}
case SQLITE3_TEXT:
convert_to_string(parameter);
- sqlite3_bind_text(stmt_obj->stmt, param->param_number, Z_STRVAL_P(parameter), Z_STRLEN_P(parameter), SQLITE_STATIC);
+ return_code = sqlite3_bind_text(stmt_obj->stmt, param->param_number, Z_STRVAL_P(parameter), Z_STRLEN_P(parameter), SQLITE_STATIC);
+ if (return_code != SQLITE_OK) {
+ php_sqlite3_error(stmt_obj->db_obj, "Unable to bind parameter number " ZEND_LONG_FMT " (%d)", param->param_number, return_code);
+ }
break;
case SQLITE_NULL:
- sqlite3_bind_null(stmt_obj->stmt, param->param_number);
+ return_code = sqlite3_bind_null(stmt_obj->stmt, param->param_number);
+ if (return_code != SQLITE_OK) {
+ php_sqlite3_error(stmt_obj->db_obj, "Unable to bind parameter number " ZEND_LONG_FMT " (%d)", param->param_number, return_code);
+ }
break;
default: