com php-src: Bug #72663 - part 3: ext/session/session.c ext/standard/tests/serialize/bug72663_3.phpt ext/wddx/wddx.c

From: Date: Wed, 17 Aug 2016 11:52:28 +0000
Subject: com php-src: Bug #72663 - part 3: ext/session/session.c ext/standard/tests/serialize/bug72663_3.phpt ext/wddx/wddx.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-93886@lists.php.net to get a copy of this message
Commit: 758a0cd8b3941935b5ec10256c336544e0d6ad41 Author: Nikita Popov <nikic@php.net> Wed, 10 Aug 2016 14:46:38 +0200 Committer: Anatol Belski <ab@php.net> Wed, 17 Aug 2016 13:52:28 +0200 Parents: d3221181c3a27e7f1e23c6db1266fde820d471d7 Branches: PHP-7.0.10 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=758a0cd8b3941935b5ec10256c336544e0d6ad41 Log: Bug #72663 - part 3 When using the php_serialize session serialization handler, do not use the result of the unserialization if it failed. (cherry picked from commit e0f9fbdfa61012101de7f4a8653ca5538c404a71) Bugs: https://bugs.php.net/72663 Changed paths: M ext/session/session.c A ext/standard/tests/serialize/bug72663_3.phpt M ext/wddx/wddx.c Diff: diff --git a/ext/session/session.c b/ext/session/session.c index 380cad5..401574c 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -905,12 +905,19 @@ PS_SERIALIZER_DECODE_FUNC(php_serialize) /* {{{ */ const char *endptr = val + vallen; zval session_vars; php_unserialize_data_t var_hash; + int result; zend_string *var_name = zend_string_init("_SESSION", sizeof("_SESSION") - 1, 0); ZVAL_NULL(&session_vars); PHP_VAR_UNSERIALIZE_INIT(var_hash); - php_var_unserialize(&session_vars, (const unsigned char **)&val, (const unsigned char *)endptr, &var_hash); + result = php_var_unserialize( + &session_vars, (const unsigned char **)&val, (const unsigned char *)endptr, &var_hash); PHP_VAR_UNSERIALIZE_DESTROY(var_hash); + if (!result) { + zval_ptr_dtor(&session_vars); + ZVAL_NULL(&session_vars); + } + if (!Z_ISUNDEF(PS(http_session_vars))) { zval_ptr_dtor(&PS(http_session_vars)); } diff --git a/ext/standard/tests/serialize/bug72663_3.phpt b/ext/standard/tests/serialize/bug72663_3.phpt new file mode 100644 index 0000000..37d6770 --- /dev/null +++ b/ext/standard/tests/serialize/bug72663_3.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #72663 (3): If unserialization fails, don't initialize the session with the result +--SKIPIF-- +<?php if (!extension_loaded('session')) die('skip Session extension required'); ?> +--INI-- +session.serialize_handler=php_serialize +--FILE-- +<?php +session_start(); +$sess = 'O:9:"Exception":2:{s:7:"'."\0".'*'."\0".'file";R:1;}'; +session_decode($sess); +var_dump($_SESSION); +?> +--EXPECTF-- +Notice: session_decode(): Unexpected end of serialized data in %s on line %d +array(0) { +} diff --git a/ext/wddx/wddx.c b/ext/wddx/wddx.c index a11efe6..0dcbd15 100644 --- a/ext/wddx/wddx.c +++ b/ext/wddx/wddx.c @@ -1089,8 +1089,12 @@ int php_wddx_deserialize_ex(const char *value, size_t vallen, zval *return_value if (stack.top == 1) { wddx_stack_top(&stack, (void**)&ent); - ZVAL_COPY(return_value, &ent->data); - retval = SUCCESS; + if (Z_ISUNDEF(ent->data)) { + retval = FAILURE; + } else { + ZVAL_COPY(return_value, &ent->data); + retval = SUCCESS; + } } else { retval = FAILURE; }

« previous php.cvs (#93886) next »