Skip to content

Commit 7e3840d

Browse files
committed
Assert that stmt is set in PDORow
1 parent 7e2f1a8 commit 7e3840d

File tree

1 file changed

+75
-78
lines changed

1 file changed

+75
-78
lines changed

ext/pdo/pdo_stmt.c

Lines changed: 75 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,26 +2259,25 @@ static zval *row_prop_read(zend_object *object, zend_string *name, int type, voi
22592259
pdo_stmt_t *stmt = row->stmt;
22602260
int colno = -1;
22612261
zend_long lval;
2262+
ZEND_ASSERT(stmt);
22622263

22632264
ZVAL_NULL(rv);
2264-
if (stmt) {
2265-
if (is_numeric_string(ZSTR_VAL(name), ZSTR_LEN(name), &lval, NULL, 0) == IS_LONG) {
2266-
if (lval >= 0 && lval < stmt->column_count) {
2267-
fetch_value(stmt, rv, lval, NULL);
2268-
}
2269-
} else {
2270-
/* TODO: replace this with a hash of available column names to column
2271-
* numbers */
2272-
for (colno = 0; colno < stmt->column_count; colno++) {
2273-
if (zend_string_equals(stmt->columns[colno].name, name)) {
2274-
fetch_value(stmt, rv, colno, NULL);
2275-
return rv;
2276-
}
2277-
}
2278-
if (zend_string_equals_literal(name, "queryString")) {
2279-
return zend_std_read_property(&stmt->std, name, type, cache_slot, rv);
2265+
if (is_numeric_string(ZSTR_VAL(name), ZSTR_LEN(name), &lval, NULL, 0) == IS_LONG) {
2266+
if (lval >= 0 && lval < stmt->column_count) {
2267+
fetch_value(stmt, rv, lval, NULL);
2268+
}
2269+
} else {
2270+
/* TODO: replace this with a hash of available column names to column
2271+
* numbers */
2272+
for (colno = 0; colno < stmt->column_count; colno++) {
2273+
if (zend_string_equals(stmt->columns[colno].name, name)) {
2274+
fetch_value(stmt, rv, colno, NULL);
2275+
return rv;
22802276
}
22812277
}
2278+
if (zend_string_equals_literal(name, "queryString")) {
2279+
return zend_std_read_property(&stmt->std, name, type, cache_slot, rv);
2280+
}
22822281
}
22832282

22842283
return rv;
@@ -2290,35 +2289,34 @@ static zval *row_dim_read(zend_object *object, zval *member, int type, zval *rv)
22902289
pdo_stmt_t *stmt = row->stmt;
22912290
int colno = -1;
22922291
zend_long lval;
2292+
ZEND_ASSERT(stmt);
22932293

22942294
ZVAL_NULL(rv);
2295-
if (stmt) {
2296-
if (Z_TYPE_P(member) == IS_LONG) {
2297-
if (Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count) {
2298-
fetch_value(stmt, rv, Z_LVAL_P(member), NULL);
2299-
}
2300-
} else if (Z_TYPE_P(member) == IS_STRING
2301-
&& is_numeric_string(Z_STRVAL_P(member), Z_STRLEN_P(member), &lval, NULL, 0) == IS_LONG) {
2302-
if (lval >= 0 && lval < stmt->column_count) {
2303-
fetch_value(stmt, rv, lval, NULL);
2304-
}
2305-
} else {
2306-
if (!try_convert_to_string(member)) {
2307-
return &EG(uninitialized_zval);
2308-
}
2295+
if (Z_TYPE_P(member) == IS_LONG) {
2296+
if (Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count) {
2297+
fetch_value(stmt, rv, Z_LVAL_P(member), NULL);
2298+
}
2299+
} else if (Z_TYPE_P(member) == IS_STRING
2300+
&& is_numeric_string(Z_STRVAL_P(member), Z_STRLEN_P(member), &lval, NULL, 0) == IS_LONG) {
2301+
if (lval >= 0 && lval < stmt->column_count) {
2302+
fetch_value(stmt, rv, lval, NULL);
2303+
}
2304+
} else {
2305+
if (!try_convert_to_string(member)) {
2306+
return &EG(uninitialized_zval);
2307+
}
23092308

2310-
/* TODO: replace this with a hash of available column names to column
2311-
* numbers */
2312-
for (colno = 0; colno < stmt->column_count; colno++) {
2313-
if (zend_string_equals(stmt->columns[colno].name, Z_STR_P(member))) {
2314-
fetch_value(stmt, rv, colno, NULL);
2315-
return rv;
2316-
}
2317-
}
2318-
if (zend_string_equals_literal(Z_STR_P(member), "queryString")) {
2319-
return zend_std_read_property(&stmt->std, Z_STR_P(member), type, NULL, rv);
2309+
/* TODO: replace this with a hash of available column names to column
2310+
* numbers */
2311+
for (colno = 0; colno < stmt->column_count; colno++) {
2312+
if (zend_string_equals(stmt->columns[colno].name, Z_STR_P(member))) {
2313+
fetch_value(stmt, rv, colno, NULL);
2314+
return rv;
23202315
}
23212316
}
2317+
if (zend_string_equals_literal(Z_STR_P(member), "queryString")) {
2318+
return zend_std_read_property(&stmt->std, Z_STR_P(member), type, NULL, rv);
2319+
}
23222320
}
23232321

23242322
return rv;
@@ -2341,25 +2339,24 @@ static int row_prop_exists(zend_object *object, zend_string *name, int check_emp
23412339
pdo_stmt_t *stmt = row->stmt;
23422340
int colno = -1;
23432341
zend_long lval;
2342+
ZEND_ASSERT(stmt);
23442343

2345-
if (stmt) {
2346-
if (is_numeric_string(ZSTR_VAL(name), ZSTR_LEN(name), &lval, NULL, 0) == IS_LONG) {
2347-
return lval >=0 && lval < stmt->column_count;
2348-
}
2344+
if (is_numeric_string(ZSTR_VAL(name), ZSTR_LEN(name), &lval, NULL, 0) == IS_LONG) {
2345+
return lval >=0 && lval < stmt->column_count;
2346+
}
23492347

2350-
/* TODO: replace this with a hash of available column names to column
2351-
* numbers */
2352-
for (colno = 0; colno < stmt->column_count; colno++) {
2353-
if (zend_string_equals(stmt->columns[colno].name, name)) {
2354-
int res;
2355-
zval val;
2348+
/* TODO: replace this with a hash of available column names to column
2349+
* numbers */
2350+
for (colno = 0; colno < stmt->column_count; colno++) {
2351+
if (zend_string_equals(stmt->columns[colno].name, name)) {
2352+
int res;
2353+
zval val;
23562354

2357-
fetch_value(stmt, &val, colno, NULL);
2358-
res = check_empty ? i_zend_is_true(&val) : Z_TYPE(val) != IS_NULL;
2359-
zval_ptr_dtor_nogc(&val);
2355+
fetch_value(stmt, &val, colno, NULL);
2356+
res = check_empty ? i_zend_is_true(&val) : Z_TYPE(val) != IS_NULL;
2357+
zval_ptr_dtor_nogc(&val);
23602358

2361-
return res;
2362-
}
2359+
return res;
23632360
}
23642361
}
23652362

@@ -2372,33 +2369,32 @@ static int row_dim_exists(zend_object *object, zval *member, int check_empty)
23722369
pdo_stmt_t *stmt = row->stmt;
23732370
int colno = -1;
23742371
zend_long lval;
2372+
ZEND_ASSERT(stmt);
23752373

2376-
if (stmt) {
2377-
if (Z_TYPE_P(member) == IS_LONG) {
2378-
return Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count;
2379-
} else if (Z_TYPE_P(member) == IS_STRING) {
2380-
if (is_numeric_string(Z_STRVAL_P(member), Z_STRLEN_P(member), &lval, NULL, 0) == IS_LONG) {
2381-
return lval >=0 && lval < stmt->column_count;
2382-
}
2383-
} else {
2384-
if (!try_convert_to_string(member)) {
2385-
return 0;
2386-
}
2374+
if (Z_TYPE_P(member) == IS_LONG) {
2375+
return Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count;
2376+
} else if (Z_TYPE_P(member) == IS_STRING) {
2377+
if (is_numeric_string(Z_STRVAL_P(member), Z_STRLEN_P(member), &lval, NULL, 0) == IS_LONG) {
2378+
return lval >=0 && lval < stmt->column_count;
2379+
}
2380+
} else {
2381+
if (!try_convert_to_string(member)) {
2382+
return 0;
23872383
}
2384+
}
23882385

2389-
/* TODO: replace this with a hash of available column names to column
2390-
* numbers */
2391-
for (colno = 0; colno < stmt->column_count; colno++) {
2392-
if (zend_string_equals(stmt->columns[colno].name, Z_STR_P(member))) {
2393-
int res;
2394-
zval val;
2386+
/* TODO: replace this with a hash of available column names to column
2387+
* numbers */
2388+
for (colno = 0; colno < stmt->column_count; colno++) {
2389+
if (zend_string_equals(stmt->columns[colno].name, Z_STR_P(member))) {
2390+
int res;
2391+
zval val;
23952392

2396-
fetch_value(stmt, &val, colno, NULL);
2397-
res = check_empty ? i_zend_is_true(&val) : Z_TYPE(val) != IS_NULL;
2398-
zval_ptr_dtor_nogc(&val);
2393+
fetch_value(stmt, &val, colno, NULL);
2394+
res = check_empty ? i_zend_is_true(&val) : Z_TYPE(val) != IS_NULL;
2395+
zval_ptr_dtor_nogc(&val);
23992396

2400-
return res;
2401-
}
2397+
return res;
24022398
}
24032399
}
24042400

@@ -2421,8 +2417,9 @@ static HashTable *row_get_properties_for(zend_object *object, zend_prop_purpose
24212417
pdo_stmt_t *stmt = row->stmt;
24222418
HashTable *props;
24232419
int i;
2420+
ZEND_ASSERT(stmt);
24242421

2425-
if (purpose != ZEND_PROP_PURPOSE_DEBUG || stmt == NULL) {
2422+
if (purpose != ZEND_PROP_PURPOSE_DEBUG) {
24262423
return zend_std_get_properties_for(object, purpose);
24272424
}
24282425

0 commit comments

Comments
 (0)