90
90
91
91
typedef struct {
92
92
zend_string * last_key ;
93
- char * basedir ;
94
- size_t basedir_len ;
93
+ zend_string * basedir ;
95
94
size_t dirdepth ;
96
95
size_t st_size ;
97
96
int filemode ;
@@ -111,13 +110,13 @@ static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, cons
111
110
size_t n ;
112
111
113
112
if (!data || ZSTR_LEN (key ) <= data -> dirdepth ||
114
- buflen < (strlen (data -> basedir ) + 2 * data -> dirdepth + ZSTR_LEN (key ) + 5 + sizeof (FILE_PREFIX ))) {
113
+ buflen < (ZSTR_LEN (data -> basedir ) + 2 * data -> dirdepth + ZSTR_LEN (key ) + 5 + sizeof (FILE_PREFIX ))) {
115
114
return NULL ;
116
115
}
117
116
118
117
p = ZSTR_VAL (key );
119
- memcpy (buf , data -> basedir , data -> basedir_len );
120
- n = data -> basedir_len ;
118
+ memcpy (buf , ZSTR_VAL ( data -> basedir ), ZSTR_LEN ( data -> basedir ) );
119
+ n = ZSTR_LEN ( data -> basedir ) ;
121
120
buf [n ++ ] = PHP_DIR_SEPARATOR ;
122
121
for (i = 0 ; i < (int )data -> dirdepth ; i ++ ) {
123
122
buf [n ++ ] = * p ++ ;
@@ -277,48 +276,45 @@ static zend_result ps_files_write(ps_files *data, zend_string *key, zend_string
277
276
return SUCCESS ;
278
277
}
279
278
280
- static int ps_files_cleanup_dir (const char * dirname , zend_long maxlifetime )
279
+ static int ps_files_cleanup_dir (const zend_string * dirname , zend_long maxlifetime )
281
280
{
282
281
DIR * dir ;
283
282
struct dirent * entry ;
284
283
zend_stat_t sbuf = {0 };
285
284
char buf [MAXPATHLEN ];
286
285
time_t now ;
287
286
int nrdels = 0 ;
288
- size_t dirname_len ;
289
287
290
- dir = opendir (dirname );
288
+ dir = opendir (ZSTR_VAL ( dirname ) );
291
289
if (!dir ) {
292
- php_error_docref (NULL , E_NOTICE , "ps_files_cleanup_dir: opendir(%s) failed: %s (%d)" , dirname , strerror (errno ), errno );
290
+ php_error_docref (NULL , E_NOTICE , "ps_files_cleanup_dir: opendir(%s) failed: %s (%d)" , ZSTR_VAL ( dirname ) , strerror (errno ), errno );
293
291
return (0 );
294
292
}
295
293
296
294
time (& now );
297
295
298
- dirname_len = strlen (dirname );
299
-
300
- if (dirname_len >= MAXPATHLEN ) {
301
- php_error_docref (NULL , E_NOTICE , "ps_files_cleanup_dir: dirname(%s) is too long" , dirname );
296
+ if (ZSTR_LEN (dirname ) >= MAXPATHLEN ) {
297
+ php_error_docref (NULL , E_NOTICE , "ps_files_cleanup_dir: dirname(%s) is too long" , ZSTR_VAL (dirname ));
302
298
closedir (dir );
303
299
return (0 );
304
300
}
305
301
306
302
/* Prepare buffer (dirname never changes) */
307
- memcpy (buf , dirname , dirname_len );
308
- buf [dirname_len ] = PHP_DIR_SEPARATOR ;
303
+ memcpy (buf , ZSTR_VAL ( dirname ), ZSTR_LEN ( dirname ) );
304
+ buf [ZSTR_LEN ( dirname ) ] = PHP_DIR_SEPARATOR ;
309
305
310
306
while ((entry = readdir (dir ))) {
311
307
/* does the file start with our prefix? */
312
308
if (!strncmp (entry -> d_name , FILE_PREFIX , sizeof (FILE_PREFIX ) - 1 )) {
313
309
size_t entry_len = strlen (entry -> d_name );
314
310
315
311
/* does it fit into our buffer? */
316
- if (entry_len + dirname_len + 2 < MAXPATHLEN ) {
312
+ if (entry_len + ZSTR_LEN ( dirname ) + 2 < MAXPATHLEN ) {
317
313
/* create the full path.. */
318
- memcpy (buf + dirname_len + 1 , entry -> d_name , entry_len );
314
+ memcpy (buf + ZSTR_LEN ( dirname ) + 1 , entry -> d_name , entry_len );
319
315
320
316
/* NUL terminate it and */
321
- buf [dirname_len + entry_len + 1 ] = '\0' ;
317
+ buf [ZSTR_LEN ( dirname ) + entry_len + 1 ] = '\0' ;
322
318
323
319
/* check whether its last access was more than maxlifetime ago */
324
320
if (VCWD_STAT (buf , & sbuf ) == 0 &&
@@ -417,8 +413,7 @@ PS_OPEN_FUNC(files)
417
413
data -> fd = -1 ;
418
414
data -> dirdepth = dirdepth ;
419
415
data -> filemode = filemode ;
420
- data -> basedir_len = strlen (save_path );
421
- data -> basedir = estrndup (save_path , data -> basedir_len );
416
+ data -> basedir = zend_string_init (save_path , strlen (save_path ), /* persistent */ false);
422
417
423
418
if (PS_GET_MOD_DATA ()) {
424
419
ps_close_files (mod_data );
@@ -450,7 +445,7 @@ PS_CLOSE_FUNC(files)
450
445
data -> last_key = NULL ;
451
446
}
452
447
453
- efree (data -> basedir );
448
+ zend_string_release_ex (data -> basedir , /* persistent */ false );
454
449
efree (data );
455
450
PS_SET_MOD_DATA (NULL );
456
451
0 commit comments