Skip to content

Commit ed19c52

Browse files
committed
Convert some Session globals from char* to zend_string*
However, the code is somewhat disgusting as I'm hitting Zend/zend_types.h:1222: zend_gc_delref: Assertion (zval_gc_flags((p)->u.type_info) & ((1<<7)|(1<<8))) != (1<<7) failed. Failures that I don't understand.
1 parent 9339833 commit ed19c52

File tree

2 files changed

+41
-26
lines changed

2 files changed

+41
-26
lines changed

ext/session/php_session.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ typedef struct _php_ps_globals {
143143
char *save_path;
144144
char *session_name;
145145
zend_string *id;
146-
char *extern_referer_chk;
147-
char *cache_limiter;
146+
zend_string *extern_referer_chk;
147+
zend_string *cache_limiter;
148148
zend_long cookie_lifetime;
149-
char *cookie_path;
150-
char *cookie_domain;
149+
zend_string *cookie_path;
150+
zend_string *cookie_domain;
151151
bool cookie_secure;
152152
bool cookie_httponly;
153-
char *cookie_samesite;
153+
zend_string *cookie_samesite;
154154
const ps_module *mod;
155155
const ps_module *default_mod;
156156
void *mod_data;

ext/session/session.c

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,14 @@ static PHP_INI_MH(OnUpdateSessionLong) /* {{{ */
708708
/* }}} */
709709

710710

711-
static PHP_INI_MH(OnUpdateSessionString) /* {{{ */
711+
static PHP_INI_MH(OnUpdateSessionStr) /* {{{ */
712712
{
713713
SESSION_CHECK_ACTIVE_STATE;
714714
SESSION_CHECK_OUTPUT_STATE;
715-
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
715+
716+
zend_string **p = (zend_string **) ZEND_INI_GET_ADDR();
717+
*p = new_value ? new_value : NULL;
718+
return SUCCESS;
716719
}
717720
/* }}} */
718721

@@ -807,16 +810,16 @@ PHP_INI_BEGIN()
807810
STD_PHP_INI_ENTRY("session.gc_maxlifetime", "1440", PHP_INI_ALL, OnUpdateSessionLong, gc_maxlifetime, php_ps_globals, ps_globals)
808811
PHP_INI_ENTRY("session.serialize_handler", "php", PHP_INI_ALL, OnUpdateSerializer)
809812
STD_PHP_INI_ENTRY("session.cookie_lifetime", "0", PHP_INI_ALL, OnUpdateCookieLifetime,cookie_lifetime, php_ps_globals, ps_globals)
810-
STD_PHP_INI_ENTRY("session.cookie_path", "/", PHP_INI_ALL, OnUpdateSessionString, cookie_path, php_ps_globals, ps_globals)
811-
STD_PHP_INI_ENTRY("session.cookie_domain", "", PHP_INI_ALL, OnUpdateSessionString, cookie_domain, php_ps_globals, ps_globals)
813+
STD_PHP_INI_ENTRY("session.cookie_path", "/", PHP_INI_ALL, OnUpdateSessionStr, cookie_path, php_ps_globals, ps_globals)
814+
STD_PHP_INI_ENTRY("session.cookie_domain", "", PHP_INI_ALL, OnUpdateSessionStr, cookie_domain, php_ps_globals, ps_globals)
812815
STD_PHP_INI_ENTRY("session.cookie_secure", "0", PHP_INI_ALL, OnUpdateSessionBool, cookie_secure, php_ps_globals, ps_globals)
813816
STD_PHP_INI_ENTRY("session.cookie_httponly", "0", PHP_INI_ALL, OnUpdateSessionBool, cookie_httponly, php_ps_globals, ps_globals)
814-
STD_PHP_INI_ENTRY("session.cookie_samesite", "", PHP_INI_ALL, OnUpdateSessionString, cookie_samesite, php_ps_globals, ps_globals)
817+
STD_PHP_INI_ENTRY("session.cookie_samesite", "", PHP_INI_ALL, OnUpdateSessionStr, cookie_samesite, php_ps_globals, ps_globals)
815818
STD_PHP_INI_ENTRY("session.use_cookies", "1", PHP_INI_ALL, OnUpdateSessionBool, use_cookies, php_ps_globals, ps_globals)
816819
STD_PHP_INI_ENTRY("session.use_only_cookies", "1", PHP_INI_ALL, OnUpdateSessionBool, use_only_cookies, php_ps_globals, ps_globals)
817820
STD_PHP_INI_ENTRY("session.use_strict_mode", "0", PHP_INI_ALL, OnUpdateSessionBool, use_strict_mode, php_ps_globals, ps_globals)
818-
STD_PHP_INI_ENTRY("session.referer_check", "", PHP_INI_ALL, OnUpdateSessionString, extern_referer_chk, php_ps_globals, ps_globals)
819-
STD_PHP_INI_ENTRY("session.cache_limiter", "nocache", PHP_INI_ALL, OnUpdateSessionString, cache_limiter, php_ps_globals, ps_globals)
821+
STD_PHP_INI_ENTRY("session.referer_check", "", PHP_INI_ALL, OnUpdateSessionStr, extern_referer_chk, php_ps_globals, ps_globals)
822+
STD_PHP_INI_ENTRY("session.cache_limiter", "nocache", PHP_INI_ALL, OnUpdateSessionStr, cache_limiter, php_ps_globals, ps_globals)
820823
STD_PHP_INI_ENTRY("session.cache_expire", "180", PHP_INI_ALL, OnUpdateSessionLong, cache_expire, php_ps_globals, ps_globals)
821824
PHP_INI_ENTRY("session.use_trans_sid", "0", PHP_INI_ALL, OnUpdateTransSid)
822825
PHP_INI_ENTRY("session.sid_length", "32", PHP_INI_ALL, OnUpdateSidLength)
@@ -1229,7 +1232,7 @@ static int php_session_cache_limiter(void) /* {{{ */
12291232
{
12301233
const php_session_cache_limiter_t *lim;
12311234

1232-
if (PS(cache_limiter)[0] == '\0') return 0;
1235+
if (!PS(cache_limiter) || ZSTR_LEN(PS(cache_limiter)) == 0) return 0;
12331236
if (PS(session_status) != php_session_active) return -1;
12341237

12351238
if (SG(headers_sent)) {
@@ -1246,7 +1249,8 @@ static int php_session_cache_limiter(void) /* {{{ */
12461249
}
12471250

12481251
for (lim = php_session_cache_limiters; lim->name; lim++) {
1249-
if (!strcasecmp(lim->name, PS(cache_limiter))) {
1252+
// TODO Use zend_string_cmp API?
1253+
if (!strcasecmp(lim->name, ZSTR_VAL(PS(cache_limiter)))) {
12501254
lim->func();
12511255
return 0;
12521256
}
@@ -1355,14 +1359,14 @@ static zend_result php_session_send_cookie(void) /* {{{ */
13551359
}
13561360
}
13571361

1358-
if (PS(cookie_path)[0]) {
1362+
if (PS(cookie_path) && ZSTR_LEN(PS(cookie_path)) != 0) {
13591363
smart_str_appends(&ncookie, COOKIE_PATH);
1360-
smart_str_appends(&ncookie, PS(cookie_path));
1364+
smart_str_append(&ncookie, PS(cookie_path));
13611365
}
13621366

1363-
if (PS(cookie_domain)[0]) {
1367+
if (PS(cookie_domain) && ZSTR_LEN(PS(cookie_domain)) != 0) {
13641368
smart_str_appends(&ncookie, COOKIE_DOMAIN);
1365-
smart_str_appends(&ncookie, PS(cookie_domain));
1369+
smart_str_append(&ncookie, PS(cookie_domain));
13661370
}
13671371

13681372
if (PS(cookie_secure)) {
@@ -1373,9 +1377,9 @@ static zend_result php_session_send_cookie(void) /* {{{ */
13731377
smart_str_appends(&ncookie, COOKIE_HTTPONLY);
13741378
}
13751379

1376-
if (PS(cookie_samesite)[0]) {
1380+
if (PS(cookie_samesite) && ZSTR_LEN(PS(cookie_samesite)) != 0) {
13771381
smart_str_appends(&ncookie, COOKIE_SAMESITE);
1378-
smart_str_appends(&ncookie, PS(cookie_samesite));
1382+
smart_str_append(&ncookie, PS(cookie_samesite));
13791383
}
13801384

13811385
smart_str_0(&ncookie);
@@ -1593,12 +1597,12 @@ PHPAPI zend_result php_session_start(void) /* {{{ */
15931597
}
15941598
/* Check whether the current request was referred to by
15951599
* an external site which invalidates the previously found id. */
1596-
if (PS(id) && PS(extern_referer_chk)[0] != '\0' &&
1600+
if (PS(id) && PS(extern_referer_chk) && ZSTR_LEN(PS(extern_referer_chk)) != 0 &&
15971601
!Z_ISUNDEF(PG(http_globals)[TRACK_VARS_SERVER]) &&
15981602
(data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_REFERER", sizeof("HTTP_REFERER") - 1)) &&
15991603
Z_TYPE_P(data) == IS_STRING &&
16001604
Z_STRLEN_P(data) != 0 &&
1601-
strstr(Z_STRVAL_P(data), PS(extern_referer_chk)) == NULL
1605+
strstr(Z_STRVAL_P(data), ZSTR_VAL(PS(extern_referer_chk))) == NULL
16021606
) {
16031607
zend_string_release_ex(PS(id), 0);
16041608
PS(id) = NULL;
@@ -1856,11 +1860,15 @@ PHP_FUNCTION(session_get_cookie_params)
18561860
array_init(return_value);
18571861

18581862
add_assoc_long(return_value, "lifetime", PS(cookie_lifetime));
1859-
add_assoc_string(return_value, "path", PS(cookie_path));
1860-
add_assoc_string(return_value, "domain", PS(cookie_domain));
1863+
// TODO Use add_assoc_str() but figure out why it emits a
1864+
// Zend/zend_types.h:1222: zend_gc_delref: Assertion `(zval_gc_flags((p)->u.type_info) & ((1<<7)|(1<<8))) != (1<<7)' failed.
1865+
add_assoc_string(return_value, "path", ZSTR_VAL(PS(cookie_path)));
1866+
add_assoc_string(return_value, "domain", ZSTR_VAL(PS(cookie_domain)));
18611867
add_assoc_bool(return_value, "secure", PS(cookie_secure));
18621868
add_assoc_bool(return_value, "httponly", PS(cookie_httponly));
1863-
add_assoc_string(return_value, "samesite", PS(cookie_samesite));
1869+
// TODO Use add_assoc_str() but figure out why it emits a
1870+
// Zend/zend_types.h:1222: zend_gc_delref: Assertion `(zval_gc_flags((p)->u.type_info) & ((1<<7)|(1<<8))) != (1<<7)' failed.
1871+
add_assoc_string(return_value, "samesite", ZSTR_VAL(PS(cookie_samesite)));
18641872
}
18651873
/* }}} */
18661874

@@ -2385,7 +2393,14 @@ PHP_FUNCTION(session_cache_limiter)
23852393
RETURN_FALSE;
23862394
}
23872395

2388-
RETVAL_STRING(PS(cache_limiter));
2396+
// TODO use RETVAL_STR, this is crappy code is done to circumvent a
2397+
// Zend/zend_types.h:1222: zend_gc_delref: Assertion `(zval_gc_flags((p)->u.type_info) & ((1<<7)|(1<<8))) != (1<<7)' failed.
2398+
// that I don't understand... - Girgias
2399+
zend_string *result_str = PS(cache_limiter);
2400+
if (!result_str) {
2401+
result_str = zend_empty_string;
2402+
}
2403+
RETVAL_STRING(ZSTR_VAL(result_str));
23892404

23902405
if (limiter) {
23912406
ini_name = zend_string_init("session.cache_limiter", sizeof("session.cache_limiter") - 1, 0);

0 commit comments

Comments
 (0)