Skip to content

Commit f872972

Browse files
committed
Session: Use zend_string* consistently for key in mod_files
1 parent 4a5699a commit f872972

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

ext/session/mod_files.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,18 @@ const ps_module ps_mod_files = {
104104
};
105105

106106

107-
static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, const char *key)
107+
static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, const zend_string *key)
108108
{
109-
size_t key_len;
110109
const char *p;
111110
int i;
112111
size_t n;
113112

114-
key_len = strlen(key);
115-
if (!data || key_len <= data->dirdepth ||
116-
buflen < (strlen(data->basedir) + 2 * data->dirdepth + key_len + 5 + sizeof(FILE_PREFIX))) {
113+
if (!data || ZSTR_LEN(key) <= data->dirdepth ||
114+
buflen < (strlen(data->basedir) + 2 * data->dirdepth + ZSTR_LEN(key) + 5 + sizeof(FILE_PREFIX))) {
117115
return NULL;
118116
}
119117

120-
p = key;
118+
p = ZSTR_VAL(key);
121119
memcpy(buf, data->basedir, data->basedir_len);
122120
n = data->basedir_len;
123121
buf[n++] = PHP_DIR_SEPARATOR;
@@ -127,8 +125,8 @@ static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, cons
127125
}
128126
memcpy(buf + n, FILE_PREFIX, sizeof(FILE_PREFIX) - 1);
129127
n += sizeof(FILE_PREFIX) - 1;
130-
memcpy(buf + n, key, key_len);
131-
n += key_len;
128+
memcpy(buf + n, ZSTR_VAL(key), ZSTR_LEN(key));
129+
n += ZSTR_LEN(key);
132130
buf[n] = '\0';
133131

134132
return buf;
@@ -151,23 +149,23 @@ static void ps_files_close(ps_files *data)
151149
}
152150
}
153151

154-
static void ps_files_open(ps_files *data, const char *key)
152+
static void ps_files_open(ps_files *data, const zend_string *key)
155153
{
156154
char buf[MAXPATHLEN];
157155
#if !defined(O_NOFOLLOW) || !defined(PHP_WIN32)
158156
struct stat sbuf = {0};
159157
#endif
160158
int ret;
161159

162-
if (data->fd < 0 || !data->lastkey || strcmp(key, data->lastkey)) {
160+
if (data->fd < 0 || !data->lastkey || strcmp(ZSTR_VAL(key), data->lastkey)) {
163161
if (data->lastkey) {
164162
efree(data->lastkey);
165163
data->lastkey = NULL;
166164
}
167165

168166
ps_files_close(data);
169167

170-
if (php_session_valid_key(key) == FAILURE) {
168+
if (php_session_valid_key(ZSTR_VAL(key)) == FAILURE) {
171169
php_error_docref(NULL, E_WARNING, "Session ID is too long or contains illegal characters. Only the A-Z, a-z, 0-9, \"-\", and \",\" characters are allowed");
172170
return;
173171
}
@@ -177,7 +175,7 @@ static void ps_files_open(ps_files *data, const char *key)
177175
return;
178176
}
179177

180-
data->lastkey = estrdup(key);
178+
data->lastkey = estrdup(ZSTR_VAL(key));
181179

182180
/* O_NOFOLLOW to prevent us from following evil symlinks */
183181
#ifdef O_NOFOLLOW
@@ -233,7 +231,7 @@ static zend_result ps_files_write(ps_files *data, zend_string *key, zend_string
233231
/* PS(id) may be changed by calling session_regenerate_id().
234232
Re-initialization should be tried here. ps_files_open() checks
235233
data->lastkey and reopen when it is needed. */
236-
ps_files_open(data, ZSTR_VAL(key));
234+
ps_files_open(data, key);
237235
if (data->fd < 0) {
238236
return FAILURE;
239237
}
@@ -337,7 +335,7 @@ static int ps_files_cleanup_dir(const char *dirname, zend_long maxlifetime)
337335
return (nrdels);
338336
}
339337

340-
static zend_result ps_files_key_exists(ps_files *data, const char *key)
338+
static zend_result ps_files_key_exists(ps_files *data, const zend_string *key)
341339
{
342340
char buf[MAXPATHLEN];
343341
zend_stat_t sbuf = {0};
@@ -476,7 +474,7 @@ PS_READ_FUNC(files)
476474
zend_stat_t sbuf = {0};
477475
PS_FILES_DATA;
478476

479-
ps_files_open(data, ZSTR_VAL(key));
477+
ps_files_open(data, key);
480478
if (data->fd < 0) {
481479
return FAILURE;
482480
}
@@ -571,7 +569,7 @@ PS_UPDATE_TIMESTAMP_FUNC(files)
571569
int ret;
572570
PS_FILES_DATA;
573571

574-
if (!ps_files_path_create(buf, sizeof(buf), data, ZSTR_VAL(key))) {
572+
if (!ps_files_path_create(buf, sizeof(buf), data, key)) {
575573
return FAILURE;
576574
}
577575

@@ -601,7 +599,7 @@ PS_DESTROY_FUNC(files)
601599
char buf[MAXPATHLEN];
602600
PS_FILES_DATA;
603601

604-
if (!ps_files_path_create(buf, sizeof(buf), data, ZSTR_VAL(key))) {
602+
if (!ps_files_path_create(buf, sizeof(buf), data, key)) {
605603
return FAILURE;
606604
}
607605

@@ -680,7 +678,7 @@ PS_CREATE_SID_FUNC(files)
680678
}
681679
/* Check collision */
682680
/* FIXME: mod_data(data) should not be NULL (User handler could be NULL) */
683-
if (data && ps_files_key_exists(data, ZSTR_VAL(sid)) == SUCCESS) {
681+
if (data && ps_files_key_exists(data, sid) == SUCCESS) {
684682
if (sid) {
685683
zend_string_release_ex(sid, 0);
686684
sid = NULL;
@@ -708,5 +706,5 @@ PS_VALIDATE_SID_FUNC(files)
708706
{
709707
PS_FILES_DATA;
710708

711-
return ps_files_key_exists(data, ZSTR_VAL(key));
709+
return ps_files_key_exists(data, key);
712710
}

0 commit comments

Comments
 (0)