diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index c310565f3b577..ded06c46b2ecf 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -14,6 +14,9 @@ on: libmysqlclient_with_mysqli: required: true type: boolean + macos_arm64_version: + required: true + type: string run_alpine: required: true type: boolean @@ -366,11 +369,11 @@ jobs: matrix: debug: [true, false] zts: [true, false] - os: ['13', '14'] + arch: ['X64', 'ARM64'] exclude: - - os: ${{ !inputs.run_macos_arm64 && '14' || '*never*' }} - name: "MACOS_${{ matrix.os == '13' && 'X64' || 'ARM64' }}_${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}" - runs-on: macos-${{ matrix.os }} + - arch: ${{ !inputs.run_macos_arm64 && 'ARM64' || '*never*' }} + name: "MACOS_${{ matrix.arch }}_${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}" + runs-on: macos-${{ matrix.arch == 'X64' && '15-intel' || inputs.macos_arm64_version }} steps: - name: git checkout uses: actions/checkout@v5 @@ -393,7 +396,7 @@ jobs: - name: Test uses: ./.github/actions/test-macos - name: Test Tracing JIT - if: matrix.os != '14' || !matrix.zts + if: matrix.arch == 'X64' || !matrix.zts uses: ./.github/actions/test-macos with: jitType: tracing @@ -405,7 +408,7 @@ jobs: runTestsParameters: >- -d opcache.enable_cli=1 - name: Test Function JIT - if: matrix.os != '14' || !matrix.zts + if: matrix.arch == 'X64' || !matrix.zts uses: ./.github/actions/test-macos with: jitType: function diff --git a/.github/workflows/root.yml b/.github/workflows/root.yml index b70b026eced07..2983a8e3c9081 100644 --- a/.github/workflows/root.yml +++ b/.github/workflows/root.yml @@ -52,6 +52,7 @@ jobs: branch: ${{ matrix.branch.ref }} community_verify_type_inference: ${{ (matrix.branch.version[0] == 8 && matrix.branch.version[1] >= 4) || matrix.branch.version[0] >= 9 }} libmysqlclient_with_mysqli: ${{ (matrix.branch.version[0] == 8 && matrix.branch.version[1] == 1) }} + macos_arm64_version: ${{ ((matrix.branch.version[0] == 8 && matrix.branch.version[1] >= 5) || matrix.branch.version[0] >= 9) && '15' || '14' }} run_alpine: ${{ (matrix.branch.version[0] == 8 && matrix.branch.version[1] >= 4) || matrix.branch.version[0] >= 9 }} run_linux_ppc64: ${{ (matrix.branch.version[0] == 8 && matrix.branch.version[1] >= 4) || matrix.branch.version[0] >= 9 }} run_macos_arm64: ${{ (matrix.branch.version[0] == 8 && matrix.branch.version[1] >= 4) || matrix.branch.version[0] >= 9 }} diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index d71c06c0a1354..3c3065e156871 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -9720,7 +9720,11 @@ ZEND_VM_HANDLER(202, ZEND_CALLABLE_CONVERT, UNUSED, UNUSED, NUM|CACHE_SLOT) if (closure) { ZVAL_OBJ_COPY(EX_VAR(opline->result.var), closure); } else { - zval *closure_zv = zend_hash_index_lookup(&EG(callable_convert_cache), (zend_ulong)(uintptr_t)call->func); + /* Rotate the key for better hash distribution. */ + const int shift = sizeof(size_t) == 4 ? 6 : 7; + zend_ulong key = (zend_ulong)(uintptr_t)call->func; + key = (key >> shift) | (key << ((sizeof(key) * 8) - shift)); + zval *closure_zv = zend_hash_index_lookup(&EG(callable_convert_cache), key); if (Z_TYPE_P(closure_zv) == IS_NULL) { zend_closure_from_frame(closure_zv, call); } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 50b65c864ed21..50870ce463de3 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -39093,7 +39093,11 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_CALLABLE_CONV if (closure) { ZVAL_OBJ_COPY(EX_VAR(opline->result.var), closure); } else { - zval *closure_zv = zend_hash_index_lookup(&EG(callable_convert_cache), (zend_ulong)(uintptr_t)call->func); + /* Rotate the key for better hash distribution. */ + const int shift = sizeof(size_t) == 4 ? 6 : 7; + zend_ulong key = (zend_ulong)(uintptr_t)call->func; + key = (key >> shift) | (key << ((sizeof(key) * 8) - shift)); + zval *closure_zv = zend_hash_index_lookup(&EG(callable_convert_cache), key); if (Z_TYPE_P(closure_zv) == IS_NULL) { zend_closure_from_frame(closure_zv, call); } @@ -94331,7 +94335,11 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_CALLABLE_CONVERT_S if (closure) { ZVAL_OBJ_COPY(EX_VAR(opline->result.var), closure); } else { - zval *closure_zv = zend_hash_index_lookup(&EG(callable_convert_cache), (zend_ulong)(uintptr_t)call->func); + /* Rotate the key for better hash distribution. */ + const int shift = sizeof(size_t) == 4 ? 6 : 7; + zend_ulong key = (zend_ulong)(uintptr_t)call->func; + key = (key >> shift) | (key << ((sizeof(key) * 8) - shift)); + zval *closure_zv = zend_hash_index_lookup(&EG(callable_convert_cache), key); if (Z_TYPE_P(closure_zv) == IS_NULL) { zend_closure_from_frame(closure_zv, call); } diff --git a/ext/ctype/tests/lc_ctype_inheritance.phpt b/ext/ctype/tests/lc_ctype_inheritance.phpt index 98a0c35cf00e6..ba5ea177c38a9 100644 --- a/ext/ctype/tests/lc_ctype_inheritance.phpt +++ b/ext/ctype/tests/lc_ctype_inheritance.phpt @@ -4,7 +4,9 @@ Do not inherit LC_CTYPE from environment ctype --SKIPIF-- =')) { + die('skip macOS 15 inherits LC_CTYPE into the thread locale'); +} if (setlocale(LC_ALL, 'invalid') === 'invalid') { die('skip setlocale() is broken /w musl'); } if (!setlocale(LC_CTYPE, "de_DE", "de-DE")) die("skip requires de_DE locale"); ?> diff --git a/ext/exif/exif.c b/ext/exif/exif.c index 9dcca2e81e0b8..2906b8c7150e8 100644 --- a/ext/exif/exif.c +++ b/ext/exif/exif.c @@ -3261,6 +3261,7 @@ static bool exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * val #define REQUIRE_NON_EMPTY() do { \ if (byte_count == 0) { \ + EFREE_IF(outside); \ exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "Process tag(x%04X=%s): Cannot be empty", tag, exif_get_tagname_debug(tag, tag_table)); \ return false; \ } \ diff --git a/ext/mysqlnd/mysqlnd_connection.c b/ext/mysqlnd/mysqlnd_connection.c index 31f3da08f6e1a..8eb61a58acb4f 100644 --- a/ext/mysqlnd/mysqlnd_connection.c +++ b/ext/mysqlnd/mysqlnd_connection.c @@ -552,7 +552,14 @@ MYSQLND_METHOD(mysqlnd_conn_data, get_scheme)(MYSQLND_CONN_DATA * conn, MYSQLND_ if (hostname.s[0] != '[' && mysqlnd_fast_is_ipv6_address(hostname.s)) { transport.l = mnd_sprintf(&transport.s, 0, "tcp://[%s]:%u", hostname.s, port); } else { - transport.l = mnd_sprintf(&transport.s, 0, "tcp://%s:%u", hostname.s, port); + /* Not ipv6, but could already contain a port number, in which case we should not add an extra port. + * See GH-8978. In a port doubling scenario, the first port would be used so we do the same to keep BC. */ + if (strchr(hostname.s, ':')) { + /* TODO: Ideally we should be able to get rid of this workaround in the future. */ + transport.l = mnd_sprintf(&transport.s, 0, "tcp://%s", hostname.s); + } else { + transport.l = mnd_sprintf(&transport.s, 0, "tcp://%s:%u", hostname.s, port); + } } } DBG_INF_FMT("transport=%s", transport.s? transport.s:"OOM"); diff --git a/ext/phar/dirstream.c b/ext/phar/dirstream.c index f23907ae7623a..81fa62c854dfd 100644 --- a/ext/phar/dirstream.c +++ b/ext/phar/dirstream.c @@ -394,7 +394,7 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo return 0; } - if ((e = phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1, 2, &error, 1))) { + if ((e = phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1, 2, &error, true))) { /* directory exists, or is a subdirectory of an existing file */ if (e->is_temp_dir) { zend_string_efree(e->filename); @@ -412,7 +412,7 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo return 0; } - if (phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1, 0, &error, 1)) { + if (phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1, 0, &error, true)) { /* entry exists as a file */ php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", file already exists", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host)); php_url_free(resource); @@ -523,7 +523,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options size_t path_len = ZSTR_LEN(resource->path) - 1; - if (!(entry = phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, path_len, 2, &error, 1))) { + if (!(entry = phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, path_len, 2, &error, true))) { if (error) { php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error); efree(error); diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 50c7b778cc404..b1f6d39171e4d 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -510,7 +510,6 @@ static zend_result phar_open_parsed_phar(char *fname, size_t fname_len, char *al && ((alias && fname_len == phar->fname_len && !strncmp(fname, phar->fname, fname_len)) || !alias) ) { - phar_entry_info *stub; #ifdef PHP_WIN32 if (fname != save_fname) { free_alloca(fname, fname_use_heap); @@ -526,7 +525,7 @@ static zend_result phar_open_parsed_phar(char *fname, size_t fname_len, char *al if (!is_data) { /* prevent any ".phar" without a stub getting through */ if (!phar->halt_offset && !phar->is_brandnew && (phar->is_tar || phar->is_zip)) { - if (PHAR_G(readonly) && NULL == (stub = zend_hash_str_find_ptr(&(phar->manifest), ".phar/stub.php", sizeof(".phar/stub.php")-1))) { + if (PHAR_G(readonly) && !zend_hash_str_exists(&(phar->manifest), ZEND_STRL(".phar/stub.php"))) { if (error) { spprintf(error, 0, "'%s' is not a phar archive. Use PharData::__construct() for a standard zip or tar archive", fname); } @@ -736,7 +735,7 @@ static zend_result phar_parse_pharfile(php_stream *fp, char *fname, size_t fname uint32_t len; zend_long offset; size_t sig_len; - int register_alias = 0, temp_alias = 0; + bool register_alias = false, temp_alias = false; char *signature = NULL; zend_string *str; @@ -1069,15 +1068,15 @@ static zend_result phar_parse_pharfile(php_stream *fp, char *fname, size_t fname alias_len = tmp_len; alias = buffer; buffer += tmp_len; - register_alias = 1; + register_alias = true; } else if (!alias_len || !alias) { /* if we neither have an explicit nor an implicit alias, we use the filename */ alias = NULL; alias_len = 0; - register_alias = 0; + register_alias = false; } else if (alias_len) { - register_alias = 1; - temp_alias = 1; + register_alias = true; + temp_alias = true; } /* we have 5 32-bit items plus 1 byte at least */ @@ -1325,12 +1324,12 @@ zend_result phar_open_or_create_filename(char *fname, size_t fname_len, char *al } /* first try to open an existing file */ - if (phar_detect_phar_fname_ext(fname, fname_len, &ext_str, &ext_len, !is_data, 0, 1) == SUCCESS) { + if (phar_detect_phar_fname_ext(fname, fname_len, &ext_str, &ext_len, !is_data, 0, true) == SUCCESS) { goto check_file; } /* next try to create a new file */ - if (FAILURE == phar_detect_phar_fname_ext(fname, fname_len, &ext_str, &ext_len, !is_data, 1, 1)) { + if (FAILURE == phar_detect_phar_fname_ext(fname, fname_len, &ext_str, &ext_len, !is_data, 1, true)) { if (error) { if (ext_len == -2) { spprintf(error, 0, "Cannot create a phar archive from a URL like \"%s\". Phar objects can only be created from local files", fname); @@ -1354,8 +1353,7 @@ zend_result phar_open_or_create_filename(char *fname, size_t fname_len, char *al } if (PHAR_G(readonly) && !(*test)->is_data && ((*test)->is_tar || (*test)->is_zip)) { - phar_entry_info *stub; - if (NULL == (stub = zend_hash_str_find_ptr(&((*test)->manifest), ".phar/stub.php", sizeof(".phar/stub.php")-1))) { + if (!zend_hash_str_exists(&((*test)->manifest), ZEND_STRL(".phar/stub.php"))) { spprintf(error, 0, "'%s' is not a phar archive. Use PharData::__construct() for a standard zip or tar archive", fname); return FAILURE; } @@ -1970,7 +1968,7 @@ static zend_result phar_check_str(const char *fname, const char *ext_str, size_t * the last parameter should be set to tell the thing to assume that filename is the full path, and only to check the * extension rules, not to iterate. */ -zend_result phar_detect_phar_fname_ext(const char *filename, size_t filename_len, const char **ext_str, size_t *ext_len, int executable, int for_create, int is_complete) /* {{{ */ +zend_result phar_detect_phar_fname_ext(const char *filename, size_t filename_len, const char **ext_str, size_t *ext_len, int executable, int for_create, bool is_complete) /* {{{ */ { const char *pos, *slash; @@ -2131,7 +2129,7 @@ static bool php_check_dots(const char *element, size_t n) /* {{{ */ /** * Remove .. and . references within a phar filename */ -char *phar_fix_filepath(char *path, size_t *new_len, int use_cwd) /* {{{ */ +char *phar_fix_filepath(char *path, size_t *new_len, bool use_cwd) /* {{{ */ { char *newpath; size_t newpath_len; @@ -2268,7 +2266,7 @@ zend_result phar_split_fname(const char *filename, size_t filename_len, char **a phar_unixify_path_separators((char *)filename, filename_len); } #endif - if (phar_detect_phar_fname_ext(filename, filename_len, &ext_str, &ext_len, executable, for_create, 0) == FAILURE) { + if (phar_detect_phar_fname_ext(filename, filename_len, &ext_str, &ext_len, executable, for_create, false) == FAILURE) { if (ext_len != -1) { if (!ext_str) { /* no / detected, restore arch for error message */ @@ -2544,7 +2542,8 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa phar_entry_info *entry, *newentry; size_t halt_offset; - int restore_alias_len, global_flags = 0; + uint32_t restore_alias_len; + uint32_t global_flags = 0; bool must_close_old_file = false; bool has_dirs = false; char manifest[18], entry_buffer[24]; @@ -2747,7 +2746,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa } continue; } - if (!phar_get_efp(entry, 0)) { + if (!phar_get_efp(entry, false)) { /* re-open internal file pointer just-in-time */ newentry = phar_open_jit(phar, entry, error); if (!newentry) { @@ -2758,8 +2757,8 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa } entry = newentry; } - file = phar_get_efp(entry, 0); - if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 1)) { + file = phar_get_efp(entry, false); + if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, true)) { if (must_close_old_file) { php_stream_close(oldfile); } @@ -2778,7 +2777,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa entry->compressed_filesize = entry->uncompressed_filesize; continue; } - filter = php_stream_filter_create(phar_compress_filter(entry, 0), NULL, 0); + filter = php_stream_filter_create(phar_compress_filter(entry, false), NULL, 0); if (!filter) { if (must_close_old_file) { php_stream_close(oldfile); @@ -2818,7 +2817,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa ZEND_ASSERT(entry->header_offset == 0); entry->header_offset = php_stream_tell(entry->cfp); php_stream_flush(file); - if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0)) { + if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, false)) { php_stream_filter_free(filter); if (must_close_old_file) { php_stream_close(oldfile); @@ -3024,8 +3023,8 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa file = entry->cfp; php_stream_seek(file, entry->header_offset, SEEK_SET); } else { - file = phar_get_efp(entry, 0); - if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0)) { + file = phar_get_efp(entry, false); + if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, false)) { if (must_close_old_file) { php_stream_close(oldfile); } @@ -3267,7 +3266,7 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type) { zend_op_array *res; zend_string *name = NULL; - int failed; + bool failed; phar_archive_data *phar; if (!file_handle || !file_handle->filename) { @@ -3318,11 +3317,11 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type) } zend_try { - failed = 0; + failed = false; CG(zend_lineno) = 0; res = phar_orig_compile_file(file_handle, type); } zend_catch { - failed = 1; + failed = true; res = NULL; } zend_end_try(); diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h index 736226783bef1..fe63e075c1b51 100644 --- a/ext/phar/phar_internal.h +++ b/ext/phar/phar_internal.h @@ -105,8 +105,8 @@ ZEND_BEGIN_MODULE_GLOBALS(phar) /* for cached phars, this is a per-process store of fp/ufp */ phar_entry_fp *cached_fp; HashTable phar_alias_map; - int phar_SERVER_mung_list; char* cache_list; + int phar_SERVER_mung_list; bool readonly; bool manifest_cached; bool persist; @@ -150,8 +150,8 @@ ZEND_BEGIN_MODULE_GLOBALS(phar) /* phar_get_archive cache */ char* last_phar_name; uint32_t last_phar_name_len; - char* last_alias; uint32_t last_alias_len; + char* last_alias; phar_archive_data* last_phar; HashTable mime_types; ZEND_END_MODULE_GLOBALS(phar) @@ -205,7 +205,6 @@ typedef struct _phar_entry_info { uint32_t old_flags; phar_metadata_tracker metadata_tracker; zend_string *filename; - enum phar_fp_type fp_type; /* offset within original phar file of the file contents */ zend_long offset_abs; /* offset within fp of the file contents */ @@ -214,6 +213,7 @@ typedef struct _phar_entry_info { zend_long header_offset; php_stream *fp; php_stream *cfp; + enum phar_fp_type fp_type; int fp_refcount; char *tmp; phar_archive_data *phar; @@ -224,21 +224,21 @@ typedef struct _phar_entry_info { /* for stat */ unsigned short inode; - uint32_t is_crc_checked:1; - uint32_t is_modified:1; - uint32_t is_deleted:1; - uint32_t is_dir:1; + bool is_crc_checked:1; + bool is_modified:1; + bool is_deleted:1; + bool is_dir:1; /* this flag is used for mounted entries (external files mapped to location inside a phar */ - uint32_t is_mounted:1; + bool is_mounted:1; /* used when iterating */ - uint32_t is_temp_dir:1; + bool is_temp_dir:1; /* tar-based phar file stuff */ - uint32_t is_tar:1; + bool is_tar:1; /* zip-based phar file stuff */ - uint32_t is_zip:1; + bool is_zip:1; /* for cached phar entries */ - uint32_t is_persistent:1; + bool is_persistent:1; } phar_entry_info; /* information about a phar file (the archive itself) */ @@ -246,10 +246,10 @@ struct _phar_archive_data { char *fname; uint32_t fname_len; /* for phar_detect_fname_ext, this stores the location of the file extension within fname */ - char *ext; uint32_t ext_len; + char *ext; char *alias; - uint32_t alias_len; + uint32_t alias_len; char version[12]; size_t halt_offset; HashTable manifest; @@ -260,30 +260,30 @@ struct _phar_archive_data { uint32_t flags; uint32_t min_timestamp; uint32_t max_timestamp; + int refcount; php_stream *fp; /* decompressed file contents are stored here */ php_stream *ufp; - int refcount; uint32_t sig_flags; uint32_t sig_len; char *signature; phar_metadata_tracker metadata_tracker; uint32_t phar_pos; /* if 1, then this alias was manually specified by the user and is not a permanent alias */ - uint32_t is_temporary_alias:1; - uint32_t is_modified:1; - uint32_t is_writeable:1; - uint32_t is_brandnew:1; + bool is_temporary_alias:1; + bool is_modified:1; + bool is_writeable:1; + bool is_brandnew:1; /* defer phar creation */ - uint32_t donotflush:1; + bool donotflush:1; /* zip-based phar variables */ - uint32_t is_zip:1; + bool is_zip:1; /* tar-based phar variables */ - uint32_t is_tar:1; + bool is_tar:1; /* PharData variables */ - uint32_t is_data:1; + bool is_data:1; /* for cached phar manifests */ - uint32_t is_persistent:1; + bool is_persistent:1; }; typedef struct _phar_entry_fp_info { @@ -416,14 +416,14 @@ zend_result phar_create_signature(phar_archive_data *phar, php_stream *fp, char /* utility functions */ zend_string *phar_create_default_stub(const char *index_php, const char *web_index, char **error); -char *phar_decompress_filter(phar_entry_info * entry, int return_unknown); -char *phar_compress_filter(phar_entry_info * entry, int return_unknown); +const char *phar_decompress_filter(const phar_entry_info *entry, bool return_unknown); +const char *phar_compress_filter(const phar_entry_info *entry, bool return_unknown); /* void phar_remove_virtual_dirs(phar_archive_data *phar, char *filename, size_t filename_len); */ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, size_t filename_len); zend_result phar_mount_entry(phar_archive_data *phar, char *filename, size_t filename_len, char *path, size_t path_len); zend_string *phar_find_in_include_path(zend_string *file, phar_archive_data **pphar); -char *phar_fix_filepath(char *path, size_t *new_len, int use_cwd); +char *phar_fix_filepath(char *path, size_t *new_len, bool use_cwd); phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, char **error); void phar_parse_metadata_lazy(const char *buffer, phar_metadata_tracker *tracker, uint32_t zip_metadata_len, bool persistent); bool phar_metadata_tracker_has_data(const phar_metadata_tracker* tracker, bool persistent); @@ -434,10 +434,10 @@ void phar_metadata_tracker_clone(phar_metadata_tracker* tracker); void phar_metadata_tracker_try_ensure_has_serialized_data(phar_metadata_tracker* tracker, bool persistent); zend_result phar_metadata_tracker_unserialize_or_copy(phar_metadata_tracker* tracker, zval *value, bool persistent, HashTable *unserialize_options, const char* method_name); void destroy_phar_manifest_entry(zval *zv); -int phar_seek_efp(phar_entry_info *entry, zend_off_t offset, int whence, zend_off_t position, int follow_links); -php_stream *phar_get_efp(phar_entry_info *entry, int follow_links); +int phar_seek_efp(phar_entry_info *entry, zend_off_t offset, int whence, zend_off_t position, bool follow_links); +php_stream *phar_get_efp(phar_entry_info *entry, bool follow_links); zend_result phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, char **error); -zend_result phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links); +zend_result phar_open_entry_fp(phar_entry_info *entry, char **error, bool follow_links); phar_entry_info *phar_get_link_source(phar_entry_info *entry); zend_result phar_open_archive_fp(phar_archive_data *phar); zend_result phar_copy_on_write(phar_archive_data **pphar); @@ -445,12 +445,12 @@ zend_result phar_copy_on_write(phar_archive_data **pphar); /* tar functions in tar.c */ bool phar_is_tar(char *buf, char *fname); zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, char *alias, size_t alias_len, phar_archive_data** pphar, uint32_t compression, char **error); -zend_result phar_open_or_create_tar(char *fname, size_t fname_len, char *alias, size_t alias_len, int is_data, uint32_t options, phar_archive_data** pphar, char **error); +zend_result phar_open_or_create_tar(char *fname, size_t fname_len, char *alias, size_t alias_len, bool is_data, uint32_t options, phar_archive_data** pphar, char **error); void phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error); /* zip functions in zip.c */ -int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alias, size_t alias_len, phar_archive_data** pphar, char **error); -int phar_open_or_create_zip(char *fname, size_t fname_len, char *alias, size_t alias_len, int is_data, uint32_t options, phar_archive_data** pphar, char **error); +zend_result phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alias, size_t alias_len, phar_archive_data** pphar, char **error); +zend_result phar_open_or_create_zip(char *fname, size_t fname_len, char *alias, size_t alias_len, bool is_data, uint32_t options, phar_archive_data** pphar, char **error); void phar_zip_flush(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error); #ifdef PHAR_MAIN @@ -463,13 +463,13 @@ extern HashTable cached_alias; bool phar_archive_delref(phar_archive_data *phar); void phar_entry_delref(phar_entry_data *idata); -phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, size_t path_len, char **error, int security); -phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, size_t path_len, char dir, char **error, int security); -phar_entry_data *phar_get_or_create_entry_data(char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, int security); -zend_result phar_get_entry_data(phar_entry_data **ret, char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, int security); +phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, size_t path_len, char **error, bool security); +phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, size_t path_len, char dir, char **error, bool security); +phar_entry_data *phar_get_or_create_entry_data(char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, bool security); +zend_result phar_get_entry_data(phar_entry_data **ret, char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, bool security); void phar_flush_ex(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error); void phar_flush(phar_archive_data *archive, char **error); -zend_result phar_detect_phar_fname_ext(const char *filename, size_t filename_len, const char **ext_str, size_t *ext_len, int executable, int for_create, int is_complete); +zend_result phar_detect_phar_fname_ext(const char *filename, size_t filename_len, const char **ext_str, size_t *ext_len, int executable, int for_create, bool is_complete); zend_result phar_split_fname(const char *filename, size_t filename_len, char **arch, size_t *arch_len, char **entry, size_t *entry_len, int executable, int for_create); typedef enum { diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index cde10da0c9415..0b7e55c5e9afa 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -199,7 +199,7 @@ static int phar_file_action(phar_archive_data *phar, phar_entry_info *info, char } /* prepare to output */ - fp = phar_get_efp(info, 1); + fp = phar_get_efp(info, true); if (!fp) { char *error; @@ -210,10 +210,10 @@ static int phar_file_action(phar_archive_data *phar, phar_entry_info *info, char } return -1; } - fp = phar_get_efp(info, 1); + fp = phar_get_efp(info, true); } position = 0; - phar_seek_efp(info, 0, SEEK_SET, 0, 1); + phar_seek_efp(info, 0, SEEK_SET, 0, true); do { got = php_stream_read(fp, buf, MIN(8192, info->uncompressed_filesize - position)); @@ -331,7 +331,7 @@ static void phar_do_404(phar_archive_data *phar, char *fname, size_t fname_len, phar_entry_info *info; if (phar && f404_len) { - info = phar_get_entry_info(phar, f404, f404_len, NULL, 1); + info = phar_get_entry_info(phar, f404, f404_len, NULL, true); if (info) { phar_file_action(phar, info, "text/html", PHAR_MIME_PHP, f404, f404_len, fname, NULL, NULL, 0); @@ -768,7 +768,7 @@ PHP_METHOD(Phar, webPhar) } if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, NULL) || - (info = phar_get_entry_info(phar, entry, entry_len, NULL, 0)) == NULL) { + (info = phar_get_entry_info(phar, entry, entry_len, NULL, false)) == NULL) { phar_do_404(phar, fname, fname_len, f404, f404_len, entry, entry_len); if (free_pathinfo) { @@ -814,7 +814,7 @@ PHP_METHOD(Phar, webPhar) } if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, NULL) || - (info = phar_get_entry_info(phar, entry, entry_len, NULL, 0)) == NULL) { + (info = phar_get_entry_info(phar, entry, entry_len, NULL, false)) == NULL) { phar_do_404(phar, fname, fname_len, f404, f404_len, entry, entry_len); zend_bailout(); } @@ -1067,15 +1067,13 @@ PHP_METHOD(Phar, isValidPharFilename) const char *ext_str; size_t fname_len; size_t ext_len; - int is_executable; - bool executable = true; + bool is_executable = true; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|b", &fname, &fname_len, &executable) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|b", &fname, &fname_len, &is_executable) == FAILURE) { RETURN_THROWS(); } - is_executable = executable; - RETVAL_BOOL(phar_detect_phar_fname_ext(fname, fname_len, &ext_str, &ext_len, is_executable, 2, 1) == SUCCESS); + RETURN_BOOL(phar_detect_phar_fname_ext(fname, fname_len, &ext_str, &ext_len, is_executable, 2, true) == SUCCESS); } /* }}} */ @@ -1193,8 +1191,8 @@ PHP_METHOD(Phar, __construct) } if (is_data && phar_data->is_tar && phar_data->is_brandnew && format == PHAR_FORMAT_ZIP) { - phar_data->is_zip = 1; - phar_data->is_tar = 0; + phar_data->is_zip = true; + phar_data->is_tar = false; } if (fname == arch) { @@ -1631,7 +1629,7 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */ return ZEND_HASH_APPLY_KEEP; } - if (!(data = phar_get_or_create_entry_data(phar_obj->archive->fname, phar_obj->archive->fname_len, str_key, str_key_len, "w+b", 0, &error, 1))) { + if (!(data = phar_get_or_create_entry_data(phar_obj->archive->fname, phar_obj->archive->fname_len, str_key, str_key_len, "w+b", 0, &error, true))) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Entry %s cannot be created: %s", str_key, error); efree(error); @@ -1914,7 +1912,7 @@ static zend_result phar_copy_file_contents(phar_entry_info *entry, php_stream *f ZEND_ASSERT(!entry->link); - if (FAILURE == phar_open_entry_fp(entry, &error, 1)) { + if (FAILURE == phar_open_entry_fp(entry, &error, true)) { if (error) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot convert phar archive \"%s\", unable to open entry \"%s\" contents: %s", entry->phar->fname, ZSTR_VAL(entry->filename), error); @@ -1927,9 +1925,9 @@ static zend_result phar_copy_file_contents(phar_entry_info *entry, php_stream *f } /* copy old contents in entirety */ - phar_seek_efp(entry, 0, SEEK_SET, 0, 0); + phar_seek_efp(entry, 0, SEEK_SET, 0, false); offset = php_stream_tell(fp); - if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(entry, 0), fp, entry->uncompressed_filesize, NULL)) { + if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(entry, false), fp, entry->uncompressed_filesize, NULL)) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot convert phar archive \"%s\", unable to copy entry \"%s\" contents", entry->phar->fname, ZSTR_VAL(entry->filename)); return FAILURE; @@ -2120,7 +2118,7 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext) /* goto err_reused_oldpath; } if (!phar->is_data) { - if (SUCCESS != phar_detect_phar_fname_ext(newpath, phar->fname_len, (const char **) &(phar->ext), &ext_len, 1, 1, 1)) { + if (SUCCESS != phar_detect_phar_fname_ext(newpath, phar->fname_len, (const char **) &(phar->ext), &ext_len, 1, 1, true)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "phar \"%s\" has invalid extension %s", phar->fname, ext); goto err_reused_oldpath; } @@ -2143,7 +2141,7 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext) /* } else { - if (SUCCESS != phar_detect_phar_fname_ext(newpath, phar->fname_len, (const char **) &(phar->ext), &ext_len, 0, 1, 1)) { + if (SUCCESS != phar_detect_phar_fname_ext(newpath, phar->fname_len, (const char **) &(phar->ext), &ext_len, 0, 1, true)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "data phar \"%s\" has invalid extension %s", phar->fname, ext); goto err_reused_oldpath; } @@ -2161,7 +2159,7 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext) /* goto err_oldpath; } - phar_flush_ex(phar, NULL, 1, &error); + phar_flush_ex(phar, NULL, true, &error); if (error) { zend_hash_str_del(&(PHAR_G(phar_fname_map)), newpath, phar->fname_len); @@ -2222,13 +2220,13 @@ static zend_object *phar_convert_to_other(phar_archive_data *source, int convert switch (convert) { case PHAR_FORMAT_TAR: - phar->is_tar = 1; + phar->is_tar = true; break; case PHAR_FORMAT_ZIP: - phar->is_zip = 1; + phar->is_zip = true; break; default: - phar->is_data = 0; + phar->is_data = false; break; } @@ -2327,7 +2325,6 @@ static zend_object *phar_convert_to_other(phar_archive_data *source, int convert PHP_METHOD(Phar, convertToExecutable) { char *ext = NULL; - int is_data; size_t ext_len = 0; uint32_t flags; zend_object *ret; @@ -2418,8 +2415,8 @@ PHP_METHOD(Phar, convertToExecutable) } } - is_data = phar_obj->archive->is_data; - phar_obj->archive->is_data = 0; + bool is_data = phar_obj->archive->is_data; + phar_obj->archive->is_data = false; ret = phar_convert_to_other(phar_obj->archive, format, ext, flags); phar_obj->archive->is_data = is_data; @@ -2438,7 +2435,6 @@ PHP_METHOD(Phar, convertToExecutable) PHP_METHOD(Phar, convertToData) { char *ext = NULL; - int is_data; size_t ext_len = 0; uint32_t flags; zend_object *ret; @@ -2528,8 +2524,8 @@ PHP_METHOD(Phar, convertToData) } } - is_data = phar_obj->archive->is_data; - phar_obj->archive->is_data = 1; + bool is_data = phar_obj->archive->is_data; + phar_obj->archive->is_data = true; ret = phar_convert_to_other(phar_obj->archive, (int)format, ext, flags); phar_obj->archive->is_data = is_data; @@ -2676,7 +2672,7 @@ PHP_METHOD(Phar, setAlias) char *error, *oldalias; phar_archive_data *fd_ptr; size_t oldalias_len; - int old_temp, readd = 0; + bool old_temp, readd = false; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &new_alias) == FAILURE) { RETURN_THROWS(); @@ -2724,7 +2720,7 @@ PHP_METHOD(Phar, setAlias) } if (phar_obj->archive->alias_len && NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), phar_obj->archive->alias, phar_obj->archive->alias_len))) { zend_hash_str_del(&(PHAR_G(phar_alias_map)), phar_obj->archive->alias, phar_obj->archive->alias_len); - readd = 1; + readd = true; } ZEND_ASSERT(!phar_obj->archive->is_persistent); @@ -2937,7 +2933,7 @@ PHP_METHOD(Phar, setDefaultStub) char *index = NULL, *webindex = NULL, *error = NULL; zend_string *stub = NULL; size_t index_len = 0, webindex_len = 0; - int created_stub = 0; + bool created_stub = false; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!", &index, &index_len, &webindex, &webindex_len) == FAILURE) { RETURN_THROWS(); @@ -3551,7 +3547,7 @@ PHP_METHOD(Phar, offsetGet) PHAR_ARCHIVE_OBJECT(); /* security is 0 here so that we can get a better error message than "entry doesn't exist" */ - if (!(entry = phar_get_entry_info_dir(phar_obj->archive, ZSTR_VAL(file_name), ZSTR_LEN(file_name), 1, &error, 0))) { + if (!(entry = phar_get_entry_info_dir(phar_obj->archive, ZSTR_VAL(file_name), ZSTR_LEN(file_name), 1, &error, false))) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Entry %s does not exist%s%s", ZSTR_VAL(file_name), error?", ":"", error?error:""); } else { if (zend_string_equals_literal(file_name, ".phar/stub.php")) { @@ -3624,7 +3620,7 @@ static void phar_add_file(phar_archive_data **pphar, zend_string *file_name, con } #endif - if (!(data = phar_get_or_create_entry_data((*pphar)->fname, (*pphar)->fname_len, filename, filename_len, "w+b", 0, &error, 1))) { + if (!(data = phar_get_or_create_entry_data((*pphar)->fname, (*pphar)->fname_len, filename, filename_len, "w+b", 0, &error, true))) { if (error) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Entry %s does not exist and cannot be created: %s", filename, error); efree(error); @@ -3696,7 +3692,7 @@ static void phar_mkdir(phar_archive_data **pphar, zend_string *dir_name) char *error; phar_entry_data *data; - if (!(data = phar_get_or_create_entry_data((*pphar)->fname, (*pphar)->fname_len, ZSTR_VAL(dir_name), ZSTR_LEN(dir_name), "w+b", 2, &error, 1))) { + if (!(data = phar_get_or_create_entry_data((*pphar)->fname, (*pphar)->fname_len, ZSTR_VAL(dir_name), ZSTR_LEN(dir_name), "w+b", 2, &error, true))) { if (error) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Directory %s does not exist and cannot be created: %s", ZSTR_VAL(dir_name), error); efree(error); @@ -3906,15 +3902,15 @@ PHP_METHOD(Phar, getStub) RETURN_THROWS(); } if (stub->flags & PHAR_ENT_COMPRESSION_MASK) { - char *filter_name; + const char *filter_name = phar_decompress_filter(stub, false); - if ((filter_name = phar_decompress_filter(stub, 0)) != NULL) { + if (filter_name != NULL) { filter = php_stream_filter_create(filter_name, NULL, php_stream_is_persistent(fp)); } else { filter = NULL; } if (!filter) { - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "phar error: unable to read stub of phar \"%s\" (cannot create %s filter)", phar_obj->archive->fname, phar_decompress_filter(stub, 1)); + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "phar error: unable to read stub of phar \"%s\" (cannot create %s filter)", phar_obj->archive->fname, phar_decompress_filter(stub, true)); RETURN_THROWS(); } php_stream_filter_append(&fp->readfilters, filter); @@ -4011,7 +4007,7 @@ PHP_METHOD(Phar, getMetadata) /* }}} */ /* {{{ Modifies the phar metadata or throws */ -static zend_result serialize_metadata_or_throw(phar_metadata_tracker *tracker, int persistent, zval *metadata) +static zend_result serialize_metadata_or_throw(phar_metadata_tracker *tracker, bool persistent, zval *metadata) { php_serialize_data_t metadata_hash; smart_str main_metadata_str = {0}; @@ -4112,7 +4108,7 @@ PHP_METHOD(Phar, delMetadata) } /* }}} */ -static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, char *dest, size_t dest_len, char **error) /* {{{ */ +static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, const zend_string *path, char **error) /* {{{ */ { php_stream_statbuf ssb; size_t len; @@ -4140,7 +4136,7 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha if (virtual_file_ex(&new_state, ZSTR_VAL(entry->filename), NULL, CWD_EXPAND) != 0 || new_state.cwd_length <= 1) { if (EINVAL == errno && ZSTR_LEN(entry->filename) > 50) { - spprintf(error, 4096, "Cannot extract \"%.50s...\" to \"%s...\", extracted filename is too long for filesystem", ZSTR_VAL(entry->filename), dest); + spprintf(error, 4096, "Cannot extract \"%.50s...\" to \"%s...\", extracted filename is too long for filesystem", ZSTR_VAL(entry->filename), ZSTR_VAL(path)); } else { spprintf(error, 4096, "Cannot extract \"%s\", internal error", ZSTR_VAL(entry->filename)); } @@ -4162,7 +4158,7 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha } #endif - len = spprintf(&fullpath, 0, "%s/%s", dest, filename); + len = spprintf(&fullpath, 0, "%s/%s", ZSTR_VAL(path), filename); if (len >= MAXPATHLEN) { /* truncate for error message */ @@ -4203,9 +4199,9 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha slash = zend_memrchr(filename, '/', filename_len); if (slash) { - fullpath[dest_len + (slash - filename) + 1] = '\0'; + fullpath[ZSTR_LEN(path) + (slash - filename) + 1] = '\0'; } else { - fullpath[dest_len] = '\0'; + fullpath[ZSTR_LEN(path)] = '\0'; } if (FAILURE == php_stream_stat_path(fullpath, &ssb)) { @@ -4227,9 +4223,9 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha } if (slash) { - fullpath[dest_len + (slash - filename) + 1] = '/'; + fullpath[ZSTR_LEN(path) + (slash - filename) + 1] = '/'; } else { - fullpath[dest_len] = '/'; + fullpath[ZSTR_LEN(path)] = '/'; } filename = NULL; @@ -4248,8 +4244,8 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha return FAILURE; } - if ((phar_get_fp_type(entry) == PHAR_FP && (entry->flags & PHAR_ENT_COMPRESSION_MASK)) || !phar_get_efp(entry, 0)) { - if (FAILURE == phar_open_entry_fp(entry, error, 1)) { + if ((phar_get_fp_type(entry) == PHAR_FP && (entry->flags & PHAR_ENT_COMPRESSION_MASK)) || !phar_get_efp(entry, false)) { + if (FAILURE == phar_open_entry_fp(entry, error, true)) { if (error) { spprintf(error, 4096, "Cannot extract \"%s\" to \"%s\", unable to open internal file pointer: %s", ZSTR_VAL(entry->filename), fullpath, *error); } else { @@ -4261,14 +4257,14 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha } } - if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0)) { + if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, false)) { spprintf(error, 4096, "Cannot extract \"%s\" to \"%s\", unable to seek internal file pointer", ZSTR_VAL(entry->filename), fullpath); efree(fullpath); php_stream_close(fp); return FAILURE; } - if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(entry, 0), fp, entry->uncompressed_filesize, NULL)) { + if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(entry, false), fp, entry->uncompressed_filesize, NULL)) { spprintf(error, 4096, "Cannot extract \"%s\" to \"%s\", copying contents failed", ZSTR_VAL(entry->filename), fullpath); efree(fullpath); php_stream_close(fp); @@ -4289,28 +4285,28 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha } /* }}} */ -static int extract_helper(phar_archive_data *archive, zend_string *search, char *pathto, size_t pathto_len, bool overwrite, char **error) { /* {{{ */ +static int extract_helper(const phar_archive_data *archive, zend_string *search, const zend_string *path_to, bool overwrite, char **error) { /* {{{ */ int extracted = 0; phar_entry_info *entry; if (!search) { /* nothing to match -- extract all files */ ZEND_HASH_MAP_FOREACH_PTR(&archive->manifest, entry) { - if (FAILURE == phar_extract_file(overwrite, entry, pathto, pathto_len, error)) return -1; + if (FAILURE == phar_extract_file(overwrite, entry, path_to, error)) return -1; extracted++; } ZEND_HASH_FOREACH_END(); } else if (ZSTR_LEN(search) > 0 && '/' == ZSTR_VAL(search)[ZSTR_LEN(search) - 1]) { /* ends in "/" -- extract all entries having that prefix */ ZEND_HASH_MAP_FOREACH_PTR(&archive->manifest, entry) { if (!zend_string_starts_with(entry->filename, search)) continue; - if (FAILURE == phar_extract_file(overwrite, entry, pathto, pathto_len, error)) return -1; + if (FAILURE == phar_extract_file(overwrite, entry, path_to, error)) return -1; extracted++; } ZEND_HASH_FOREACH_END(); } else { /* otherwise, looking for an exact match */ entry = zend_hash_find_ptr(&archive->manifest, search); if (NULL == entry) return 0; - if (FAILURE == phar_extract_file(overwrite, entry, pathto, pathto_len, error)) return -1; + if (FAILURE == phar_extract_file(overwrite, entry, path_to, error)) return -1; return 1; } @@ -4323,9 +4319,8 @@ PHP_METHOD(Phar, extractTo) { php_stream *fp; php_stream_statbuf ssb; - char *pathto; + zend_string *path_to; zend_string *filename = NULL; - size_t pathto_len; int ret; zval *zval_file; HashTable *files_ht = NULL; @@ -4333,7 +4328,7 @@ PHP_METHOD(Phar, extractTo) char *error = NULL; ZEND_PARSE_PARAMETERS_START(1, 3) - Z_PARAM_PATH(pathto, pathto_len) + Z_PARAM_PATH_STR(path_to) Z_PARAM_OPTIONAL Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(files_ht, filename) Z_PARAM_BOOL(overwrite) @@ -4351,30 +4346,30 @@ PHP_METHOD(Phar, extractTo) php_stream_close(fp); - if (pathto_len < 1) { + if (ZSTR_LEN(path_to) == 0) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Invalid argument, extraction path must be non-zero length"); RETURN_THROWS(); } - if (pathto_len >= MAXPATHLEN) { - char *tmp = estrndup(pathto, 50); + if (ZSTR_LEN(path_to) >= MAXPATHLEN) { + char *tmp = estrndup(ZSTR_VAL(path_to), 50); /* truncate for error message */ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Cannot extract to \"%s...\", destination directory is too long for filesystem", tmp); efree(tmp); RETURN_THROWS(); } - if (php_stream_stat_path(pathto, &ssb) < 0) { - ret = php_stream_mkdir(pathto, 0777, PHP_STREAM_MKDIR_RECURSIVE, NULL); + if (php_stream_stat_path(ZSTR_VAL(path_to), &ssb) < 0) { + ret = php_stream_mkdir(ZSTR_VAL(path_to), 0777, PHP_STREAM_MKDIR_RECURSIVE, NULL); if (!ret) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, - "Unable to create path \"%s\" for extraction", pathto); + "Unable to create path \"%s\" for extraction", ZSTR_VAL(path_to)); RETURN_THROWS(); } } else if (!(ssb.sb.st_mode & S_IFDIR)) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, - "Unable to use path \"%s\" for extraction, it is a file, must be a directory", pathto); + "Unable to use path \"%s\" for extraction, it is a file, must be a directory", ZSTR_VAL(path_to)); RETURN_THROWS(); } @@ -4390,7 +4385,7 @@ PHP_METHOD(Phar, extractTo) "Invalid argument, array of filenames to extract contains non-string value"); RETURN_THROWS(); } - switch (extract_helper(phar_obj->archive, Z_STR_P(zval_file), pathto, pathto_len, overwrite, &error)) { + switch (extract_helper(phar_obj->archive, Z_STR_P(zval_file), path_to, overwrite, &error)) { case -1: zend_throw_exception_ex(phar_ce_PharException, 0, "Extraction from phar \"%s\" failed: %s", phar_obj->archive->fname, error); @@ -4406,7 +4401,7 @@ PHP_METHOD(Phar, extractTo) RETURN_TRUE; } - ret = extract_helper(phar_obj->archive, filename, pathto, pathto_len, overwrite, &error); + ret = extract_helper(phar_obj->archive, filename, path_to, overwrite, &error); if (-1 == ret) { zend_throw_exception_ex(phar_ce_PharException, 0, "Extraction from phar \"%s\" failed: %s", phar_obj->archive->fname, error); @@ -4464,7 +4459,7 @@ PHP_METHOD(PharFileInfo, __construct) RETURN_THROWS(); } - if ((entry_info = phar_get_entry_info_dir(phar_data, entry, entry_len, 1, &error, 1)) == NULL) { + if ((entry_info = phar_get_entry_info_dir(phar_data, entry, entry_len, 1, &error, true)) == NULL) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot access phar file entry '%s' in archive '%s'%s%s", entry, arch, error ? ", " : "", error ? error : ""); efree(arch); @@ -4844,20 +4839,20 @@ PHP_METHOD(PharFileInfo, getContent) link = entry_obj->entry; } - if (SUCCESS != phar_open_entry_fp(link, &error, 0)) { + if (SUCCESS != phar_open_entry_fp(link, &error, false)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "phar error: Cannot retrieve contents, \"%s\" in phar \"%s\": %s", ZSTR_VAL(entry_obj->entry->filename), entry_obj->entry->phar->fname, error); efree(error); RETURN_THROWS(); } - if (!(fp = phar_get_efp(link, 0))) { + if (!(fp = phar_get_efp(link, false))) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "phar error: Cannot retrieve contents of \"%s\" in phar \"%s\"", ZSTR_VAL(entry_obj->entry->filename), entry_obj->entry->phar->fname); RETURN_THROWS(); } - phar_seek_efp(link, 0, SEEK_SET, 0, 0); + phar_seek_efp(link, 0, SEEK_SET, 0, false); str = php_stream_copy_to_mem(fp, link->uncompressed_filesize, 0); if (str) { RETURN_STR(str); @@ -4927,7 +4922,7 @@ PHP_METHOD(PharFileInfo, compress) } /* decompress this file indirectly */ - if (SUCCESS != phar_open_entry_fp(entry_obj->entry, &error, 1)) { + if (SUCCESS != phar_open_entry_fp(entry_obj->entry, &error, true)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "phar error: Cannot decompress bzip2-compressed file \"%s\" in phar \"%s\" in order to compress with gzip: %s", ZSTR_VAL(entry_obj->entry->filename), entry_obj->entry->phar->fname, error); efree(error); @@ -4958,7 +4953,7 @@ PHP_METHOD(PharFileInfo, compress) } /* decompress this file indirectly */ - if (SUCCESS != phar_open_entry_fp(entry_obj->entry, &error, 1)) { + if (SUCCESS != phar_open_entry_fp(entry_obj->entry, &error, true)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "phar error: Cannot decompress gzip-compressed file \"%s\" in phar \"%s\" in order to compress with bzip2: %s", ZSTR_VAL(entry_obj->entry->filename), entry_obj->entry->phar->fname, error); efree(error); @@ -5063,7 +5058,7 @@ PHP_METHOD(PharFileInfo, decompress) RETURN_THROWS(); } /* decompress this file indirectly */ - if (SUCCESS != phar_open_entry_fp(entry_obj->entry, &error, 1)) { + if (SUCCESS != phar_open_entry_fp(entry_obj->entry, &error, true)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Phar error: Cannot decompress %s-compressed file \"%s\" in phar \"%s\": %s", compression_type, ZSTR_VAL(entry_obj->entry->filename), entry_obj->entry->phar->fname, error); efree(error); diff --git a/ext/phar/stream.c b/ext/phar/stream.c index 285b73cf88fd9..d7bcc78fd8a8d 100644 --- a/ext/phar/stream.c +++ b/ext/phar/stream.c @@ -191,7 +191,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha /* strip leading "/" */ internal_file = estrndup(ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1); if (mode[0] == 'w' || (mode[0] == 'r' && mode[1] == '+')) { - if (NULL == (idata = phar_get_or_create_entry_data(ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), internal_file, strlen(internal_file), mode, 0, &error, 1))) { + if (NULL == (idata = phar_get_or_create_entry_data(ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), internal_file, strlen(internal_file), mode, 0, &error, true))) { if (error) { php_stream_wrapper_log_error(wrapper, options, "%s", error); efree(error); @@ -225,7 +225,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha metadata = pzoption; ZVAL_COPY_DEREF(&idata->internal_file->metadata_tracker.val, metadata); - idata->phar->is_modified = 1; + idata->phar->is_modified = true; } } if (opened_path) { @@ -242,7 +242,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha return NULL; } if (phar->is_tar || phar->is_zip) { - if ((FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), ".phar/stub.php", sizeof(".phar/stub.php")-1, "r", 0, &error, 0)) || !idata) { + if ((FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), ".phar/stub.php", sizeof(".phar/stub.php")-1, "r", 0, &error, false)) || !idata) { goto idata_error; } efree(internal_file); @@ -290,7 +290,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha } } /* read-only access is allowed to magic files in .phar directory */ - if ((FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), internal_file, strlen(internal_file), "r", 0, &error, 0)) || !idata) { + if ((FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), internal_file, strlen(internal_file), "r", 0, &error, false)) || !idata) { idata_error: if (error) { php_stream_wrapper_log_error(wrapper, options, "%s", error); @@ -447,7 +447,7 @@ static ssize_t phar_stream_write(php_stream *stream, const char *buf, size_t cou php_stream_seek(data->fp, data->position + data->zero, SEEK_SET); if (count != php_stream_write(data->fp, buf, count)) { - php_stream_wrapper_log_error(stream->wrapper, stream->flags, "phar error: Could not write %d characters to \"%s\" in phar \"%s\"", (int) count, ZSTR_VAL(data->internal_file->filename), data->phar->fname); + php_stream_wrapper_log_error(stream->wrapper, stream->flags, "phar error: Could not write %zu characters to \"%s\" in phar \"%s\"", count, ZSTR_VAL(data->internal_file->filename), data->phar->fname); return -1; } data->position = php_stream_tell(data->fp) - data->zero; @@ -456,7 +456,7 @@ static ssize_t phar_stream_write(php_stream *stream, const char *buf, size_t cou } data->internal_file->compressed_filesize = data->internal_file->uncompressed_filesize; data->internal_file->old_flags = data->internal_file->flags; - data->internal_file->is_modified = 1; + data->internal_file->is_modified = true; return count; } /* }}} */ @@ -699,7 +699,7 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int /* need to copy to strip leading "/", will get touched again */ internal_file = estrndup(ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1); internal_file_len = ZSTR_LEN(resource->path) - 1; - if (FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), internal_file, internal_file_len, "r", 0, &error, 1)) { + if (FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), internal_file, internal_file_len, "r", 0, &error, true)) { /* constraints of fp refcount were not met */ if (error) { php_stream_wrapper_log_error(wrapper, options, "unlink of \"%s\" failed: %s", url, error); @@ -739,8 +739,8 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from char *error; phar_archive_data *phar, *pfrom, *pto; phar_entry_info *entry; - int is_dir = 0; - int is_modified = 0; + bool is_dir = false; + bool is_modified = false; error = NULL; @@ -861,8 +861,8 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from zend_hash_del(&phar->manifest, entry->filename); return 0; } - is_modified = 1; - entry->is_modified = 1; + is_modified = true; + entry->is_modified = true; is_dir = entry->is_dir; } else { is_dir = zend_hash_str_exists(&(phar->virtual_dirs), ZSTR_VAL(resource_from->path)+1, ZSTR_LEN(resource_from->path)-1); @@ -897,8 +897,8 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from memcpy(ZSTR_VAL(new_str_key) + to_len, ZSTR_VAL(str_key) + from_len, ZSTR_LEN(str_key) - from_len); ZSTR_VAL(new_str_key)[ZSTR_LEN(new_str_key)] = 0; - is_modified = 1; - entry->is_modified = 1; + is_modified = true; + entry->is_modified = true; zend_string_release(entry->filename); entry->filename = zend_string_copy(new_str_key); diff --git a/ext/phar/tar.c b/ext/phar/tar.c index c8477e9e9928b..540f265892299 100644 --- a/ext/phar/tar.c +++ b/ext/phar/tar.c @@ -127,7 +127,7 @@ bool phar_is_tar(char *buf, char *fname) /* {{{ */ } /* }}} */ -zend_result phar_open_or_create_tar(char *fname, size_t fname_len, char *alias, size_t alias_len, int is_data, uint32_t options, phar_archive_data** pphar, char **error) /* {{{ */ +zend_result phar_open_or_create_tar(char *fname, size_t fname_len, char *alias, size_t alias_len, bool is_data, uint32_t options, phar_archive_data** pphar, char **error) /* {{{ */ { phar_archive_data *phar; zend_result ret = phar_create_or_parse_filename(fname, fname_len, alias, alias_len, is_data, options, &phar, error); @@ -210,7 +210,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch tar_header *hdr; uint32_t sum1, sum2, size, old; phar_archive_data *myphar, *actual; - int last_was_longlink = 0; + bool last_was_longlink = false; size_t linkname_len; if (error) { @@ -361,7 +361,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch } if (!last_was_longlink && hdr->typeflag == 'L') { - last_was_longlink = 1; + last_was_longlink = true; /* support the ././@LongLink system for storing long filenames */ /* Check for overflow - bug 61065 */ @@ -465,7 +465,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch GC_MAKE_PERSISTENT_LOCAL(entry.filename); } } - last_was_longlink = 0; + last_was_longlink = false; phar_add_virtual_dirs(myphar, ZSTR_VAL(entry.filename), ZSTR_LEN(entry.filename)); @@ -819,18 +819,18 @@ static int phar_tar_writeheaders_int(phar_entry_info *entry, void *argument) /* /* write contents */ if (entry->uncompressed_filesize) { - if (FAILURE == phar_open_entry_fp(entry, fp->error, 0)) { + if (FAILURE == phar_open_entry_fp(entry, fp->error, false)) { return ZEND_HASH_APPLY_STOP; } - if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0)) { + if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, false)) { if (fp->error) { spprintf(fp->error, 4096, "tar-based phar \"%s\" cannot be created, contents of file \"%s\" could not be written, seek failed", entry->phar->fname, ZSTR_VAL(entry->filename)); } return ZEND_HASH_APPLY_STOP; } - if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(entry, 0), fp->new, entry->uncompressed_filesize, NULL)) { + if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(entry, false), fp->new, entry->uncompressed_filesize, NULL)) { if (fp->error) { spprintf(fp->error, 4096, "tar-based phar \"%s\" cannot be created, contents of file \"%s\" could not be written", entry->phar->fname, ZSTR_VAL(entry->filename)); } diff --git a/ext/phar/util.c b/ext/phar/util.c index 26a11d99a9c14..51ebfb36275d7 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -96,13 +96,13 @@ static php_stream *phar_get_entrypufp(const phar_entry_info *entry) } /* retrieve a phar_entry_info's current file pointer for reading contents */ -php_stream *phar_get_efp(phar_entry_info *entry, int follow_links) /* {{{ */ +php_stream *phar_get_efp(phar_entry_info *entry, bool follow_links) /* {{{ */ { if (follow_links && entry->link) { phar_entry_info *link_entry = phar_get_link_source(entry); if (link_entry && link_entry != entry) { - return phar_get_efp(link_entry, 1); + return phar_get_efp(link_entry, true); } } @@ -139,7 +139,7 @@ static zend_off_t phar_get_fp_offset(const phar_entry_info *entry) return PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos].offset; } -int phar_seek_efp(phar_entry_info *entry, zend_off_t offset, int whence, zend_off_t position, int follow_links) /* {{{ */ +int phar_seek_efp(phar_entry_info *entry, zend_off_t offset, int whence, zend_off_t position, bool follow_links) /* {{{ */ { php_stream *fp = phar_get_efp(entry, follow_links); zend_off_t temp, eoffset; @@ -193,7 +193,7 @@ zend_result phar_mount_entry(phar_archive_data *phar, char *filename, size_t fil { phar_entry_info entry = {0}; php_stream_statbuf ssb; - int is_phar; + bool is_phar; const char *err; if (phar_path_check(&path, &path_len, &err) > pcr_is_ok) { @@ -225,8 +225,8 @@ zend_result phar_mount_entry(phar_archive_data *phar, char *filename, size_t fil return FAILURE; } - entry.is_mounted = 1; - entry.is_crc_checked = 1; + entry.is_mounted = true; + entry.is_crc_checked = true; entry.fp_type = PHAR_TMP; if (SUCCESS != php_stream_stat_path(filename, &ssb)) { @@ -240,7 +240,7 @@ zend_result phar_mount_entry(phar_archive_data *phar, char *filename, size_t fil #endif if (ssb.sb.st_mode & S_IFDIR) { - entry.is_dir = 1; + entry.is_dir = true; if (NULL == zend_hash_add_ptr(&phar->mounted_dirs, entry.filename, entry.filename)) { /* directory already mounted */ efree(entry.tmp); @@ -248,7 +248,7 @@ zend_result phar_mount_entry(phar_archive_data *phar, char *filename, size_t fil return FAILURE; } } else { - entry.is_dir = 0; + entry.is_dir = false; entry.uncompressed_filesize = entry.compressed_filesize = ssb.sb.st_size; } @@ -420,7 +420,7 @@ static zend_result phar_separate_entry_fp(phar_entry_info *entry, char **error) php_stream *fp; phar_entry_info *link; - if (FAILURE == phar_open_entry_fp(entry, error, 1)) { + if (FAILURE == phar_open_entry_fp(entry, error, true)) { return FAILURE; } @@ -433,14 +433,14 @@ static zend_result phar_separate_entry_fp(phar_entry_info *entry, char **error) spprintf(error, 0, "phar error: unable to create temporary file"); return FAILURE; } - phar_seek_efp(entry, 0, SEEK_SET, 0, 1); + phar_seek_efp(entry, 0, SEEK_SET, 0, true); link = phar_get_link_source(entry); if (!link) { link = entry; } - if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(link, 0), fp, link->uncompressed_filesize, NULL)) { + if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(link, false), fp, link->uncompressed_filesize, NULL)) { if (error) { spprintf(error, 4096, "phar error: cannot separate entry file \"%s\" contents in phar archive \"%s\" for write access", ZSTR_VAL(entry->filename), entry->phar->fname); } @@ -469,7 +469,7 @@ static zend_result phar_separate_entry_fp(phar_entry_info *entry, char **error) * appended, truncated, or read. For read, if the entry is marked unmodified, it is * assumed that the file pointer, if present, is opened for reading */ -zend_result phar_get_entry_data(phar_entry_data **ret, char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, int security) /* {{{ */ +zend_result phar_get_entry_data(phar_entry_data **ret, char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, bool security) /* {{{ */ { phar_archive_data *phar; phar_entry_info *entry; @@ -575,7 +575,7 @@ zend_result phar_get_entry_data(phar_entry_data **ret, char *fname, size_t fname return FAILURE; } } else if (for_append) { - phar_seek_efp(entry, 0, SEEK_END, 0, 0); + phar_seek_efp(entry, 0, SEEK_END, 0, false); } } else { if (for_write) { @@ -595,7 +595,7 @@ zend_result phar_get_entry_data(phar_entry_data **ret, char *fname, size_t fname } } } else { - if (FAILURE == phar_open_entry_fp(entry, error, 1)) { + if (FAILURE == phar_open_entry_fp(entry, error, true)) { return FAILURE; } } @@ -605,7 +605,7 @@ zend_result phar_get_entry_data(phar_entry_data **ret, char *fname, size_t fname (*ret)->position = 0; (*ret)->phar = phar; (*ret)->internal_file = entry; - (*ret)->fp = phar_get_efp(entry, 1); + (*ret)->fp = phar_get_efp(entry, true); if (entry->link) { phar_entry_info *link = phar_get_link_source(entry); if(!link) { @@ -629,7 +629,7 @@ zend_result phar_get_entry_data(phar_entry_data **ret, char *fname, size_t fname /** * Create a new dummy file slot within a writeable phar for a newly created file */ -phar_entry_data *phar_get_or_create_entry_data(char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, int security) /* {{{ */ +phar_entry_data *phar_get_or_create_entry_data(char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, bool security) /* {{{ */ { phar_archive_data *phar; phar_entry_info *entry, etemp; @@ -764,7 +764,7 @@ zend_result phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, c { phar_entry_info *link; - if (FAILURE == phar_open_entry_fp(source, error, 1)) { + if (FAILURE == phar_open_entry_fp(source, error, true)) { return FAILURE; } @@ -782,14 +782,14 @@ zend_result phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, c spprintf(error, 0, "phar error: unable to create temporary file"); return EOF; } - phar_seek_efp(source, 0, SEEK_SET, 0, 1); + phar_seek_efp(source, 0, SEEK_SET, 0, true); link = phar_get_link_source(source); if (!link) { link = source; } - if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(link, 0), dest->fp, link->uncompressed_filesize, NULL)) { + if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(link, false), dest->fp, link->uncompressed_filesize, NULL)) { php_stream_close(dest->fp); dest->fp_type = PHAR_FP; if (error) { @@ -828,11 +828,10 @@ static void phar_set_fp_type(phar_entry_info *entry, enum phar_fp_type type, zen /* open and decompress a compressed phar entry */ -zend_result phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links) /* {{{ */ +zend_result phar_open_entry_fp(phar_entry_info *entry, char **error, bool follow_links) /* {{{ */ { php_stream_filter *filter; phar_archive_data *phar = entry->phar; - char *filtername; zend_off_t loc; php_stream *ufp; phar_entry_data dummy; @@ -840,7 +839,7 @@ zend_result phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_ if (follow_links && entry->link) { phar_entry_info *link_entry = phar_get_link_source(entry); if (link_entry && link_entry != entry) { - return phar_open_entry_fp(link_entry, error, 1); + return phar_open_entry_fp(link_entry, error, true); } } @@ -896,14 +895,15 @@ zend_result phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_ ufp = phar_get_entrypufp(entry); - if ((filtername = phar_decompress_filter(entry, 0)) != NULL) { - filter = php_stream_filter_create(filtername, NULL, 0); + const char *filter_name = phar_decompress_filter(entry, false); + if (filter_name != NULL) { + filter = php_stream_filter_create(filter_name, NULL, 0); } else { filter = NULL; } if (!filter) { - spprintf(error, 4096, "phar error: unable to read phar \"%s\" (cannot create %s filter while decompressing file \"%s\")", phar->fname, phar_decompress_filter(entry, 1), ZSTR_VAL(entry->filename)); + spprintf(error, 4096, "phar error: unable to read phar \"%s\" (cannot create %s filter while decompressing file \"%s\")", phar->fname, phar_decompress_filter(entry, true), ZSTR_VAL(entry->filename)); return FAILURE; } @@ -953,10 +953,10 @@ phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, *error = NULL; } /* seek to start of internal file and read it */ - if (FAILURE == phar_open_entry_fp(entry, error, 1)) { + if (FAILURE == phar_open_entry_fp(entry, error, true)) { return NULL; } - if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 1)) { + if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, true)) { spprintf(error, 4096, "phar error: cannot seek to start of file \"%s\" in phar \"%s\"", ZSTR_VAL(entry->filename), phar->fname); return NULL; } @@ -1191,7 +1191,7 @@ zend_result phar_get_archive(phar_archive_data **archive, char *fname, size_t fn /** * Determine which stream compression filter (if any) we need to read this file */ -char * phar_compress_filter(phar_entry_info * entry, int return_unknown) /* {{{ */ +const char * phar_compress_filter(const phar_entry_info *entry, bool return_unknown) /* {{{ */ { switch (entry->flags & PHAR_ENT_COMPRESSION_MASK) { case PHAR_ENT_COMPRESSED_GZ: @@ -1207,7 +1207,7 @@ char * phar_compress_filter(phar_entry_info * entry, int return_unknown) /* {{{ /** * Determine which stream decompression filter (if any) we need to read this file */ -char * phar_decompress_filter(phar_entry_info * entry, int return_unknown) /* {{{ */ +const char * phar_decompress_filter(const phar_entry_info *entry, bool return_unknown) /* {{{ */ { uint32_t flags; @@ -1231,7 +1231,7 @@ char * phar_decompress_filter(phar_entry_info * entry, int return_unknown) /* {{ /** * retrieve information on a file contained within a phar, or null if it ain't there */ -phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, size_t path_len, char **error, int security) /* {{{ */ +phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, size_t path_len, char **error, bool security) /* {{{ */ { return phar_get_entry_info_dir(phar, path, path_len, 0, error, security); } @@ -1242,17 +1242,17 @@ phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, size_t * valid pre-existing empty directory entries */ // TODO: convert this to use zend_string too -phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, size_t path_len, char dir, char **error, int security) /* {{{ */ +phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, size_t path_len, char dir, char **error, bool security) /* {{{ */ { const char *pcr_error; phar_entry_info *entry; - int is_dir; + bool is_dir; #ifdef PHP_WIN32 phar_unixify_path_separators(path, path_len); #endif - is_dir = (path_len && (path[path_len - 1] == '/')) ? 1 : 0; + is_dir = path_len && (path[path_len - 1] == '/'); if (error) { *error = NULL; diff --git a/ext/phar/zip.c b/ext/phar/zip.c index 0783b5f4e2c95..4949750e28706 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -41,7 +41,7 @@ static inline void phar_write_16(char buffer[2], uint32_t value) # define PHAR_SET_32(var, value) phar_write_32(var, (uint32_t) (value)); # define PHAR_SET_16(var, value) phar_write_16(var, (uint16_t) (value)); -static int phar_zip_process_extra(php_stream *fp, phar_entry_info *entry, uint16_t len) /* {{{ */ +static zend_result phar_zip_process_extra(php_stream *fp, phar_entry_info *entry, uint16_t len) /* {{{ */ { union { phar_zip_extra_field_header header; @@ -226,7 +226,7 @@ static char *phar_find_eocd(const char *s, size_t n) * This is used by phar_open_from_fp to process a zip-based phar, but can be called * directly. */ -int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alias, size_t alias_len, phar_archive_data** pphar, char **error) /* {{{ */ +zend_result phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alias, size_t alias_len, phar_archive_data** pphar, char **error) /* {{{ */ { phar_zip_dir_end locator; char buf[sizeof(locator) + 65536]; @@ -798,10 +798,10 @@ int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alia /** * Create or open a zip-based phar for writing */ -int phar_open_or_create_zip(char *fname, size_t fname_len, char *alias, size_t alias_len, int is_data, uint32_t options, phar_archive_data** pphar, char **error) /* {{{ */ +zend_result phar_open_or_create_zip(char *fname, size_t fname_len, char *alias, size_t alias_len, bool is_data, uint32_t options, phar_archive_data** pphar, char **error) /* {{{ */ { phar_archive_data *phar; - int ret = phar_create_or_parse_filename(fname, fname_len, alias, alias_len, is_data, options, &phar, error); + zend_result ret = phar_create_or_parse_filename(fname, fname_len, alias, alias_len, is_data, options, &phar, error); if (FAILURE == ret) { return FAILURE; @@ -849,7 +849,7 @@ static int phar_zip_changed_apply_int(phar_entry_info *entry, void *arg) /* {{{ struct _phar_zip_pass *p; uint32_t newcrc32; zend_off_t offset; - int not_really_modified = 0; + bool not_really_modified = false; p = (struct _phar_zip_pass*) arg; uint16_t general_purpose_flags; @@ -923,23 +923,23 @@ static int phar_zip_changed_apply_int(phar_entry_info *entry, void *arg) /* {{{ goto continue_dir; } - if (FAILURE == phar_open_entry_fp(entry, p->error, 0)) { + if (FAILURE == phar_open_entry_fp(entry, p->error, false)) { spprintf(p->error, 0, "unable to open file contents of file \"%s\" in zip-based phar \"%s\"", ZSTR_VAL(entry->filename), entry->phar->fname); return ZEND_HASH_APPLY_STOP; } /* we can be modified and already be compressed, such as when chmod() is executed */ if (entry->flags & PHAR_ENT_COMPRESSION_MASK && (entry->old_flags == entry->flags || !entry->old_flags)) { - not_really_modified = 1; + not_really_modified = true; goto is_compressed; } - if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0)) { + if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, false)) { spprintf(p->error, 0, "unable to seek to start of file \"%s\" to zip-based phar \"%s\"", ZSTR_VAL(entry->filename), entry->phar->fname); return ZEND_HASH_APPLY_STOP; } - efp = phar_get_efp(entry, 0); + efp = phar_get_efp(entry, false); newcrc32 = php_crc32_bulk_init(); php_crc32_stream_bulk_update(&newcrc32, efp, entry->uncompressed_filesize); @@ -956,7 +956,7 @@ static int phar_zip_changed_apply_int(phar_entry_info *entry, void *arg) /* {{{ goto not_compressed; } - filter = php_stream_filter_create(phar_compress_filter(entry, 0), NULL, 0); + filter = php_stream_filter_create(phar_compress_filter(entry, false), NULL, 0); if (!filter) { if (entry->flags & PHAR_ENT_COMPRESSED_GZ) { @@ -980,7 +980,7 @@ static int phar_zip_changed_apply_int(phar_entry_info *entry, void *arg) /* {{{ php_stream_flush(efp); - if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0)) { + if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, false)) { php_stream_filter_free(filter); spprintf(p->error, 0, "unable to seek to start of file \"%s\" to zip-based phar \"%s\"", ZSTR_VAL(entry->filename), entry->phar->fname); return ZEND_HASH_APPLY_STOP; @@ -1093,13 +1093,13 @@ static int phar_zip_changed_apply_int(phar_entry_info *entry, void *arg) /* {{{ php_stream_close(entry->cfp); entry->cfp = NULL; } else { - if (FAILURE == phar_open_entry_fp(entry, p->error, 0)) { + if (FAILURE == phar_open_entry_fp(entry, p->error, false)) { return ZEND_HASH_APPLY_STOP; } - phar_seek_efp(entry, 0, SEEK_SET, 0, 0); + phar_seek_efp(entry, 0, SEEK_SET, 0, false); - if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(entry, 0), p->filefp, entry->uncompressed_filesize, NULL)) { + if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(entry, false), p->filefp, entry->uncompressed_filesize, NULL)) { spprintf(p->error, 0, "unable to write contents of file \"%s\" in zip-based phar \"%s\"", ZSTR_VAL(entry->filename), entry->phar->fname); return ZEND_HASH_APPLY_STOP; } @@ -1152,7 +1152,7 @@ static int phar_zip_changed_apply(zval *zv, void *arg) /* {{{ */ } /* }}} */ -static int phar_zip_applysignature(phar_archive_data *phar, struct _phar_zip_pass *pass) /* {{{ */ +static zend_result phar_zip_applysignature(phar_archive_data *phar, struct _phar_zip_pass *pass) /* {{{ */ { /* add signature for executable tars or tars explicitly set with setSignatureAlgorithm */ if (!phar->is_data || phar->sig_flags) { @@ -1442,7 +1442,7 @@ void phar_zip_flush(phar_archive_data *phar, zend_string *user_stub, bool is_def { size_t clen; - int ret = php_stream_copy_to_stream_ex(pass.centralfp, pass.filefp, PHP_STREAM_COPY_ALL, &clen); + zend_result ret = php_stream_copy_to_stream_ex(pass.centralfp, pass.filefp, PHP_STREAM_COPY_ALL, &clen); if (SUCCESS != ret || clen != cdir_size) { if (error) { spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write central-directory", phar->fname);