Skip to content

Commit f31e4e6

Browse files
authored
ext/phar: convert phar_open_executed_filename() to use zend_string for alias (#21916)
1 parent 7a3d889 commit f31e4e6

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

ext/phar/phar.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,7 +2252,7 @@ zend_string* phar_split_fname(const char *filename, size_t filename_len, zend_st
22522252
* Invoked when a user calls Phar::mapPhar() from within an executing .phar
22532253
* to set up its manifest directly
22542254
*/
2255-
ZEND_ATTRIBUTE_NONNULL_ARGS(3) zend_result phar_open_executed_filename(const char *alias, size_t alias_len, char **error) /* {{{ */
2255+
ZEND_ATTRIBUTE_NONNULL_ARGS(2) zend_result phar_open_executed_filename(const zend_string *alias, char **error) /* {{{ */
22562256
{
22572257
*error = NULL;
22582258

@@ -2263,7 +2263,9 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(3) zend_result phar_open_executed_filename(const cha
22632263
return FAILURE;
22642264
}
22652265

2266-
if (phar_open_parsed_phar(ZSTR_VAL(fname), ZSTR_LEN(fname), alias, alias_len, false, REPORT_ERRORS, NULL, NULL) == SUCCESS) {
2266+
const char *alias_cstr = alias ? ZSTR_VAL(alias) : NULL;
2267+
size_t alias_len = alias ? ZSTR_LEN(alias) : 0;
2268+
if (phar_open_parsed_phar(ZSTR_VAL(fname), ZSTR_LEN(fname), alias_cstr, alias_len, false, REPORT_ERRORS, NULL, NULL) == SUCCESS) {
22672269
return SUCCESS;
22682270
}
22692271

@@ -2292,7 +2294,7 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(3) zend_result phar_open_executed_filename(const cha
22922294
fname = actual;
22932295
}
22942296

2295-
zend_result ret = phar_open_from_fp(fp, ZSTR_VAL(fname), ZSTR_LEN(fname), alias, alias_len, REPORT_ERRORS, NULL, error);
2297+
zend_result ret = phar_open_from_fp(fp, ZSTR_VAL(fname), ZSTR_LEN(fname), alias_cstr, alias_len, REPORT_ERRORS, NULL, error);
22962298

22972299
if (actual) {
22982300
zend_string_release_ex(actual, 0);

ext/phar/phar_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ ZEND_ATTRIBUTE_NONNULL zend_result phar_postprocess_file(phar_entry_data *idata,
409409
zend_result phar_open_from_filename(char *fname, size_t fname_len, const char *alias, size_t alias_len, uint32_t options, phar_archive_data** pphar, char **error);
410410
ZEND_ATTRIBUTE_NONNULL_ARGS(1, 6, 7) zend_result phar_open_or_create_filename(zend_string *fname, const char *alias, size_t alias_len, bool is_data, uint32_t options, phar_archive_data** pphar, char **error);
411411
ZEND_ATTRIBUTE_NONNULL_ARGS(1, 6, 7) zend_result phar_create_or_parse_filename(zend_string *fname, const char *alias, size_t alias_len, bool is_data, uint32_t options, phar_archive_data** pphar, char **error);
412-
ZEND_ATTRIBUTE_NONNULL_ARGS(3) zend_result phar_open_executed_filename(const char *alias, size_t alias_len, char **error);
412+
ZEND_ATTRIBUTE_NONNULL_ARGS(2) zend_result phar_open_executed_filename(const zend_string *alias, char **error);
413413
zend_result phar_free_alias(const phar_archive_data *phar);
414414
phar_archive_data* phar_get_archive(const char *fname, size_t fname_len, const char *alias, size_t alias_len, char **error);
415415
zend_result phar_verify_signature(php_stream *fp, size_t end_of_phar, uint32_t sig_type, const char *sig, size_t sig_len, const char *fname, char **signature, size_t *signature_len, char **error);

ext/phar/phar_object.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ PHP_METHOD(Phar, webPhar)
549549
zval *mimeoverride = NULL;
550550
zend_fcall_info rewrite_fci = {0};
551551
zend_fcall_info_cache rewrite_fcc;
552-
char *alias = NULL, *error, *index_php = NULL, *ru = NULL;
553-
size_t alias_len = 0, free_pathinfo = 0;
552+
char *error, *index_php = NULL, *ru = NULL;
553+
size_t free_pathinfo = 0;
554554
zend_string *f404 = NULL;
555555
size_t ru_len = 0;
556556
char *fname, *path_info, *mime_type = NULL, *entry, *pt;
@@ -562,14 +562,15 @@ PHP_METHOD(Phar, webPhar)
562562
phar_entry_info *info = NULL;
563563
size_t sapi_mod_name_len = strlen(sapi_module.name);
564564
phar_action_status status = PHAR_ACT_DO_EXIT;
565+
zend_string *alias = NULL;
565566

566-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!S!af!", &alias, &alias_len, &index_php, &index_php_len, &f404, &mimeoverride, &rewrite_fci, &rewrite_fcc) == FAILURE) {
567+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!s!S!af!", &alias, &index_php, &index_php_len, &f404, &mimeoverride, &rewrite_fci, &rewrite_fcc) == FAILURE) {
567568
RETURN_THROWS();
568569
}
569570

570571
phar_request_initialize();
571572

572-
if (phar_open_executed_filename(alias, alias_len, &error) != SUCCESS) {
573+
if (phar_open_executed_filename(alias, &error) != SUCCESS) {
573574
if (error) {
574575
zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error);
575576
efree(error);
@@ -947,17 +948,17 @@ PHP_METHOD(Phar, createDefaultStub)
947948
/* {{{ Reads the currently executed file (a phar) and registers its manifest */
948949
PHP_METHOD(Phar, mapPhar)
949950
{
950-
char *alias = NULL, *error;
951-
size_t alias_len = 0;
951+
zend_string *alias = NULL;
952+
char *error;
952953
zend_long dataoffset = 0;
953954

954-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!l", &alias, &alias_len, &dataoffset) == FAILURE) {
955+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!l", &alias, &dataoffset) == FAILURE) {
955956
RETURN_THROWS();
956957
}
957958

958959
phar_request_initialize();
959960

960-
RETVAL_BOOL(phar_open_executed_filename(alias, alias_len, &error) == SUCCESS);
961+
RETVAL_BOOL(phar_open_executed_filename(alias, &error) == SUCCESS);
961962

962963
if (error) {
963964
zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error);

0 commit comments

Comments
 (0)