]> granicus.if.org Git - php/commitdiff
Assert that stmt is set in PDORow
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 15 Mar 2021 13:22:49 +0000 (14:22 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 15 Mar 2021 13:22:49 +0000 (14:22 +0100)
ext/pdo/pdo_stmt.c

index d630c31aef8296d0fcc34e3d679296a2a50a942c..dbd2666226b1022b7034baa7546bcf69681b7fc9 100644 (file)
@@ -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);
        }