@@ -2600,12 +2600,11 @@ PHP_METHOD(Phar, isWritable)
2600
2600
/* {{{ Deletes a named file within the archive. */
2601
2601
PHP_METHOD (Phar , delete )
2602
2602
{
2603
- char * fname ;
2604
- size_t fname_len ;
2603
+ zend_string * file_name ;
2605
2604
char * error ;
2606
2605
phar_entry_info * entry ;
2607
2606
2608
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "p " , & fname , & fname_len ) == FAILURE ) {
2607
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "P " , & file_name ) == FAILURE ) {
2609
2608
RETURN_THROWS ();
2610
2609
}
2611
2610
@@ -2621,7 +2620,7 @@ PHP_METHOD(Phar, delete)
2621
2620
zend_throw_exception_ex (phar_ce_PharException , 0 , "phar \"%s\" is persistent, unable to copy on write" , phar_obj -> archive -> fname );
2622
2621
RETURN_THROWS ();
2623
2622
}
2624
- if (NULL != (entry = zend_hash_str_find_ptr (& phar_obj -> archive -> manifest , fname , fname_len ))) {
2623
+ if (NULL != (entry = zend_hash_find_ptr (& phar_obj -> archive -> manifest , file_name ))) {
2625
2624
if (entry -> is_deleted ) {
2626
2625
/* entry is deleted, but has not been flushed to disk yet */
2627
2626
RETURN_TRUE ;
@@ -2631,7 +2630,7 @@ PHP_METHOD(Phar, delete)
2631
2630
phar_obj -> archive -> is_modified = 1 ;
2632
2631
}
2633
2632
} else {
2634
- zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Entry %s does not exist and cannot be deleted" , fname );
2633
+ zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Entry %s does not exist and cannot be deleted" , ZSTR_VAL ( file_name ) );
2635
2634
RETURN_THROWS ();
2636
2635
}
2637
2636
@@ -2679,12 +2678,19 @@ PHP_METHOD(Phar, getPath)
2679
2678
*/
2680
2679
PHP_METHOD (Phar , setAlias )
2681
2680
{
2682
- char * alias , * error , * oldalias ;
2681
+ zend_string * new_alias = NULL ;
2682
+ char * error , * oldalias ;
2683
2683
phar_archive_data * fd_ptr ;
2684
- size_t alias_len , oldalias_len ;
2684
+ size_t oldalias_len ;
2685
2685
int old_temp , readd = 0 ;
2686
2686
2687
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "s" , & alias , & alias_len ) == FAILURE ) {
2687
+ // TODO Should this be using a "P" modifier?
2688
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "S" , & new_alias ) == FAILURE ) {
2689
+ RETURN_THROWS ();
2690
+ }
2691
+
2692
+ if (ZSTR_LEN (new_alias ) == 0 ) {
2693
+ zend_argument_value_error (1 , "cannot be empty" );
2688
2694
RETURN_THROWS ();
2689
2695
}
2690
2696
@@ -2711,22 +2717,22 @@ PHP_METHOD(Phar, setAlias)
2711
2717
RETURN_THROWS ();
2712
2718
}
2713
2719
2714
- if (alias_len == phar_obj -> archive -> alias_len && memcmp ( phar_obj -> archive -> alias , alias , alias_len ) == 0 ) {
2720
+ if (zend_string_equals_cstr ( new_alias , phar_obj -> archive -> alias , phar_obj -> archive -> alias_len )) {
2715
2721
RETURN_TRUE ;
2716
2722
}
2717
- if (alias_len && NULL != (fd_ptr = zend_hash_str_find_ptr (& (PHAR_G (phar_alias_map )), alias , alias_len ))) {
2718
- spprintf (& error , 0 , "alias \"%s\" is already used for archive \"%s\" and cannot be used for other archives" , alias , fd_ptr -> fname );
2719
- if (SUCCESS == phar_free_alias (fd_ptr , alias , alias_len )) {
2723
+ if (NULL != (fd_ptr = zend_hash_find_ptr (& (PHAR_G (phar_alias_map )), new_alias ))) {
2724
+ spprintf (& error , 0 , "alias \"%s\" is already used for archive \"%s\" and cannot be used for other archives" , ZSTR_VAL ( new_alias ) , fd_ptr -> fname );
2725
+ if (SUCCESS == phar_free_alias (fd_ptr , ZSTR_VAL ( new_alias ), ZSTR_LEN ( new_alias ) )) {
2720
2726
efree (error );
2721
2727
goto valid_alias ;
2722
2728
}
2723
2729
zend_throw_exception_ex (phar_ce_PharException , 0 , "%s" , error );
2724
2730
efree (error );
2725
2731
RETURN_THROWS ();
2726
2732
}
2727
- if (!phar_validate_alias (alias , alias_len )) {
2733
+ if (!phar_validate_alias (ZSTR_VAL ( new_alias ), ZSTR_LEN ( new_alias ) )) {
2728
2734
zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
2729
- "Invalid alias \"%s\" specified for phar \"%s\"" , alias , phar_obj -> archive -> fname );
2735
+ "Invalid alias \"%s\" specified for phar \"%s\"" , ZSTR_VAL ( new_alias ) , phar_obj -> archive -> fname );
2730
2736
RETURN_THROWS ();
2731
2737
}
2732
2738
valid_alias :
@@ -2743,13 +2749,8 @@ PHP_METHOD(Phar, setAlias)
2743
2749
oldalias_len = phar_obj -> archive -> alias_len ;
2744
2750
old_temp = phar_obj -> archive -> is_temporary_alias ;
2745
2751
2746
- if (alias_len ) {
2747
- phar_obj -> archive -> alias = estrndup (alias , alias_len );
2748
- } else {
2749
- phar_obj -> archive -> alias = NULL ;
2750
- }
2751
-
2752
- phar_obj -> archive -> alias_len = alias_len ;
2752
+ phar_obj -> archive -> alias = estrndup (ZSTR_VAL (new_alias ), ZSTR_LEN (new_alias ));
2753
+ phar_obj -> archive -> alias_len = ZSTR_LEN (new_alias );
2753
2754
phar_obj -> archive -> is_temporary_alias = 0 ;
2754
2755
phar_flush (phar_obj -> archive , NULL , 0 , 0 , & error );
2755
2756
@@ -2765,7 +2766,7 @@ PHP_METHOD(Phar, setAlias)
2765
2766
RETURN_THROWS ();
2766
2767
}
2767
2768
2768
- zend_hash_str_add_ptr (& (PHAR_G (phar_alias_map )), alias , alias_len , phar_obj -> archive );
2769
+ zend_hash_add_ptr (& (PHAR_G (phar_alias_map )), new_alias , phar_obj -> archive );
2769
2770
2770
2771
if (oldalias ) {
2771
2772
efree (oldalias );
@@ -3408,73 +3409,73 @@ PHP_METHOD(Phar, decompressFiles)
3408
3409
/* {{{ copy a file internal to the phar archive to another new file within the phar */
3409
3410
PHP_METHOD (Phar , copy )
3410
3411
{
3411
- char * oldfile , * newfile , * error ;
3412
+ char * error ;
3412
3413
const char * pcr_error ;
3413
- size_t oldfile_len , newfile_len ;
3414
3414
phar_entry_info * oldentry , newentry = {0 }, * temp ;
3415
- size_t tmp_len = 0 ;
3415
+ zend_string * new_file = NULL ;
3416
+ zend_string * old_file = NULL ;
3416
3417
3417
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "pp " , & oldfile , & oldfile_len , & newfile , & newfile_len ) == FAILURE ) {
3418
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "PP " , & old_file , & new_file ) == FAILURE ) {
3418
3419
RETURN_THROWS ();
3419
3420
}
3420
3421
3421
3422
PHAR_ARCHIVE_OBJECT ();
3422
3423
3423
3424
if (PHAR_G (readonly ) && !phar_obj -> archive -> is_data ) {
3424
3425
zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
3425
- "Cannot copy \"%s\" to \"%s\", phar is read-only" , oldfile , newfile );
3426
+ "Cannot copy \"%s\" to \"%s\", phar is read-only" , ZSTR_VAL ( old_file ), ZSTR_VAL ( new_file ) );
3426
3427
RETURN_THROWS ();
3427
3428
}
3428
3429
3429
- if (oldfile_len >= sizeof (".phar" )- 1 && !memcmp (oldfile , ".phar" , sizeof (".phar" )- 1 )) {
3430
+ if (ZSTR_LEN ( old_file ) >= sizeof (".phar" )- 1 && !memcmp (ZSTR_VAL ( old_file ) , ".phar" , sizeof (".phar" )- 1 )) {
3430
3431
/* can't copy a meta file */
3431
3432
zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
3432
- "file \"%s\" cannot be copied to file \"%s\", cannot copy Phar meta-file in %s" , oldfile , newfile , phar_obj -> archive -> fname );
3433
+ "file \"%s\" cannot be copied to file \"%s\", cannot copy Phar meta-file in %s" , ZSTR_VAL ( old_file ), ZSTR_VAL ( new_file ) , phar_obj -> archive -> fname );
3433
3434
RETURN_THROWS ();
3434
3435
}
3435
3436
3436
- if (newfile_len >= sizeof (".phar" )- 1 && !memcmp (newfile , ".phar" , sizeof (".phar" )- 1 )) {
3437
+ if (ZSTR_LEN ( new_file ) >= sizeof (".phar" )- 1 && !memcmp (ZSTR_VAL ( new_file ) , ".phar" , sizeof (".phar" )- 1 )) {
3437
3438
/* can't copy a meta file */
3438
3439
zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
3439
- "file \"%s\" cannot be copied to file \"%s\", cannot copy to Phar meta-file in %s" , oldfile , newfile , phar_obj -> archive -> fname );
3440
+ "file \"%s\" cannot be copied to file \"%s\", cannot copy to Phar meta-file in %s" , ZSTR_VAL ( old_file ), ZSTR_VAL ( new_file ) , phar_obj -> archive -> fname );
3440
3441
RETURN_THROWS ();
3441
3442
}
3442
3443
3443
- if (NULL == (oldentry = zend_hash_str_find_ptr (& phar_obj -> archive -> manifest , oldfile , oldfile_len )) || oldentry -> is_deleted ) {
3444
+ if (NULL == (oldentry = zend_hash_str_find_ptr (& phar_obj -> archive -> manifest , ZSTR_VAL ( old_file ), ZSTR_LEN ( old_file ) )) || oldentry -> is_deleted ) {
3444
3445
zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
3445
- "file \"%s\" cannot be copied to file \"%s\", file does not exist in %s" , oldfile , newfile , phar_obj -> archive -> fname );
3446
+ "file \"%s\" cannot be copied to file \"%s\", file does not exist in %s" , ZSTR_VAL ( old_file ), ZSTR_VAL ( new_file ) , phar_obj -> archive -> fname );
3446
3447
RETURN_THROWS ();
3447
3448
}
3448
3449
3449
- if (NULL != (temp = zend_hash_str_find_ptr (& phar_obj -> archive -> manifest , newfile , newfile_len )) && !temp -> is_deleted ) {
3450
+ if (NULL != (temp = zend_hash_find_ptr (& phar_obj -> archive -> manifest , new_file )) && !temp -> is_deleted ) {
3450
3451
zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
3451
- "file \"%s\" cannot be copied to file \"%s\", file must not already exist in phar %s" , oldfile , newfile , phar_obj -> archive -> fname );
3452
+ "file \"%s\" cannot be copied to file \"%s\", file must not already exist in phar %s" , ZSTR_VAL ( old_file ), ZSTR_VAL ( new_file ) , phar_obj -> archive -> fname );
3452
3453
RETURN_THROWS ();
3453
3454
}
3454
3455
3455
- tmp_len = newfile_len ;
3456
- if (phar_path_check (& newfile , & tmp_len , & pcr_error ) > pcr_is_ok ) {
3456
+ size_t tmp_len = ZSTR_LEN (new_file );
3457
+ char * tmp_new_file = ZSTR_VAL (new_file );
3458
+ if (phar_path_check (& tmp_new_file , & tmp_len , & pcr_error ) > pcr_is_ok ) {
3457
3459
zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
3458
- "file \"%s\" contains invalid characters %s, cannot be copied from \"%s\" in phar %s" , newfile , pcr_error , oldfile , phar_obj -> archive -> fname );
3460
+ "file \"%s\" contains invalid characters %s, cannot be copied from \"%s\" in phar %s" , ZSTR_VAL ( new_file ) , pcr_error , ZSTR_VAL ( old_file ) , phar_obj -> archive -> fname );
3459
3461
RETURN_THROWS ();
3460
3462
}
3461
- newfile_len = tmp_len ;
3462
3463
3463
3464
if (phar_obj -> archive -> is_persistent ) {
3464
3465
if (FAILURE == phar_copy_on_write (& (phar_obj -> archive ))) {
3465
3466
zend_throw_exception_ex (phar_ce_PharException , 0 , "phar \"%s\" is persistent, unable to copy on write" , phar_obj -> archive -> fname );
3466
3467
RETURN_THROWS ();
3467
3468
}
3468
3469
/* re-populate with copied-on-write entry */
3469
- oldentry = zend_hash_str_find_ptr (& phar_obj -> archive -> manifest , oldfile , oldfile_len );
3470
+ oldentry = zend_hash_find_ptr (& phar_obj -> archive -> manifest , old_file );
3470
3471
}
3471
3472
3472
3473
memcpy ((void * ) & newentry , oldentry , sizeof (phar_entry_info ));
3473
3474
3474
3475
phar_metadata_tracker_clone (& newentry .metadata_tracker );
3475
3476
3476
- newentry .filename = estrndup (newfile , newfile_len );
3477
- newentry .filename_len = newfile_len ;
3477
+ newentry .filename = estrndup (tmp_new_file , tmp_len );
3478
+ newentry .filename_len = tmp_len ;
3478
3479
newentry .fp_refcount = 0 ;
3479
3480
3480
3481
if (oldentry -> fp_type != PHAR_FP ) {
@@ -3487,7 +3488,7 @@ PHP_METHOD(Phar, copy)
3487
3488
}
3488
3489
}
3489
3490
3490
- zend_hash_str_add_mem (& oldentry -> phar -> manifest , newfile , newfile_len , & newentry , sizeof (phar_entry_info ));
3491
+ zend_hash_str_add_mem (& oldentry -> phar -> manifest , ZSTR_VAL ( new_file ), tmp_len , & newentry , sizeof (phar_entry_info ));
3491
3492
phar_obj -> archive -> is_modified = 1 ;
3492
3493
phar_flush (phar_obj -> archive , 0 , 0 , 0 , & error );
3493
3494
@@ -3503,31 +3504,30 @@ PHP_METHOD(Phar, copy)
3503
3504
/* {{{ determines whether a file exists in the phar */
3504
3505
PHP_METHOD (Phar , offsetExists )
3505
3506
{
3506
- char * fname ;
3507
- size_t fname_len ;
3507
+ zend_string * file_name ;
3508
3508
phar_entry_info * entry ;
3509
3509
3510
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "p " , & fname , & fname_len ) == FAILURE ) {
3510
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "P " , & file_name ) == FAILURE ) {
3511
3511
RETURN_THROWS ();
3512
3512
}
3513
3513
3514
3514
PHAR_ARCHIVE_OBJECT ();
3515
3515
3516
- if (zend_hash_str_exists (& phar_obj -> archive -> manifest , fname , fname_len )) {
3517
- if (NULL != (entry = zend_hash_str_find_ptr (& phar_obj -> archive -> manifest , fname , fname_len ))) {
3516
+ if (zend_hash_exists (& phar_obj -> archive -> manifest , file_name )) {
3517
+ if (NULL != (entry = zend_hash_find_ptr (& phar_obj -> archive -> manifest , file_name ))) {
3518
3518
if (entry -> is_deleted ) {
3519
3519
/* entry is deleted, but has not been flushed to disk yet */
3520
3520
RETURN_FALSE ;
3521
3521
}
3522
3522
}
3523
3523
3524
- if (fname_len >= sizeof (".phar" )- 1 && !memcmp (fname , ".phar" , sizeof (".phar" )- 1 )) {
3524
+ if (ZSTR_LEN ( file_name ) >= sizeof (".phar" )- 1 && !memcmp (ZSTR_VAL ( file_name ) , ".phar" , sizeof (".phar" )- 1 )) {
3525
3525
/* none of these are real files, so they don't exist */
3526
3526
RETURN_FALSE ;
3527
3527
}
3528
3528
RETURN_TRUE ;
3529
3529
} else {
3530
- RETURN_BOOL (zend_hash_str_exists (& phar_obj -> archive -> virtual_dirs , fname , fname_len ));
3530
+ RETURN_BOOL (zend_hash_exists (& phar_obj -> archive -> virtual_dirs , file_name ));
3531
3531
}
3532
3532
}
3533
3533
/* }}} */
@@ -3754,11 +3754,11 @@ PHP_METHOD(Phar, offsetSet)
3754
3754
/* {{{ remove a file from a phar */
3755
3755
PHP_METHOD (Phar , offsetUnset )
3756
3756
{
3757
- char * fname , * error ;
3758
- size_t fname_len ;
3757
+ char * error ;
3758
+ zend_string * file_name ;
3759
3759
phar_entry_info * entry ;
3760
3760
3761
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "p " , & fname , & fname_len ) == FAILURE ) {
3761
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "P " , & file_name ) == FAILURE ) {
3762
3762
RETURN_THROWS ();
3763
3763
}
3764
3764
@@ -3769,8 +3769,8 @@ PHP_METHOD(Phar, offsetUnset)
3769
3769
RETURN_THROWS ();
3770
3770
}
3771
3771
3772
- if (zend_hash_str_exists (& phar_obj -> archive -> manifest , fname , fname_len )) {
3773
- if (NULL != (entry = zend_hash_str_find_ptr (& phar_obj -> archive -> manifest , fname , fname_len ))) {
3772
+ if (zend_hash_exists (& phar_obj -> archive -> manifest , file_name )) {
3773
+ if (NULL != (entry = zend_hash_find_ptr (& phar_obj -> archive -> manifest , file_name ))) {
3774
3774
if (entry -> is_deleted ) {
3775
3775
/* entry is deleted, but has not been flushed to disk yet */
3776
3776
return ;
@@ -3782,7 +3782,7 @@ PHP_METHOD(Phar, offsetUnset)
3782
3782
RETURN_THROWS ();
3783
3783
}
3784
3784
/* re-populate entry after copy on write */
3785
- entry = zend_hash_str_find_ptr (& phar_obj -> archive -> manifest , fname , fname_len );
3785
+ entry = zend_hash_find_ptr (& phar_obj -> archive -> manifest , file_name );
3786
3786
}
3787
3787
entry -> is_modified = 0 ;
3788
3788
entry -> is_deleted = 1 ;
0 commit comments