summaryrefslogtreecommitdiff
path: root/main/php_open_temporary_file.c
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2017-07-26 23:10:07 +0200
committerAnatol Belski <ab@php.net>2017-07-27 20:11:21 +0200
commit49d9b3013fb2ee18b59694aa36036104a4bdd6f2 (patch)
tree40da76daa5117b1ba623c3e6fcc5c4d44ce94777 /main/php_open_temporary_file.c
parent00bed31d9f24ce46b461e911c06d7a8b6e2cf1c0 (diff)
downloadphp-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/php_open_temporary_file.c')
-rw-r--r--main/php_open_temporary_file.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c
index f2303882f4..71354654b5 100644
--- a/main/php_open_temporary_file.c
+++ b/main/php_open_temporary_file.c
@@ -125,7 +125,7 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, zend_st
}
new_state.cwd = estrdup(cwd);
- new_state.cwd_length = (int)strlen(cwd);
+ new_state.cwd_length = strlen(cwd);
if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)) {
efree(new_state.cwd);
@@ -216,7 +216,7 @@ PHPAPI const char* php_get_temporary_directory(void)
{
char *sys_temp_dir = PG(sys_temp_dir);
if (sys_temp_dir) {
- int len = (int)strlen(sys_temp_dir);
+ size_t len = strlen(sys_temp_dir);
if (len >= 2 && sys_temp_dir[len - 1] == DEFAULT_SLASH) {
PG(php_sys_temp_dir) = estrndup(sys_temp_dir, len - 1);
return PG(php_sys_temp_dir);
@@ -237,7 +237,10 @@ PHPAPI const char* php_get_temporary_directory(void)
wchar_t sTemp[MAXPATHLEN];
char *tmp;
size_t len = GetTempPathW(MAXPATHLEN, sTemp);
- assert(0 < len); /* should *never* fail! */
+
+ if (!len) {
+ return NULL;
+ }
if (NULL == (tmp = php_win32_ioutil_conv_w_to_any(sTemp, len, &len))) {
return NULL;
@@ -253,7 +256,7 @@ PHPAPI const char* php_get_temporary_directory(void)
{
char* s = getenv("TMPDIR");
if (s && *s) {
- int len = strlen(s);
+ size_t len = strlen(s);
if (s[len - 1] == DEFAULT_SLASH) {
PG(php_sys_temp_dir) = estrndup(s, len - 1);