mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
ext/phar: Use size_t for string lenghts
And remove useless casts
This commit is contained in:
parent
947f72c181
commit
009039d447
4 changed files with 24 additions and 32 deletions
|
@ -295,7 +295,6 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path,
|
||||||
zend_ulong unused;
|
zend_ulong unused;
|
||||||
phar_archive_data *phar;
|
phar_archive_data *phar;
|
||||||
phar_entry_info *entry = NULL;
|
phar_entry_info *entry = NULL;
|
||||||
uint32_t host_len;
|
|
||||||
|
|
||||||
if ((resource = phar_parse_url(wrapper, path, mode, options)) == NULL) {
|
if ((resource = phar_parse_url(wrapper, path, mode, options)) == NULL) {
|
||||||
php_stream_wrapper_log_error(wrapper, options, "phar url \"%s\" is unknown", path);
|
php_stream_wrapper_log_error(wrapper, options, "phar url \"%s\" is unknown", path);
|
||||||
|
@ -320,7 +319,7 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
host_len = ZSTR_LEN(resource->host);
|
size_t host_len = ZSTR_LEN(resource->host);
|
||||||
phar_request_initialize();
|
phar_request_initialize();
|
||||||
internal_file = ZSTR_VAL(resource->path) + 1; /* strip leading "/" */
|
internal_file = ZSTR_VAL(resource->path) + 1; /* strip leading "/" */
|
||||||
|
|
||||||
|
@ -401,7 +400,6 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo
|
||||||
char *error, *arch, *entry2;
|
char *error, *arch, *entry2;
|
||||||
size_t arch_len, entry_len;
|
size_t arch_len, entry_len;
|
||||||
php_url *resource = NULL;
|
php_url *resource = NULL;
|
||||||
uint32_t host_len;
|
|
||||||
|
|
||||||
/* pre-readonly check, we need to know if this is a data phar */
|
/* pre-readonly check, we need to know if this is a data phar */
|
||||||
if (FAILURE == phar_split_fname(url_from, strlen(url_from), &arch, &arch_len, &entry2, &entry_len, 2, 2)) {
|
if (FAILURE == phar_split_fname(url_from, strlen(url_from), &arch, &arch_len, &entry2, &entry_len, 2, 2)) {
|
||||||
|
@ -438,7 +436,7 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
host_len = ZSTR_LEN(resource->host);
|
size_t host_len = ZSTR_LEN(resource->host);
|
||||||
|
|
||||||
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) {
|
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) {
|
||||||
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", error retrieving phar information: %s", ZSTR_VAL(resource->path) + 1, ZSTR_VAL(resource->host), error);
|
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", error retrieving phar information: %s", ZSTR_VAL(resource->path) + 1, ZSTR_VAL(resource->host), error);
|
||||||
|
@ -533,10 +531,8 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options
|
||||||
char *error, *arch, *entry2;
|
char *error, *arch, *entry2;
|
||||||
size_t arch_len, entry_len;
|
size_t arch_len, entry_len;
|
||||||
php_url *resource = NULL;
|
php_url *resource = NULL;
|
||||||
uint32_t host_len;
|
|
||||||
zend_string *str_key;
|
zend_string *str_key;
|
||||||
zend_ulong unused;
|
zend_ulong unused;
|
||||||
uint32_t path_len;
|
|
||||||
|
|
||||||
/* pre-readonly check, we need to know if this is a data phar */
|
/* pre-readonly check, we need to know if this is a data phar */
|
||||||
if (FAILURE == phar_split_fname(url, strlen(url), &arch, &arch_len, &entry2, &entry_len, 2, 2)) {
|
if (FAILURE == phar_split_fname(url, strlen(url), &arch, &arch_len, &entry2, &entry_len, 2, 2)) {
|
||||||
|
@ -573,7 +569,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
host_len = ZSTR_LEN(resource->host);
|
size_t host_len = ZSTR_LEN(resource->host);
|
||||||
|
|
||||||
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) {
|
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) {
|
||||||
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", error retrieving phar information: %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error);
|
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", error retrieving phar information: %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error);
|
||||||
|
@ -582,7 +578,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
path_len = ZSTR_LEN(resource->path) - 1;
|
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, 1))) {
|
if (!(entry = phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, path_len, 2, &error, 1))) {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
|
@ -2023,11 +2023,11 @@ woohoo:
|
||||||
zend_string *str_key;
|
zend_string *str_key;
|
||||||
|
|
||||||
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&PHAR_G(phar_fname_map), str_key, pphar) {
|
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&PHAR_G(phar_fname_map), str_key, pphar) {
|
||||||
if (ZSTR_LEN(str_key) > (uint32_t) filename_len) {
|
if (ZSTR_LEN(str_key) > filename_len) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!memcmp(filename, ZSTR_VAL(str_key), ZSTR_LEN(str_key)) && ((uint32_t)filename_len == ZSTR_LEN(str_key)
|
if (!memcmp(filename, ZSTR_VAL(str_key), ZSTR_LEN(str_key)) && (filename_len == ZSTR_LEN(str_key)
|
||||||
|| filename[ZSTR_LEN(str_key)] == '/' || filename[ZSTR_LEN(str_key)] == '\0')) {
|
|| filename[ZSTR_LEN(str_key)] == '/' || filename[ZSTR_LEN(str_key)] == '\0')) {
|
||||||
*ext_str = filename + (ZSTR_LEN(str_key) - pphar->ext_len);
|
*ext_str = filename + (ZSTR_LEN(str_key) - pphar->ext_len);
|
||||||
goto woohoo;
|
goto woohoo;
|
||||||
|
@ -2036,11 +2036,11 @@ woohoo:
|
||||||
|
|
||||||
if (PHAR_G(manifest_cached)) {
|
if (PHAR_G(manifest_cached)) {
|
||||||
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&cached_phars, str_key, pphar) {
|
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&cached_phars, str_key, pphar) {
|
||||||
if (ZSTR_LEN(str_key) > (uint32_t) filename_len) {
|
if (ZSTR_LEN(str_key) > filename_len) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!memcmp(filename, ZSTR_VAL(str_key), ZSTR_LEN(str_key)) && ((uint32_t)filename_len == ZSTR_LEN(str_key)
|
if (!memcmp(filename, ZSTR_VAL(str_key), ZSTR_LEN(str_key)) && (filename_len == ZSTR_LEN(str_key)
|
||||||
|| filename[ZSTR_LEN(str_key)] == '/' || filename[ZSTR_LEN(str_key)] == '\0')) {
|
|| filename[ZSTR_LEN(str_key)] == '/' || filename[ZSTR_LEN(str_key)] == '\0')) {
|
||||||
*ext_str = filename + (ZSTR_LEN(str_key) - pphar->ext_len);
|
*ext_str = filename + (ZSTR_LEN(str_key) - pphar->ext_len);
|
||||||
goto woohoo;
|
goto woohoo;
|
||||||
|
|
|
@ -2621,7 +2621,7 @@ PHP_METHOD(Phar, delete)
|
||||||
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname);
|
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname);
|
||||||
RETURN_THROWS();
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, (uint32_t) fname_len))) {
|
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, fname_len))) {
|
||||||
if (entry->is_deleted) {
|
if (entry->is_deleted) {
|
||||||
/* entry is deleted, but has not been flushed to disk yet */
|
/* entry is deleted, but has not been flushed to disk yet */
|
||||||
RETURN_TRUE;
|
RETURN_TRUE;
|
||||||
|
@ -3440,13 +3440,13 @@ PHP_METHOD(Phar, copy)
|
||||||
RETURN_THROWS();
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == (oldentry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, oldfile, (uint32_t) oldfile_len)) || oldentry->is_deleted) {
|
if (NULL == (oldentry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, oldfile, oldfile_len)) || oldentry->is_deleted) {
|
||||||
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
|
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
|
||||||
"file \"%s\" cannot be copied to file \"%s\", file does not exist in %s", oldfile, newfile, phar_obj->archive->fname);
|
"file \"%s\" cannot be copied to file \"%s\", file does not exist in %s", oldfile, newfile, phar_obj->archive->fname);
|
||||||
RETURN_THROWS();
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != (temp = zend_hash_str_find_ptr(&phar_obj->archive->manifest, newfile, (uint32_t) newfile_len)) && !temp->is_deleted) {
|
if (NULL != (temp = zend_hash_str_find_ptr(&phar_obj->archive->manifest, newfile, newfile_len)) && !temp->is_deleted) {
|
||||||
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
|
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
|
||||||
"file \"%s\" cannot be copied to file \"%s\", file must not already exist in phar %s", oldfile, newfile, phar_obj->archive->fname);
|
"file \"%s\" cannot be copied to file \"%s\", file must not already exist in phar %s", oldfile, newfile, phar_obj->archive->fname);
|
||||||
RETURN_THROWS();
|
RETURN_THROWS();
|
||||||
|
@ -3466,7 +3466,7 @@ PHP_METHOD(Phar, copy)
|
||||||
RETURN_THROWS();
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
/* re-populate with copied-on-write entry */
|
/* re-populate with copied-on-write entry */
|
||||||
oldentry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, oldfile, (uint32_t) oldfile_len);
|
oldentry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, oldfile, oldfile_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy((void *) &newentry, oldentry, sizeof(phar_entry_info));
|
memcpy((void *) &newentry, oldentry, sizeof(phar_entry_info));
|
||||||
|
@ -3513,8 +3513,8 @@ PHP_METHOD(Phar, offsetExists)
|
||||||
|
|
||||||
PHAR_ARCHIVE_OBJECT();
|
PHAR_ARCHIVE_OBJECT();
|
||||||
|
|
||||||
if (zend_hash_str_exists(&phar_obj->archive->manifest, fname, (uint32_t) fname_len)) {
|
if (zend_hash_str_exists(&phar_obj->archive->manifest, fname, fname_len)) {
|
||||||
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, (uint32_t) fname_len))) {
|
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, fname_len))) {
|
||||||
if (entry->is_deleted) {
|
if (entry->is_deleted) {
|
||||||
/* entry is deleted, but has not been flushed to disk yet */
|
/* entry is deleted, but has not been flushed to disk yet */
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
|
@ -3527,7 +3527,7 @@ PHP_METHOD(Phar, offsetExists)
|
||||||
}
|
}
|
||||||
RETURN_TRUE;
|
RETURN_TRUE;
|
||||||
} else {
|
} else {
|
||||||
if (zend_hash_str_exists(&phar_obj->archive->virtual_dirs, fname, (uint32_t) fname_len)) {
|
if (zend_hash_str_exists(&phar_obj->archive->virtual_dirs, fname, fname_len)) {
|
||||||
RETURN_TRUE;
|
RETURN_TRUE;
|
||||||
}
|
}
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
|
@ -3772,8 +3772,8 @@ PHP_METHOD(Phar, offsetUnset)
|
||||||
RETURN_THROWS();
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zend_hash_str_exists(&phar_obj->archive->manifest, fname, (uint32_t) fname_len)) {
|
if (zend_hash_str_exists(&phar_obj->archive->manifest, fname, fname_len)) {
|
||||||
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, (uint32_t) fname_len))) {
|
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, fname_len))) {
|
||||||
if (entry->is_deleted) {
|
if (entry->is_deleted) {
|
||||||
/* entry is deleted, but has not been flushed to disk yet */
|
/* entry is deleted, but has not been flushed to disk yet */
|
||||||
return;
|
return;
|
||||||
|
@ -3785,7 +3785,7 @@ PHP_METHOD(Phar, offsetUnset)
|
||||||
RETURN_THROWS();
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
/* re-populate entry after copy on write */
|
/* re-populate entry after copy on write */
|
||||||
entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, (uint32_t) fname_len);
|
entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, fname_len);
|
||||||
}
|
}
|
||||||
entry->is_modified = 0;
|
entry->is_modified = 0;
|
||||||
entry->is_deleted = 1;
|
entry->is_deleted = 1;
|
||||||
|
|
|
@ -168,7 +168,6 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
|
||||||
php_url *resource = NULL;
|
php_url *resource = NULL;
|
||||||
php_stream *fpf;
|
php_stream *fpf;
|
||||||
zval *pzoption, *metadata;
|
zval *pzoption, *metadata;
|
||||||
uint32_t host_len;
|
|
||||||
|
|
||||||
if ((resource = phar_parse_url(wrapper, path, mode, options)) == NULL) {
|
if ((resource = phar_parse_url(wrapper, path, mode, options)) == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -187,7 +186,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
host_len = ZSTR_LEN(resource->host);
|
size_t host_len = ZSTR_LEN(resource->host);
|
||||||
phar_request_initialize();
|
phar_request_initialize();
|
||||||
|
|
||||||
/* strip leading "/" */
|
/* strip leading "/" */
|
||||||
|
@ -565,7 +564,6 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int f
|
||||||
char *internal_file, *error;
|
char *internal_file, *error;
|
||||||
phar_archive_data *phar;
|
phar_archive_data *phar;
|
||||||
phar_entry_info *entry;
|
phar_entry_info *entry;
|
||||||
uint32_t host_len;
|
|
||||||
size_t internal_file_len;
|
size_t internal_file_len;
|
||||||
|
|
||||||
if ((resource = phar_parse_url(wrapper, url, "r", flags|PHP_STREAM_URL_STAT_QUIET)) == NULL) {
|
if ((resource = phar_parse_url(wrapper, url, "r", flags|PHP_STREAM_URL_STAT_QUIET)) == NULL) {
|
||||||
|
@ -583,7 +581,7 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int f
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
host_len = ZSTR_LEN(resource->host);
|
size_t host_len = ZSTR_LEN(resource->host);
|
||||||
phar_request_initialize();
|
phar_request_initialize();
|
||||||
|
|
||||||
internal_file = ZSTR_VAL(resource->path) + 1; /* strip leading "/" */
|
internal_file = ZSTR_VAL(resource->path) + 1; /* strip leading "/" */
|
||||||
|
@ -674,7 +672,6 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
|
||||||
int internal_file_len;
|
int internal_file_len;
|
||||||
phar_entry_data *idata;
|
phar_entry_data *idata;
|
||||||
phar_archive_data *pphar;
|
phar_archive_data *pphar;
|
||||||
uint32_t host_len;
|
|
||||||
|
|
||||||
if ((resource = phar_parse_url(wrapper, url, "rb", options)) == NULL) {
|
if ((resource = phar_parse_url(wrapper, url, "rb", options)) == NULL) {
|
||||||
php_stream_wrapper_log_error(wrapper, options, "phar error: unlink failed");
|
php_stream_wrapper_log_error(wrapper, options, "phar error: unlink failed");
|
||||||
|
@ -694,7 +691,7 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
host_len = ZSTR_LEN(resource->host);
|
size_t host_len = ZSTR_LEN(resource->host);
|
||||||
phar_request_initialize();
|
phar_request_initialize();
|
||||||
|
|
||||||
pphar = zend_hash_find_ptr(&(PHAR_G(phar_fname_map)), resource->host);
|
pphar = zend_hash_find_ptr(&(PHAR_G(phar_fname_map)), resource->host);
|
||||||
|
@ -747,7 +744,6 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
|
||||||
char *error;
|
char *error;
|
||||||
phar_archive_data *phar, *pfrom, *pto;
|
phar_archive_data *phar, *pfrom, *pto;
|
||||||
phar_entry_info *entry;
|
phar_entry_info *entry;
|
||||||
uint32_t host_len;
|
|
||||||
int is_dir = 0;
|
int is_dir = 0;
|
||||||
int is_modified = 0;
|
int is_modified = 0;
|
||||||
|
|
||||||
|
@ -823,7 +819,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
host_len = ZSTR_LEN(resource_from->host);
|
size_t host_len = ZSTR_LEN(resource_from->host);
|
||||||
|
|
||||||
if (SUCCESS != phar_get_archive(&phar, ZSTR_VAL(resource_from->host), host_len, NULL, 0, &error)) {
|
if (SUCCESS != phar_get_archive(&phar, ZSTR_VAL(resource_from->host), host_len, NULL, 0, &error)) {
|
||||||
php_url_free(resource_from);
|
php_url_free(resource_from);
|
||||||
|
@ -893,8 +889,8 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
|
||||||
Bucket *b;
|
Bucket *b;
|
||||||
zend_string *str_key;
|
zend_string *str_key;
|
||||||
zend_string *new_str_key;
|
zend_string *new_str_key;
|
||||||
uint32_t from_len = ZSTR_LEN(resource_from->path) - 1;
|
size_t from_len = ZSTR_LEN(resource_from->path) - 1;
|
||||||
uint32_t to_len = ZSTR_LEN(resource_to->path) - 1;
|
size_t to_len = ZSTR_LEN(resource_to->path) - 1;
|
||||||
|
|
||||||
ZEND_HASH_MAP_FOREACH_BUCKET(&phar->manifest, b) {
|
ZEND_HASH_MAP_FOREACH_BUCKET(&phar->manifest, b) {
|
||||||
str_key = b->key;
|
str_key = b->key;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue