Skip to content

Fix type confusion with session SID constant #17548

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

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1479,15 +1479,15 @@ PHPAPI zend_result php_session_reset_id(void) /* {{{ */
smart_str_appends(&var, ZSTR_VAL(PS(id)));
smart_str_0(&var);
if (sid) {
zval_ptr_dtor_str(sid);
zval_ptr_dtor(sid);
ZVAL_STR(sid, smart_str_extract(&var));
} else {
REGISTER_STRINGL_CONSTANT("SID", ZSTR_VAL(var.s), ZSTR_LEN(var.s), 0);
smart_str_free(&var);
}
} else {
if (sid) {
zval_ptr_dtor_str(sid);
zval_ptr_dtor(sid);
ZVAL_EMPTY_STRING(sid);
} else {
REGISTER_STRINGL_CONSTANT("SID", "", 0, 0);
Expand Down
19 changes: 19 additions & 0 deletions ext/session/tests/SID_type_confusion.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
SID constant type confusion
--EXTENSIONS--
session
--SKIPIF--
<?php include('skipif.inc'); ?>
--INI--
session.use_cookies=0
session.use_only_cookies=1
--FILE--
<?php

define('SID', [0xdeadbeef]);
session_start();
var_dump(SID);

?>
--EXPECT--
string(0) ""
Loading