Skip to content

Commit f8e1d98

Browse files
committed
Clean up ext/session errors
1 parent e9b47df commit f8e1d98

16 files changed

+132
-154
lines changed

ext/session/mod_files.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ static void ps_files_open(ps_files *data, const char *key)
168168
ps_files_close(data);
169169

170170
if (php_session_valid_key(key) == FAILURE) {
171-
php_error_docref(NULL, E_WARNING, "The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,'");
171+
php_error_docref(NULL, E_WARNING, "The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and \"-\"");
172172
return;
173173
}
174174

175175
if (!ps_files_path_create(buf, sizeof(buf), data, key)) {
176-
php_error_docref(NULL, E_WARNING, "Failed to create session data file path. Too short session ID, invalid save_path or path lentgth exceeds MAXPATHLEN(%d)", MAXPATHLEN);
176+
php_error_docref(NULL, E_WARNING, "Failed to create session data file path. Too short session ID, invalid save_path or path length exceeds MAXPATHLEN(%d)", MAXPATHLEN);
177177
return;
178178
}
179179

ext/session/mod_user.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ static void ps_call_handler(zval *func, int argc, zval *argv, zval *retval)
6565
ret = SUCCESS; \
6666
} else { \
6767
if (!EG(exception)) { \
68-
php_error_docref(NULL, E_WARNING, \
69-
"Session callback expects true/false return value"); \
68+
php_error_docref(NULL, E_WARNING, "Session callback expects a boolean return value"); \
7069
} \
7170
ret = FAILURE; \
7271
zval_ptr_dtor(&retval); \
@@ -80,8 +79,7 @@ PS_OPEN_FUNC(user)
8079
STDVARS;
8180

8281
if (Z_ISUNDEF(PSF(open))) {
83-
php_error_docref(NULL, E_WARNING,
84-
"user session functions not defined");
82+
php_error_docref(NULL, E_WARNING, "User session functions not defined");
8583

8684
return FAILURE;
8785
}

ext/session/php_session.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ PHPAPI int php_session_reset_id(void);
291291
HashTable *_ht = Z_ARRVAL_P(Z_REFVAL(PS(http_session_vars))); \
292292
ZEND_HASH_FOREACH_KEY(_ht, num_key, key) { \
293293
if (key == NULL) { \
294-
php_error_docref(NULL, E_NOTICE, \
294+
php_error_docref(NULL, E_WARNING, \
295295
"Skipping numeric key " ZEND_LONG_FMT, num_key);\
296296
continue; \
297297
} \

ext/session/session.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -1506,15 +1506,15 @@ PHPAPI int php_session_start(void) /* {{{ */
15061506
if (!PS(mod) && value) {
15071507
PS(mod) = _php_find_ps_module(value);
15081508
if (!PS(mod)) {
1509-
php_error_docref(NULL, E_WARNING, "Cannot find save handler '%s' - session startup failed", value);
1509+
php_error_docref(NULL, E_WARNING, "Cannot find save handler \"%s\" - session startup failed", value);
15101510
return FAILURE;
15111511
}
15121512
}
15131513
value = zend_ini_string("session.serialize_handler", sizeof("session.serialize_handler") - 1, 0);
15141514
if (!PS(serializer) && value) {
15151515
PS(serializer) = _php_find_ps_serializer(value);
15161516
if (!PS(serializer)) {
1517-
php_error_docref(NULL, E_WARNING, "Cannot find serialization handler '%s' - session startup failed", value);
1517+
php_error_docref(NULL, E_WARNING, "Cannot find serialization handler \"%s\" - session startup failed", value);
15181518
return FAILURE;
15191519
}
15201520
}
@@ -1733,7 +1733,7 @@ PHP_FUNCTION(session_set_cookie_params)
17331733
samesite = zval_get_string(value);
17341734
found++;
17351735
} else {
1736-
php_error_docref(NULL, E_WARNING, "Unrecognized key '%s' found in the options array", ZSTR_VAL(key));
1736+
php_error_docref(NULL, E_WARNING, "Unrecognized key \"%s\" found in the options array", ZSTR_VAL(key));
17371737
}
17381738
} else {
17391739
php_error_docref(NULL, E_WARNING, "Numeric key found in the options array");
@@ -2062,9 +2062,9 @@ PHP_FUNCTION(session_set_save_handler)
20622062
for (i = 0; i < argc; i++) {
20632063
if (!zend_is_callable(&args[i], 0, NULL)) {
20642064
zend_string *name = zend_get_callable_name(&args[i]);
2065-
php_error_docref(NULL, E_WARNING, "Argument %d is not a valid callback", i+1);
2066-
zend_string_release_ex(name, 0);
2067-
RETURN_FALSE;
2065+
zend_argument_type_error(i + 1, "must be a valid callback, function \"%s\" not found or invalid function name", ZSTR_VAL(name));
2066+
zend_string_release(name);
2067+
RETURN_THROWS();
20682068
}
20692069
}
20702070

@@ -2274,7 +2274,7 @@ PHP_FUNCTION(session_create_id)
22742274
if (prefix && ZSTR_LEN(prefix)) {
22752275
if (php_session_valid_key(ZSTR_VAL(prefix)) == FAILURE) {
22762276
/* E_ERROR raised for security reason. */
2277-
php_error_docref(NULL, E_WARNING, "Prefix cannot contain special characters. Only aphanumeric, ',', '-' are allowed");
2277+
php_error_docref(NULL, E_WARNING, "Prefix cannot contain special characters. Only aphanumeric, \",\", \"-\" are allowed");
22782278
RETURN_FALSE;
22792279
} else {
22802280
smart_str_append(&id, prefix);
@@ -2470,7 +2470,7 @@ PHP_FUNCTION(session_start)
24702470
zend_string *tmp_val;
24712471
zend_string *val = zval_get_tmp_string(value, &tmp_val);
24722472
if (php_session_start_set_ini(str_idx, val) == FAILURE) {
2473-
php_error_docref(NULL, E_WARNING, "Setting option '%s' failed", ZSTR_VAL(str_idx));
2473+
php_error_docref(NULL, E_WARNING, "Setting option \"%s\" failed", ZSTR_VAL(str_idx));
24742474
}
24752475
zend_tmp_string_release(tmp_val);
24762476
}

ext/session/session.stub.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,8 @@ function session_commit(): bool {}
4242
/**
4343
* @param callable|object $open
4444
* @param callable|bool $close
45-
* @param callable $read
46-
* @param callable $write
47-
* @param callable $destroy
48-
* @param callable $gc
49-
* @param callable $create_sid
50-
* @param callable $validate_sid
51-
* @param callable $update_timestamp
5245
*/
53-
function session_set_save_handler($open, $close = UNKNOWN, $read = UNKNOWN, $write = UNKNOWN, $destroy = UNKNOWN, $gc = UNKNOWN, $create_sid = UNKNOWN, $validate_sid = UNKNOWN, $update_timestamp = UNKNOWN): bool {}
46+
function session_set_save_handler($open, $close = UNKNOWN, callable $read = UNKNOWN, callable $write = UNKNOWN, callable $destroy = UNKNOWN, callable $gc = UNKNOWN, callable $create_sid = UNKNOWN, callable $validate_sid = UNKNOWN, callable $update_timestamp = UNKNOWN): bool {}
5447

5548
function session_cache_limiter(?string $cache_limiter = null): string|false {}
5649

ext/session/session_arginfo.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 9e4a4b1d719197772b283abfb1e515180d7b8bb0 */
2+
* Stub hash: 22b829d3cdd092c393c924f323cd19bea1517579 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_session_name, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 1, "null")
@@ -60,13 +60,13 @@ ZEND_END_ARG_INFO()
6060
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_session_set_save_handler, 0, 1, _IS_BOOL, 0)
6161
ZEND_ARG_INFO(0, open)
6262
ZEND_ARG_INFO(0, close)
63-
ZEND_ARG_INFO(0, read)
64-
ZEND_ARG_INFO(0, write)
65-
ZEND_ARG_INFO(0, destroy)
66-
ZEND_ARG_INFO(0, gc)
67-
ZEND_ARG_INFO(0, create_sid)
68-
ZEND_ARG_INFO(0, validate_sid)
69-
ZEND_ARG_INFO(0, update_timestamp)
63+
ZEND_ARG_TYPE_INFO(0, read, IS_CALLABLE, 0)
64+
ZEND_ARG_TYPE_INFO(0, write, IS_CALLABLE, 0)
65+
ZEND_ARG_TYPE_INFO(0, destroy, IS_CALLABLE, 0)
66+
ZEND_ARG_TYPE_INFO(0, gc, IS_CALLABLE, 0)
67+
ZEND_ARG_TYPE_INFO(0, create_sid, IS_CALLABLE, 0)
68+
ZEND_ARG_TYPE_INFO(0, validate_sid, IS_CALLABLE, 0)
69+
ZEND_ARG_TYPE_INFO(0, update_timestamp, IS_CALLABLE, 0)
7070
ZEND_END_ARG_INFO()
7171

7272
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_session_cache_limiter, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)

