summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-03-15 14:22:49 +0100
committerNikita Popov <nikita.ppv@gmail.com>2021-03-15 14:22:49 +0100
commit7e3840df90db038de89f0a5041fac2f08497923d (patch)
tree7ca240cf9e02dcf1ac3d0ecf5e08fcef74be1840
parent7e2f1a80d6c369d88d89ed8b7d14fda7126cc44d (diff)
downloadphp-git-7e3840df90db038de89f0a5041fac2f08497923d.tar.gz
Assert that stmt is set in PDORow
-rw-r--r--ext/pdo/pdo_stmt.c153
1 files changed, 75 insertions, 78 deletions
diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c
index d630c31aef..dbd2666226 100644
--- a/ext/pdo/pdo_stmt.c
+++ b/ext/pdo/pdo_stmt.c
@@ -2259,26 +2259,25 @@ static zval *row_prop_read(zend_object *object, zend_string *name, int type, voi
pdo_stmt_t *stmt = row->stmt;
int colno = -1;
zend_long lval;
+ ZEND_ASSERT(stmt);
ZVAL_NULL(rv);
- if (stmt) {
- if (is_numeric_string(ZSTR_VAL(name), ZSTR_LEN(name), &lval, NULL, 0) == IS_LONG) {
- if (lval >= 0 && lval < stmt->column_count) {
- fetch_value(stmt, rv, lval, NULL);
- }
- } else {
- /* TODO: replace this with a hash of available column names to column
- * numbers */
- for (colno = 0; colno < stmt->column_count; colno++) {
- if (zend_string_equals(stmt->columns[colno].name, name)) {
- fetch_value(stmt, rv, colno, NULL);
- return rv;
- }
- }
- if (zend_string_equals_literal(name, "queryString")) {
- return zend_std_read_property(&stmt->std, name, type, cache_slot, rv);
+ if (is_numeric_string(ZSTR_VAL(name), ZSTR_LEN(name), &lval, NULL, 0) == IS_LONG) {
+ if (lval >= 0 && lval < stmt->column_count) {
+ fetch_value(stmt, rv, lval, NULL);
+ }
+ } else {
+ /* TODO: replace this with a hash of available column names to column
+ * numbers */
+ for (colno = 0; colno < stmt->column_count; colno++) {
+ if (zend_string_equals(stmt->columns[colno].name, name)) {
+ fetch_value(stmt, rv, colno, NULL);
+ return rv;
}
}
+ if (zend_string_equals_literal(name, "queryString")) {
+ return zend_std_read_property(&stmt->std, name, type, cache_slot, rv);
+ }
}
return rv;
@@ -2290,35 +2289,34 @@ static zval *row_dim_read(zend_object *object, zval *member, int type, zval *rv)
pdo_stmt_t *stmt = row->stmt;
int colno = -1;
zend_long lval;
+ ZEND_ASSERT(stmt);
ZVAL_NULL(rv);
- if (stmt) {
- if (Z_TYPE_P(member) == IS_LONG) {
- if (Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count) {
- fetch_value(stmt, rv, Z_LVAL_P(member), NULL);
- }
- } else if (Z_TYPE_P(member) == IS_STRING
- && is_numeric_string(Z_STRVAL_P(member), Z_STRLEN_P(member), &lval, NULL, 0) == IS_LONG) {
- if (lval >= 0 && lval < stmt->column_count) {
- fetch_value(stmt, rv, lval, NULL);
- }
- } else {
- if (!try_convert_to_string(member)) {
- return &EG(uninitialized_zval);
- }
+ if (Z_TYPE_P(member) == IS_LONG) {
+ if (Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count) {
+ fetch_value(stmt, rv, Z_LVAL_P(member), NULL);
+ }
+ } else if (Z_TYPE_P(member) == IS_STRING
+ && is_numeric_string(Z_STRVAL_P(member), Z_STRLEN_P(member), &lval, NULL, 0) == IS_LONG) {
+ if (lval >= 0 && lval < stmt->column_count) {
+ fetch_value(stmt, rv, lval, NULL);
+ }
+ } else {
+ if (!try_convert_to_string(member)) {
+ return &EG(uninitialized_zval);
+ }
- /* TODO: replace this with a hash of available column names to column
- * numbers */
- for (colno = 0; colno < stmt->column_count; colno++) {
- if (zend_string_equals(stmt->columns[colno].name, Z_STR_P(member))) {
- fetch_value(stmt, rv, colno, NULL);
- return rv;
- }
- }
- if (zend_string_equals_literal(Z_STR_P(member), "queryString")) {
- return zend_std_read_property(&stmt->std, Z_STR_P(member), type, NULL, rv);
+ /* TODO: replace this with a hash of available column names to column
+ * numbers */
+ for (colno = 0; colno < stmt->column_count; colno++) {
+ if (zend_string_equals(stmt->columns[colno].name, Z_STR_P(member))) {
+ fetch_value(stmt, rv, colno, NULL);
+ return rv;
}
}
+ if (zend_string_equals_literal(Z_STR_P(member), "queryString")) {
+ return zend_std_read_property(&stmt->std, Z_STR_P(member), type, NULL, rv);
+ }
}
return rv;
@@ -2341,25 +2339,24 @@ static int row_prop_exists(zend_object *object, zend_string *name, int check_emp
pdo_stmt_t *stmt = row->stmt;
int colno = -1;
zend_long lval;
+ ZEND_ASSERT(stmt);
- if (stmt) {
- if (is_numeric_string(ZSTR_VAL(name), ZSTR_LEN(name), &lval, NULL, 0) == IS_LONG) {
- return lval >=0 && lval < stmt->column_count;
- }
+ if (is_numeric_string(ZSTR_VAL(name), ZSTR_LEN(name), &lval, NULL, 0) == IS_LONG) {
+ return lval >=0 && lval < stmt->column_count;
+ }
- /* TODO: replace this with a hash of available column names to column
- * numbers */
- for (colno = 0; colno < stmt->column_count; colno++) {
- if (zend_string_equals(stmt->columns[colno].name, name)) {
- int res;
- zval val;
+ /* TODO: replace this with a hash of available column names to column
+ * numbers */
+ for (colno = 0; colno < stmt->column_count; colno++) {
+ if (zend_string_equals(stmt->columns[colno].name, name)) {
+ int res;
+ zval val;
- fetch_value(stmt, &val, colno, NULL);
- res = check_empty ? i_zend_is_true(&val) : Z_TYPE(val) != IS_NULL;
- zval_ptr_dtor_nogc(&val);
+ fetch_value(stmt, &val, colno, NULL);
+ res = check_empty ? i_zend_is_true(&val) : Z_TYPE(val) != IS_NULL;
+ zval_ptr_dtor_nogc(&val);
- return res;
- }
+ return res;
}
}
@@ -2372,33 +2369,32 @@ static int row_dim_exists(zend_object *object, zval *member, int check_empty)
pdo_stmt_t *stmt = row->stmt;
int colno = -1;
zend_long lval;
+ ZEND_ASSERT(stmt);
- if (stmt) {
- if (Z_TYPE_P(member) == IS_LONG) {
- return Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count;
- } else if (Z_TYPE_P(member) == IS_STRING) {
- if (is_numeric_string(Z_STRVAL_P(member), Z_STRLEN_P(member), &lval, NULL, 0) == IS_LONG) {
- return lval >=0 && lval < stmt->column_count;
- }
- } else {
- if (!try_convert_to_string(member)) {
- return 0;
- }
+ if (Z_TYPE_P(member) == IS_LONG) {
+ return Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count;
+ } else if (Z_TYPE_P(member) == IS_STRING) {
+ if (is_numeric_string(Z_STRVAL_P(member), Z_STRLEN_P(member), &lval, NULL, 0) == IS_LONG) {
+ return lval >=0 && lval < stmt->column_count;
+ }
+ } else {
+ if (!try_convert_to_string(member)) {
+ return 0;
}
+ }
- /* TODO: replace this with a hash of available column names to column
- * numbers */
- for (colno = 0; colno < stmt->column_count; colno++) {
- if (zend_string_equals(stmt->columns[colno].name, Z_STR_P(member))) {
- int res;
- zval val;
+ /* TODO: replace this with a hash of available column names to column
+ * numbers */
+ for (colno = 0; colno < stmt->column_count; colno++) {
+ if (zend_string_equals(stmt->columns[colno].name, Z_STR_P(member))) {
+ int res;
+ zval val;
- fetch_value(stmt, &val, colno, NULL);
- res = check_empty ? i_zend_is_true(&val) : Z_TYPE(val) != IS_NULL;
- zval_ptr_dtor_nogc(&val);
+ fetch_value(stmt, &val, colno, NULL);
+ res = check_empty ? i_zend_is_true(&val) : Z_TYPE(val) != IS_NULL;
+ zval_ptr_dtor_nogc(&val);
- return res;
- }
+ return res;
}
}
@@ -2421,8 +2417,9 @@ static HashTable *row_get_properties_for(zend_object *object, zend_prop_purpose
pdo_stmt_t *stmt = row->stmt;
HashTable *props;
int i;
+ ZEND_ASSERT(stmt);
- if (purpose != ZEND_PROP_PURPOSE_DEBUG || stmt == NULL) {
+ if (purpose != ZEND_PROP_PURPOSE_DEBUG) {
return zend_std_get_properties_for(object, purpose);
}