summaryrefslogtreecommitdiff
path: root/ext/pdo
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2009-10-12 17:09:11 +0000
committerFelipe Pena <felipe@php.net>2009-10-12 17:09:11 +0000
commitb394a75ad56377504974770cff89c54fbad8a97e (patch)
tree4baba30dd03e30f7fcb2d3152b13d7f48fa950b6 /ext/pdo
parente5d4b019b9097307b0180b1a8e66338d949e6f0a (diff)
downloadphp-git-b394a75ad56377504974770cff89c54fbad8a97e.tar.gz
- Fixed PDORow and PDOStatement crashes when instantiating throught Reflection
Diffstat (limited to 'ext/pdo')
-rwxr-xr-xext/pdo/pdo_dbh.c2
-rwxr-xr-xext/pdo/pdo_stmt.c64
-rw-r--r--ext/pdo/tests/pdo_036.phpt21
3 files changed, 58 insertions, 29 deletions
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index 8a39b7fe57..265b05aa6f 100755
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -110,7 +110,7 @@ void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
char *message = NULL;
zval *info = NULL;
- if (dbh->error_mode == PDO_ERRMODE_SILENT) {
+ if (dbh == NULL || dbh->error_mode == PDO_ERRMODE_SILENT) {
return;
}
diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c
index c937f68714..7f95f60f74 100755
--- a/ext/pdo/pdo_stmt.c
+++ b/ext/pdo/pdo_stmt.c
@@ -2663,26 +2663,28 @@ static zval *row_prop_or_dim_read(zval *object, zval *member, int type TSRMLS_DC
MAKE_STD_ZVAL(return_value);
RETVAL_NULL();
-
- if (Z_TYPE_P(member) == IS_LONG) {
- if (Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count) {
- fetch_value(stmt, return_value, Z_LVAL_P(member), NULL TSRMLS_CC);
- }
- } else {
- convert_to_string(member);
- /* TODO: replace this with a hash of available column names to column
- * numbers */
- for (colno = 0; colno < stmt->column_count; colno++) {
- if (strcmp(stmt->columns[colno].name, Z_STRVAL_P(member)) == 0) {
- fetch_value(stmt, return_value, colno, NULL TSRMLS_CC);
- Z_SET_REFCOUNT_P(return_value, 0);
- Z_UNSET_ISREF_P(return_value);
- return return_value;
+
+ 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, return_value, Z_LVAL_P(member), NULL TSRMLS_CC);
+ }
+ } else {
+ convert_to_string(member);
+ /* TODO: replace this with a hash of available column names to column
+ * numbers */
+ for (colno = 0; colno < stmt->column_count; colno++) {
+ if (strcmp(stmt->columns[colno].name, Z_STRVAL_P(member)) == 0) {
+ fetch_value(stmt, return_value, colno, NULL TSRMLS_CC);
+ Z_SET_REFCOUNT_P(return_value, 0);
+ Z_UNSET_ISREF_P(return_value);
+ return return_value;
+ }
+ }
+ if (strcmp(Z_STRVAL_P(member), "queryString") == 0) {
+ zval_ptr_dtor(&return_value);
+ return std_object_handlers.read_property(object, member, IS_STRING TSRMLS_CC);
}
- }
- if (strcmp(Z_STRVAL_P(member), "queryString") == 0) {
- zval_ptr_dtor(&return_value);
- return std_object_handlers.read_property(object, member, IS_STRING TSRMLS_CC);
}
}
@@ -2702,16 +2704,18 @@ static int row_prop_or_dim_exists(zval *object, zval *member, int check_empty TS
pdo_stmt_t * stmt = (pdo_stmt_t *) zend_object_store_get_object(object TSRMLS_CC);
int colno = -1;
- if (Z_TYPE_P(member) == IS_LONG) {
- return Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count;
- } else {
- convert_to_string(member);
+ if (stmt) {
+ if (Z_TYPE_P(member) == IS_LONG) {
+ return Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count;
+ } else {
+ convert_to_string(member);
- /* TODO: replace this with a hash of available column names to column
- * numbers */
- for (colno = 0; colno < stmt->column_count; colno++) {
- if (strcmp(stmt->columns[colno].name, Z_STRVAL_P(member)) == 0) {
- return 1;
+ /* TODO: replace this with a hash of available column names to column
+ * numbers */
+ for (colno = 0; colno < stmt->column_count; colno++) {
+ if (strcmp(stmt->columns[colno].name, Z_STRVAL_P(member)) == 0) {
+ return 1;
+ }
}
}
}
@@ -2729,6 +2733,10 @@ static HashTable *row_get_properties(zval *object TSRMLS_DC)
pdo_stmt_t * stmt = (pdo_stmt_t *) zend_object_store_get_object(object TSRMLS_CC);
int i;
+ if (stmt == NULL) {
+ return NULL;
+ }
+
for (i = 0; i < stmt->column_count; i++) {
zval *val;
MAKE_STD_ZVAL(val);
diff --git a/ext/pdo/tests/pdo_036.phpt b/ext/pdo/tests/pdo_036.phpt
new file mode 100644
index 0000000000..6bd38cb06a
--- /dev/null
+++ b/ext/pdo/tests/pdo_036.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Testing PDORow and PDOStatement instances with Reflection
+--FILE--
+<?php
+
+$instance = new reflectionclass('pdorow');
+$x = $instance->newInstance();
+var_dump($x);
+
+$instance = new reflectionclass('pdostatement');
+$x = $instance->newInstance();
+var_dump($x);
+
+?>
+--EXPECTF--
+object(PDORow)#%d (0) {
+}
+object(PDOStatement)#%d (1) {
+ [%u|b%"queryString"]=>
+ NULL
+}