Skip to content

Remove impossible paths from session_decode and session_encode #13796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,7 @@ static void php_session_track_init(void) /* {{{ */
static zend_string *php_session_encode(void) /* {{{ */
{
IF_SESSION_VARS() {
if (!PS(serializer)) {
php_error_docref(NULL, E_WARNING, "Unknown session.serialize_handler. Failed to encode session object");
return NULL;
}
ZEND_ASSERT(PS(serializer));
return PS(serializer)->encode();
} else {
php_error_docref(NULL, E_WARNING, "Cannot encode non-existent session");
Expand All @@ -268,10 +265,7 @@ static ZEND_COLD void php_session_cancel_decode(void)

static zend_result 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 FAILURE;
}
ZEND_ASSERT(PS(serializer));
zend_result result = SUCCESS;
zend_try {
if (PS(serializer)->decode(ZSTR_VAL(data), ZSTR_LEN(data)) == FAILURE) {
Expand Down
27 changes: 27 additions & 0 deletions ext/session/tests/session_decode_error3.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Test session_decode() function : error functionality
--EXTENSIONS--
session
--SKIPIF--
<?php include('skipif.inc'); ?>
--INI--
session.serialize_handler = wrong_handler
--FILE--
<?php

ob_start();
session_start();
ini_set('session.serialize_handler', 'wrong_handler');
var_dump(session_decode(''));

echo "Done";
ob_end_flush();
?>
--EXPECTF--
Warning: session_start(): Cannot find session serialization handler "wrong_handler" - session startup failed in %s on line 4

Warning: ini_set(): Serialization handler "wrong_handler" cannot be found in %s on line 5

Warning: session_decode(): Session data cannot be decoded when there is no active session in %s on line 6
bool(false)
Done