Skip to content

Commit 766ccc2

Browse files
committed
ext/session: Use zend_string for some session globals
1 parent f5166b3 commit 766ccc2

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

ext/session/php_session.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ typedef struct _php_ps_globals {
143143
zend_string *session_name;
144144
zend_string *id;
145145
char *extern_referer_chk;
146-
char *cache_limiter;
146+
zend_string *cache_limiter;
147147
zend_long cookie_lifetime;
148-
char *cookie_path;
149-
char *cookie_domain;
150-
char *cookie_samesite;
148+
zend_string *cookie_path;
149+
zend_string *cookie_domain;
150+
zend_string *cookie_samesite;
151151
bool cookie_secure;
152152
bool cookie_httponly;
153153
const ps_module *mod;

ext/session/session.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -738,11 +738,11 @@ static PHP_INI_MH(OnUpdateSessionLong)
738738
return OnUpdateLong(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
739739
}
740740

741-
static PHP_INI_MH(OnUpdateSessionString)
741+
static PHP_INI_MH(OnUpdateSessionStr)
742742
{
743743
SESSION_CHECK_ACTIVE_STATE;
744744
SESSION_CHECK_OUTPUT_STATE;
745-
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
745+
return OnUpdateStr(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
746746
}
747747

748748

@@ -897,16 +897,16 @@ PHP_INI_BEGIN()
897897
STD_PHP_INI_ENTRY("session.gc_maxlifetime", "1440", PHP_INI_ALL, OnUpdateSessionLong, gc_maxlifetime, php_ps_globals, ps_globals)
898898
PHP_INI_ENTRY("session.serialize_handler", "php", PHP_INI_ALL, OnUpdateSerializer)
899899
STD_PHP_INI_ENTRY("session.cookie_lifetime", "0", PHP_INI_ALL, OnUpdateCookieLifetime,cookie_lifetime, php_ps_globals, ps_globals)
900-
STD_PHP_INI_ENTRY("session.cookie_path", "/", PHP_INI_ALL, OnUpdateSessionString, cookie_path, php_ps_globals, ps_globals)
901-
STD_PHP_INI_ENTRY("session.cookie_domain", "", PHP_INI_ALL, OnUpdateSessionString, cookie_domain, php_ps_globals, ps_globals)
900+
STD_PHP_INI_ENTRY("session.cookie_path", "/", PHP_INI_ALL, OnUpdateSessionStr, cookie_path, php_ps_globals, ps_globals)
901+
STD_PHP_INI_ENTRY("session.cookie_domain", "", PHP_INI_ALL, OnUpdateSessionStr, cookie_domain, php_ps_globals, ps_globals)
902902
STD_PHP_INI_BOOLEAN("session.cookie_secure", "0", PHP_INI_ALL, OnUpdateSessionBool, cookie_secure, php_ps_globals, ps_globals)
903903
STD_PHP_INI_BOOLEAN("session.cookie_httponly", "0", PHP_INI_ALL, OnUpdateSessionBool, cookie_httponly, php_ps_globals, ps_globals)
904-
STD_PHP_INI_ENTRY("session.cookie_samesite", "", PHP_INI_ALL, OnUpdateSessionString, cookie_samesite, php_ps_globals, ps_globals)
904+
STD_PHP_INI_ENTRY("session.cookie_samesite", "", PHP_INI_ALL, OnUpdateSessionStr, cookie_samesite, php_ps_globals, ps_globals)
905905
STD_PHP_INI_BOOLEAN("session.use_cookies", "1", PHP_INI_ALL, OnUpdateSessionBool, use_cookies, php_ps_globals, ps_globals)
906906
STD_PHP_INI_BOOLEAN("session.use_only_cookies", "1", PHP_INI_ALL, OnUpdateUseOnlyCookies, use_only_cookies, php_ps_globals, ps_globals)
907907
STD_PHP_INI_BOOLEAN("session.use_strict_mode", "0", PHP_INI_ALL, OnUpdateSessionBool, use_strict_mode, php_ps_globals, ps_globals)
908908
STD_PHP_INI_ENTRY("session.referer_check", "", PHP_INI_ALL, OnUpdateRefererCheck, extern_referer_chk, php_ps_globals, ps_globals)
909-
STD_PHP_INI_ENTRY("session.cache_limiter", "nocache", PHP_INI_ALL, OnUpdateSessionString, cache_limiter, php_ps_globals, ps_globals)
909+
STD_PHP_INI_ENTRY("session.cache_limiter", "nocache", PHP_INI_ALL, OnUpdateSessionStr, cache_limiter, php_ps_globals, ps_globals)
910910
STD_PHP_INI_ENTRY("session.cache_expire", "180", PHP_INI_ALL, OnUpdateSessionLong, cache_expire, php_ps_globals, ps_globals)
911911
STD_PHP_INI_BOOLEAN("session.use_trans_sid", "0", PHP_INI_ALL, OnUpdateUseTransSid, use_trans_sid, php_ps_globals, ps_globals)
912912
PHP_INI_ENTRY("session.sid_length", "32", PHP_INI_ALL, OnUpdateSidLength)
@@ -1312,7 +1312,9 @@ static int php_session_cache_limiter(void)
13121312
{
13131313
const php_session_cache_limiter_t *lim;
13141314

1315-
if (PS(cache_limiter)[0] == '\0') return 0;
1315+
if (ZSTR_LEN(PS(cache_limiter)) == 0) {
1316+
return 0;
1317+
}
13161318
if (PS(session_status) != php_session_active) return -1;
13171319

13181320
if (SG(headers_sent)) {
@@ -1322,7 +1324,7 @@ static int php_session_cache_limiter(void)
13221324
}
13231325

13241326
for (lim = php_session_cache_limiters; lim->name; lim++) {
1325-
if (!strcasecmp(lim->name, PS(cache_limiter))) {
1327+
if (!strcasecmp(lim->name, ZSTR_VAL(PS(cache_limiter)))) {
13261328
lim->func();
13271329
return 0;
13281330
}
@@ -1418,14 +1420,14 @@ static zend_result php_session_send_cookie(void)
14181420
}
14191421
}
14201422

1421-
if (PS(cookie_path)[0]) {
1423+
if (ZSTR_LEN(PS(cookie_path))) {
14221424
smart_str_appends(&ncookie, COOKIE_PATH);
1423-
smart_str_appends(&ncookie, PS(cookie_path));
1425+
smart_str_append(&ncookie, PS(cookie_path));
14241426
}
14251427

1426-
if (PS(cookie_domain)[0]) {
1428+
if (ZSTR_LEN(PS(cookie_domain))) {
14271429
smart_str_appends(&ncookie, COOKIE_DOMAIN);
1428-
smart_str_appends(&ncookie, PS(cookie_domain));
1430+
smart_str_append(&ncookie, PS(cookie_domain));
14291431
}
14301432

14311433
if (PS(cookie_secure)) {
@@ -1436,9 +1438,9 @@ static zend_result php_session_send_cookie(void)
14361438
smart_str_appends(&ncookie, COOKIE_HTTPONLY);
14371439
}
14381440

1439-
if (PS(cookie_samesite)[0]) {
1441+
if (ZSTR_LEN(PS(cookie_samesite))) {
14401442
smart_str_appends(&ncookie, COOKIE_SAMESITE);
1441-
smart_str_appends(&ncookie, PS(cookie_samesite));
1443+
smart_str_append(&ncookie, PS(cookie_samesite));
14421444
}
14431445

14441446
smart_str_0(&ncookie);
@@ -1895,11 +1897,11 @@ PHP_FUNCTION(session_get_cookie_params)
18951897
array_init(return_value);
18961898

18971899
add_assoc_long(return_value, "lifetime", PS(cookie_lifetime));
1898-
add_assoc_string(return_value, "path", PS(cookie_path));
1899-
add_assoc_string(return_value, "domain", PS(cookie_domain));
1900+
add_assoc_str(return_value, "path", zend_string_dup(PS(cookie_path), false));
1901+
add_assoc_str(return_value, "domain", zend_string_dup(PS(cookie_domain), false));
19001902
add_assoc_bool(return_value, "secure", PS(cookie_secure));
19011903
add_assoc_bool(return_value, "httponly", PS(cookie_httponly));
1902-
add_assoc_string(return_value, "samesite", PS(cookie_samesite));
1904+
add_assoc_str(return_value, "samesite", zend_string_dup(PS(cookie_samesite), false));
19031905
}
19041906

19051907
/* Return the current session name. If new name is given, the session name is replaced with new name */
@@ -2463,7 +2465,7 @@ PHP_FUNCTION(session_cache_limiter)
24632465
RETURN_FALSE;
24642466
}
24652467

2466-
RETVAL_STRING(PS(cache_limiter));
2468+
RETVAL_STRINGL(ZSTR_VAL(PS(cache_limiter)), ZSTR_LEN(PS(cache_limiter)));
24672469

24682470
if (limiter) {
24692471
ini_name = ZSTR_INIT_LITERAL("session.cache_limiter", 0);

0 commit comments

Comments
 (0)