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/dirstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,15 +447,15 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo

void *had_been_added = zend_hash_add_mem(&phar->manifest, entry.filename, &entry, sizeof(phar_entry_info));
if (!had_been_added) {
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", adding to manifest failed", ZSTR_VAL(entry.filename), phar->fname);
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", adding to manifest failed", ZSTR_VAL(entry.filename), ZSTR_VAL(phar->fname));
zend_string_efree(entry.filename);
return 0;
}

phar_flush(phar, &error);

if (error) {
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", ZSTR_VAL(entry.filename), phar->fname, error);
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", ZSTR_VAL(entry.filename), ZSTR_VAL(phar->fname), error);
zend_hash_del(&phar->manifest, entry.filename);
efree(error);
return 0;
Expand Down Expand Up @@ -576,7 +576,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options
phar_flush(phar, &error);

if (error) {
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", %s", ZSTR_VAL(entry->filename), phar->fname, error);
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", %s", ZSTR_VAL(entry->filename), ZSTR_VAL(phar->fname), error);
php_url_free(resource);
efree(error);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion ext/phar/func_interceptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ static void phar_file_stat(const char *filename, size_t filename_length, int typ
goto skip_phar;
}

if (PHAR_G(last_phar) && ZSTR_LEN(fname) - 7 >= PHAR_G(last_phar_name_len) && !memcmp(ZSTR_VAL(fname) + 7, PHAR_G(last_phar_name), PHAR_G(last_phar_name_len))) {
if (PHAR_G(last_phar) && ZSTR_LEN(fname) - 7 >= ZSTR_LEN(PHAR_G(last_phar_name)) && !memcmp(ZSTR_VAL(fname) + 7, ZSTR_VAL(PHAR_G(last_phar_name)), ZSTR_LEN(PHAR_G(last_phar_name)))) {
/* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */
phar = PHAR_G(last_phar);
goto splitted;
Expand Down
123 changes: 63 additions & 60 deletions ext/phar/phar.c

Large diffs are not rendered by default.

29 changes: 13 additions & 16 deletions ext/phar/phar_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phar)
char *openssl_privatekey;
uint32_t openssl_privatekey_len;
/* phar_get_archive cache */
const char *last_phar_name;
uint32_t last_phar_name_len;
const zend_string *last_phar_name;
uint32_t last_alias_len;
const char* last_alias;
phar_archive_data* last_phar;
Expand Down Expand Up @@ -243,8 +242,7 @@ typedef struct _phar_entry_info {

/* information about a phar file (the archive itself) */
struct _phar_archive_data {
char *fname;
uint32_t fname_len;
zend_string *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;
const char *ext;
Expand Down Expand Up @@ -380,21 +378,20 @@ static inline bool phar_validate_alias(const char *alias, size_t alias_len) /* {

static inline void phar_set_inode(phar_entry_info *entry) /* {{{ */
{
char tmp[MAXPATHLEN];
size_t tmp_len;
size_t len1, len2;

tmp_len = MIN(MAXPATHLEN, ZSTR_LEN(entry->filename) + entry->phar->fname_len);

len1 = MIN(entry->phar->fname_len, tmp_len);
if (entry->phar->fname) {
memcpy(tmp, entry->phar->fname, len1);
}
char tmp[MAXPATHLEN];
size_t tmp_len = MIN(MAXPATHLEN, ZSTR_LEN(entry->filename) + ZSTR_LEN(entry->phar->fname));

len2 = MIN(tmp_len - len1, ZSTR_LEN(entry->filename));
memcpy(tmp + len1, entry->filename, len2);
size_t len1 = MIN(ZSTR_LEN(entry->phar->fname), tmp_len);
memcpy(tmp, ZSTR_VAL(entry->phar->fname), len1);

entry->inode = (unsigned short) zend_hash_func(tmp, tmp_len);
size_t len2 = MIN(tmp_len - len1, ZSTR_LEN(entry->filename));
memcpy(tmp + len1, entry->filename, len2);

entry->inode = (unsigned short) zend_hash_func(tmp, tmp_len);
} else {
entry->inode = (unsigned short) zend_string_hash_val(entry->filename);
}
}
/* }}} */

Expand Down
Loading