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
20 changes: 11 additions & 9 deletions ext/phar/dirstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ static php_stream *phar_make_dirstream(const char *dir, size_t dirlen, const Has
*/
php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC) /* {{{ */
{
php_url *resource = NULL;
char *error;
phar_archive_data *phar;

if ((resource = phar_parse_url(wrapper, path, mode, options)) == NULL) {
php_url *resource = phar_parse_url(wrapper, path, mode, options);
if (!resource) {
php_stream_wrapper_log_error(wrapper, options, "phar url \"%s\" is unknown", path);
return NULL;
}
Expand Down Expand Up @@ -343,7 +343,7 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path,
*/
int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mode, int options, php_stream_context *context) /* {{{ */
{
phar_entry_info entry, *e;
phar_entry_info entry;
phar_archive_data *phar = NULL;
char *error;
php_url *resource = NULL;
Expand Down Expand Up @@ -390,7 +390,8 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo
return 0;
}

if ((e = phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1, 2, &error, true))) {
phar_entry_info *e = phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1, 2, &error, true);
if (e) {
/* directory exists, or is a subdirectory of an existing file */
if (e->is_temp_dir) {
zend_string_efree(e->filename);
Expand Down Expand Up @@ -444,7 +445,8 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo
entry.flags = PHAR_ENT_PERM_DEF_DIR;
entry.old_flags = PHAR_ENT_PERM_DEF_DIR;

if (NULL == zend_hash_add_mem(&phar->manifest, entry.filename, &entry, sizeof(phar_entry_info))) {
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);
zend_string_efree(entry.filename);
return 0;
Expand All @@ -469,10 +471,8 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo
*/
int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context) /* {{{ */
{
phar_entry_info *entry;
phar_archive_data *phar = NULL;
char *error;
php_url *resource = NULL;

/* pre-readonly check, we need to know if this is a data phar */
zend_string *arch = phar_split_fname(url, strlen(url), NULL, 2, 2);
Expand All @@ -492,7 +492,8 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options
return 0;
}

if ((resource = phar_parse_url(wrapper, url, "w", options)) == NULL) {
php_url *resource = phar_parse_url(wrapper, url, "w", options);
if (!resource) {
return 0;
}

Expand All @@ -518,7 +519,8 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options

size_t path_len = ZSTR_LEN(resource->path) - 1;

if (!(entry = phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, path_len, 2, &error, true))) {
phar_entry_info *entry = phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, path_len, 2, &error, true);
if (!entry) {
if (error) {
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error);
efree(error);
Expand Down
21 changes: 10 additions & 11 deletions ext/phar/func_interceptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ static zend_string* phar_get_name_for_relative_paths(zend_string *filename, bool

zend_string *name = NULL;
if (using_include_path) {
if (!(name = phar_find_in_include_path(filename, NULL))) {
name = phar_find_in_include_path(filename, NULL);
if (!name) {
/* this file is not in the phar, use the original path */
zend_string_release_ex(arch, false);
return NULL;
Expand Down Expand Up @@ -337,15 +338,12 @@ static void phar_fancy_stat(zend_stat_t *stat_sb, int type, zval *return_value)
wmask=S_IWGRP;
xmask=S_IXGRP;
} else {
int groups, n, i;
gid_t *gids;

groups = getgroups(0, NULL);
if(groups > 0) {
gids=(gid_t *)safe_emalloc(groups, sizeof(gid_t), 0);
n=getgroups(groups, gids);
for(i=0;i<n;++i){
if(stat_sb->st_gid==gids[i]) {
int groups = getgroups(0, NULL);
if (groups > 0) {
gid_t *gids = safe_emalloc(groups, sizeof(gid_t), 0);
int n = getgroups(groups, gids);
for(int i = 0; i < n; ++i){
if (stat_sb->st_gid==gids[i]) {
rmask=S_IRGRP;
wmask=S_IWGRP;
xmask=S_IXGRP;
Expand Down Expand Up @@ -844,7 +842,8 @@ void phar_release_functions(void)
/* {{{ void phar_intercept_functions_init(void) */
#define PHAR_INTERCEPT(func) \
PHAR_G(orig_##func) = NULL; \
if (NULL != (orig = zend_hash_str_find_ptr(CG(function_table), #func, sizeof(#func)-1))) { \
orig = zend_hash_str_find_ptr(CG(function_table), #func, sizeof(#func)-1); \
if (orig) { \
PHAR_G(orig_##func) = orig->internal_function.handler; \
orig->internal_function.handler = PHP_FN(phar_##func); \
}
Expand Down
31 changes: 17 additions & 14 deletions ext/phar/phar.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ HashTable cached_alias;
static void phar_split_cache_list(void) /* {{{ */
{
char *tmp;
char *key, *lasts, *end;
char *key, *lasts;
char ds[2];
phar_archive_data *phar;
uint32_t i = 0;
Expand Down Expand Up @@ -124,7 +124,7 @@ static void phar_split_cache_list(void) /* {{{ */
key;
key = php_strtok_r(NULL, ds, &lasts)) {
size_t len;
end = strchr(key, DEFAULT_DIR_SEPARATOR);
const char *end = strchr(key, DEFAULT_DIR_SEPARATOR);
if (end) {
len = end - key;
} else {
Expand Down Expand Up @@ -1263,7 +1263,8 @@ static zend_result phar_parse_pharfile(php_stream *fp, char *fname, size_t fname
MAPPHAR_FAIL("Cannot open archive \"%s\", invalid alias");
}

if (NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), alias, alias_len))) {
fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), alias, alias_len);
if (fd_ptr) {
if (SUCCESS != phar_free_alias(fd_ptr)) {
signature = NULL;
fp = NULL;
Expand Down Expand Up @@ -1460,10 +1461,9 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(1, 7, 8) zend_result phar_create_or_parse_filename(c
/* assume tar format, PharData can specify other */
mydata->is_tar = 1;
} else {
phar_archive_data *fd_ptr;

if (alias && NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), alias, alias_len))) {
if (SUCCESS != phar_free_alias(fd_ptr)) {
if (alias) {
const phar_archive_data *fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), alias, alias_len);
if (fd_ptr && SUCCESS != phar_free_alias(fd_ptr)) {
spprintf(error, 4096, "phar error: phar \"%s\" cannot set alias \"%s\", already in use by another phar archive", mydata->fname, alias);

zend_hash_str_del(&(PHAR_G(phar_fname_map)), mydata->fname, fname_len);
Expand Down Expand Up @@ -1669,14 +1669,14 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
continue;
} else if (!memcmp(pos, bz_magic, 3)) {
php_stream_filter *filter;
php_stream *temp;

if (!PHAR_G(has_bz2)) {
MAPPHAR_ALLOC_FAIL("unable to decompress bzipped phar archive \"%s\" to temporary file, enable bz2 extension in php.ini")
}

/* entire file is bzip-compressed, uncompress to temporary file */
if (!(temp = php_stream_fopen_tmpfile())) {
php_stream *temp = php_stream_fopen_tmpfile();
if (!temp) {
MAPPHAR_ALLOC_FAIL("unable to create temporary file for decompression of bzipped phar archive \"%s\"")
}

Expand Down Expand Up @@ -1750,10 +1750,10 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
static zend_result phar_analyze_path(const char *fname, const char *ext, size_t ext_len, int for_create) /* {{{ */
{
php_stream_statbuf ssb;
char *realpath;
char *filename = estrndup(fname, (ext - fname) + ext_len);

if ((realpath = expand_filepath(filename, NULL))) {
char *realpath = expand_filepath(filename, NULL);
if (realpath) {
#ifdef PHP_WIN32
phar_unixify_path_separators(realpath, strlen(realpath));
#endif
Expand Down Expand Up @@ -1800,7 +1800,8 @@ static zend_result phar_analyze_path(const char *fname, const char *ext, size_t

if (SUCCESS != php_stream_stat_path((char *) filename, &ssb)) {
if (!slash) {
if (!(realpath = expand_filepath(filename, NULL))) {
realpath = expand_filepath(filename, NULL);
if (!realpath) {
efree(filename);
return FAILURE;
}
Expand Down Expand Up @@ -1943,7 +1944,8 @@ zend_result phar_detect_phar_fname_ext(const char *filename, size_t filename_len
phar_archive_data *pphar;

if (is_complete) {
if (NULL != (pphar = zend_hash_str_find_ptr(&(PHAR_G(phar_fname_map)), (char *) filename, filename_len))) {
pphar = zend_hash_str_find_ptr(&(PHAR_G(phar_fname_map)), filename, filename_len);
if (pphar) {
*ext_str = filename + (filename_len - pphar->ext_len);
woohoo:
*ext_len = pphar->ext_len;
Expand All @@ -1963,7 +1965,8 @@ zend_result phar_detect_phar_fname_ext(const char *filename, size_t filename_len
return FAILURE;
}

if (PHAR_G(manifest_cached) && NULL != (pphar = zend_hash_str_find_ptr(&cached_phars, (char *) filename, filename_len))) {
pphar = PHAR_G(manifest_cached) ? zend_hash_str_find_ptr(&cached_phars, filename, filename_len) : NULL;
if (pphar) {
*ext_str = filename + (filename_len - pphar->ext_len);
goto woohoo;
}
Expand Down
Loading
Loading