PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/phar - phar_internal.h (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 46 51 90.2 %
Date: 2016-04-27 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | phar php single-file executable PHP extension                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 2006-2016 The PHP Group                                |
       6             :   +----------------------------------------------------------------------+
       7             :   | This source file is subject to version 3.01 of the PHP license,      |
       8             :   | that is bundled with this package in the file LICENSE, and is        |
       9             :   | available through the world-wide-web at the following url:           |
      10             :   | http://www.php.net/license/3_01.txt.                                 |
      11             :   | If you did not receive a copy of the PHP license and are unable to   |
      12             :   | obtain it through the world-wide-web, please send a note to          |
      13             :   | license@php.net so we can mail you a copy immediately.               |
      14             :   +----------------------------------------------------------------------+
      15             :   | Authors: Gregory Beaver <cellog@php.net>                             |
      16             :   |          Marcus Boerger <helly@php.net>                              |
      17             :   +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include "config.h"
      24             : #endif
      25             : 
      26             : #include <time.h>
      27             : #include "php.h"
      28             : #include "tar.h"
      29             : #include "php_ini.h"
      30             : #include "zend_constants.h"
      31             : #include "zend_execute.h"
      32             : #include "zend_exceptions.h"
      33             : #include "zend_hash.h"
      34             : #include "zend_interfaces.h"
      35             : #include "zend_operators.h"
      36             : #include "zend_sort.h"
      37             : #include "zend_vm.h"
      38             : #include "zend_smart_str.h"
      39             : #include "main/php_streams.h"
      40             : #include "main/streams/php_stream_plain_wrapper.h"
      41             : #include "main/SAPI.h"
      42             : #include "main/php_main.h"
      43             : #include "main/php_open_temporary_file.h"
      44             : #include "ext/standard/info.h"
      45             : #include "ext/standard/basic_functions.h"
      46             : #include "ext/standard/file.h"
      47             : #include "ext/standard/php_string.h"
      48             : #include "ext/standard/url.h"
      49             : #include "ext/standard/crc32.h"
      50             : #include "ext/standard/md5.h"
      51             : #include "ext/standard/sha1.h"
      52             : #include "ext/standard/php_var.h"
      53             : #include "ext/standard/php_versioning.h"
      54             : #ifndef PHP_WIN32
      55             : #include "TSRM/tsrm_strtok_r.h"
      56             : #endif
      57             : #include "Zend/zend_virtual_cwd.h"
      58             : #include "ext/spl/spl_array.h"
      59             : #include "ext/spl/spl_directory.h"
      60             : #include "ext/spl/spl_engine.h"
      61             : #include "ext/spl/spl_exceptions.h"
      62             : #include "ext/spl/spl_iterators.h"
      63             : #include "php_phar.h"
      64             : #ifdef PHAR_HASH_OK
      65             : #include "ext/hash/php_hash.h"
      66             : #include "ext/hash/php_hash_sha.h"
      67             : #endif
      68             : 
      69             : /* PHP_ because this is public information via MINFO */
      70             : #define PHP_PHAR_API_VERSION      "1.1.1"
      71             : /* x.y.z maps to 0xyz0 */
      72             : #define PHAR_API_VERSION          0x1110
      73             : /* if we bump PHAR_API_VERSION, change this from 0x1100 to PHAR_API_VERSION */
      74             : #define PHAR_API_VERSION_NODIR    0x1100
      75             : #define PHAR_API_MIN_DIR          0x1110
      76             : #define PHAR_API_MIN_READ         0x1000
      77             : #define PHAR_API_MAJORVERSION     0x1000
      78             : #define PHAR_API_MAJORVER_MASK    0xF000
      79             : #define PHAR_API_VER_MASK         0xFFF0
      80             : 
      81             : #define PHAR_HDR_COMPRESSION_MASK 0x0000F000
      82             : #define PHAR_HDR_COMPRESSED_NONE  0x00000000
      83             : #define PHAR_HDR_COMPRESSED_GZ    0x00001000
      84             : #define PHAR_HDR_COMPRESSED_BZ2   0x00002000
      85             : #define PHAR_HDR_SIGNATURE        0x00010000
      86             : 
      87             : /* flags for defining that the entire file should be compressed */
      88             : #define PHAR_FILE_COMPRESSION_MASK 0x00F00000
      89             : #define PHAR_FILE_COMPRESSED_NONE  0x00000000
      90             : #define PHAR_FILE_COMPRESSED_GZ    0x00100000
      91             : #define PHAR_FILE_COMPRESSED_BZ2   0x00200000
      92             : 
      93             : #define PHAR_SIG_MD5              0x0001
      94             : #define PHAR_SIG_SHA1             0x0002
      95             : #define PHAR_SIG_SHA256           0x0003
      96             : #define PHAR_SIG_SHA512           0x0004
      97             : #define PHAR_SIG_OPENSSL          0x0010
      98             : 
      99             : /* flags byte for each file adheres to these bitmasks.
     100             :    All unused values are reserved */
     101             : #define PHAR_ENT_COMPRESSION_MASK 0x0000F000
     102             : #define PHAR_ENT_COMPRESSED_NONE  0x00000000
     103             : #define PHAR_ENT_COMPRESSED_GZ    0x00001000
     104             : #define PHAR_ENT_COMPRESSED_BZ2   0x00002000
     105             : 
     106             : #define PHAR_ENT_PERM_MASK        0x000001FF
     107             : #define PHAR_ENT_PERM_MASK_USR    0x000001C0
     108             : #define PHAR_ENT_PERM_SHIFT_USR   6
     109             : #define PHAR_ENT_PERM_MASK_GRP    0x00000038
     110             : #define PHAR_ENT_PERM_SHIFT_GRP   3
     111             : #define PHAR_ENT_PERM_MASK_OTH    0x00000007
     112             : #define PHAR_ENT_PERM_DEF_FILE    0x000001B6
     113             : #define PHAR_ENT_PERM_DEF_DIR     0x000001FF
     114             : 
     115             : #define PHAR_FORMAT_SAME    0
     116             : #define PHAR_FORMAT_PHAR    1
     117             : #define PHAR_FORMAT_TAR     2
     118             : #define PHAR_FORMAT_ZIP     3
     119             : 
     120             : #define TAR_FILE    '0'
     121             : #define TAR_LINK    '1'
     122             : #define TAR_SYMLINK '2'
     123             : #define TAR_DIR     '5'
     124             : #define TAR_NEW     '8'
     125             : #define TAR_GLOBAL_HDR 'g'
     126             : #define TAR_FILE_HDR   'x'
     127             : 
     128             : #define PHAR_MUNG_PHP_SELF                      (1<<0)
     129             : #define PHAR_MUNG_REQUEST_URI           (1<<1)
     130             : #define PHAR_MUNG_SCRIPT_NAME           (1<<2)
     131             : #define PHAR_MUNG_SCRIPT_FILENAME       (1<<3)
     132             : 
     133             : typedef struct _phar_entry_fp phar_entry_fp;
     134             : typedef struct _phar_archive_data phar_archive_data;
     135             : 
     136             : ZEND_BEGIN_MODULE_GLOBALS(phar)
     137             :         /* a list of phar_archive_data objects that reference a cached phar, so
     138             :            that if copy-on-write is performed, we can swap them out for the new value */
     139             :         HashTable   phar_persist_map;
     140             :         HashTable   phar_fname_map;
     141             :         /* for cached phars, this is a per-process store of fp/ufp */
     142             :         phar_entry_fp *cached_fp;
     143             :         HashTable   phar_alias_map;
     144             :         int         phar_SERVER_mung_list;
     145             :         int         readonly;
     146             :         char*       cache_list;
     147             :         int         manifest_cached;
     148             :         int         persist;
     149             :         int         has_zlib;
     150             :         int         has_bz2;
     151             :         zend_bool   readonly_orig;
     152             :         zend_bool   require_hash_orig;
     153             :         zend_bool   intercepted;
     154             :         int         request_init;
     155             :         int         require_hash;
     156             :         int         request_done;
     157             :         int         request_ends;
     158             :         void        (*orig_fopen)(INTERNAL_FUNCTION_PARAMETERS);
     159             :         void        (*orig_file_get_contents)(INTERNAL_FUNCTION_PARAMETERS);
     160             :         void        (*orig_is_file)(INTERNAL_FUNCTION_PARAMETERS);
     161             :         void        (*orig_is_link)(INTERNAL_FUNCTION_PARAMETERS);
     162             :         void        (*orig_is_dir)(INTERNAL_FUNCTION_PARAMETERS);
     163             :         void        (*orig_opendir)(INTERNAL_FUNCTION_PARAMETERS);
     164             :         void        (*orig_file_exists)(INTERNAL_FUNCTION_PARAMETERS);
     165             :         void        (*orig_fileperms)(INTERNAL_FUNCTION_PARAMETERS);
     166             :         void        (*orig_fileinode)(INTERNAL_FUNCTION_PARAMETERS);
     167             :         void        (*orig_filesize)(INTERNAL_FUNCTION_PARAMETERS);
     168             :         void        (*orig_fileowner)(INTERNAL_FUNCTION_PARAMETERS);
     169             :         void        (*orig_filegroup)(INTERNAL_FUNCTION_PARAMETERS);
     170             :         void        (*orig_fileatime)(INTERNAL_FUNCTION_PARAMETERS);
     171             :         void        (*orig_filemtime)(INTERNAL_FUNCTION_PARAMETERS);
     172             :         void        (*orig_filectime)(INTERNAL_FUNCTION_PARAMETERS);
     173             :         void        (*orig_filetype)(INTERNAL_FUNCTION_PARAMETERS);
     174             :         void        (*orig_is_writable)(INTERNAL_FUNCTION_PARAMETERS);
     175             :         void        (*orig_is_readable)(INTERNAL_FUNCTION_PARAMETERS);
     176             :         void        (*orig_is_executable)(INTERNAL_FUNCTION_PARAMETERS);
     177             :         void        (*orig_lstat)(INTERNAL_FUNCTION_PARAMETERS);
     178             :         void        (*orig_readfile)(INTERNAL_FUNCTION_PARAMETERS);
     179             :         void        (*orig_stat)(INTERNAL_FUNCTION_PARAMETERS);
     180             :         /* used for includes with . in them inside front controller */
     181             :         char*       cwd;
     182             :         int         cwd_len;
     183             :         int         cwd_init;
     184             :         char        *openssl_privatekey;
     185             :         int         openssl_privatekey_len;
     186             :         /* phar_get_archive cache */
     187             :         char*       last_phar_name;
     188             :         int         last_phar_name_len;
     189             :         char*       last_alias;
     190             :         int         last_alias_len;
     191             :         phar_archive_data* last_phar;
     192             :         HashTable mime_types;
     193             : ZEND_END_MODULE_GLOBALS(phar)
     194             : 
     195             : ZEND_EXTERN_MODULE_GLOBALS(phar)
     196             : #define PHAR_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(phar, v)
     197             : 
     198             : #if defined(ZTS) && defined(COMPILE_DL_PHAR)
     199             : ZEND_TSRMLS_CACHE_EXTERN();
     200             : #endif
     201             : 
     202             : #include "pharzip.h"
     203             : 
     204             : typedef union _phar_archive_object  phar_archive_object;
     205             : typedef union _phar_entry_object    phar_entry_object;
     206             : 
     207             : /*
     208             :  * used in phar_entry_info->fp_type to
     209             :  */
     210             : enum phar_fp_type {
     211             :         /* regular file pointer phar_archive_data->fp */
     212             :         PHAR_FP,
     213             :         /* uncompressed file pointer phar_archive_data->uncompressed_fp */
     214             :         PHAR_UFP,
     215             :         /* modified file pointer phar_entry_info->fp */
     216             :         PHAR_MOD,
     217             :         /* temporary manifest entry (file outside of the phar mapped to a location inside the phar)
     218             :            this entry stores the stream to open in link (normally used for tars, but we steal it here) */
     219             :         PHAR_TMP
     220             : };
     221             : 
     222             : /* entry for one file in a phar file */
     223             : typedef struct _phar_entry_info {
     224             :         /* first bytes are exactly as in file */
     225             :         uint32_t                 uncompressed_filesize;
     226             :         uint32_t                 timestamp;
     227             :         uint32_t                 compressed_filesize;
     228             :         uint32_t                 crc32;
     229             :         uint32_t                 flags;
     230             :         /* remainder */
     231             :         /* when changing compression, save old flags in case fp is NULL */
     232             :         uint32_t                 old_flags;
     233             :         zval                     metadata;
     234             :         int                      metadata_len; /* only used for cached manifests */
     235             :         uint32_t                 filename_len;
     236             :         char                     *filename;
     237             :         enum phar_fp_type        fp_type;
     238             :         /* offset within original phar file of the file contents */
     239             :         zend_long                     offset_abs;
     240             :         /* offset within fp of the file contents */
     241             :         zend_long                     offset;
     242             :         /* offset within original phar file of the file header (for zip-based/tar-based) */
     243             :         zend_long                     header_offset;
     244             :         php_stream               *fp;
     245             :         php_stream               *cfp;
     246             :         int                      fp_refcount;
     247             :         char                     *tmp;
     248             :         phar_archive_data        *phar;
     249             :         smart_str                metadata_str;
     250             :         char                     *link; /* symbolic link to another file */
     251             :         char                     tar_type;
     252             :         /* position in the manifest */
     253             :         uint                     manifest_pos;
     254             :         /* for stat */
     255             :         unsigned short           inode;
     256             : 
     257             :         unsigned int             is_crc_checked:1;
     258             :         unsigned int             is_modified:1;
     259             :         unsigned int             is_deleted:1;
     260             :         unsigned int             is_dir:1;
     261             :         /* this flag is used for mounted entries (external files mapped to location
     262             :            inside a phar */
     263             :         unsigned int             is_mounted:1;
     264             :         /* used when iterating */
     265             :         unsigned int             is_temp_dir:1;
     266             :         /* tar-based phar file stuff */
     267             :         unsigned int             is_tar:1;
     268             :         /* zip-based phar file stuff */
     269             :         unsigned int             is_zip:1;
     270             :         /* for cached phar entries */
     271             :         unsigned int             is_persistent:1;
     272             : } phar_entry_info;
     273             : 
     274             : /* information about a phar file (the archive itself) */
     275             : struct _phar_archive_data {
     276             :         char                     *fname;
     277             :         int                      fname_len;
     278             :         /* for phar_detect_fname_ext, this stores the location of the file extension within fname */
     279             :         char                     *ext;
     280             :         int                      ext_len;
     281             :         char                     *alias;
     282             :         int                      alias_len;
     283             :         char                     version[12];
     284             :         size_t                   internal_file_start;
     285             :         size_t                   halt_offset;
     286             :         HashTable                manifest;
     287             :         /* hash of virtual directories, as in path/to/file.txt has path/to and path as virtual directories */
     288             :         HashTable                virtual_dirs;
     289             :         /* hash of mounted directory paths */
     290             :         HashTable                mounted_dirs;
     291             :         uint32_t                 flags;
     292             :         uint32_t                 min_timestamp;
     293             :         uint32_t                 max_timestamp;
     294             :         php_stream               *fp;
     295             :         /* decompressed file contents are stored here */
     296             :         php_stream               *ufp;
     297             :         int                      refcount;
     298             :         uint32_t                 sig_flags;
     299             :         int                      sig_len;
     300             :         char                     *signature;
     301             :         zval                     metadata;
     302             :         int                      metadata_len; /* only used for cached manifests */
     303             :         uint                     phar_pos;
     304             :         /* if 1, then this alias was manually specified by the user and is not a permanent alias */
     305             :         unsigned int             is_temporary_alias:1;
     306             :         unsigned int             is_modified:1;
     307             :         unsigned int             is_writeable:1;
     308             :         unsigned int             is_brandnew:1;
     309             :         /* defer phar creation */
     310             :         unsigned int             donotflush:1;
     311             :         /* zip-based phar variables */
     312             :         unsigned int             is_zip:1;
     313             :         /* tar-based phar variables */
     314             :         unsigned int             is_tar:1;
     315             :         /* PharData variables       */
     316             :         unsigned int             is_data:1;
     317             :         /* for cached phar manifests */
     318             :         unsigned int             is_persistent:1;
     319             : };
     320             : 
     321             : typedef struct _phar_entry_fp_info {
     322             :         enum phar_fp_type        fp_type;
     323             :         /* offset within fp of the file contents */
     324             :         zend_long                     offset;
     325             : } phar_entry_fp_info;
     326             : 
     327             : struct _phar_entry_fp {
     328             :         php_stream *fp;
     329             :         php_stream *ufp;
     330             :         phar_entry_fp_info *manifest;
     331             : };
     332             : 
     333       32493 : static inline php_stream *phar_get_entrypfp(phar_entry_info *entry)
     334             : {
     335       32493 :         if (!entry->is_persistent) {
     336       32489 :                 return entry->phar->fp;
     337             :         }
     338           4 :         return PHAR_G(cached_fp)[entry->phar->phar_pos].fp;
     339             : }
     340             : 
     341       15744 : static inline php_stream *phar_get_entrypufp(phar_entry_info *entry)
     342             : {
     343       15744 :         if (!entry->is_persistent) {
     344       15744 :                 return entry->phar->ufp;
     345             :         }
     346           0 :         return PHAR_G(cached_fp)[entry->phar->phar_pos].ufp;
     347             : }
     348             : 
     349             : static inline void phar_set_entrypfp(phar_entry_info *entry, php_stream *fp)
     350             : {
     351             :         if (!entry->phar->is_persistent) {
     352             :                 entry->phar->fp =  fp;
     353             :                 return;
     354             :         }
     355             : 
     356             :         PHAR_G(cached_fp)[entry->phar->phar_pos].fp = fp;
     357             : }
     358             : 
     359          24 : static inline void phar_set_entrypufp(phar_entry_info *entry, php_stream *fp)
     360             : {
     361          24 :         if (!entry->phar->is_persistent) {
     362          24 :                 entry->phar->ufp =  fp;
     363          24 :                 return;
     364             :         }
     365             : 
     366           0 :         PHAR_G(cached_fp)[entry->phar->phar_pos].ufp = fp;
     367             : }
     368             : 
     369        2639 : static inline php_stream *phar_get_pharfp(phar_archive_data *phar)
     370             : {
     371        2639 :         if (!phar->is_persistent) {
     372        2635 :                 return phar->fp;
     373             :         }
     374           4 :         return PHAR_G(cached_fp)[phar->phar_pos].fp;
     375             : }
     376             : 
     377             : static inline php_stream *phar_get_pharufp(phar_archive_data *phar)
     378             : {
     379             :         if (!phar->is_persistent) {
     380             :                 return phar->ufp;
     381             :         }
     382             :         return PHAR_G(cached_fp)[phar->phar_pos].ufp;
     383             : }
     384             : 
     385         169 : static inline void phar_set_pharfp(phar_archive_data *phar, php_stream *fp)
     386             : {
     387         169 :         if (!phar->is_persistent) {
     388         168 :                 phar->fp =  fp;
     389         168 :                 return;
     390             :         }
     391             : 
     392           1 :         PHAR_G(cached_fp)[phar->phar_pos].fp = fp;
     393             : }
     394             : 
     395             : static inline void phar_set_pharufp(phar_archive_data *phar, php_stream *fp)
     396             : {
     397             :         if (!phar->is_persistent) {
     398             :                 phar->ufp =  fp;
     399             :                 return;
     400             :         }
     401             : 
     402             :         PHAR_G(cached_fp)[phar->phar_pos].ufp = fp;
     403             : }
     404             : 
     405          37 : static inline void phar_set_fp_type(phar_entry_info *entry, enum phar_fp_type type, zend_off_t offset)
     406             : {
     407             :         phar_entry_fp_info *data;
     408             : 
     409          37 :         if (!entry->is_persistent) {
     410          37 :                 entry->fp_type = type;
     411          37 :                 entry->offset = offset;
     412          37 :                 return;
     413             :         }
     414           0 :         data = &(PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos]);
     415           0 :         data->fp_type = type;
     416           0 :         data->offset = offset;
     417             : }
     418             : 
     419      103550 : static inline enum phar_fp_type phar_get_fp_type(phar_entry_info *entry)
     420             : {
     421      103550 :         if (!entry->is_persistent) {
     422      103548 :                 return entry->fp_type;
     423             :         }
     424           2 :         return PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos].fp_type;
     425             : }
     426             : 
     427       28494 : static inline zend_off_t phar_get_fp_offset(phar_entry_info *entry)
     428             : {
     429       28494 :         if (!entry->is_persistent) {
     430       28493 :                 return entry->offset;
     431             :         }
     432           1 :         if (PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos].fp_type == PHAR_FP) {
     433           1 :                 if (!PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos].offset) {
     434           1 :                         PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos].offset = entry->offset;
     435             :                 }
     436             :         }
     437           1 :         return PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos].offset;
     438             : }
     439             : 
     440             : #define PHAR_MIME_PHP '\0'
     441             : #define PHAR_MIME_PHPS '\1'
     442             : #define PHAR_MIME_OTHER '\2'
     443             : 
     444             : typedef struct _phar_mime_type {
     445             :         char *mime;
     446             :         int len;
     447             :         /* one of PHAR_MIME_* */
     448             :         char type;
     449             : } phar_mime_type;
     450             : 
     451             : /* stream access data for one file entry in a phar file */
     452             : typedef struct _phar_entry_data {
     453             :         phar_archive_data        *phar;
     454             :         php_stream               *fp;
     455             :         /* stream position proxy, allows multiple open streams referring to the same fp */
     456             :         zend_off_t                    position;
     457             :         /* for copies of the phar fp, defines where 0 is */
     458             :         zend_off_t                    zero;
     459             :         unsigned int             for_write:1;
     460             :         unsigned int             is_zip:1;
     461             :         unsigned int             is_tar:1;
     462             :         phar_entry_info          *internal_file;
     463             : } phar_entry_data;
     464             : 
     465             : /* archive php object */
     466             : union _phar_archive_object {
     467             :         spl_filesystem_object    spl;
     468             :         phar_archive_data        *archive;
     469             : };
     470             : 
     471             : /* entry php object */
     472             : union _phar_entry_object {
     473             :         spl_filesystem_object    spl;
     474             :         phar_entry_info          *entry;
     475             : };
     476             : 
     477             : #ifndef PHAR_MAIN
     478             : extern zend_string *(*phar_save_resolve_path)(const char *filename, int filename_len);
     479             : #endif
     480             : 
     481             : BEGIN_EXTERN_C()
     482             : 
     483             : #ifdef PHP_WIN32
     484             : char *tsrm_strtok_r(char *s, const char *delim, char **last);
     485             : 
     486             : static inline void phar_unixify_path_separators(char *path, int path_len)
     487             : {
     488             :         char *s;
     489             : 
     490             :         /* unixify win paths */
     491             :         for (s = path; s - path < path_len; ++s) {
     492             :                 if (*s == '\\') {
     493             :                         *s = '/';
     494             :                 }
     495             :         }
     496             : }
     497             : #endif
     498             : /**
     499             :  * validate an alias, returns 1 for success, 0 for failure
     500             :  */
     501         210 : static inline int phar_validate_alias(const char *alias, int alias_len) /* {{{ */
     502             : {
     503         210 :         return !(memchr(alias, '/', alias_len) || memchr(alias, '\\', alias_len) || memchr(alias, ':', alias_len) ||
     504             :                 memchr(alias, ';', alias_len) || memchr(alias, '\n', alias_len) || memchr(alias, '\r', alias_len));
     505             : }
     506             : /* }}} */
     507             : 
     508        1533 : static inline void phar_set_inode(phar_entry_info *entry) /* {{{ */
     509             : {
     510             :         char tmp[MAXPATHLEN];
     511             :         int tmp_len;
     512             :         size_t len1, len2;
     513             : 
     514        1533 :         tmp_len = MIN(MAXPATHLEN, entry->filename_len + entry->phar->fname_len);
     515             : 
     516        1533 :         len1 = MIN(entry->phar->fname_len, tmp_len);
     517        1533 :         memcpy(tmp, entry->phar->fname, len1);
     518             : 
     519        1533 :         len2 = MIN(tmp_len - len1, entry->filename_len);
     520        1533 :         memcpy(tmp + len1, entry->filename, len2);
     521             : 
     522        1533 :         entry->inode = (unsigned short) zend_hash_func(tmp, tmp_len);
     523        1533 : }
     524             : /* }}} */
     525             : 
     526             : void phar_request_initialize(void);
     527             : 
     528             : void phar_object_init(void);
     529             : void phar_destroy_phar_data(phar_archive_data *phar);
     530             : 
     531             : int phar_open_entry_file(phar_archive_data *phar, phar_entry_info *entry, char **error);
     532             : int phar_postprocess_file(phar_entry_data *idata, uint32_t crc32, char **error, int process_zip);
     533             : int phar_open_from_filename(char *fname, int fname_len, char *alias, int alias_len, int options, phar_archive_data** pphar, char **error);
     534             : int phar_open_or_create_filename(char *fname, int fname_len, char *alias, int alias_len, int is_data, int options, phar_archive_data** pphar, char **error);
     535             : int phar_create_or_parse_filename(char *fname, int fname_len, char *alias, int alias_len, int is_data, int options, phar_archive_data** pphar, char **error);
     536             : int phar_open_executed_filename(char *alias, int alias_len, char **error);
     537             : int phar_free_alias(phar_archive_data *phar, char *alias, int alias_len);
     538             : int phar_get_archive(phar_archive_data **archive, char *fname, int fname_len, char *alias, int alias_len, char **error);
     539             : int phar_open_parsed_phar(char *fname, int fname_len, char *alias, int alias_len, int is_data, int options, phar_archive_data** pphar, char **error);
     540             : int phar_verify_signature(php_stream *fp, size_t end_of_phar, uint32_t sig_type, char *sig, int sig_len, char *fname, char **signature, int *signature_len, char **error);
     541             : int phar_create_signature(phar_archive_data *phar, php_stream *fp, char **signature, int *signature_length, char **error);
     542             : 
     543             : /* utility functions */
     544             : zend_string *phar_create_default_stub(const char *index_php, const char *web_index, char **error);
     545             : char *phar_decompress_filter(phar_entry_info * entry, int return_unknown);
     546             : char *phar_compress_filter(phar_entry_info * entry, int return_unknown);
     547             : 
     548             : void phar_remove_virtual_dirs(phar_archive_data *phar, char *filename, int filename_len);
     549             : void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename_len);
     550             : int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len, char *path, int path_len);
     551             : zend_string *phar_find_in_include_path(char *file, int file_len, phar_archive_data **pphar);
     552             : char *phar_fix_filepath(char *path, int *new_len, int use_cwd);
     553             : phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, char **error);
     554             : int phar_parse_metadata(char **buffer, zval *metadata, uint32_t zip_metadata_len);
     555             : void destroy_phar_manifest_entry(zval *zv);
     556             : int phar_seek_efp(phar_entry_info *entry, zend_off_t offset, int whence, zend_off_t position, int follow_links);
     557             : php_stream *phar_get_efp(phar_entry_info *entry, int follow_links);
     558             : int phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, char **error);
     559             : int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links);
     560             : phar_entry_info *phar_get_link_source(phar_entry_info *entry);
     561             : int phar_create_writeable_entry(phar_archive_data *phar, phar_entry_info *entry, char **error);
     562             : int phar_separate_entry_fp(phar_entry_info *entry, char **error);
     563             : int phar_open_archive_fp(phar_archive_data *phar);
     564             : int phar_copy_on_write(phar_archive_data **pphar);
     565             : 
     566             : /* tar functions in tar.c */
     567             : int phar_is_tar(char *buf, char *fname);
     568             : int phar_parse_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, int alias_len, phar_archive_data** pphar, int is_data, uint32_t compression, char **error);
     569             : int phar_open_or_create_tar(char *fname, int fname_len, char *alias, int alias_len, int is_data, int options, phar_archive_data** pphar, char **error);
     570             : int phar_tar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int defaultstub, char **error);
     571             : 
     572             : /* zip functions in zip.c */
     573             : int phar_parse_zipfile(php_stream *fp, char *fname, int fname_len, char *alias, int alias_len, phar_archive_data** pphar, char **error);
     574             : int phar_open_or_create_zip(char *fname, int fname_len, char *alias, int alias_len, int is_data, int options, phar_archive_data** pphar, char **error);
     575             : int phar_zip_flush(phar_archive_data *archive, char *user_stub, zend_long len, int defaultstub, char **error);
     576             : 
     577             : #ifdef PHAR_MAIN
     578             : static int phar_open_from_fp(php_stream* fp, char *fname, int fname_len, char *alias, int alias_len, int options, phar_archive_data** pphar, int is_data, char **error);
     579             : extern php_stream_wrapper php_stream_phar_wrapper;
     580             : #else
     581             : extern HashTable cached_phars;
     582             : extern HashTable cached_alias;
     583             : #endif
     584             : 
     585             : int phar_archive_delref(phar_archive_data *phar);
     586             : int phar_entry_delref(phar_entry_data *idata);
     587             : 
     588             : phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, int path_len, char **error, int security);
     589             : phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, int path_len, char dir, char **error, int security);
     590             : phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char *path, int path_len, const char *mode, char allow_dir, char **error, int security);
     591             : int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char *path, int path_len, const char *mode, char allow_dir, char **error, int security);
     592             : int phar_flush(phar_archive_data *archive, char *user_stub, zend_long len, int convert, char **error);
     593             : int phar_detect_phar_fname_ext(const char *filename, int filename_len, const char **ext_str, int *ext_len, int executable, int for_create, int is_complete);
     594             : int phar_split_fname(const char *filename, int filename_len, char **arch, int *arch_len, char **entry, int *entry_len, int executable, int for_create);
     595             : 
     596             : typedef enum {
     597             :         pcr_use_query,
     598             :         pcr_is_ok,
     599             :         pcr_err_double_slash,
     600             :         pcr_err_up_dir,
     601             :         pcr_err_curr_dir,
     602             :         pcr_err_back_slash,
     603             :         pcr_err_star,
     604             :         pcr_err_illegal_char,
     605             :         pcr_err_empty_entry
     606             : } phar_path_check_result;
     607             : 
     608             : phar_path_check_result phar_path_check(char **p, int *len, const char **error);
     609             : 
     610             : END_EXTERN_C()
     611             : 
     612             : /*
     613             :  * Local variables:
     614             :  * tab-width: 4
     615             :  * c-basic-offset: 4
     616             :  * End:
     617             :  * vim600: noet sw=4 ts=4 fdm=marker
     618             :  * vim<600: noet sw=4 ts=4
     619             :  */

Generated by: LCOV version 1.10

Generated at Wed, 27 Apr 2016 15:51:47 +0000 (5 days ago)

Copyright © 2005-2016 The PHP Group
All rights reserved.