Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ext/phar/phar_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phar)
char *openssl_privatekey;
uint32_t openssl_privatekey_len;
/* phar_get_archive cache */
char* last_phar_name;
const char *last_phar_name;
uint32_t last_phar_name_len;
uint32_t last_alias_len;
const char* last_alias;
Expand Down Expand Up @@ -245,9 +245,9 @@ typedef struct _phar_entry_info {
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 */
/* The ext field stores the location of the file extension from the fname field, and thus should never be freed. */
uint32_t ext_len;
char *ext;
const char *ext;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you actually need to store the ext string, or do you only need the length? Memory and gut tells me you only need the length

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't fully looked into this, as I mainly wanted to split this change out of #21823 :) but happy to look into it to double-check if it is needed as this whole thing does seem slightly dubious

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the one case that requires closer investigation is the usage of phar_detect_phar_fname_ext() in phar_rename_archive() as this sets the ext field. But it does seem indeed like neither the ext_len nor ext are really used for anything?

Makes me think that refactoring phar_detect_phar_fname_ext() to return an enum of PATH_IS_URL|USE_ALIAS|IS_TAR|IS_ZIP|IS_PHAR might be more sensible.

Anyhow, I'll merge the PR as is to unblock the fname to zend_string conversion, but will definitely have another look at this ext field mess :)

char *alias;
uint32_t alias_len;
char version[12];
Expand Down
4 changes: 2 additions & 2 deletions ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,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, true)) {
if (SUCCESS != phar_detect_phar_fname_ext(newpath, phar->fname_len, &(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;
}
Expand All @@ -2136,7 +2136,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, true)) {
if (SUCCESS != phar_detect_phar_fname_ext(newpath, phar->fname_len, &(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;
}
Expand Down
Loading