ext/session/tests/016.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ session_write_close();
2222
print "I live\n";
2323
?>
2424
--EXPECTF--
25-
Warning: session_start(): Failed to create session data file path. Too short session ID, invalid save_path or path lentgth exceeds MAXPATHLEN(%d) in %s on line 4
25+
Warning: session_start(): Failed to create session data file path. Too short session ID, invalid save_path or path length exceeds MAXPATHLEN(%d) in %s on line %d
2626

2727
Warning: session_start(): Failed to read session data: files (path: 123;:/really%scompletely:::/invalid;;,23123;213) in %s on line 4
2828
I live

ext/session/tests/bug31454.phpt

+14-9
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@ Bug #31454 (session_set_save_handler crashes PHP when supplied non-existent obje
55
--FILE--
66
<?php
77

8-
session_set_save_handler(
9-
array(&$arf, 'open'),
10-
array(&$arf, 'close'),
11-
array(&$arf, 'read'),
12-
array(&$arf, 'write'),
13-
array(&$arf, 'destroy'),
14-
array(&$arf, 'gc'));
8+
try {
9+
session_set_save_handler(
10+
array(&$arf, 'open'),
11+
array(&$arf, 'close'),
12+
array(&$arf, 'read'),
13+
array(&$arf, 'write'),
14+
array(&$arf, 'destroy'),
15+
array(&$arf, 'gc')
16+
);
17+
} catch (TypeError $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
1520

1621
echo "Done\n";
1722
?>
18-
--EXPECTF--
19-
Warning: session_set_save_handler(): Argument 1 is not a valid callback in %sbug31454.php on line %d
23+
--EXPECT--
24+
session_set_save_handler(): Argument #1 ($open) must be a valid callback, function "Array" not found or invalid function name
2025
Done

ext/session/tests/rfc1867_sid_invalid.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ var_dump($_SESSION["upload_progress_" . basename(__FILE__)]);
4646
session_destroy();
4747
?>
4848
--EXPECTF--
49-
Warning: Unknown: The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0
49+
Warning: Unknown: The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and "-" in Unknown on line 0
5050

5151
Warning: Unknown: Failed to read session data: files (path: ) in Unknown on line 0
5252

5353
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0
5454

55-
Warning: Unknown: The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0
55+
Warning: Unknown: The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and "-" in Unknown on line 0
5656

5757
Warning: Unknown: Failed to read session data: files (path: ) in Unknown on line 0
5858

ext/session/tests/session_decode_variation3.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ob_end_flush();
2828
--EXPECTF--
2929
*** Testing session_decode() : variation ***
3030

31-
Warning: session_start(): Cannot find serialization handler 'blah' - session startup failed in %s on line %d
31+
Warning: session_start(): Cannot find serialization handler "blah" - session startup failed in %s on line %d
3232
bool(false)
3333

3434
Warning: Undefined variable $_SESSION in %s on line %d

ext/session/tests/session_encode_error2.phpt

+14-14
Original file line numberDiff line numberDiff line change
@@ -98,63 +98,63 @@ ob_end_flush();
9898
-- Iteration 1 --
9999
bool(true)
100100

101-
Notice: session_encode(): Skipping numeric key 0 in %s on line %d
101+
Warning: session_encode(): Skipping numeric key 0 in %s on line %d
102102
bool(false)
103103
bool(true)
104104

105105
-- Iteration 2 --
106106
bool(true)
107107

108-
Notice: session_encode(): Skipping numeric key 1 in %s on line %d
108+
Warning: session_encode(): Skipping numeric key 1 in %s on line %d
109109
bool(false)
110110
bool(true)
111111

112112
-- Iteration 3 --
113113
bool(true)
114114

115-
Notice: session_encode(): Skipping numeric key 12345 in %s on line %d
115+
Warning: session_encode(): Skipping numeric key 12345 in %s on line %d
116116
bool(false)
117117
bool(true)
118118

119119
-- Iteration 4 --
120120
bool(true)
121121

122-
Notice: session_encode(): Skipping numeric key -2345 in %s on line %d
122+
Warning: session_encode(): Skipping numeric key -2345 in %s on line %d
123123
bool(false)
124124
bool(true)
125125

126126
-- Iteration 5 --
127127
bool(true)
128128

129-
Notice: session_encode(): Skipping numeric key 10 in %s on line %d
129+
Warning: session_encode(): Skipping numeric key 10 in %s on line %d
130130
bool(false)
131131
bool(true)
132132

133133
-- Iteration 6 --
134134
bool(true)
135135

136-
Notice: session_encode(): Skipping numeric key -10 in %s on line %d
136+
Warning: session_encode(): Skipping numeric key -10 in %s on line %d
137137
bool(false)
138138
bool(true)
139139

140140
-- Iteration 7 --
141141
bool(true)
142142

143-
Notice: session_encode(): Skipping numeric key %s in %s on line %d
143+
Warning: session_encode(): Skipping numeric key 123456789000 in %s on line %d
144144
bool(false)
145145
bool(true)
146146

147147
-- Iteration 8 --
148148
bool(true)
149149

150-
Notice: session_encode(): Skipping numeric key 0 in %s on line %d
150+
Warning: session_encode(): Skipping numeric key 0 in %s on line %d
151151
bool(false)
152152
bool(true)
153153

154154
-- Iteration 9 --
155155
bool(true)
156156

157-
Notice: session_encode(): Skipping numeric key 0 in %s on line %d
157+
Warning: session_encode(): Skipping numeric key 0 in %s on line %d
158158
bool(false)
159159
bool(true)
160160

@@ -171,28 +171,28 @@ bool(true)
171171
-- Iteration 12 --
172172
bool(true)
173173

174-
Notice: session_encode(): Skipping numeric key 1 in %s on line %d
174+
Warning: session_encode(): Skipping numeric key 1 in %s on line %d
175175
bool(false)
176176
bool(true)
177177

178178
-- Iteration 13 --
179179
bool(true)
180180

181-
Notice: session_encode(): Skipping numeric key 0 in %s on line %d
181+
Warning: session_encode(): Skipping numeric key 0 in %s on line %d
182182
bool(false)
183183
bool(true)
184184

185185
-- Iteration 14 --
186186
bool(true)
187187

188-
Notice: session_encode(): Skipping numeric key 1 in %s on line %d
188+
Warning: session_encode(): Skipping numeric key 1 in %s on line %d
189189
bool(false)
190190
bool(true)
191191

192192
-- Iteration 15 --
193193
bool(true)
194194

195-
Notice: session_encode(): Skipping numeric key 0 in %s on line %d
195+
Warning: session_encode(): Skipping numeric key 0 in %s on line %d
196196
bool(false)
197197
bool(true)
198198

@@ -242,7 +242,7 @@ bool(true)
242242

243243
Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
244244

245-
Notice: session_encode(): Skipping numeric key %d in %s on line %d
245+
Warning: session_encode(): Skipping numeric key %d in %s on line %d
246246
bool(false)
247247
bool(true)
248248
Done

ext/session/tests/session_encode_variation6.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ ob_end_flush();
2929
*** Testing session_encode() : variation ***
3030
bool(true)
3131

32-
Notice: session_encode(): Skipping numeric key 0 in %s on line %d
32+
Warning: session_encode(): Skipping numeric key 0 in %s on line %d
3333
bool(false)
3434
bool(true)
3535
bool(true)
3636

37-
Notice: session_encode(): Skipping numeric key 1234567890 in %s on line %d
37+
Warning: session_encode(): Skipping numeric key 1234567890 in %s on line %d
3838
bool(false)
3939
bool(true)
4040
bool(true)
4141

42-
Notice: session_encode(): Skipping numeric key -1234567890 in %s on line %d
42+
Warning: session_encode(): Skipping numeric key -1234567890 in %s on line %d
4343
bool(false)
4444
bool(true)
4545
Done

ext/session/tests/session_encode_variation8.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ob_end_flush();
2323
--EXPECTF--
2424
*** Testing session_encode() : variation ***
2525

26-
Warning: session_start(): Cannot find serialization handler 'blah' - session startup failed in %s on line %d
26+
Warning: session_start(): Cannot find serialization handler "blah" - session startup failed in %s on line %d
2727
bool(false)
2828

2929
Warning: session_encode(): Cannot encode non-existent session in %s on line %d

ext/session/tests/session_set_cookie_params_variation7.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ ob_end_flush();
4343
Warning: session_set_cookie_params(): No valid keys were found in the options array in %s
4444
bool(false)
4545

46-
Warning: session_set_cookie_params(): Unrecognized key 'unknown_key' found in the options array in %s
46+
Warning: session_set_cookie_params(): Unrecognized key "unknown_key" found in the options array in %s on line %d
4747

48-
Warning: session_set_cookie_params(): Unrecognized key 'secure_invalid' found in the options array in %s
48+
Warning: session_set_cookie_params(): Unrecognized key "secure_invalid" found in the options array in %s on line %d
4949

5050
Warning: session_set_cookie_params(): No valid keys were found in the options array in %s
5151
bool(false)

0 commit comments

Comments
 (0)