Skip to content

Commit

Permalink
Fix type confusion with session SID constant
Browse files Browse the repository at this point in the history
Closes GH-17548.
  • Loading branch information
nielsdos committed Jan 23, 2025
1 parent 0b3e637 commit 2a2cc2c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ PHP NEWS
- PHPDBG:
. Fix crashes in function registration + test. (nielsdos, Girgias)

- Session:
. Fix type confusion with session SID constant. (nielsdos)

- SimpleXML:
. Fixed bug GH-17409 (Assertion failure Zend/zend_hash.c:1730). (nielsdos)

Expand Down
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) ""

0 comments on commit 2a2cc2c

Please sign in to comment.