- Fix crash with non string property
authorFelipe Pena <felipe@php.net>
Sat, 5 Jun 2010 17:50:09 +0000 (17:50 +0000)
committerFelipe Pena <felipe@php.net>
Sat, 5 Jun 2010 17:50:09 +0000 (17:50 +0000)
http_message_object.c
php_http_std_defs.h

index c3585c1..3129193 100644 (file)
@@ -579,11 +579,24 @@ static zval *_http_message_object_read_prop(zval *object, zval *member, int type
 {
        getObjectEx(http_message_object, obj, object);
        http_message_object_prophandler *handler;
-       zval *return_value;
+       zval *return_value, *tmp_member = NULL;
+       
+       if (Z_TYPE_P(member) != IS_STRING) {
+               ALLOC_ZVAL(tmp_member);
+               MAKE_COPY_ZVAL(&member, tmp_member);
+               convert_to_string(tmp_member);
+               member = tmp_member;
+#if PHP_VERSION_ID >= 50399
+               _zend_literal_key = NULL;
+#endif
+       }
 
        if (SUCCESS == http_message_object_get_prophandler(Z_STRVAL_P(member), Z_STRLEN_P(member), &handler)) {
                if (type == BP_VAR_W) {
                        zend_error(E_ERROR, "Cannot access HttpMessage properties by reference or array key/index");
+                       if (tmp_member) {
+                               zval_ptr_dtor(&tmp_member);
+                       }
                        return NULL;
                }
 
@@ -602,6 +615,9 @@ static zval *_http_message_object_read_prop(zval *object, zval *member, int type
                return_value = zend_get_std_object_handlers()->read_property(object, member, type ZEND_LITERAL_KEY_CC TSRMLS_CC);
        }
        
+       if (tmp_member) {
+               zval_ptr_dtor(&tmp_member);
+       }
        return return_value;
 }
 
@@ -609,12 +625,26 @@ static void _http_message_object_write_prop(zval *object, zval *member, zval *va
 {
        getObjectEx(http_message_object, obj, object);
        http_message_object_prophandler *handler;
+       zval *tmp_member = NULL;
+       
+       if (Z_TYPE_P(member) != IS_STRING) {
+               ALLOC_ZVAL(tmp_member);
+               MAKE_COPY_ZVAL(&member, tmp_member);
+               convert_to_string(tmp_member);
+               member = tmp_member;
+#if PHP_VERSION_ID >= 50399
+               _zend_literal_key = NULL;
+#endif
+       }
        
        if (SUCCESS == http_message_object_get_prophandler(Z_STRVAL_P(member), Z_STRLEN_P(member), &handler)) {
                handler->write(obj, value TSRMLS_CC);
        } else {
                zend_get_std_object_handlers()->write_property(object, member, value ZEND_LITERAL_KEY_CC TSRMLS_CC);
        }
+       if (tmp_member) {
+               zval_ptr_dtor(&tmp_member);
+       }
 }
 
 static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC)
index 1f8e45d..0c5a9e5 100644 (file)
@@ -58,6 +58,13 @@ typedef int STATUS;
                Z_ARRVAL(zv) = (ht); \
        }
 
+#ifndef MAKE_COPY_ZVAL
+# define MAKE_COPY_ZVAL(ppzv, pzv) \
+       *(pzv) = **(ppzv);            \
+       zval_copy_ctor((pzv));        \
+       INIT_PZVAL((pzv));
+#endif
+    
 /* return bool (v == SUCCESS) */
 #define RETVAL_SUCCESS(v) RETVAL_BOOL(SUCCESS == (v))
 #define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))