diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 99767468ee71c..2add01357408f 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -730,7 +730,7 @@ void phar_parse_metadata_lazy(const char *buffer, phar_metadata_tracker *tracker * This is used by phar_open_from_filename to process the manifest, but can be called * directly. */ -static int phar_parse_pharfile(php_stream *fp, char *fname, size_t fname_len, char *alias, size_t alias_len, zend_long halt_offset, phar_archive_data** pphar, uint32_t compression, char **error) /* {{{ */ +static zend_result phar_parse_pharfile(php_stream *fp, char *fname, size_t fname_len, char *alias, size_t alias_len, zend_long halt_offset, phar_archive_data** pphar, uint32_t compression, char **error) /* {{{ */ { char b32[4], *buffer, *endbuffer, *savebuf; phar_archive_data *mydata = NULL; @@ -1806,7 +1806,7 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l * if not, check to see if its dirname() exists (i.e. "/path/to") and is a directory * succeed if we are creating the file, otherwise fail. */ -static int phar_analyze_path(const char *fname, const char *ext, size_t ext_len, int for_create) /* {{{ */ +static zend_result phar_analyze_path(const char *fname, const char *ext, size_t ext_len, int for_create) /* {{{ */ { php_stream_statbuf ssb; char *realpath; @@ -1911,7 +1911,7 @@ static int phar_analyze_path(const char *fname, const char *ext, size_t ext_len, /* }}} */ /* check for ".phar" in extension */ -static int phar_check_str(const char *fname, const char *ext_str, size_t ext_len, int executable, int for_create) /* {{{ */ +static zend_result phar_check_str(const char *fname, const char *ext_str, size_t ext_len, int executable, int for_create) /* {{{ */ { const char *pos; @@ -2057,6 +2057,7 @@ zend_result phar_detect_phar_fname_ext(const char *filename, size_t filename_len } } + // TODO Use some sort of loop here instead of a goto pos = memchr(filename + 1, '.', filename_len); next_extension: if (!pos) { @@ -2078,30 +2079,23 @@ zend_result phar_detect_phar_fname_ext(const char *filename, size_t filename_len *ext_len = strlen(pos); /* file extension must contain "phar" */ - switch (phar_check_str(filename, *ext_str, *ext_len, executable, for_create)) { - case SUCCESS: - return SUCCESS; - case FAILURE: - /* we are at the end of the string, so we fail */ - return FAILURE; - } + return phar_check_str(filename, *ext_str, *ext_len, executable, for_create); } /* we've found an extension that ends at a directory separator */ *ext_str = pos; *ext_len = slash - pos; - switch (phar_check_str(filename, *ext_str, *ext_len, executable, for_create)) { - case SUCCESS: - return SUCCESS; - case FAILURE: - /* look for more extensions */ - pos = strchr(pos + 1, '.'); - if (pos) { - *ext_str = NULL; - *ext_len = 0; - } - goto next_extension; + if (phar_check_str(filename, *ext_str, *ext_len, executable, for_create) == SUCCESS) { + return SUCCESS; + } + + /* look for more extensions */ + pos = strchr(pos + 1, '.'); + if (pos) { + *ext_str = NULL; + *ext_len = 0; + goto next_extension; } return FAILURE; @@ -2186,9 +2180,9 @@ char *phar_fix_filepath(char *path, size_t *new_len, int use_cwd) /* {{{ */ ptr_length = ptr - tok; last_time: if (IS_DIRECTORY_UP(tok, ptr_length)) { -#define PREVIOUS newpath[newpath_len - 1] + const char previous = newpath[newpath_len - 1]; - while (newpath_len > 1 && !IS_BACKSLASH(PREVIOUS)) { + while (newpath_len > 1 && !IS_BACKSLASH(previous)) { newpath_len--; } @@ -2487,7 +2481,7 @@ static int phar_flush_clean_deleted_apply(zval *zv) /* {{{ */ } /* }}} */ -#include "stub.h" +#include "stub.h" /* Generated phar_get_stub() function from makestub.php script */ zend_string *phar_create_default_stub(const char *index_php, const char *web_index, char **error) /* {{{ */ { @@ -2552,7 +2546,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv php_stream_filter *filter; php_serialize_data_t metadata_hash; smart_str main_metadata_str = {0}; - int free_user_stub, free_fp = 1, free_ufp = 1; + int free_fp = 1, free_ufp = 1; int manifest_hack = 0; php_stream *shared_cfp = NULL; @@ -2606,6 +2600,8 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv if (user_stub) { zend_string *suser_stub; + bool free_user_stub = false; + if (len < 0) { /* resource passed in */ if (!(php_stream_from_zval_no_verify(stubfile, (zval *)user_stub))) { @@ -2635,12 +2631,11 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv } return EOF; } - free_user_stub = 1; + free_user_stub = true; user_stub = ZSTR_VAL(suser_stub); len = ZSTR_LEN(suser_stub); - } else { - free_user_stub = 0; } + if ((pos = php_stristr(user_stub, halt_stub, len, sizeof(halt_stub) - 1)) == NULL) { if (closeoldfile) { php_stream_close(oldfile); @@ -3519,8 +3514,6 @@ void phar_request_initialize(void) /* {{{ */ PHP_RSHUTDOWN_FUNCTION(phar) /* {{{ */ { - uint32_t i; - PHAR_G(request_ends) = 1; if (PHAR_G(request_init)) @@ -3535,7 +3528,7 @@ PHP_RSHUTDOWN_FUNCTION(phar) /* {{{ */ PHAR_G(phar_SERVER_mung_list) = 0; if (PHAR_G(cached_fp)) { - for (i = 0; i < zend_hash_num_elements(&cached_phars); ++i) { + for (uint32_t i = 0; i < zend_hash_num_elements(&cached_phars); ++i) { if (PHAR_G(cached_fp)[i].fp) { php_stream_close(PHAR_G(cached_fp)[i].fp); }