@@ -2184,7 +2184,7 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext) /*
2184
2184
goto err_oldpath ;
2185
2185
}
2186
2186
2187
- phar_flush_ex (phar , NULL , 1 , & error );
2187
+ phar_flush_ex (phar , NULL , true , & error );
2188
2188
2189
2189
if (error ) {
2190
2190
zend_hash_str_del (& (PHAR_G (phar_fname_map )), newpath , phar -> fname_len );
@@ -4133,7 +4133,7 @@ PHP_METHOD(Phar, delMetadata)
4133
4133
}
4134
4134
/* }}} */
4135
4135
4136
- static zend_result phar_extract_file (bool overwrite , phar_entry_info * entry , char * dest , size_t dest_len , char * * error ) /* {{{ */
4136
+ ZEND_ATTRIBUTE_NONNULL static zend_result phar_extract_file (bool overwrite , phar_entry_info * entry , const zend_string * dest , char * * error ) /* {{{ */
4137
4137
{
4138
4138
php_stream_statbuf ssb ;
4139
4139
size_t len ;
@@ -4161,7 +4161,7 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
4161
4161
if (virtual_file_ex (& new_state , ZSTR_VAL (entry -> filename ), NULL , CWD_EXPAND ) != 0 ||
4162
4162
new_state .cwd_length <= 1 ) {
4163
4163
if (EINVAL == errno && ZSTR_LEN (entry -> filename ) > 50 ) {
4164
- spprintf (error , 4096 , "Cannot extract \"%.50s...\" to \"%s...\", extracted filename is too long for filesystem" , ZSTR_VAL (entry -> filename ), dest );
4164
+ spprintf (error , 4096 , "Cannot extract \"%.50s...\" to \"%s...\", extracted filename is too long for filesystem" , ZSTR_VAL (entry -> filename ), ZSTR_VAL ( dest ) );
4165
4165
} else {
4166
4166
spprintf (error , 4096 , "Cannot extract \"%s\", internal error" , ZSTR_VAL (entry -> filename ));
4167
4167
}
@@ -4183,7 +4183,7 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
4183
4183
}
4184
4184
#endif
4185
4185
4186
- len = spprintf (& fullpath , 0 , "%s/%s" , dest , filename );
4186
+ len = spprintf (& fullpath , 0 , "%s/%s" , ZSTR_VAL ( dest ) , filename );
4187
4187
4188
4188
if (len >= MAXPATHLEN ) {
4189
4189
/* truncate for error message */
@@ -4224,9 +4224,9 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
4224
4224
slash = zend_memrchr (filename , '/' , filename_len );
4225
4225
4226
4226
if (slash ) {
4227
- fullpath [dest_len + (slash - filename ) + 1 ] = '\0' ;
4227
+ fullpath [ZSTR_LEN ( dest ) + (slash - filename ) + 1 ] = '\0' ;
4228
4228
} else {
4229
- fullpath [dest_len ] = '\0' ;
4229
+ fullpath [ZSTR_LEN ( dest ) ] = '\0' ;
4230
4230
}
4231
4231
4232
4232
if (FAILURE == php_stream_stat_path (fullpath , & ssb )) {
@@ -4248,9 +4248,9 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
4248
4248
}
4249
4249
4250
4250
if (slash ) {
4251
- fullpath [dest_len + (slash - filename ) + 1 ] = '/' ;
4251
+ fullpath [ZSTR_LEN ( dest ) + (slash - filename ) + 1 ] = '/' ;
4252
4252
} else {
4253
- fullpath [dest_len ] = '/' ;
4253
+ fullpath [ZSTR_LEN ( dest ) ] = '/' ;
4254
4254
}
4255
4255
4256
4256
filename = NULL ;
@@ -4270,9 +4270,10 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
4270
4270
}
4271
4271
4272
4272
if ((phar_get_fp_type (entry ) == PHAR_FP && (entry -> flags & PHAR_ENT_COMPRESSION_MASK )) || !phar_get_efp (entry , 0 )) {
4273
- if (FAILURE == phar_open_entry_fp (entry , error , 1 )) {
4274
- if (error ) {
4275
- spprintf (error , 4096 , "Cannot extract \"%s\" to \"%s\", unable to open internal file pointer: %s" , ZSTR_VAL (entry -> filename ), fullpath , * error );
4273
+ char * open_entry_error = NULL ;
4274
+ if (FAILURE == phar_open_entry_fp (entry , & open_entry_error , 1 )) {
4275
+ if (open_entry_error ) {
4276
+ spprintf (error , 4096 , "Cannot extract \"%s\" to \"%s\", unable to open internal file pointer: %s" , ZSTR_VAL (entry -> filename ), fullpath , open_entry_error );
4276
4277
} else {
4277
4278
spprintf (error , 4096 , "Cannot extract \"%s\" to \"%s\", unable to open internal file pointer" , ZSTR_VAL (entry -> filename ), fullpath );
4278
4279
}
@@ -4310,28 +4311,28 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
4310
4311
}
4311
4312
/* }}} */
4312
4313
4313
- static int extract_helper (phar_archive_data * archive , zend_string * search , char * pathto , size_t pathto_len , bool overwrite , char * * error ) { /* {{{ */
4314
+ ZEND_ATTRIBUTE_NONNULL_ARGS ( 1 , 3 , 5 ) static int extract_helper (const phar_archive_data * archive , zend_string * search , const zend_string * pathto , bool overwrite , char * * error ) { /* {{{ */
4314
4315
int extracted = 0 ;
4315
4316
phar_entry_info * entry ;
4316
4317
4317
4318
if (!search ) {
4318
4319
/* nothing to match -- extract all files */
4319
4320
ZEND_HASH_MAP_FOREACH_PTR (& archive -> manifest , entry ) {
4320
- if (FAILURE == phar_extract_file (overwrite , entry , pathto , pathto_len , error )) return -1 ;
4321
+ if (FAILURE == phar_extract_file (overwrite , entry , pathto , error )) return -1 ;
4321
4322
extracted ++ ;
4322
4323
} ZEND_HASH_FOREACH_END ();
4323
4324
} else if (ZSTR_LEN (search ) > 0 && '/' == ZSTR_VAL (search )[ZSTR_LEN (search ) - 1 ]) {
4324
4325
/* ends in "/" -- extract all entries having that prefix */
4325
4326
ZEND_HASH_MAP_FOREACH_PTR (& archive -> manifest , entry ) {
4326
4327
if (!zend_string_starts_with (entry -> filename , search )) continue ;
4327
- if (FAILURE == phar_extract_file (overwrite , entry , pathto , pathto_len , error )) return -1 ;
4328
+ if (FAILURE == phar_extract_file (overwrite , entry , pathto , error )) return -1 ;
4328
4329
extracted ++ ;
4329
4330
} ZEND_HASH_FOREACH_END ();
4330
4331
} else {
4331
4332
/* otherwise, looking for an exact match */
4332
4333
entry = zend_hash_find_ptr (& archive -> manifest , search );
4333
4334
if (NULL == entry ) return 0 ;
4334
- if (FAILURE == phar_extract_file (overwrite , entry , pathto , pathto_len , error )) return -1 ;
4335
+ if (FAILURE == phar_extract_file (overwrite , entry , pathto , error )) return -1 ;
4335
4336
return 1 ;
4336
4337
}
4337
4338
@@ -4344,17 +4345,16 @@ PHP_METHOD(Phar, extractTo)
4344
4345
{
4345
4346
php_stream * fp ;
4346
4347
php_stream_statbuf ssb ;
4347
- char * pathto ;
4348
+ zend_string * path_to ;
4348
4349
zend_string * filename = NULL ;
4349
- size_t pathto_len ;
4350
4350
int ret ;
4351
4351
zval * zval_file ;
4352
4352
HashTable * files_ht = NULL ;
4353
4353
bool overwrite = 0 ;
4354
4354
char * error = NULL ;
4355
4355
4356
4356
ZEND_PARSE_PARAMETERS_START (1 , 3 )
4357
- Z_PARAM_PATH ( pathto , pathto_len )
4357
+ Z_PARAM_PATH_STR ( path_to )
4358
4358
Z_PARAM_OPTIONAL
4359
4359
Z_PARAM_ARRAY_HT_OR_STR_OR_NULL (files_ht , filename )
4360
4360
Z_PARAM_BOOL (overwrite )
@@ -4372,30 +4372,30 @@ PHP_METHOD(Phar, extractTo)
4372
4372
4373
4373
php_stream_close (fp );
4374
4374
4375
- if (pathto_len < 1 ) {
4375
+ if (ZSTR_LEN ( path_to ) < 1 ) {
4376
4376
zend_throw_exception_ex (spl_ce_InvalidArgumentException , 0 ,
4377
4377
"Invalid argument, extraction path must be non-zero length" );
4378
4378
RETURN_THROWS ();
4379
4379
}
4380
4380
4381
- if (pathto_len >= MAXPATHLEN ) {
4382
- char * tmp = estrndup (pathto , 50 );
4381
+ if (ZSTR_LEN ( path_to ) >= MAXPATHLEN ) {
4382
+ char * tmp = estrndup (ZSTR_VAL ( path_to ) , 50 );
4383
4383
/* truncate for error message */
4384
4384
zend_throw_exception_ex (spl_ce_InvalidArgumentException , 0 , "Cannot extract to \"%s...\", destination directory is too long for filesystem" , tmp );
4385
4385
efree (tmp );
4386
4386
RETURN_THROWS ();
4387
4387
}
4388
4388
4389
- if (php_stream_stat_path (pathto , & ssb ) < 0 ) {
4390
- ret = php_stream_mkdir (pathto , 0777 , PHP_STREAM_MKDIR_RECURSIVE , NULL );
4389
+ if (php_stream_stat_path (ZSTR_VAL ( path_to ) , & ssb ) < 0 ) {
4390
+ ret = php_stream_mkdir (ZSTR_VAL ( path_to ) , 0777 , PHP_STREAM_MKDIR_RECURSIVE , NULL );
4391
4391
if (!ret ) {
4392
4392
zend_throw_exception_ex (spl_ce_RuntimeException , 0 ,
4393
- "Unable to create path \"%s\" for extraction" , pathto );
4393
+ "Unable to create path \"%s\" for extraction" , ZSTR_VAL ( path_to ) );
4394
4394
RETURN_THROWS ();
4395
4395
}
4396
4396
} else if (!(ssb .sb .st_mode & S_IFDIR )) {
4397
4397
zend_throw_exception_ex (spl_ce_RuntimeException , 0 ,
4398
- "Unable to use path \"%s\" for extraction, it is a file, must be a directory" , pathto );
4398
+ "Unable to use path \"%s\" for extraction, it is a file, must be a directory" , ZSTR_VAL ( path_to ) );
4399
4399
RETURN_THROWS ();
4400
4400
}
4401
4401
@@ -4411,7 +4411,7 @@ PHP_METHOD(Phar, extractTo)
4411
4411
"Invalid argument, array of filenames to extract contains non-string value" );
4412
4412
RETURN_THROWS ();
4413
4413
}
4414
- switch (extract_helper (phar_obj -> archive , Z_STR_P (zval_file ), pathto , pathto_len , overwrite , & error )) {
4414
+ switch (extract_helper (phar_obj -> archive , Z_STR_P (zval_file ), path_to , overwrite , & error )) {
4415
4415
case -1 :
4416
4416
zend_throw_exception_ex (phar_ce_PharException , 0 , "Extraction from phar \"%s\" failed: %s" ,
4417
4417
phar_obj -> archive -> fname , error );
@@ -4427,7 +4427,7 @@ PHP_METHOD(Phar, extractTo)
4427
4427
RETURN_TRUE ;
4428
4428
}
4429
4429
4430
- ret = extract_helper (phar_obj -> archive , filename , pathto , pathto_len , overwrite , & error );
4430
+ ret = extract_helper (phar_obj -> archive , filename , path_to , overwrite , & error );
4431
4431
if (-1 == ret ) {
4432
4432
zend_throw_exception_ex (phar_ce_PharException , 0 , "Extraction from phar \"%s\" failed: %s" ,
4433
4433
phar_obj -> archive -> fname , error );
0 commit comments