Skip to content

Commit eaee504

Browse files
committed
ext/session: Concert save_path to zstr
1 parent 9c68853 commit eaee504

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

ext/session/php_session.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ typedef struct _php_session_rfc1867_progress {
139139
} php_session_rfc1867_progress;
140140

141141
typedef struct _php_ps_globals {
142-
char *save_path;
142+
zend_string *save_path;
143143
char *session_name;
144144
zend_string *id;
145145
char *extern_referer_chk;

ext/session/session.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,12 @@ static zend_result php_session_initialize(void)
425425
}
426426

427427
/* Open session handler first */
428-
if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE
428+
if (PS(mod)->s_open(&PS(mod_data), ZSTR_VAL(PS(save_path)), PS(session_name)) == FAILURE
429429
/* || PS(mod_data) == NULL */ /* FIXME: open must set valid PS(mod_data) with success */
430430
) {
431431
php_session_abort();
432432
if (!EG(exception)) {
433-
php_error_docref(NULL, E_WARNING, "Failed to initialize storage module: %s (path: %s)", PS(mod)->s_name, PS(save_path));
433+
php_error_docref(NULL, E_WARNING, "Failed to initialize storage module: %s (path: %s)", PS(mod)->s_name, ZSTR_VAL(PS(save_path)));
434434
}
435435
return FAILURE;
436436
}
@@ -444,7 +444,7 @@ static zend_result php_session_initialize(void)
444444
if (!PS(id)) {
445445
php_session_abort();
446446
if (!EG(exception)) {
447-
zend_throw_error(NULL, "Failed to create session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
447+
zend_throw_error(NULL, "Failed to create session ID: %s (path: %s)", PS(mod)->s_name, ZSTR_VAL(PS(save_path)));
448448
}
449449
return FAILURE;
450450
}
@@ -477,7 +477,7 @@ static zend_result php_session_initialize(void)
477477
php_session_abort();
478478
/* FYI: Some broken save handlers return FAILURE for non-existent session ID, this is incorrect */
479479
if (!EG(exception)) {
480-
php_error_docref(NULL, E_WARNING, "Failed to read session data: %s (path: %s)", PS(mod)->s_name, PS(save_path));
480+
php_error_docref(NULL, E_WARNING, "Failed to read session data: %s (path: %s)", PS(mod)->s_name, ZSTR_VAL(PS(save_path)));
481481
}
482482
return FAILURE;
483483
}
@@ -544,14 +544,14 @@ static void php_session_save_current_state(int write)
544544
"verify that the current setting of session.save_path "
545545
"is correct (%s)",
546546
PS(mod)->s_name,
547-
PS(save_path));
547+
ZSTR_VAL(PS(save_path)));
548548
} else if (handler_class_name != NULL) {
549549
php_error_docref(NULL, E_WARNING, "Failed to write session data using user "
550-
"defined save handler. (session.save_path: %s, handler: %s::%s)", PS(save_path),
550+
"defined save handler. (session.save_path: %s, handler: %s::%s)", ZSTR_VAL(PS(save_path)),
551551
ZSTR_VAL(handler_class_name), handler_function_name);
552552
} else {
553553
php_error_docref(NULL, E_WARNING, "Failed to write session data using user "
554-
"defined save handler. (session.save_path: %s, handler: %s)", PS(save_path),
554+
"defined save handler. (session.save_path: %s, handler: %s)", ZSTR_VAL(PS(save_path)),
555555
handler_function_name);
556556
}
557557
}
@@ -675,7 +675,7 @@ static PHP_INI_MH(OnUpdateSaveDir)
675675
}
676676
}
677677

678-
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
678+
return OnUpdateStr(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
679679
}
680680

681681

@@ -2218,7 +2218,6 @@ PHP_FUNCTION(session_set_save_handler)
22182218
PHP_FUNCTION(session_save_path)
22192219
{
22202220
zend_string *name = NULL;
2221-
zend_string *ini_name;
22222221

22232222
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|P!", &name) == FAILURE) {
22242223
RETURN_THROWS();
@@ -2234,12 +2233,12 @@ PHP_FUNCTION(session_save_path)
22342233
RETURN_FALSE;
22352234
}
22362235

