From bc4baf608b69b1f6ba05aa136900c4467343592b Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Mon, 28 Dec 2015 14:46:35 -0800 Subject: [PATCH] Fixed bug #70661 (Use After Free Vulnerability in WDDX Packet Deserialization) Conflicts: ext/wddx/wddx.c --- ext/wddx/tests/bug70661.phpt | 69 ++++++++++++++++++++++++++++++++++++ ext/wddx/wddx.c | 2 +- 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 ext/wddx/tests/bug70661.phpt diff --git a/ext/wddx/tests/bug70661.phpt b/ext/wddx/tests/bug70661.phpt new file mode 100644 index 0000000000..e068c20a7a --- /dev/null +++ b/ext/wddx/tests/bug70661.phpt @@ -0,0 +1,69 @@ +--TEST-- +Bug #70661 (Use After Free Vulnerability in WDDX Packet Deserialization) +--SKIPIF-- + +--FILE-- + + +
+ + + + + + stdClass + + + + + + + +EOT; + +$y = wddx_deserialize($x); + +for ($i = 0; $i < 5; $i++) { + $v[$i] = $fakezval.$i; +} + +var_dump($y); + +function ptr2str($ptr) +{ + $out = ''; + + for ($i = 0; $i < 8; $i++) { + $out .= chr($ptr & 0xff); + $ptr >>= 8; + } + + return $out; +} +?> +DONE +--EXPECTF-- +array(1) { + [0]=> + array(1) { + ["ryat"]=> + array(2) { + ["php_class_name"]=> + string(8) "stdClass" + [0]=> + NULL + } + } +} +DONE \ No newline at end of file diff --git a/ext/wddx/wddx.c b/ext/wddx/wddx.c index 6632890084..83b8f97294 100644 --- a/ext/wddx/wddx.c +++ b/ext/wddx/wddx.c @@ -908,7 +908,7 @@ static void php_wddx_pop_element(void *user_data, const XML_Char *name) if (ent1->varname) { if (!strcmp(ent1->varname, PHP_CLASS_NAME_VAR) && - Z_TYPE(ent1->data) == IS_STRING && Z_STRLEN(ent1->data)) { + Z_TYPE(ent1->data) == IS_STRING && Z_STRLEN(ent1->data) && ent2->type == ST_STRUCT) { zend_bool incomplete_class = 0; zend_str_tolower(Z_STRVAL(ent1->data), Z_STRLEN(ent1->data)); -- 2.40.0