Skip to content

Commit 71096cd

Browse files
committed
ext/session: use zend_strings for open handler
1 parent ba17532 commit 71096cd

6 files changed

Lines changed: 22 additions & 17 deletions

File tree

UPGRADING.INTERNALS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ PHP 8.6 INTERNALS UPGRADE NOTES
100100
- ext/session:
101101
. php_session_flush() now returns a bool rather than a zend_result.
102102
. Removed session_adapt_url().
103+
. PS_OPEN_ARGS is now defined as
104+
`void **mod_data, zend_string *save_path, zend_string *session_name`
105+
rather than
106+
`void **mod_data, const char *save_path, const char *session_name`
103107

104108
- ext/standard:
105109
. _php_error_log() now has a formal return type of zend_result.

ext/session/mod_files.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,19 +369,22 @@ PS_OPEN_FUNC(files)
369369
int argc = 0;
370370
size_t dirdepth = 0;
371371
int filemode = 0600;
372+
const char *used_save_path;
372373

373-
if (*save_path == '\0') {
374+
if (ZSTR_LEN(save_path) == 0) {
374375
/* if save path is an empty string, determine the temporary dir */
375-
save_path = php_get_temporary_directory();
376+
used_save_path = php_get_temporary_directory();
376377

377-
if (php_check_open_basedir(save_path)) {
378+
if (php_check_open_basedir(used_save_path)) {
378379
return FAILURE;
379380
}
381+
} else {
382+
used_save_path = ZSTR_VAL(save_path);
380383
}
381384

382385
/* split up input parameter */
383-
last = save_path;
384-
p = strchr(save_path, ';');
386+
last = used_save_path;
387+
p = strchr(used_save_path, ';');
385388
while (p) {
386389
argv[argc++] = last;
387390
last = ++p;
@@ -407,14 +410,14 @@ PS_OPEN_FUNC(files)
407410
return FAILURE;
408411
}
409412
}
410-
save_path = argv[argc - 1];
413+
used_save_path = argv[argc - 1];
411414

412415
data = ecalloc(1, sizeof(*data));
413416

414417
data->fd = -1;
415418
data->dirdepth = dirdepth;
416419
data->filemode = filemode;
417-
data->basedir = zend_string_init(save_path, strlen(save_path), /* persistent */ false);
420+
data->basedir = zend_string_init(used_save_path, strlen(used_save_path), /* persistent */ false);
418421

419422
if (PS_GET_MOD_DATA()) {
420423
ps_close_files(mod_data);

ext/session/mod_user.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,11 @@ PS_OPEN_FUNC(user)
8383
{
8484
zval args[2];
8585
zval retval;
86-
zend_result ret = FAILURE;
8786

8887
ZEND_ASSERT(!Z_ISUNDEF(PSF(open)));
8988

90-
ZVAL_STRING(&args[0], (char*)save_path);
91-
ZVAL_STRING(&args[1], (char*)session_name);
89+
ZVAL_STR(&args[0], zend_string_dup(save_path, false));
90+
ZVAL_STR(&args[1], zend_string_dup(session_name, false));
9291

9392
zend_try {
9493
ps_call_handler(&PSF(open), 2, args, &retval);
@@ -102,7 +101,7 @@ PS_OPEN_FUNC(user)
102101

103102
PS(mod_user_implemented) = true;
104103

105-
ret = verify_bool_return_type_userland_calls(&retval);
104+
zend_result ret = verify_bool_return_type_userland_calls(&retval);
106105
zval_ptr_dtor(&retval);
107106
return ret;
108107
}

ext/session/mod_user_class.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@
3636

3737
PHP_METHOD(SessionHandler, open)
3838
{
39-
char *save_path = NULL, *session_name = NULL;
40-
size_t save_path_len, session_name_len;
39+
zend_string *save_path, *session_name;
4140
zend_result ret;
4241

43-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &save_path, &save_path_len, &session_name, &session_name_len) == FAILURE) {
42+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &save_path, &session_name) == FAILURE) {
4443
RETURN_THROWS();
4544
}
4645

ext/session/php_session.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define PHP_SESSION_VERSION PHP_VERSION
2727

2828
/* save handler macros */
29-
#define PS_OPEN_ARGS void **mod_data, const char *save_path, const char *session_name
29+
#define PS_OPEN_ARGS void **mod_data, zend_string *save_path, zend_string *session_name
3030
#define PS_CLOSE_ARGS void **mod_data
3131
#define PS_READ_ARGS void **mod_data, zend_string *key, zend_string **val, zend_long maxlifetime
3232
#define PS_WRITE_ARGS void **mod_data, zend_string *key, zend_string *val, zend_long maxlifetime

ext/session/session.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ static zend_result php_session_initialize(void)
424424
}
425425

426426
/* Open session handler first */
427-
if (PS(mod)->s_open(&PS(mod_data), ZSTR_VAL(PS(save_path)), ZSTR_VAL(PS(session_name))) == FAILURE
427+
if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE
428428
/* || PS(mod_data) == NULL */ /* FIXME: open must set valid PS(mod_data) with success */
429429
) {
430430
php_session_abort();
@@ -2351,7 +2351,7 @@ PHP_FUNCTION(session_regenerate_id)
23512351
zend_string_release_ex(PS(id), false);
23522352
PS(id) = NULL;
23532353

2354-
if (PS(mod)->s_open(&PS(mod_data), ZSTR_VAL(PS(save_path)), ZSTR_VAL(PS(session_name))) == FAILURE) {
2354+
if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE) {
23552355
PS(session_status) = php_session_none;
23562356
if (!EG(exception)) {
23572357
zend_throw_error(NULL, "Failed to open session: %s (path: %s)", PS(mod)->s_name, ZSTR_VAL(PS(save_path)));

0 commit comments

Comments
 (0)