2237-
RETVAL_STRING(PS(save_path));
2236+
RETVAL_STRINGL(ZSTR_VAL(PS(save_path)), ZSTR_LEN(PS(save_path)));
22382237

22392238
if (name) {
2240-
ini_name = ZSTR_INIT_LITERAL("session.save_path", 0);
2239+
zend_string *ini_name = ZSTR_INIT_LITERAL("session.save_path", false);
22412240
zend_alter_ini_entry(ini_name, name, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
2242-
zend_string_release_ex(ini_name, 0);
2241+
zend_string_release_ex(ini_name, false);
22432242
}
22442243
}
22452244

@@ -2309,7 +2308,7 @@ PHP_FUNCTION(session_regenerate_id)
23092308
PS(mod)->s_close(&PS(mod_data));
23102309
PS(session_status) = php_session_none;
23112310
if (!EG(exception)) {
2312-
php_error_docref(NULL, E_WARNING, "Session object destruction failed. ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2311+
php_error_docref(NULL, E_WARNING, "Session object destruction failed. ID: %s (path: %s)", PS(mod)->s_name, ZSTR_VAL(PS(save_path)));
23132312
}
23142313
RETURN_FALSE;
23152314
}
@@ -2325,7 +2324,7 @@ PHP_FUNCTION(session_regenerate_id)
23252324
if (ret == FAILURE) {
23262325
PS(mod)->s_close(&PS(mod_data));
23272326
PS(session_status) = php_session_none;
2328-
php_error_docref(NULL, E_WARNING, "Session write failed. ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2327+
php_error_docref(NULL, E_WARNING, "Session write failed. ID: %s (path: %s)", PS(mod)->s_name, ZSTR_VAL(PS(save_path)));
23292328
RETURN_FALSE;
23302329
}
23312330
}
@@ -2339,10 +2338,10 @@ PHP_FUNCTION(session_regenerate_id)
23392338
zend_string_release_ex(PS(id), 0);
23402339
PS(id) = NULL;
23412340

2342-
if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE) {
2341+
if (PS(mod)->s_open(&PS(mod_data), ZSTR_VAL(PS(save_path)), PS(session_name)) == FAILURE) {
23432342
PS(session_status) = php_session_none;
23442343
if (!EG(exception)) {
2345-
zend_throw_error(NULL, "Failed to open session: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2344+
zend_throw_error(NULL, "Failed to open session: %s (path: %s)", PS(mod)->s_name, ZSTR_VAL(PS(save_path)));
23462345
}
23472346
RETURN_THROWS();
23482347
}
@@ -2351,7 +2350,7 @@ PHP_FUNCTION(session_regenerate_id)
23512350
if (!PS(id)) {
23522351
PS(session_status) = php_session_none;
23532352
if (!EG(exception)) {
2354-
zend_throw_error(NULL, "Failed to create new session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2353+
zend_throw_error(NULL, "Failed to create new session ID: %s (path: %s)", PS(mod)->s_name, ZSTR_VAL(PS(save_path)));
23552354
}
23562355
RETURN_THROWS();
23572356
}
@@ -2366,7 +2365,7 @@ PHP_FUNCTION(session_regenerate_id)
23662365
PS(mod)->s_close(&PS(mod_data));
23672366
PS(session_status) = php_session_none;
23682367
if (!EG(exception)) {
2369-
zend_throw_error(NULL, "Failed to create session ID by collision: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2368+
zend_throw_error(NULL, "Failed to create session ID by collision: %s (path: %s)", PS(mod)->s_name, ZSTR_VAL(PS(save_path)));
23702369
}
23712370
RETURN_THROWS();
23722371
}
@@ -2379,7 +2378,7 @@ PHP_FUNCTION(session_regenerate_id)
23792378
PS(mod)->s_close(&PS(mod_data));
23802379
PS(session_status) = php_session_none;
23812380
if (!EG(exception)) {
2382-
zend_throw_error(NULL, "Failed to create(read) session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2381+
zend_throw_error(NULL, "Failed to create(read) session ID: %s (path: %s)", PS(mod)->s_name, ZSTR_VAL(PS(save_path)));
23832382
}
23842383
RETURN_THROWS();
23852384
}

0 commit comments

Comments
 (0)