Skip to content

Commit 814ade8

Browse files
authored
session: clean-up code relating to calling user functions (#23909)
1 parent 398dde5 commit 814ade8

1 file changed

Lines changed: 26 additions & 44 deletions

File tree

‎ext/session/mod_user.c‎

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ const ps_module ps_mod_user = {
2222
PS_MOD_UPDATE_TIMESTAMP(user)
2323
};
2424

25-
static void ps_call_handler(zval *func, int argc, zval *argv, zval *retval)
25+
static void ps_call_handler(zval *func, uint32_t argc, zval *argv, zval *retval)
2626
{
27-
int i;
2827
if (PS(in_save_handler)) {
2928
PS(in_save_handler) = false;
3029
ZVAL_UNDEF(retval);
@@ -34,12 +33,10 @@ static void ps_call_handler(zval *func, int argc, zval *argv, zval *retval)
3433
if (call_user_function(NULL, NULL, func, retval, argc, argv) == FAILURE) {
3534
zval_ptr_dtor(retval);
3635
ZVAL_UNDEF(retval);
37-
} else if (Z_ISUNDEF_P(retval)) {
38-
ZVAL_NULL(retval);
3936
}
4037
PS(in_save_handler) = false;
4138
}
42-
for (i = 0; i < argc; i++) {
39+
for (uint32_t i = 0; i < argc; i++) {
4340
zval_ptr_dtor(&argv[i]);
4441
}
4542
}
@@ -48,34 +45,27 @@ static void ps_call_handler(zval *func, int argc, zval *argv, zval *retval)
4845

4946
static zend_result verify_bool_return_type_userland_calls(const zval *value)
5047
{
51-
/* Exit or exception in userland call */
52-
if (Z_TYPE_P(value) == IS_UNDEF) {
53-
return FAILURE;
54-
}
55-
if (Z_TYPE_P(value) == IS_TRUE) {
56-
return SUCCESS;
57-
}
58-
if (Z_TYPE_P(value) == IS_FALSE) {
59-
return FAILURE;
60-
}
61-
if ((Z_TYPE_P(value) == IS_LONG) && (Z_LVAL_P(value) == -1)) {
62-
/* TODO Why are exceptions checked? */
63-
if (!EG(exception)) {
64-
php_error_docref(NULL, E_DEPRECATED, "Session callback must have a return value of type bool, %s returned", zend_zval_value_name(value));
65-
}
66-
return FAILURE;
67-
}
68-
if ((Z_TYPE_P(value) == IS_LONG) && (Z_LVAL_P(value) == 0)) {
69-
/* TODO Why are exceptions checked? */
70-
if (!EG(exception)) {
71-
php_error_docref(NULL, E_DEPRECATED, "Session callback must have a return value of type bool, %s returned", zend_zval_value_name(value));
72-
}
73-
return SUCCESS;
74-
}
75-
if (!EG(exception)) {
76-
zend_type_error("Session callback must have a return value of type bool, %s returned", zend_zval_value_name(value)); \
48+
switch (Z_TYPE_P(value)) {
49+
case IS_TRUE:
50+
return SUCCESS;
51+
case IS_FALSE:
52+
/* Exit or exception in userland call */
53+
case IS_UNDEF:
54+
return FAILURE;
55+
case IS_LONG:
56+
/* Deprecated cases */
57+
if (Z_LVAL_P(value) == 0) {
58+
php_error_docref(NULL, E_DEPRECATED, "Session callback must have a return value of type bool, %s returned", zend_zval_value_name(value));
59+
return SUCCESS;
60+
} else if (Z_LVAL_P(value) == -1) {
61+
php_error_docref(NULL, E_DEPRECATED, "Session callback must have a return value of type bool, %s returned", zend_zval_value_name(value));
62+
return FAILURE;
63+
}
64+
ZEND_FALLTHROUGH;
65+
default:
66+
zend_type_error("Session callback must have a return value of type bool, %s returned", zend_zval_value_name(value));
67+
return FAILURE;
7768
}
78-
return FAILURE;
7969
}
8070

8171
PS_OPEN_FUNC(user)
@@ -92,9 +82,7 @@ PS_OPEN_FUNC(user)
9282
ps_call_handler(&PSF(open), 2, args, &retval);
9383
} zend_catch {
9484
PS(session_status) = php_session_none;
95-
if (!Z_ISUNDEF(retval)) {
96-
zval_ptr_dtor(&retval);
97-
}
85+
zval_ptr_dtor(&retval);
9886
zend_bailout();
9987
} zend_end_try();
10088

@@ -107,7 +95,6 @@ PS_OPEN_FUNC(user)
10795

10896
PS_CLOSE_FUNC(user)
10997
{
110-
bool bailout = false;
11198
zval retval;
11299
zend_result ret = FAILURE;
113100

@@ -121,18 +108,13 @@ PS_CLOSE_FUNC(user)
121108
zend_try {
122109
ps_call_handler(&PSF(close), 0, NULL, &retval);
123110
} zend_catch {
124-
bailout = true;
111+
PS(mod_user_implemented) = false;
112+
zval_ptr_dtor(&retval);
113+
zend_bailout();
125114
} zend_end_try();
126115

127116
PS(mod_user_implemented) = false;
128117

129-
if (bailout) {
130-
if (!Z_ISUNDEF(retval)) {
131-
zval_ptr_dtor(&retval);
132-
}
133-
zend_bailout();
134-
}
135-
136118
ret = verify_bool_return_type_userland_calls(&retval);
137119
zval_ptr_dtor(&retval);
138120
return ret;

0 commit comments

Comments
 (0)