From 2513258a2b4e83a5c864cc1152914414d6565375 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Fri, 13 Sep 2024 13:42:46 +0200 Subject: [PATCH] ext/phar: Voidify flush function as it always returns EOL --- ext/phar/phar.c | 41 ++++++++++++++++++------------------ ext/phar/phar_internal.h | 8 +++---- ext/phar/stream.c | 5 ++--- ext/phar/tar.c | 45 ++++++++++++++++++++-------------------- ext/phar/zip.c | 29 +++++++++++++------------- 5 files changed, 62 insertions(+), 66 deletions(-) diff --git a/ext/phar/phar.c b/ext/phar/phar.c index e644c4792be..5ae2d2f9a45 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -2520,8 +2520,8 @@ zend_string *phar_create_default_stub(const char *index_php, const char *web_ind } /* }}} */ -int phar_flush(phar_archive_data *phar, char **error) { - return phar_flush_ex(phar, NULL, false, error); +void phar_flush(phar_archive_data *phar, char **error) { + phar_flush_ex(phar, NULL, false, error); } /** @@ -2529,7 +2529,7 @@ int phar_flush(phar_archive_data *phar, char **error) { * * if user_stub is NULL the default or existing stub should be used */ -int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error) /* {{{ */ +void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error) /* {{{ */ { static const char halt_stub[] = "__HALT_COMPILER();"; @@ -2557,7 +2557,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau if (error) { spprintf(error, 0, "internal error: attempt to flush cached zip-based phar \"%s\"", phar->fname); } - return EOF; + return; } if (error) { @@ -2565,21 +2565,23 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau } if (!zend_hash_num_elements(&phar->manifest) && !user_stub) { - return EOF; + return; } zend_hash_clean(&phar->virtual_dirs); if (phar->is_zip) { - return phar_zip_flush(phar, user_stub, is_default_stub, error); + phar_zip_flush(phar, user_stub, is_default_stub, error); + return; } if (phar->is_tar) { - return phar_tar_flush(phar, user_stub, is_default_stub, error); + phar_tar_flush(phar, user_stub, is_default_stub, error); + return; } if (PHAR_G(readonly)) { - return EOF; + return; } if (phar->fp && !phar->is_brandnew) { @@ -2598,7 +2600,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau if (must_close_old_file) { php_stream_close(oldfile); } - return EOF; + return; } if (user_stub) { @@ -2612,7 +2614,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau if (error) { spprintf(error, 0, "illegal stub for phar \"%s\" (__HALT_COMPILER(); is missing)", phar->fname); } - return EOF; + return; } size_t len = pos - ZSTR_VAL(user_stub) + strlen(halt_stub); @@ -2630,7 +2632,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau if (error) { spprintf(error, 0, "unable to create stub from string in new phar \"%s\"", phar->fname); } - return EOF; + return; } phar->halt_offset = len + end_sequence_len; } else { @@ -2660,7 +2662,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau if (new_stub) { zend_string_free(new_stub); } - return EOF; + return; } if (new_stub) { zend_string_free(new_stub); @@ -2756,7 +2758,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau if (error) { spprintf(error, 0, "unable to seek to start of file \"%s\" while creating new phar \"%s\"", entry->filename, phar->fname); } - return EOF; + return; } newcrc32 = php_crc32_bulk_init(); php_crc32_stream_bulk_update(&newcrc32, file, entry->uncompressed_filesize); @@ -2782,7 +2784,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau spprintf(error, 0, "unable to bzip2 compress file \"%s\" to new phar \"%s\"", entry->filename, phar->fname); } } - return EOF; + return; } /* create new file that holds the compressed versions */ @@ -3105,7 +3107,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau php_stream_close(oldfile); } php_stream_close(newfile); - return EOF; + return; } php_stream_write(newfile, digest, digest_len); @@ -3157,7 +3159,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau if (error) { spprintf(error, 4096, "unable to open new phar \"%s\" for writing", phar->fname); } - return EOF; + return; } if (phar->flags & PHAR_FILE_COMPRESSED_GZ) { @@ -3173,7 +3175,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau if (error) { spprintf(error, 4096, "unable to compress all contents of phar \"%s\" using zlib, PHP versions older than 5.2.6 have a buggy zlib", phar->fname); } - return EOF; + return; } php_stream_filter_append(&phar->fp->writefilters, filter); @@ -3203,10 +3205,9 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau if (error) { spprintf(error, 0, "unable to seek to __HALT_COMPILER(); in new phar \"%s\"", phar->fname); } - return EOF; } - return EOF; + return; cleanup: if (shared_cfp != NULL) { @@ -3218,8 +3219,6 @@ cleanup: entry->header_offset = 0; } } ZEND_HASH_FOREACH_END(); - - return EOF; } /* }}} */ diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h index d8e319eeb6e..2f9ae7c1c84 100644 --- a/ext/phar/phar_internal.h +++ b/ext/phar/phar_internal.h @@ -447,12 +447,12 @@ zend_result phar_copy_on_write(phar_archive_data **pphar); 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); -int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, 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); -int phar_zip_flush(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error); +void phar_zip_flush(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error); #ifdef PHAR_MAIN extern const php_stream_wrapper php_stream_phar_wrapper; @@ -468,8 +468,8 @@ phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, size_t 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); -int phar_flush_ex(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error); -int phar_flush(phar_archive_data *archive, char **error); +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_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); diff --git a/ext/phar/stream.c b/ext/phar/stream.c index 710de5d63c3..17563f7fad0 100644 --- a/ext/phar/stream.c +++ b/ext/phar/stream.c @@ -469,17 +469,16 @@ static ssize_t phar_stream_write(php_stream *stream, const char *buf, size_t cou static int phar_stream_flush(php_stream *stream) /* {{{ */ { char *error; - int ret; phar_entry_data *data = (phar_entry_data *) stream->abstract; if (data->internal_file->is_modified) { data->internal_file->timestamp = time(0); - ret = phar_flush(data->phar, &error); + phar_flush(data->phar, &error); if (error) { php_stream_wrapper_log_error(stream->wrapper, REPORT_ERRORS, "%s", error); efree(error); } - return ret; + return EOF; } else { return EOF; } diff --git a/ext/phar/tar.c b/ext/phar/tar.c index 024d35b0b35..bfbcd4216af 100644 --- a/ext/phar/tar.c +++ b/ext/phar/tar.c @@ -955,7 +955,7 @@ static int phar_tar_setupmetadata(zval *zv, void *argument) /* {{{ */ } /* }}} */ -int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error) /* {{{ */ +void phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error) /* {{{ */ { static const char newstub[] = "fname); } - return EOF; + return; } if (phar->is_data) { @@ -997,7 +997,7 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa if (entry.fp == NULL) { efree(entry.filename); spprintf(error, 0, "phar error: unable to create temporary file"); - return -1; + return; } if (phar->alias_len != php_stream_write(entry.fp, phar->alias, phar->alias_len)) { if (error) { @@ -1005,7 +1005,7 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa } php_stream_close(entry.fp); efree(entry.filename); - return EOF; + return; } entry.uncompressed_filesize = phar->alias_len; @@ -1025,7 +1025,7 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa if (error) { spprintf(error, 0, "illegal stub for tar-based phar \"%s\"", phar->fname); } - return EOF; + return; } size_t len = pos - ZSTR_VAL(user_stub) + strlen(halt_stub); @@ -1035,7 +1035,7 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa entry.fp = php_stream_fopen_tmpfile(); if (entry.fp == NULL) { spprintf(error, 0, "phar error: unable to create temporary file"); - return EOF; + return; } entry.uncompressed_filesize = len + end_sequence_len; @@ -1047,7 +1047,7 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa spprintf(error, 0, "unable to create stub from string in new tar-based phar \"%s\"", phar->fname); } php_stream_close(entry.fp); - return EOF; + return; } entry.filename = estrndup(".phar/stub.php", sizeof(".phar/stub.php")-1); @@ -1058,14 +1058,14 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa entry.fp = php_stream_fopen_tmpfile(); if (entry.fp == NULL) { spprintf(error, 0, "phar error: unable to create temporary file"); - return EOF; + return; } if (sizeof(newstub)-1 != php_stream_write(entry.fp, newstub, sizeof(newstub)-1)) { php_stream_close(entry.fp); if (error) { spprintf(error, 0, "unable to %s stub in%star-based phar \"%s\", failed", user_stub ? "overwrite" : "create", user_stub ? " " : " new ", phar->fname); } - return EOF; + return; } entry.uncompressed_filesize = entry.compressed_filesize = sizeof(newstub) - 1; @@ -1080,7 +1080,7 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa if (error) { spprintf(error, 0, "unable to create stub in tar-based phar \"%s\"", phar->fname); } - return EOF; + return; } } else { php_stream_close(entry.fp); @@ -1108,7 +1108,7 @@ nostub: if (must_close_old_file) { php_stream_close(oldfile); } - return EOF; + return; } pass.old = oldfile; @@ -1124,7 +1124,7 @@ nostub: if (must_close_old_file) { php_stream_close(oldfile); } - return EOF; + return; } } else { phar_entry_info newentry = {0}; @@ -1140,7 +1140,7 @@ nostub: if (must_close_old_file) { php_stream_close(oldfile); } - return EOF; + return; } if (ZEND_HASH_APPLY_KEEP != phar_tar_setmetadata(&phar->metadata_tracker, mentry, error)) { @@ -1148,7 +1148,7 @@ nostub: if (must_close_old_file) { php_stream_close(oldfile); } - return EOF; + return; } } } @@ -1162,7 +1162,7 @@ nostub: /* on error in the hash iterator above, error is set */ php_stream_close(newfile); - return EOF; + return; } zend_hash_apply_with_argument(&phar->manifest, phar_tar_writeheaders, (void *) &pass); @@ -1181,7 +1181,7 @@ nostub: } php_stream_close(newfile); - return EOF; + return; } entry.filename = ".phar/signature.bin"; @@ -1189,7 +1189,7 @@ nostub: entry.fp = php_stream_fopen_tmpfile(); if (entry.fp == NULL) { spprintf(error, 0, "phar error: unable to create temporary file"); - return EOF; + return; } #ifdef WORDS_BIGENDIAN # define PHAR_SET_32(destination, source) do { \ @@ -1215,7 +1215,7 @@ nostub: php_stream_close(oldfile); } php_stream_close(newfile); - return EOF; + return; } efree(signature); @@ -1229,7 +1229,7 @@ nostub: } /* error is set by writeheaders */ php_stream_close(newfile); - return EOF; + return; } } /* signature */ @@ -1245,7 +1245,7 @@ nostub: /* on error in the hash iterator above, error is set */ if (error && *error) { php_stream_close(newfile); - return EOF; + return; } if (phar->fp && pass.free_fp) { @@ -1272,7 +1272,7 @@ nostub: if (error) { spprintf(error, 0, "unable to open new phar \"%s\" for writing", phar->fname); } - return EOF; + return; } if (phar->flags & PHAR_FILE_COMPRESSED_GZ) { @@ -1296,7 +1296,7 @@ nostub: if (error) { spprintf(error, 4096, "unable to compress all contents of phar \"%s\" using zlib, PHP versions older than 5.2.6 have a buggy zlib", phar->fname); } - return EOF; + return; } php_stream_filter_append(&phar->fp->writefilters, filter); @@ -1323,6 +1323,5 @@ nostub: php_stream_close(newfile); } } - return EOF; } /* }}} */ diff --git a/ext/phar/zip.c b/ext/phar/zip.c index e1ee8eddc69..ad0e53a80c4 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -1251,7 +1251,7 @@ static int phar_zip_applysignature(phar_archive_data *phar, struct _phar_zip_pas } /* }}} */ -int phar_zip_flush(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error) /* {{{ */ +void phar_zip_flush(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error) /* {{{ */ { static const char newstub[] = "fname); } - return EOF; + return; } if (phar->is_data) { @@ -1288,13 +1288,13 @@ int phar_zip_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa entry.fp = php_stream_fopen_tmpfile(); if (entry.fp == NULL) { spprintf(error, 0, "phar error: unable to create temporary file"); - return EOF; + return; } if (phar->alias_len != php_stream_write(entry.fp, phar->alias, phar->alias_len)) { if (error) { spprintf(error, 0, "unable to set alias in zip-based phar \"%s\"", phar->fname); } - return EOF; + return; } entry.uncompressed_filesize = entry.compressed_filesize = phar->alias_len; @@ -1309,7 +1309,7 @@ int phar_zip_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa /* register alias */ if (phar->alias_len) { if (FAILURE == phar_get_archive(&phar, phar->fname, phar->fname_len, phar->alias, phar->alias_len, error)) { - return EOF; + return; } } @@ -1321,7 +1321,7 @@ int phar_zip_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa if (error) { spprintf(error, 0, "illegal stub for zip-based phar \"%s\"", phar->fname); } - return EOF; + return; } size_t len = pos - ZSTR_VAL(user_stub) + strlen(halt_stub); @@ -1331,7 +1331,7 @@ int phar_zip_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa entry.fp = php_stream_fopen_tmpfile(); if (entry.fp == NULL) { spprintf(error, 0, "phar error: unable to create temporary file"); - return EOF; + return; } entry.uncompressed_filesize = len + end_sequence_len; @@ -1343,7 +1343,7 @@ int phar_zip_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa spprintf(error, 0, "unable to create stub from string in new zip-based phar \"%s\"", phar->fname); } php_stream_close(entry.fp); - return EOF; + return; } entry.filename = estrndup(".phar/stub.php", sizeof(".phar/stub.php")-1); @@ -1355,14 +1355,14 @@ int phar_zip_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa entry.fp = php_stream_fopen_tmpfile(); if (entry.fp == NULL) { spprintf(error, 0, "phar error: unable to create temporary file"); - return EOF; + return; } if (sizeof(newstub)-1 != php_stream_write(entry.fp, newstub, sizeof(newstub)-1)) { php_stream_close(entry.fp); if (error) { spprintf(error, 0, "unable to %s stub in%szip-based phar \"%s\", failed", user_stub ? "overwrite" : "create", user_stub ? " " : " new ", phar->fname); } - return EOF; + return; } entry.uncompressed_filesize = entry.compressed_filesize = sizeof(newstub) - 1; @@ -1377,7 +1377,7 @@ int phar_zip_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa if (error) { spprintf(error, 0, "unable to create stub in zip-based phar \"%s\"", phar->fname); } - return EOF; + return; } } else { php_stream_close(entry.fp); @@ -1409,7 +1409,7 @@ fperror: if (error) { spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to open temporary file", phar->fname); } - return EOF; + return; } pass.centralfp = php_stream_fopen_tmpfile(); @@ -1447,7 +1447,7 @@ nocentralerror: if (must_close_old_file) { php_stream_close(oldfile); } - return EOF; + return; } if (FAILURE == phar_zip_applysignature(phar, &pass)) { @@ -1528,7 +1528,7 @@ nocentralerror: if (error) { spprintf(error, 4096, "unable to open new phar \"%s\" for writing", phar->fname); } - return EOF; + return; } php_stream_rewind(pass.filefp); php_stream_copy_to_stream_ex(pass.filefp, phar->fp, PHP_STREAM_COPY_ALL, NULL); @@ -1539,6 +1539,5 @@ nocentralerror: if (must_close_old_file) { php_stream_close(oldfile); } - return EOF; } /* }}} */