From: Stanislav Malyshev Date: Mon, 26 Sep 2016 02:53:59 +0000 (-0700) Subject: Fix bug #73147: Use After Free in PHP7 unserialize() X-Git-Tag: php-7.1.0RC4~48 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=54003ab6631b489af54631a548597e8bd599b266;p=php Fix bug #73147: Use After Free in PHP7 unserialize() (cherry picked from commit 0e6fe3a4c96be2d3e88389a5776f878021b4c59f) (cherry picked from commit f42cbd749cde1f91274c1d03df9024baba141a8f) --- diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 6ce60e1f06..a71aca8106 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -3886,6 +3886,24 @@ ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, c } /* }}} */ +ZEND_API void zend_unset_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length) /* {{{ */ +{ + zval property; + zend_class_entry *old_scope = EG(scope); + + EG(scope) = scope; + + if (!Z_OBJ_HT_P(object)->unset_property) { + zend_error_noreturn(E_CORE_ERROR, "Property %s of class %s cannot be unset", name, ZSTR_VAL(Z_OBJCE_P(object)->name)); + } + ZVAL_STRINGL(&property, name, name_length); + Z_OBJ_HT_P(object)->unset_property(object, &property, 0); + zval_ptr_dtor(&property); + + EG(scope) = old_scope; +} +/* }}} */ + ZEND_API void zend_update_property_bool(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value) /* {{{ */ { zval tmp; diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 199e88a8af..8c4a2ccccd 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -346,6 +346,7 @@ ZEND_API void zend_update_property_double(zend_class_entry *scope, zval *object, ZEND_API void zend_update_property_str(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_string *value); ZEND_API void zend_update_property_string(zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value); ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value, size_t value_length); +ZEND_API void zend_unset_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length); ZEND_API int zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value); ZEND_API int zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length); diff --git a/ext/curl/curl_file.c b/ext/curl/curl_file.c index de173a5f42..ba8a7de108 100644 --- a/ext/curl/curl_file.c +++ b/ext/curl/curl_file.c @@ -137,6 +137,7 @@ ZEND_METHOD(CURLFile, setPostFilename) Unserialization handler */ ZEND_METHOD(CURLFile, __wakeup) { + zend_unset_property(curl_CURLFile_class, getThis(), "name", sizeof("name")-1); zend_update_property_string(curl_CURLFile_class, getThis(), "name", sizeof("name")-1, ""); zend_throw_exception(NULL, "Unserialization of CURLFile instances is not allowed", 0); } diff --git a/ext/curl/tests/bug73147.phpt b/ext/curl/tests/bug73147.phpt new file mode 100644 index 0000000000..118177d871 --- /dev/null +++ b/ext/curl/tests/bug73147.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #73147: Use After Free in PHP7 unserialize() +--SKIPIF-- + +--FILE-- +getMessage(); +} +?> +--EXPECT-- +Unserialization of CURLFile instances is not allowed