Skip to content

Commit 3873858

Browse files
committed
session: Fix for #18634, Warning on pipe character in session variable key
Changes based on feedback. Updated error message, added explicit test for session_write_close() and tidied up tests.
1 parent f92b09c commit 3873858

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

ext/session/session.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ PS_SERIALIZER_ENCODE_FUNC(php) /* {{{ */
994994
if (memchr(ZSTR_VAL(key), PS_DELIMITER, ZSTR_LEN(key))) {
995995
PHP_VAR_SERIALIZE_DESTROY(var_hash);
996996
smart_str_free(&buf);
997-
php_error_docref(NULL, E_WARNING, "Failed to write session data. Data contains invalid key \"%s\".", ZSTR_VAL(key));
997+
php_error_docref(NULL, E_WARNING, "Failed to write session data. Data contains invalid key \"%s\"", ZSTR_VAL(key));
998998
return NULL;
999999
}
10001000
smart_str_appendc(&buf, PS_DELIMITER);

ext/session/tests/gh18634.phpt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
--TEST--
22
GH-18634 (Using pipe character in session variable key causes session data to be removed)
3-
--INI--
43
--EXTENSIONS--
54
session
65
--SKIPIF--
76
<?php include('skipif.inc'); ?>
87
--FILE--
98
<?php
10-
ob_start();
119
session_start();
1210
$_SESSION['foo|bar'] = 'value';
13-
ob_end_clean();
1411
?>
15-
--EXPECTF--
16-
Warning: PHP Request Shutdown: Failed to write session data. Data contains invalid key "foo|bar". in Unknown on line 0
12+
--EXPECT--
13+
Warning: PHP Request Shutdown: Failed to write session data. Data contains invalid key "foo|bar" in Unknown on line 0

ext/session/tests/gh18634_2.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-18634 (Using pipe character in session variable key causes session data to be removed - explicit session write)
3+
--EXTENSIONS--
4+
session
5+
--SKIPIF--
6+
<?php include('skipif.inc'); ?>
7+
--FILE--
8+
<?php
9+
session_start();
10+
$_SESSION['foo|bar'] = 'value';
11+
session_write_close()
12+
?>
13+
--EXPECTF--
14+
Warning: session_write_close(): Failed to write session data. Data contains invalid key "foo|bar" in %s on line %d

0 commit comments

Comments
 (0)