com php-src: Fix bug #72749: wddx_deserialize allows ille gal memory access: ext/wddx/tests/bug72749. phpt ext/wddx/wddx.c
| From: | Anatol Belski | Date: | Wed, 17 Aug 2016 11:46:52 +0000 |
| Subject: | com php-src: Fix bug #72749: wddx_deserialize allows ille gal memory access: ext/wddx/tests/bug72749. phpt ext/wddx/wddx.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-93892@lists.php.net to get a copy of this message | ||
Commit: d9fac3953d5b8a6b14c612b4ae351b8ae6dda481
Author: Stanislav Malyshev <stas@php.net> Thu, 4 Aug 2016 00:17:42 -0700
Committer: Anatol Belski <ab@php.net> Wed, 17 Aug 2016 13:46:52 +0200
Parents: 749cae0fa13a097c13f96d631cc4e081e545efd4
Branches: PHP-7.0.10
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d9fac3953d5b8a6b14c612b4ae351b8ae6dda481
Log:
Fix bug #72749: wddx_deserialize allows illegal memory access
(cherry picked from commit 659a21dc20f0b64dafd8cb16573059d3b45cce6b)
Conflicts:
ext/wddx/wddx.c
(cherry picked from commit e3829b88694460a2e5af10ad5eee9966fa55e589)
Bugs:
https://bugs.php.net/72749
Changed paths:
A ext/wddx/tests/bug72749.phpt
M ext/wddx/wddx.c
Diff:
diff --git a/ext/wddx/tests/bug72749.phpt b/ext/wddx/tests/bug72749.phpt
new file mode 100644
index 0000000..ee17d0f
--- /dev/null
+++ b/ext/wddx/tests/bug72749.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Bug #72749: wddx_deserialize allows illegal memory access
+--SKIPIF--
+<?php
+if (!extension_loaded('wddx')) {
+ die('skip. wddx not available');
+}
+?>
+--FILE--
+<?php
+$xml = <<<XML
+<?xml version='1.0'?>
+<!DOCTYPE wddxPacket SYSTEM 'wddx_0100.dtd'>
+<wddxPacket version='1.0'>
+<header/>
+ <data>
+ <struct>
+ <var name='aDateTime3'>
+ <dateTime>2\r2004-09-10T05:52:49+00</dateTime>
+ </var>
+ </struct>
+ </data>
+</wddxPacket>
+XML;
+
+$array = wddx_deserialize($xml);
+var_dump($array);
+?>
+--EXPECT--
+array(1) {
+ ["aDateTime3"]=>
+ string(24) "2
+2004-09-10T05:52:49+00"
+}
diff --git a/ext/wddx/wddx.c b/ext/wddx/wddx.c
index 40b41ba..a11efe6 100644
--- a/ext/wddx/wddx.c
+++ b/ext/wddx/wddx.c
@@ -1038,14 +1038,22 @@ static void php_wddx_process_data(void *user_data, const XML_Char *s, int
len)
case ST_DATETIME: {
char *tmp;
- tmp = emalloc(len + 1);
- memcpy(tmp, (char *)s, len);
+ if (Z_TYPE(ent->data) == IS_STRING) {
+ tmp = safe_emalloc(Z_STRLEN(ent->data), 1, (size_t)len + 1);
+ memcpy(tmp, Z_STRVAL(ent->data), Z_STRLEN(ent->data));
+ memcpy(tmp + Z_STRLEN(ent->data), s, len);
+ len += Z_STRLEN(ent->data);
+ zval_dtor(&ent->data);
+ } else {
+ tmp = emalloc(len + 1);
+ memcpy(tmp, (char *)s, len);
+ }
tmp[len] = '\0';
- Z_LVAL(ent->data) = php_parse_date(tmp, NULL);
+ ZVAL_LONG(&ent->data, php_parse_date(tmp, NULL));
/* date out of range < 1969 or > 2038 */
if (Z_LVAL(ent->data) == -1) {
- ZVAL_STRINGL(&ent->data, (char *)s, len);
+ ZVAL_STRINGL(&ent->data, (char *)tmp, len);
}
efree(tmp);
}