Skip to content

Commit 5662ffb

Browse files
conormcdYasuo Ohgaki
authored andcommitted
Bug #66481 Segfaults on session_name()
If the previous value of session.name was NULL then any call to session_name($string) would result in a segmentation fault. This changes the behaviour to set the value of session.name to "PHPSESSID" if a blank value is given in php.ini or via -d on the command line. There is already protection against setting it to NULL via session_name() or ini_set().
1 parent b877451 commit 5662ffb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

ext/session/session.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,13 @@ static PHP_INI_MH(OnUpdateSaveDir) /* {{{ */
617617

618618
static PHP_INI_MH(OnUpdateName) /* {{{ */
619619
{
620+
/* Don't accept a blank session name from php.ini or -d session.name= */
621+
if (!PG(modules_activated) && !new_value_length) {
622+
/* Force the default value. */
623+
new_value = "PHPSESSID";
624+
new_value_length = 9;
625+
}
626+
620627
/* Numeric session.name won't work at all */
621628
if (PG(modules_activated) &&
622629
(!new_value_length || is_numeric_string(new_value, new_value_length, NULL, NULL, 0))) {

ext/session/tests/bug66481.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #66481: Calls to session_name() segfault when session.name is null.
3+
--INI--
4+
session.name=
5+
--SKIPIF--
6+
<?php include('skipif.inc'); ?>
7+
--FILE--
8+
<?php
9+
10+
var_dump(session_name("foo"));
11+
var_dump(session_name("bar"));
12+
13+
--EXPECTF--
14+
string(9) "PHPSESSID"
15+
string(3) "foo"
16+

0 commit comments

Comments
 (0)