From: Felipe Pena Date: Sat, 5 Jun 2010 17:50:09 +0000 (+0000) Subject: - Fix crash with non string property X-Git-Tag: RELEASE_1_7_0~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=7e20868975f5c23ccd74af0d8f7147c506d2b8cf;p=m6w6%2Fext-http - Fix crash with non string property --- diff --git a/http_message_object.c b/http_message_object.c index c3585c1..3129193 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -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) diff --git a/php_http_std_defs.h b/php_http_std_defs.h index 1f8e45d..0c5a9e5 100644 --- a/php_http_std_defs.h +++ b/php_http_std_defs.h @@ -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))