@@ -38,50 +38,50 @@ static zend_result phar_call_openssl_signverify(bool is_sign, php_stream *fp, ze
3838#endif
3939
4040/* for links to relative location, prepend cwd of the entry */
41- static char * phar_get_link_location (phar_entry_info * entry ) /* {{{ */
41+ static zend_string * phar_get_link_location (phar_entry_info * entry ) /* {{{ */
4242{
43- char * p , * ret = NULL ;
43+ ZEND_ASSERT ( entry -> symlink ) ;
4444
45- ZEND_ASSERT (entry -> link );
46-
47- if (entry -> link [0 ] == '/' ) {
48- return estrdup (entry -> link + 1 );
45+ if (ZSTR_VAL (entry -> symlink )[0 ] == '/' ) {
46+ return zend_string_init (ZSTR_VAL (entry -> symlink ) + 1 , ZSTR_LEN (entry -> symlink ) - 1 , false);
4947 }
50- p = strrchr (ZSTR_VAL (entry -> filename ), '/' );
48+ const char * p = strrchr (ZSTR_VAL (entry -> filename ), '/' );
5149 if (p ) {
5250 /* Important: don't modify the original `p` data because it is a shared string. */
5351 zend_string * new_name = zend_string_init (ZSTR_VAL (entry -> filename ), p - ZSTR_VAL (entry -> filename ), false);
54- spprintf (& ret , 0 , "%s/%s" , ZSTR_VAL (new_name ), entry -> link );
52+ zend_string * location = zend_string_concat3 (
53+ ZSTR_VAL (new_name ), ZSTR_LEN (new_name ),
54+ ZEND_STRL ("/" ),
55+ ZSTR_VAL (entry -> symlink ), ZSTR_LEN (entry -> symlink )
56+ );
5557 zend_string_release (entry -> filename );
5658 entry -> filename = new_name ;
57- return ret ;
59+ return location ;
5860 }
59- return entry -> link ;
61+ return zend_string_copy ( entry -> symlink ) ;
6062}
6163/* }}} */
6264
6365phar_entry_info * phar_get_link_source (phar_entry_info * entry ) /* {{{ */
6466{
6567 phar_entry_info * link_entry ;
66- char * link ;
6768
68- if (!entry -> link ) {
69+ if (!entry -> symlink ) {
6970 return entry ;
7071 }
7172
72- link = phar_get_link_location (entry );
73- if (NULL != (link_entry = zend_hash_str_find_ptr (& (entry -> phar -> manifest ), entry -> link , strlen (entry -> link ))) ||
74- NULL != (link_entry = zend_hash_str_find_ptr (& (entry -> phar -> manifest ), link , strlen (link )))) {
75- if (link != entry -> link ) {
76- efree (link );
77- }
73+ link_entry = zend_hash_find_ptr (& (entry -> phar -> manifest ), entry -> symlink );
74+ if (link_entry ) {
7875 return phar_get_link_source (link_entry );
79- } else {
80- if (link != entry -> link ) {
81- efree (link );
82- }
83- return NULL ;
8476 }
77+
78+ zend_string * link = phar_get_link_location (entry );
79+ link_entry = zend_hash_find_ptr (& (entry -> phar -> manifest ), link );
80+ zend_string_release (link );
81+ if (link_entry ) {
82+ return phar_get_link_source (link_entry );
83+ }
84+ return NULL ;
8585}
8686/* }}} */
8787
@@ -96,7 +96,7 @@ static php_stream *phar_get_entrypufp(const phar_entry_info *entry)
9696/* retrieve a phar_entry_info's current file pointer for reading contents */
9797php_stream * phar_get_efp (phar_entry_info * entry , bool follow_links ) /* {{{ */
9898{
99- if (follow_links && entry -> link ) {
99+ if (follow_links && entry -> symlink ) {
100100 phar_entry_info * link_entry = phar_get_link_source (entry );
101101
102102 if (link_entry && link_entry != entry ) {
@@ -387,9 +387,9 @@ static ZEND_ATTRIBUTE_NONNULL zend_result phar_create_writeable_entry(phar_archi
387387 }
388388
389389 /* open a new temp file for writing */
390- if (entry -> link ) {
391- efree (entry -> link );
392- entry -> link = NULL ;
390+ if (entry -> symlink ) {
391+ zend_string_release (entry -> symlink );
392+ entry -> symlink = NULL ;
393393 entry -> tar_type = (entry -> is_tar ? TAR_FILE : '\0' );
394394 }
395395
@@ -444,9 +444,9 @@ ZEND_ATTRIBUTE_NONNULL static zend_result phar_separate_entry_fp(phar_entry_info
444444 return FAILURE ;
445445 }
446446
447- if (entry -> link ) {
448- efree (entry -> link );
449- entry -> link = NULL ;
447+ if (entry -> symlink ) {
448+ zend_string_release (entry -> symlink );
449+ entry -> symlink = NULL ;
450450 entry -> tar_type = (entry -> is_tar ? TAR_FILE : '\0' );
451451 }
452452
@@ -559,9 +559,9 @@ ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, co
559559 }
560560 } else {
561561 if (for_write ) {
562- if (entry -> link ) {
563- efree (entry -> link );
564- entry -> link = NULL ;
562+ if (entry -> symlink ) {
563+ zend_string_release (entry -> symlink );
564+ entry -> symlink = NULL ;
565565 entry -> tar_type = (entry -> is_tar ? TAR_FILE : '\0' );
566566 }
567567
@@ -586,7 +586,7 @@ ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, co
586586 (* ret )-> phar = phar ;
587587 (* ret )-> internal_file = entry ;
588588 (* ret )-> fp = phar_get_efp (entry , true);
589- if (entry -> link ) {
589+ if (entry -> symlink ) {
590590 phar_entry_info * link = phar_get_link_source (entry );
591591 if (!link ) {
592592 efree (* ret );
@@ -740,9 +740,9 @@ ZEND_ATTRIBUTE_NONNULL zend_result phar_copy_entry_fp(phar_entry_info *source, p
740740 return FAILURE ;
741741 }
742742
743- if (dest -> link ) {
744- efree (dest -> link );
745- dest -> link = NULL ;
743+ if (dest -> symlink ) {
744+ zend_string_release (dest -> symlink );
745+ dest -> symlink = NULL ;
746746 dest -> tar_type = (dest -> is_tar ? TAR_FILE : '\0' );
747747 }
748748
@@ -807,7 +807,7 @@ ZEND_ATTRIBUTE_NONNULL zend_result phar_open_entry_fp(phar_entry_info *entry, ch
807807 php_stream * ufp ;
808808 phar_entry_data dummy ;
809809
810- if (follow_links && entry -> link ) {
810+ if (follow_links && entry -> symlink ) {
811811 phar_entry_info * link_entry = phar_get_link_source (entry );
812812 if (link_entry && link_entry != entry ) {
813813 return phar_open_entry_fp (link_entry , error , true);
@@ -1995,8 +1995,8 @@ static int phar_update_cached_entry(zval *data, void *argument) /* {{{ */
19951995
19961996 entry -> phar = (phar_archive_data * )argument ;
19971997
1998- if (entry -> link ) {
1999- entry -> link = estrdup (entry -> link );
1998+ if (entry -> symlink ) {
1999+ zend_string_addref (entry -> symlink );
20002000 }
20012001
20022002 if (entry -> tmp ) {
0 commit comments