Skip to content

Commit cdc84d9

Browse files
committed
ext/phar: refactor phar_get_entry_data() to use a zend_string* for fname
1 parent 11f0288 commit cdc84d9

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

ext/phar/phar_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ void phar_entry_delref(phar_entry_data *idata);
467467
phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, size_t path_len, char **error, bool security);
468468
phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, size_t path_len, char dir, char **error, bool security);
469469
ZEND_ATTRIBUTE_NONNULL phar_entry_data *phar_get_or_create_entry_data(zend_string *fname, char *path, size_t path_len, const char *mode, char allow_dir, char **error, bool security, uint32_t timestamp);
470-
ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, const char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, bool security);
470+
ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, const zend_string *fname, char *path, size_t path_len, const char *mode, char allow_dir, char **error, bool security);
471471
ZEND_ATTRIBUTE_NONNULL_ARGS(1, 4) int phar_flush_ex(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error);
472472
ZEND_ATTRIBUTE_NONNULL int phar_flush(phar_archive_data *archive, char **error);
473473
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);

ext/phar/stream.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
240240
return NULL;
241241
}
242242
if (phar->is_tar || phar->is_zip) {
243-
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) {
243+
if ((FAILURE == phar_get_entry_data(&idata, resource->host, ".phar/stub.php", sizeof(".phar/stub.php")-1, "r", 0, &error, false)) || !idata) {
244244
goto idata_error;
245245
}
246246
efree(internal_file);
@@ -288,7 +288,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
288288
}
289289
}
290290
/* read-only access is allowed to magic files in .phar directory */
291-
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) {
291+
if ((FAILURE == phar_get_entry_data(&idata, resource->host, internal_file, strlen(internal_file), "r", 0, &error, false)) || !idata) {
292292
idata_error:
293293
if (error) {
294294
php_stream_wrapper_log_error(wrapper, options, "%s", error);
@@ -694,7 +694,7 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
694694
/* need to copy to strip leading "/", will get touched again */
695695
internal_file = estrndup(ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1);
696696
internal_file_len = ZSTR_LEN(resource->path) - 1;
697-
if (FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), internal_file, internal_file_len, "r", 0, &error, true)) {
697+
if (FAILURE == phar_get_entry_data(&idata, resource->host, internal_file, internal_file_len, "r", 0, &error, true)) {
698698
/* constraints of fp refcount were not met */
699699
if (error) {
700700
php_stream_wrapper_log_error(wrapper, options, "unlink of \"%s\" failed: %s", url, error);

ext/phar/util.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ ZEND_ATTRIBUTE_NONNULL static zend_result phar_separate_entry_fp(phar_entry_info
466466
* appended, truncated, or read. For read, if the entry is marked unmodified, it is
467467
* assumed that the file pointer, if present, is opened for reading
468468
*/
469-
ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, const char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, bool security) /* {{{ */
469+
ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, const zend_string *fname, char *path, size_t path_len, const char *mode, char allow_dir, char **error, bool security) /* {{{ */
470470
{
471471
phar_archive_data *phar;
472472
phar_entry_info *entry;
@@ -478,17 +478,17 @@ ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, co
478478
*ret = NULL;
479479
*error = NULL;
480480

481-
if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, error)) {
481+
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(fname), ZSTR_LEN(fname), NULL, 0, error)) {
482482
return FAILURE;
483483
}
484484

485485
if (for_write && PHAR_G(readonly) && !phar->is_data) {
486-
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, disabled by ini setting", path, fname);
486+
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, disabled by ini setting", path, ZSTR_VAL(fname));
487487
return FAILURE;
488488
}
489489

490490
if (!path_len) {
491-
spprintf(error, 4096, "phar error: file \"\" in phar \"%s\" must not be empty", fname);
491+
spprintf(error, 4096, "phar error: file \"\" in phar \"%s\" must not be empty", ZSTR_VAL(fname));
492492
return FAILURE;
493493
}
494494
really_get_entry:
@@ -512,20 +512,20 @@ ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, co
512512

513513
if (for_write && phar->is_persistent) {
514514
if (FAILURE == phar_copy_on_write(&phar)) {
515-
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, could not make cached phar writeable", path, fname);
515+
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, could not make cached phar writeable", path, ZSTR_VAL(fname));
516516
return FAILURE;
517517
} else {
518518
goto really_get_entry;
519519
}
520520
}
521521

522522
if (entry->is_modified && !for_write) {
523-
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for reading, writable file pointers are open", path, fname);
523+
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for reading, writable file pointers are open", path, ZSTR_VAL(fname));
524524
return FAILURE;
525525
}
526526

527527
if (entry->fp_refcount && for_write) {
528-
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, readable file pointers are open", path, fname);
528+
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, readable file pointers are open", path, ZSTR_VAL(fname));
529529
return FAILURE;
530530
}
531531

@@ -629,7 +629,7 @@ ZEND_ATTRIBUTE_NONNULL phar_entry_data *phar_get_or_create_entry_data(zend_strin
629629
return NULL;
630630
}
631631

632-
if (FAILURE == phar_get_entry_data(&ret, ZSTR_VAL(fname), ZSTR_LEN(fname), path, path_len, mode, allow_dir, error, security)) {
632+
if (FAILURE == phar_get_entry_data(&ret, fname, path, path_len, mode, allow_dir, error, security)) {
633633
return NULL;
634634
} else if (ret) {
635635
return ret;

0 commit comments

Comments
 (0)