diff options
author | Anatol Belski <ab@php.net> | 2017-07-26 23:10:07 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2017-07-27 20:11:21 +0200 |
commit | 49d9b3013fb2ee18b59694aa36036104a4bdd6f2 (patch) | |
tree | 40da76daa5117b1ba623c3e6fcc5c4d44ce94777 /main/fopen_wrappers.c | |
parent | 00bed31d9f24ce46b461e911c06d7a8b6e2cf1c0 (diff) | |
download | php-git-49d9b3013fb2ee18b59694aa36036104a4bdd6f2.tar.gz |
Move cwd_state and path related routines to size_t
Having `int` there is no real profit in the size or speed, while unsigned
improves security and overall integration. ZPP supplied strings can
be then accepted directly and structs can be still handled with smaller
unsigned types for size reasons, which is safe. Yet some related places
are to go.
basic move tsrm_realpath_r to size_t
fix conditions and sync with affected places
touch ocurrences of php_sys_readlink usage
follow up on phar path handling
remove duplicated check
move zend_resolve_path and related pieces to size_t
touch yet resolve path related places
remove cast
missing pieces
missing piece
yet cleanups for php_sys_readlink for ssize_t
fix wrong return
Diffstat (limited to 'main/fopen_wrappers.c')
-rw-r--r-- | main/fopen_wrappers.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 12de33be83..06b0eb35fa 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -168,11 +168,11 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path while (VCWD_REALPATH(path_tmp, resolved_name) == NULL) { #if defined(PHP_WIN32) || defined(HAVE_SYMLINK) if (nesting_level == 0) { - int ret; + ssize_t ret; char buf[MAXPATHLEN]; ret = php_sys_readlink(path_tmp, buf, MAXPATHLEN - 1); - if (ret < 0) { + if (ret == -1) { /* not a broken symlink, move along.. */ } else { /* put the real path into the path buffer */ @@ -355,7 +355,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle) char *path_info; char *filename = NULL; zend_string *resolved_path = NULL; - int length; + size_t length; zend_bool orig_display_errors; path_info = SG(request_info).request_uri; @@ -378,7 +378,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle) pwbuf = emalloc(pwbuflen); #endif length = s - (path_info + 2); - if (length > (int)sizeof(user) - 1) { + if (length > sizeof(user) - 1) { length = sizeof(user) - 1; } memcpy(user, path_info + 2, length); @@ -402,9 +402,9 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle) } } else #endif - if (PG(doc_root) && path_info && (length = (int)strlen(PG(doc_root))) && + if (PG(doc_root) && path_info && (length = strlen(PG(doc_root))) && IS_ABSOLUTE_PATH(PG(doc_root), length)) { - int path_len = (int)strlen(path_info); + size_t path_len = strlen(path_info); filename = emalloc(length + path_len + 2); memcpy(filename, PG(doc_root), length); if (!IS_SLASH(filename[length - 1])) { /* length is never 0 */ @@ -420,7 +420,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle) if (filename) { - resolved_path = zend_resolve_path(filename, (int)strlen(filename)); + resolved_path = zend_resolve_path(filename, strlen(filename)); } if (!resolved_path) { @@ -472,7 +472,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle) /* {{{ php_resolve_path * Returns the realpath for given filename according to include path */ -PHPAPI zend_string *php_resolve_path(const char *filename, int filename_length, const char *path) +PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_length, const char *path) { char resolved_path[MAXPATHLEN]; char trypath[MAXPATHLEN]; @@ -532,7 +532,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, int filename_length, } end = strchr(p, DEFAULT_DIR_SEPARATOR); if (end) { - if (filename_length > (MAXPATHLEN - 2) || (end-ptr) > MAXPATHLEN || (end-ptr) + 1 + (size_t)filename_length + 1 >= MAXPATHLEN) { + if (filename_length > (MAXPATHLEN - 2) || (end-ptr) > MAXPATHLEN || (end-ptr) + 1 + filename_length + 1 >= MAXPATHLEN) { ptr = end + 1; continue; } @@ -543,7 +543,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, int filename_length, } else { size_t len = strlen(ptr); - if (filename_length > (MAXPATHLEN - 2) || len > MAXPATHLEN || len + 1 + (size_t)filename_length + 1 >= MAXPATHLEN) { + if (filename_length > (MAXPATHLEN - 2) || len > MAXPATHLEN || len + 1 + filename_length + 1 >= MAXPATHLEN) { break; } memcpy(trypath, ptr, len); @@ -624,7 +624,7 @@ PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const c char *pathbuf, *ptr, *end; char trypath[MAXPATHLEN]; FILE *fp; - int filename_length; + size_t filename_length; zend_string *exec_filename; if (opened_path) { @@ -635,7 +635,7 @@ PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const c return NULL; } - filename_length = (int)strlen(filename); + filename_length = strlen(filename); #ifndef PHP_WIN32 (void) filename_length; #endif @@ -761,14 +761,14 @@ PHPAPI char *expand_filepath_with_mode(const char *filepath, char *real_path, co { cwd_state new_state; char cwd[MAXPATHLEN]; - int copy_len; - int path_len; + size_t copy_len; + size_t path_len; if (!filepath[0]) { return NULL; } - path_len = (int)strlen(filepath); + path_len = strlen(filepath); if (IS_ABSOLUTE_PATH(filepath, path_len)) { cwd[0] = '\0'; @@ -811,7 +811,7 @@ PHPAPI char *expand_filepath_with_mode(const char *filepath, char *real_path, co } new_state.cwd = estrdup(cwd); - new_state.cwd_length = (int)strlen(cwd); + new_state.cwd_length = strlen(cwd); if (virtual_file_ex(&new_state, filepath, NULL, realpath_mode)) { efree(new_state.cwd); |