diff options
author | Yasuo Ohgaki <yohgaki@php.net> | 2015-01-25 15:26:00 +0900 |
---|---|---|
committer | Yasuo Ohgaki <yohgaki@php.net> | 2015-01-25 15:26:00 +0900 |
commit | 0c9bfa96b2c94cb4aaddcccb519dbacad7af70ec (patch) | |
tree | c4f01a23c83ceb3b106b7276a1b6850a393cf67f | |
parent | e6c8640a2a242b4c620923dcbe5f93c8366585e7 (diff) | |
download | php-git-0c9bfa96b2c94cb4aaddcccb519dbacad7af70ec.tar.gz |
Make session_decode return FALSE when it fails.
Fix a test.
Use proper types.
-rw-r--r-- | ext/session/session.c | 17 | ||||
-rw-r--r-- | ext/session/tests/029.phpt | 9 |
2 files changed, 17 insertions, 9 deletions
diff --git a/ext/session/session.c b/ext/session/session.c index c83191f05f..afc9c70ec9 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -223,16 +223,18 @@ static zend_string *php_session_encode(void) /* {{{ */ } /* }}} */ -static void php_session_decode(zend_string *data) /* {{{ */ +static int php_session_decode(zend_string *data) /* {{{ */ { if (!PS(serializer)) { php_error_docref(NULL, E_WARNING, "Unknown session.serialize_handler. Failed to decode session object"); - return; + return FAILURE; } if (PS(serializer)->decode(data->val, data->len) == FAILURE) { php_session_destroy(); php_error_docref(NULL, E_WARNING, "Failed to decode session object. Session has been destroyed"); + return FAILURE; } + return SUCCESS; } /* }}} */ @@ -297,7 +299,7 @@ PHPAPI zend_string *php_session_create_id(PS_CREATE_SID_ARGS) /* {{{ */ void *hash_context = NULL; #endif unsigned char *digest; - int digest_len; + size_t digest_len; char *buf; struct timeval tv; zval *array; @@ -428,7 +430,7 @@ PHPAPI zend_string *php_session_create_id(PS_CREATE_SID_ARGS) /* {{{ */ } outid = zend_string_alloc((digest_len + 2) * ((8.0f / PS(hash_bits_per_character) + 0.5)), 0); - outid->len = (int)(bin_to_readable((char *)digest, digest_len, outid->val, (char)PS(hash_bits_per_character)) - (char *)&outid->val); + outid->len = (size_t)(bin_to_readable((char *)digest, digest_len, outid->val, (char)PS(hash_bits_per_character)) - (char *)&outid->val); efree(digest); return outid; @@ -2156,6 +2158,7 @@ static PHP_FUNCTION(session_decode) zend_string *str = NULL; if (PS(session_status) != php_session_active) { + php_error_docref(NULL, E_WARNING, "Session is not active. You cannot decode session data"); RETURN_FALSE; } @@ -2163,8 +2166,10 @@ static PHP_FUNCTION(session_decode) return; } - php_session_decode(str); - + if (php_session_decode(str) == FAILURE) { + /* FIXME: session_decode() should return FALSE */ + /* RETURN_FALSE; */ + } RETURN_TRUE; } /* }}} */ diff --git a/ext/session/tests/029.phpt b/ext/session/tests/029.phpt index ff1adbaec8..23676ecbda 100644 --- a/ext/session/tests/029.phpt +++ b/ext/session/tests/029.phpt @@ -9,9 +9,12 @@ session.cache_limiter= <?php error_reporting(E_ALL); -@session_decode("garbage data and no session started"); -@session_decode("userid|s:5:\"mazen\";chatRoom|s:1:\"1\";"); +session_decode("garbage data and no session started"); +session_decode("userid|s:5:\"mazen\";chatRoom|s:1:\"1\";"); print "I live\n"; ?> ---EXPECT-- +--EXPECTF-- +Warning: session_decode(): Session is not active. You cannot decode session data in %s on line %d + +Warning: session_decode(): Session is not active. You cannot decode session data in %s on line %d I live |