@@ -104,20 +104,18 @@ const ps_module ps_mod_files = {
104
104
};
105
105
106
106
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 )
108
108
{
109
- size_t key_len ;
110
109
const char * p ;
111
110
int i ;
112
111
size_t n ;
113
112
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 ))) {
117
115
return NULL ;
118
116
}
119
117
120
- p = key ;
118
+ p = ZSTR_VAL ( key ) ;
121
119
memcpy (buf , data -> basedir , data -> basedir_len );
122
120
n = data -> basedir_len ;
123
121
buf [n ++ ] = PHP_DIR_SEPARATOR ;
@@ -127,8 +125,8 @@ static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, cons
127
125
}
128
126
memcpy (buf + n , FILE_PREFIX , sizeof (FILE_PREFIX ) - 1 );
129
127
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 ) ;
132
130
buf [n ] = '\0' ;
133
131
134
132
return buf ;
@@ -151,23 +149,23 @@ static void ps_files_close(ps_files *data)
151
149
}
152
150
}
153
151
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 )
155
153
{
156
154
char buf [MAXPATHLEN ];
157
155
#if !defined(O_NOFOLLOW ) || !defined(PHP_WIN32 )
158
156
struct stat sbuf = {0 };
159
157
#endif
160
158
int ret ;
161
159
162
- if (data -> fd < 0 || !data -> lastkey || strcmp (key , data -> lastkey )) {
160
+ if (data -> fd < 0 || !data -> lastkey || strcmp (ZSTR_VAL ( key ) , data -> lastkey )) {
163
161
if (data -> lastkey ) {
164
162
efree (data -> lastkey );
165
163
data -> lastkey = NULL ;
166
164
}
167
165
168
166
ps_files_close (data );
169
167
170
- if (php_session_valid_key (key ) == FAILURE ) {
168
+ if (php_session_valid_key (ZSTR_VAL ( key ) ) == FAILURE ) {
171
169
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" );
172
170
return ;
173
171
}
@@ -177,7 +175,7 @@ static void ps_files_open(ps_files *data, const char *key)
177
175
return ;
178
176
}
179
177
180
- data -> lastkey = estrdup (key );
178
+ data -> lastkey = estrdup (ZSTR_VAL ( key ) );
181
179
182
180
/* O_NOFOLLOW to prevent us from following evil symlinks */
183
181
#ifdef O_NOFOLLOW
@@ -233,7 +231,7 @@ static zend_result ps_files_write(ps_files *data, zend_string *key, zend_string
233
231
/* PS(id) may be changed by calling session_regenerate_id().
234
232
Re-initialization should be tried here. ps_files_open() checks
235
233
data->lastkey and reopen when it is needed. */
236
- ps_files_open (data , ZSTR_VAL ( key ) );
234
+ ps_files_open (data , key );
237
235
if (data -> fd < 0 ) {
238
236
return FAILURE ;
239
237
}
@@ -337,7 +335,7 @@ static int ps_files_cleanup_dir(const char *dirname, zend_long maxlifetime)
337
335
return (nrdels );
338
336
}
339
337
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 )
341
339
{
342
340
char buf [MAXPATHLEN ];
343
341
zend_stat_t sbuf = {0 };
@@ -476,7 +474,7 @@ PS_READ_FUNC(files)
476
474
zend_stat_t sbuf = {0 };
477
475
PS_FILES_DATA ;
478
476
479
- ps_files_open (data , ZSTR_VAL ( key ) );
477
+ ps_files_open (data , key );
480
478
if (data -> fd < 0 ) {
481
479
return FAILURE ;
482
480
}
@@ -571,7 +569,7 @@ PS_UPDATE_TIMESTAMP_FUNC(files)
571
569
int ret ;
572
570
PS_FILES_DATA ;
573
571
574
- if (!ps_files_path_create (buf , sizeof (buf ), data , ZSTR_VAL ( key ) )) {
572
+ if (!ps_files_path_create (buf , sizeof (buf ), data , key )) {
575
573
return FAILURE ;
576
574
}
577
575
@@ -601,7 +599,7 @@ PS_DESTROY_FUNC(files)
601
599
char buf [MAXPATHLEN ];
602
600
PS_FILES_DATA ;
603
601
604
- if (!ps_files_path_create (buf , sizeof (buf ), data , ZSTR_VAL ( key ) )) {
602
+ if (!ps_files_path_create (buf , sizeof (buf ), data , key )) {
605
603
return FAILURE ;
606
604
}
607
605
@@ -680,7 +678,7 @@ PS_CREATE_SID_FUNC(files)
680
678
}
681
679
/* Check collision */
682
680
/* 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 ) {
684
682
if (sid ) {
685
683
zend_string_release_ex (sid , 0 );
686
684
sid = NULL ;
@@ -708,5 +706,5 @@ PS_VALIDATE_SID_FUNC(files)
708
706
{
709
707
PS_FILES_DATA ;
710
708
711
- return ps_files_key_exists (data , ZSTR_VAL ( key ) );
709
+ return ps_files_key_exists (data , key );
712
710
}
0 commit comments