Skip to content

Commit 07dbb54

Browse files
committed
Improved error messages
1 parent c3f9b42 commit 07dbb54

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

ext/session/session.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ zend_class_entry *php_session_update_timestamp_iface_entry;
9393
return FAILURE; \
9494
}
9595

96-
#define SESSION_FORBIDDEN_CHARS "=,;.[ \t\r\n\013\014"
96+
#define SESSION_FORBIDDEN_CHARS "=,;.[ \t\r\n\v\f"
9797

9898
#define APPLY_TRANS_SID (PS(use_trans_sid) && !PS(use_only_cookies))
9999

@@ -703,14 +703,14 @@ static bool is_session_name_valid(const zend_string *name, int diagnostic_type)
703703
{
704704
if (ZSTR_LEN(name) == 0) {
705705
if (diagnostic_type) {
706-
php_error_docref(NULL, diagnostic_type, "session.name \"%s\" cannot be empty", ZSTR_VAL(name));
706+
php_error_docref(NULL, diagnostic_type, "session.name \"%s\" must not be empty", ZSTR_VAL(name));
707707
}
708708
return false;
709709
}
710710
/* NUL bytes are not allowed */
711711
if (zend_str_has_nul_byte(name)) {
712712
if (diagnostic_type) {
713-
php_error_docref(NULL, diagnostic_type, "session.name \"%s\" cannot contain NUL bytes", ZSTR_VAL(name));
713+
php_error_docref(NULL, diagnostic_type, "session.name \"%s\" must not contain any null bytes", ZSTR_VAL(name));
714714
}
715715
return false;
716716
}
@@ -719,15 +719,15 @@ static bool is_session_name_valid(const zend_string *name, int diagnostic_type)
719719
(TL;DR: name is stored in HashTable so numeric string is converted to int key, but lookup looks for string key). */
720720
if (is_numeric_str_function(name, NULL, NULL)) {
721721
if (diagnostic_type) {
722-
php_error_docref(NULL, diagnostic_type, "session.name \"%s\" cannot be numeric", ZSTR_VAL(name));
722+
php_error_docref(NULL, diagnostic_type, "session.name \"%s\" must not be numeric", ZSTR_VAL(name));
723723
}
724724
return false;
725725
}
726726
/* Prevent broken Set-Cookie header, because the session_name might be user supplied */
727-
if (strpbrk(ZSTR_VAL(name), "=,; \t\r\n\013\014") != NULL) { /* man isspace for \013 and \014 */
727+
if (strpbrk(ZSTR_VAL(name), "=,; \t\r\n\v\f") != NULL) { /* man isspace for \v and \f */
728728
if (diagnostic_type) {
729-
php_error_docref(NULL, diagnostic_type, "session.name \"%s\" cannot contain any of the following "
730-
"'=,; \\t\\r\\n\\013\\014'", ZSTR_VAL(name));
729+
php_error_docref(NULL, diagnostic_type, "session.name \"%s\" must not contain any of the following "
730+
"'=,; \\t\\r\\n\\v\\f'", ZSTR_VAL(name));
731731
}
732732
return false;
733733
}

ext/session/tests/bug66481.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ var_dump(session_name("foo"));
1515
var_dump(session_name("bar"));
1616
?>
1717
--EXPECT--
18-
Warning: PHP Startup: session.name "" cannot be empty in Unknown on line 0
18+
Warning: PHP Startup: session.name "" must not be empty in Unknown on line 0
1919
string(9) "PHPSESSID"
2020
string(3) "foo"

ext/session/tests/session_name_variation1.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,28 @@ ob_end_flush();
4545
--EXPECTF--
4646
*** Testing session_name() : variation ***
4747

48-
Warning: session_name(): session.name "15" cannot be numeric in %s on line %d
48+
Warning: session_name(): session.name "15" must not be numeric in %s on line %d
4949
string(9) "PHPSESSID"
5050
bool(true)
5151
string(9) "PHPSESSID"
5252
bool(true)
5353
string(9) "PHPSESSID"
5454

55-
Warning: session_name(): session.name "10.25" cannot be numeric in %s on line %d
55+
Warning: session_name(): session.name "10.25" must not be numeric in %s on line %d
5656
string(9) "PHPSESSID"
5757
bool(true)
5858
string(9) "PHPSESSID"
5959
bool(true)
6060
string(9) "PHPSESSID"
6161

62-
Warning: session_name(): session.name " " cannot contain any of the following '=,; \t\r\n\013\014' in %s on line %d
62+
Warning: session_name(): session.name " " must not contain any of the following '=,; \t\r\n\v\f' in %s on line %d
6363
string(9) "PHPSESSID"
6464
bool(true)
6565
string(9) "PHPSESSID"
6666
bool(true)
6767
string(9) "PHPSESSID"
6868

69-
Warning: session_name(): session.name "" cannot be empty in %s on line %d
69+
Warning: session_name(): session.name "" must not be empty in %s on line %d
7070
string(9) "PHPSESSID"
7171
bool(true)
7272
string(9) "PHPSESSID"

0 commit comments

Comments
 (0)