guard against uninitialized property write, too
authorMichael Wallner <mike@php.net>
Wed, 17 Sep 2014 07:23:45 +0000 (09:23 +0200)
committerMichael Wallner <mike@php.net>
Wed, 17 Sep 2014 07:23:45 +0000 (09:23 +0200)
use php_error with E_RECOVERABLE_ERROR

src/php_pq_object.c
src/php_pqconn.c

index ecfbbf7..77207ea 100644 (file)
@@ -114,12 +114,12 @@ zval *php_pq_object_read_prop(zval *object, zval *member, int type, const zend_l
        zval *return_value = NULL;
 
        if (!obj->intern) {
-               zend_error(E_WARNING, "%s not initialized", ancestor(obj->zo.ce)->name);
+               php_error(E_RECOVERABLE_ERROR, "%s not initialized", ancestor(obj->zo.ce)->name);
                return_value = zend_get_std_object_handlers()->read_property(object, member, type, key TSRMLS_CC);
        } else if ((SUCCESS != zend_hash_find(obj->prophandler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void *) &handler)) || !handler->read) {
                return_value = zend_get_std_object_handlers()->read_property(object, member, type, key TSRMLS_CC);
        } else if (type != BP_VAR_R) {
-               zend_error(E_ERROR, "Cannot access %s properties by reference or array key/index", ancestor(obj->zo.ce)->name);
+               php_error(E_WARNING, "Cannot access %s properties by reference or array key/index", ancestor(obj->zo.ce)->name);
                return_value = zend_get_std_object_handlers()->read_property(object, member, type, key TSRMLS_CC);
        } else {
                ALLOC_ZVAL(return_value);
@@ -137,7 +137,10 @@ void php_pq_object_write_prop(zval *object, zval *member, zval *value, const zen
        php_pq_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
        php_pq_object_prophandler_t *handler;
 
-       if (SUCCESS == zend_hash_find(obj->prophandler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void *) &handler)) {
+       if (!obj->intern) {
+               php_error(E_RECOVERABLE_ERROR, "%s not initialized", ancestor(obj->zo.ce)->name);
+               zend_get_std_object_handlers()->write_property(object, member, value, key TSRMLS_CC);
+       } else if (SUCCESS == zend_hash_find(obj->prophandler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void *) &handler)) {
                if (handler->write) {
                        handler->write(object, obj, value TSRMLS_CC);
                }
index 3b920e7..c4d6c80 100644 (file)
@@ -219,7 +219,7 @@ static void php_pqconn_object_write_encoding(zval *object, void *o, zval *value
        }
 
        if (0 > PQsetClientEncoding(obj->intern->conn, Z_STRVAL_P(zenc))) {
-               zend_error(E_NOTICE, "Unrecognized encoding '%s'", Z_STRVAL_P(zenc));
+               php_error(E_NOTICE, "Unrecognized encoding '%s'", Z_STRVAL_P(zenc));
        }
 
        if (zenc != value) {