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
This commit is contained in:
Anatol Belski 2017-07-26 23:10:07 +02:00
parent 00bed31d9f
commit 49d9b3013f
19 changed files with 113 additions and 108 deletions

View file

@ -75,7 +75,7 @@ ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint3
void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap); void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap);
void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap); void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
ZEND_API char *(*zend_getenv)(char *name, size_t name_len); ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
ZEND_API zend_string *(*zend_resolve_path)(const char *filename, int filename_len); ZEND_API zend_string *(*zend_resolve_path)(const char *filename, size_t filename_len);
void (*zend_on_timeout)(int seconds); void (*zend_on_timeout)(int seconds);

View file

@ -189,7 +189,7 @@ typedef struct _zend_utility_functions {
void (*printf_to_smart_string_function)(smart_string *buf, const char *format, va_list ap); void (*printf_to_smart_string_function)(smart_string *buf, const char *format, va_list ap);
void (*printf_to_smart_str_function)(smart_str *buf, const char *format, va_list ap); void (*printf_to_smart_str_function)(smart_str *buf, const char *format, va_list ap);
char *(*getenv_function)(char *name, size_t name_len); char *(*getenv_function)(char *name, size_t name_len);
zend_string *(*resolve_path_function)(const char *filename, int filename_len); zend_string *(*resolve_path_function)(const char *filename, size_t filename_len);
} zend_utility_functions; } zend_utility_functions;
typedef struct _zend_utility_values { typedef struct _zend_utility_values {
@ -269,7 +269,7 @@ extern ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file
extern void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap); extern void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap);
extern void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap); extern void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len); extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, int filename_len); extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, size_t filename_len);
ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);

View file

@ -2780,7 +2780,7 @@ static zend_never_inline zend_op_array* ZEND_FASTCALL zend_include_or_eval(zval
zend_file_handle file_handle; zend_file_handle file_handle;
zend_string *resolved_path; zend_string *resolved_path;
resolved_path = zend_resolve_path(Z_STRVAL_P(inc_filename), (int)Z_STRLEN_P(inc_filename)); resolved_path = zend_resolve_path(Z_STRVAL_P(inc_filename), Z_STRLEN_P(inc_filename));
if (resolved_path) { if (resolved_path) {
if (zend_hash_exists(&EG(included_files), resolved_path)) { if (zend_hash_exists(&EG(included_files), resolved_path)) {
goto already_compiled; goto already_compiled;

View file

@ -163,7 +163,7 @@ static inline time_t FileTimeToUnixTime(const FILETIME *FileTime)
return (time_t)UnixTime; return (time_t)UnixTime;
} }
CWD_API int php_sys_readlink(const char *link, char *target, size_t target_len){ /* {{{ */ CWD_API ssize_t php_sys_readlink(const char *link, char *target, size_t target_len){ /* {{{ */
HANDLE hFile; HANDLE hFile;
wchar_t *linkw = php_win32_ioutil_any_to_w(link), targetw[MAXPATHLEN]; wchar_t *linkw = php_win32_ioutil_any_to_w(link), targetw[MAXPATHLEN];
size_t ret_len, targetw_len, offset = 0; size_t ret_len, targetw_len, offset = 0;
@ -229,7 +229,7 @@ CWD_API int php_sys_readlink(const char *link, char *target, size_t target_len){
CloseHandle(hFile); CloseHandle(hFile);
free(linkw); free(linkw);
return ret_len; return (ssize_t)ret_len;
} }
/* }}} */ /* }}} */
@ -404,7 +404,7 @@ CWD_API void virtual_cwd_startup(void) /* {{{ */
cwd[0] = '\0'; cwd[0] = '\0';
} }
main_cwd_state.cwd_length = (int)strlen(cwd); main_cwd_state.cwd_length = strlen(cwd);
#ifdef ZEND_WIN32 #ifdef ZEND_WIN32
if (main_cwd_state.cwd_length >= 2 && cwd[1] == ':') { if (main_cwd_state.cwd_length >= 2 && cwd[1] == ':') {
cwd[0] = toupper(cwd[0]); cwd[0] = toupper(cwd[0]);
@ -706,10 +706,10 @@ CWD_API realpath_cache_bucket** realpath_cache_get_buckets(void)
#undef LINK_MAX #undef LINK_MAX
#define LINK_MAX 32 #define LINK_MAX 32
static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, int use_realpath, int is_dir, int *link_is_dir) /* {{{ */ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, time_t *t, int use_realpath, int is_dir, int *link_is_dir) /* {{{ */
{ {
int i, j, save; size_t i, j;
int directory = 0; int directory = 0, save;
#ifdef ZEND_WIN32 #ifdef ZEND_WIN32
WIN32_FIND_DATAW dataw; WIN32_FIND_DATAW dataw;
HANDLE hFind = INVALID_HANDLE_VALUE; HANDLE hFind = INVALID_HANDLE_VALUE;
@ -739,7 +739,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
} }
if (i == len || if (i == len ||
(i == len - 1 && path[i] == '.')) { (i + 1 == len && path[i] == '.')) {
/* remove double slashes and '.' */ /* remove double slashes and '.' */
len = i - 1; len = i - 1;
is_dir = 1; is_dir = 1;
@ -750,7 +750,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
if (link_is_dir) { if (link_is_dir) {
*link_is_dir = 1; *link_is_dir = 1;
} }
if (i - 1 <= start) { if (i <= start + 1) {
return start ? start : len; return start ? start : len;
} }
j = tsrm_realpath_r(path, start, i-1, ll, t, use_realpath, 1, NULL); j = tsrm_realpath_r(path, start, i-1, ll, t, use_realpath, 1, NULL);
@ -798,7 +798,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
if ((bucket = realpath_cache_find(path, len, *t)) != NULL) { if ((bucket = realpath_cache_find(path, len, *t)) != NULL) {
if (is_dir && !bucket->is_dir) { if (is_dir && !bucket->is_dir) {
/* not a directory */ /* not a directory */
return -1; return (size_t)-1;
} else { } else {
if (link_is_dir) { if (link_is_dir) {
*link_is_dir = bucket->is_dir; *link_is_dir = bucket->is_dir;
@ -813,14 +813,14 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
if (save) { if (save) {
pathw = php_win32_ioutil_any_to_w(path); pathw = php_win32_ioutil_any_to_w(path);
if (!pathw) { if (!pathw) {
return -1; return (size_t)-1;
} }
hFind = FindFirstFileExW(pathw, FindExInfoBasic, &dataw, FindExSearchNameMatch, NULL, 0); hFind = FindFirstFileExW(pathw, FindExInfoBasic, &dataw, FindExSearchNameMatch, NULL, 0);
if (INVALID_HANDLE_VALUE == hFind) { if (INVALID_HANDLE_VALUE == hFind) {
if (use_realpath == CWD_REALPATH) { if (use_realpath == CWD_REALPATH) {
/* file not found */ /* file not found */
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
/* continue resolution anyway but don't save result in the cache */ /* continue resolution anyway but don't save result in the cache */
save = 0; save = 0;
@ -840,7 +840,8 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
HANDLE hLink = NULL; HANDLE hLink = NULL;
REPARSE_DATA_BUFFER * pbuffer; REPARSE_DATA_BUFFER * pbuffer;
DWORD retlength = 0; DWORD retlength = 0;
int bufindex = 0, isabsolute = 0; size_t bufindex = 0;
uint8_t isabsolute = 0;
wchar_t * reparsetarget; wchar_t * reparsetarget;
BOOL isVolume = FALSE; BOOL isVolume = FALSE;
#if VIRTUAL_CWD_DEBUG #if VIRTUAL_CWD_DEBUG
@ -848,20 +849,20 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
#endif #endif
char *substitutename = NULL; char *substitutename = NULL;
size_t substitutename_len; size_t substitutename_len;
int substitutename_off = 0; size_t substitutename_off = 0;
wchar_t tmpsubstname[MAXPATHLEN]; wchar_t tmpsubstname[MAXPATHLEN];
if(++(*ll) > LINK_MAX) { if(++(*ll) > LINK_MAX) {
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
hLink = CreateFileW(pathw, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS, NULL); hLink = CreateFileW(pathw, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS, NULL);
if(hLink == INVALID_HANDLE_VALUE) { if(hLink == INVALID_HANDLE_VALUE) {
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
pbuffer = (REPARSE_DATA_BUFFER *)do_alloca(MAXIMUM_REPARSE_DATA_BUFFER_SIZE, use_heap_large); pbuffer = (REPARSE_DATA_BUFFER *)do_alloca(MAXIMUM_REPARSE_DATA_BUFFER_SIZE, use_heap_large);
@ -869,14 +870,14 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
CloseHandle(hLink); CloseHandle(hLink);
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
if(!DeviceIoControl(hLink, FSCTL_GET_REPARSE_POINT, NULL, 0, pbuffer, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &retlength, NULL)) { if(!DeviceIoControl(hLink, FSCTL_GET_REPARSE_POINT, NULL, 0, pbuffer, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &retlength, NULL)) {
free_alloca(pbuffer, use_heap_large); free_alloca(pbuffer, use_heap_large);
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
CloseHandle(hLink); CloseHandle(hLink);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
CloseHandle(hLink); CloseHandle(hLink);
@ -890,7 +891,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
free_alloca(pbuffer, use_heap_large); free_alloca(pbuffer, use_heap_large);
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
#endif #endif
@ -899,7 +900,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
free_alloca(pbuffer, use_heap_large); free_alloca(pbuffer, use_heap_large);
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
memmove(tmpsubstname, reparsetarget + pbuffer->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR), pbuffer->MountPointReparseBuffer.SubstituteNameLength); memmove(tmpsubstname, reparsetarget + pbuffer->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR), pbuffer->MountPointReparseBuffer.SubstituteNameLength);
tmpsubstname[substitutename_len] = L'\0'; tmpsubstname[substitutename_len] = L'\0';
@ -912,7 +913,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
free(printname); free(printname);
#endif #endif
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
} }
else if(pbuffer->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) { else if(pbuffer->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) {
@ -924,7 +925,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
free_alloca(pbuffer, use_heap_large); free_alloca(pbuffer, use_heap_large);
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
#endif #endif
@ -934,7 +935,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
free_alloca(pbuffer, use_heap_large); free_alloca(pbuffer, use_heap_large);
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
memmove(tmpsubstname, reparsetarget + pbuffer->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR), pbuffer->MountPointReparseBuffer.SubstituteNameLength); memmove(tmpsubstname, reparsetarget + pbuffer->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR), pbuffer->MountPointReparseBuffer.SubstituteNameLength);
tmpsubstname[substitutename_len] = L'\0'; tmpsubstname[substitutename_len] = L'\0';
@ -947,7 +948,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
free(printname); free(printname);
#endif #endif
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
} }
else if (pbuffer->ReparseTag == IO_REPARSE_TAG_DEDUP) { else if (pbuffer->ReparseTag == IO_REPARSE_TAG_DEDUP) {
@ -957,7 +958,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
free_alloca(pbuffer, use_heap_large); free_alloca(pbuffer, use_heap_large);
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
memcpy(substitutename, path, len + 1); memcpy(substitutename, path, len + 1);
substitutename_len = len; substitutename_len = len;
@ -966,7 +967,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
free_alloca(pbuffer, use_heap_large); free_alloca(pbuffer, use_heap_large);
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
if(isabsolute && substitutename_len > 4) { if(isabsolute && substitutename_len > 4) {
@ -993,7 +994,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
if (!isVolume) { if (!isVolume) {
char * tmp2 = substitutename + substitutename_off; char * tmp2 = substitutename + substitutename_off;
for(bufindex = 0; bufindex < (substitutename_len - substitutename_off); bufindex++) { for (bufindex = 0; bufindex + substitutename_off < substitutename_len; bufindex++) {
*(path + bufindex) = *(tmp2 + bufindex); *(path + bufindex) = *(tmp2 + bufindex);
} }
@ -1017,10 +1018,10 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
if (!((j == 3) && (path[1] == ':') && (path[2] == '\\'))) { if (!((j == 3) && (path[1] == ':') && (path[2] == '\\'))) {
/* use_realpath is 0 in the call below coz path is absolute*/ /* use_realpath is 0 in the call below coz path is absolute*/
j = tsrm_realpath_r(path, 0, j, ll, t, 0, is_dir, &directory); j = tsrm_realpath_r(path, 0, j, ll, t, 0, is_dir, &directory);
if(j < 0) { if(j == (size_t)-1) {
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
} }
} }
@ -1028,17 +1029,17 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
if(i + j >= MAXPATHLEN - 1) { if(i + j >= MAXPATHLEN - 1) {
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
memmove(path+i, path, j+1); memmove(path+i, path, j+1);
memcpy(path, tmp, i-1); memcpy(path, tmp, i-1);
path[i-1] = DEFAULT_SLASH; path[i-1] = DEFAULT_SLASH;
j = tsrm_realpath_r(path, start, i + j, ll, t, use_realpath, is_dir, &directory); j = tsrm_realpath_r(path, start, i + j, ll, t, use_realpath, is_dir, &directory);
if(j < 0) { if(j == (size_t)-1) {
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
} }
directory = (dataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); directory = (dataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
@ -1054,14 +1055,14 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
/* not a directory */ /* not a directory */
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
} }
#else #else
if (save && php_sys_lstat(path, &st) < 0) { if (save && php_sys_lstat(path, &st) < 0) {
if (use_realpath == CWD_REALPATH) { if (use_realpath == CWD_REALPATH) {
/* file not found */ /* file not found */
return -1; return (size_t)-1;
} }
/* continue resolution anyway but don't save result in the cache */ /* continue resolution anyway but don't save result in the cache */
save = 0; save = 0;
@ -1071,30 +1072,30 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
memcpy(tmp, path, len+1); memcpy(tmp, path, len+1);
if (save && S_ISLNK(st.st_mode)) { if (save && S_ISLNK(st.st_mode)) {
if (++(*ll) > LINK_MAX || (j = php_sys_readlink(tmp, path, MAXPATHLEN)) < 0) { if (++(*ll) > LINK_MAX || (j = (size_t)php_sys_readlink(tmp, path, MAXPATHLEN)) == (size_t)-1) {
/* too many links or broken symlinks */ /* too many links or broken symlinks */
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
return -1; return (size_t)-1;
} }
path[j] = 0; path[j] = 0;
if (IS_ABSOLUTE_PATH(path, j)) { if (IS_ABSOLUTE_PATH(path, j)) {
j = tsrm_realpath_r(path, 1, j, ll, t, use_realpath, is_dir, &directory); j = tsrm_realpath_r(path, 1, j, ll, t, use_realpath, is_dir, &directory);
if (j < 0) { if (j == (size_t)-1) {
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
return -1; return (size_t)-1;
} }
} else { } else {
if (i + j >= MAXPATHLEN-1) { if (i + j >= MAXPATHLEN-1) {
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
return -1; /* buffer overflow */ return (size_t)-1; /* buffer overflow */
} }
memmove(path+i, path, j+1); memmove(path+i, path, j+1);
memcpy(path, tmp, i-1); memcpy(path, tmp, i-1);
path[i-1] = DEFAULT_SLASH; path[i-1] = DEFAULT_SLASH;
j = tsrm_realpath_r(path, start, i + j, ll, t, use_realpath, is_dir, &directory); j = tsrm_realpath_r(path, start, i + j, ll, t, use_realpath, is_dir, &directory);
if (j < 0) { if (j == (size_t)-1) {
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
return -1; return (size_t)-1;
} }
} }
if (link_is_dir) { if (link_is_dir) {
@ -1109,11 +1110,11 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
if (is_dir && !directory) { if (is_dir && !directory) {
/* not a directory */ /* not a directory */
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
return -1; return (size_t)-1;
} }
} }
#endif #endif
if (i - 1 <= start) { if (i <= start + 1) {
j = start; j = start;
} else { } else {
/* some leading directories may be unaccessable */ /* some leading directories may be unaccessable */
@ -1123,10 +1124,10 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
} }
} }
#ifdef ZEND_WIN32 #ifdef ZEND_WIN32
if (j < 0 || j + len - i >= MAXPATHLEN-1) { if (j == (size_t)-1 || j + len >= MAXPATHLEN - 1 + i) {
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
if (save) { if (save) {
size_t sz; size_t sz;
@ -1134,9 +1135,9 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
if (!tmp_path) { if (!tmp_path) {
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
FREE_PATHW() FREE_PATHW()
return -1; return (size_t)-1;
} }
i = (int)sz; i = sz;
memcpy(path+j, tmp_path, i+1); memcpy(path+j, tmp_path, i+1);
free(tmp_path); free(tmp_path);
j += i; j += i;
@ -1147,9 +1148,9 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
} }
} }
#else #else
if (j < 0 || j + len - i >= MAXPATHLEN-1) { if (j == (size_t)-1 || j + len >= MAXPATHLEN - 1 + i) {
free_alloca(tmp, use_heap); free_alloca(tmp, use_heap);
return -1; return (size_t)-1;
} }
memcpy(path+j, tmp+i, len-i+1); memcpy(path+j, tmp+i, len-i+1);
j += (len-i); j += (len-i);
@ -1175,16 +1176,16 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
/* returns 0 for ok, 1 for error */ /* returns 0 for ok, 1 for error */
CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath) /* {{{ */ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath) /* {{{ */
{ {
int path_length = (int)strlen(path); size_t path_length = strlen(path);
char resolved_path[MAXPATHLEN]; char resolved_path[MAXPATHLEN];
int start = 1; size_t start = 1;
int ll = 0; int ll = 0;
time_t t; time_t t;
int ret; int ret;
int add_slash; int add_slash;
void *tmp; void *tmp;
if (path_length <= 0 || path_length >= MAXPATHLEN-1) { if (!path_length || path_length >= MAXPATHLEN-1) {
#ifdef ZEND_WIN32 #ifdef ZEND_WIN32
_set_errno(EINVAL); _set_errno(EINVAL);
#else #else
@ -1206,7 +1207,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
start = 0; start = 0;
memcpy(resolved_path , path, path_length + 1); memcpy(resolved_path , path, path_length + 1);
} else { } else {
int state_cwd_length = state->cwd_length; size_t state_cwd_length = state->cwd_length;
#ifdef ZEND_WIN32 #ifdef ZEND_WIN32
if (IS_SLASH(path[0])) { if (IS_SLASH(path[0])) {
@ -1300,7 +1301,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
t = CWDG(realpath_cache_ttl) ? 0 : -1; t = CWDG(realpath_cache_ttl) ? 0 : -1;
path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL); path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL);
if (path_length < 0) { if (path_length == (size_t)-1) {
errno = ENOENT; errno = ENOENT;
return 1; return 1;
} }
@ -1416,7 +1417,7 @@ CWD_API char *virtual_realpath(const char *path, char *real_path) /* {{{ */
} }
if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)==0) { if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)==0) {
int len = new_state.cwd_length>MAXPATHLEN-1?MAXPATHLEN-1:new_state.cwd_length; size_t len = new_state.cwd_length>MAXPATHLEN-1?MAXPATHLEN-1:new_state.cwd_length;
memcpy(real_path, new_state.cwd, len); memcpy(real_path, new_state.cwd, len);
real_path[len] = '\0'; real_path[len] = '\0';
@ -1880,7 +1881,7 @@ CWD_API char *tsrm_realpath(const char *path, char *real_path) /* {{{ */
} else if (!IS_ABSOLUTE_PATH(path, strlen(path)) && } else if (!IS_ABSOLUTE_PATH(path, strlen(path)) &&
VCWD_GETCWD(cwd, MAXPATHLEN)) { VCWD_GETCWD(cwd, MAXPATHLEN)) {
new_state.cwd = estrdup(cwd); new_state.cwd = estrdup(cwd);
new_state.cwd_length = (int)strlen(cwd); new_state.cwd_length = strlen(cwd);
} else { } else {
new_state.cwd = (char*)emalloc(1); new_state.cwd = (char*)emalloc(1);
new_state.cwd[0] = '\0'; new_state.cwd[0] = '\0';
@ -1893,7 +1894,7 @@ CWD_API char *tsrm_realpath(const char *path, char *real_path) /* {{{ */
} }
if (real_path) { if (real_path) {
int copy_len = new_state.cwd_length>MAXPATHLEN-1 ? MAXPATHLEN-1 : new_state.cwd_length; size_t copy_len = new_state.cwd_length>MAXPATHLEN-1 ? MAXPATHLEN-1 : new_state.cwd_length;
memcpy(real_path, new_state.cwd, copy_len); memcpy(real_path, new_state.cwd, copy_len);
real_path[copy_len] = '\0'; real_path[copy_len] = '\0';
efree(new_state.cwd); efree(new_state.cwd);

View file

@ -121,7 +121,7 @@ typedef unsigned short mode_t;
CWD_API int php_sys_stat_ex(const char *path, zend_stat_t *buf, int lstat); CWD_API int php_sys_stat_ex(const char *path, zend_stat_t *buf, int lstat);
# define php_sys_stat(path, buf) php_sys_stat_ex(path, buf, 0) # define php_sys_stat(path, buf) php_sys_stat_ex(path, buf, 0)
# define php_sys_lstat(path, buf) php_sys_stat_ex(path, buf, 1) # define php_sys_lstat(path, buf) php_sys_stat_ex(path, buf, 1)
CWD_API int php_sys_readlink(const char *link, char *target, size_t target_len); CWD_API ssize_t php_sys_readlink(const char *link, char *target, size_t target_len);
#else #else
# define php_sys_stat stat # define php_sys_stat stat
# define php_sys_lstat lstat # define php_sys_lstat lstat
@ -132,7 +132,7 @@ CWD_API int php_sys_readlink(const char *link, char *target, size_t target_len);
typedef struct _cwd_state { typedef struct _cwd_state {
char *cwd; char *cwd;
int cwd_length; size_t cwd_length;
} cwd_state; } cwd_state;
typedef int (*verify_path_func)(const cwd_state *); typedef int (*verify_path_func)(const cwd_state *);

View file

@ -114,7 +114,7 @@ zend_bool fallback_process = 0; /* process uses file cache fallback */
static zend_op_array *(*accelerator_orig_compile_file)(zend_file_handle *file_handle, int type); static zend_op_array *(*accelerator_orig_compile_file)(zend_file_handle *file_handle, int type);
static int (*accelerator_orig_zend_stream_open_function)(const char *filename, zend_file_handle *handle ); static int (*accelerator_orig_zend_stream_open_function)(const char *filename, zend_file_handle *handle );
static zend_string *(*accelerator_orig_zend_resolve_path)(const char *filename, int filename_len); static zend_string *(*accelerator_orig_zend_resolve_path)(const char *filename, size_t filename_len);
static zif_handler orig_chdir = NULL; static zif_handler orig_chdir = NULL;
static ZEND_INI_MH((*orig_include_path_on_modify)) = NULL; static ZEND_INI_MH((*orig_include_path_on_modify)) = NULL;
@ -1015,7 +1015,7 @@ int validate_timestamp_and_record_ex(zend_persistent_script *persistent_script,
/* Instead of resolving full real path name each time we need to identify file, /* Instead of resolving full real path name each time we need to identify file,
* we create a key that consist from requested file name, current working * we create a key that consist from requested file name, current working
* directory, current include_path, etc */ * directory, current include_path, etc */
char *accel_make_persistent_key(const char *path, int path_length, int *key_len) char *accel_make_persistent_key(const char *path, size_t path_length, int *key_len)
{ {
int key_length; int key_length;
@ -1171,7 +1171,7 @@ char *accel_make_persistent_key(const char *path, int path_length, int *key_len)
return (char*)path; return (char*)path;
} }
int zend_accel_invalidate(const char *filename, int filename_len, zend_bool force) int zend_accel_invalidate(const char *filename, size_t filename_len, zend_bool force)
{ {
zend_string *realpath; zend_string *realpath;
zend_persistent_script *persistent_script; zend_persistent_script *persistent_script;
@ -2018,7 +2018,7 @@ static int persistent_stream_open_function(const char *filename, zend_file_handl
} }
/* zend_resolve_path() replacement for PHP 5.3 and above */ /* zend_resolve_path() replacement for PHP 5.3 and above */
static zend_string* persistent_zend_resolve_path(const char *filename, int filename_len) static zend_string* persistent_zend_resolve_path(const char *filename, size_t filename_len)
{ {
if (ZCG(enabled) && accel_startup_ok && if (ZCG(enabled) && accel_startup_ok &&
(ZCG(counted) || ZCSG(accelerator_enabled)) && (ZCG(counted) || ZCSG(accelerator_enabled)) &&

View file

@ -310,11 +310,11 @@ void zend_accel_schedule_restart_if_necessary(zend_accel_restart_reason reason);
accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle, size_t *size); accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle, size_t *size);
int validate_timestamp_and_record(zend_persistent_script *persistent_script, zend_file_handle *file_handle); int validate_timestamp_and_record(zend_persistent_script *persistent_script, zend_file_handle *file_handle);
int validate_timestamp_and_record_ex(zend_persistent_script *persistent_script, zend_file_handle *file_handle); int validate_timestamp_and_record_ex(zend_persistent_script *persistent_script, zend_file_handle *file_handle);
int zend_accel_invalidate(const char *filename, int filename_len, zend_bool force); int zend_accel_invalidate(const char *filename, size_t filename_len, zend_bool force);
int accelerator_shm_read_lock(void); int accelerator_shm_read_lock(void);
void accelerator_shm_read_unlock(void); void accelerator_shm_read_unlock(void);
char *accel_make_persistent_key(const char *path, int path_length, int *key_len); char *accel_make_persistent_key(const char *path, size_t path_length, int *key_len);
zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type); zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type);
#define IS_ACCEL_INTERNED(str) \ #define IS_ACCEL_INTERNED(str) \

View file

@ -27,7 +27,7 @@
static void destroy_phar_data(zval *zv); static void destroy_phar_data(zval *zv);
ZEND_DECLARE_MODULE_GLOBALS(phar) ZEND_DECLARE_MODULE_GLOBALS(phar)
zend_string *(*phar_save_resolve_path)(const char *filename, int filename_len); zend_string *(*phar_save_resolve_path)(const char *filename, size_t filename_len);
/** /**
* set's phar->is_writeable based on the current INI value * set's phar->is_writeable based on the current INI value
@ -3249,7 +3249,7 @@ static size_t phar_zend_stream_fsizer(void *handle) /* {{{ */
zend_op_array *(*phar_orig_compile_file)(zend_file_handle *file_handle, int type); zend_op_array *(*phar_orig_compile_file)(zend_file_handle *file_handle, int type);
#define phar_orig_zend_open zend_stream_open_function #define phar_orig_zend_open zend_stream_open_function
static zend_string *phar_resolve_path(const char *filename, int filename_len) static zend_string *phar_resolve_path(const char *filename, size_t filename_len)
{ {
return phar_find_in_include_path((char *) filename, filename_len, NULL); return phar_find_in_include_path((char *) filename, filename_len, NULL);
} }

View file

@ -4164,7 +4164,7 @@ PHP_METHOD(Phar, delMetadata)
} }
/* }}} */ /* }}} */
static int phar_extract_file(zend_bool overwrite, phar_entry_info *entry, char *dest, int dest_len, char **error) /* {{{ */ static int phar_extract_file(zend_bool overwrite, phar_entry_info *entry, char *dest, size_t dest_len, char **error) /* {{{ */
{ {
php_stream_statbuf ssb; php_stream_statbuf ssb;
size_t len; size_t len;
@ -4206,13 +4206,13 @@ static int phar_extract_file(zend_bool overwrite, phar_entry_info *entry, char *
#ifdef PHP_WIN32 #ifdef PHP_WIN32
/* unixify the path back, otherwise non zip formats might be broken */ /* unixify the path back, otherwise non zip formats might be broken */
{ {
int cnt = filename_len; size_t cnt = 0;
do { do {
if ('\\' == filename[cnt]) { if ('\\' == filename[cnt]) {
filename[cnt] = '/'; filename[cnt] = '/';
} }
} while (cnt-- >= 0); } while (cnt++ < filename_len);
} }
#endif #endif
@ -4433,7 +4433,7 @@ PHP_METHOD(Phar, extractTo)
zend_throw_exception_ex(phar_ce_PharException, 0, zend_throw_exception_ex(phar_ce_PharException, 0,
"Phar Error: attempted to extract non-existent file \"%s\" from phar \"%s\"", Z_STRVAL_P(zval_file), phar_obj->archive->fname); "Phar Error: attempted to extract non-existent file \"%s\" from phar \"%s\"", Z_STRVAL_P(zval_file), phar_obj->archive->fname);
} }
if (FAILURE == phar_extract_file(overwrite, entry, pathto, (int)pathto_len, &error)) { if (FAILURE == phar_extract_file(overwrite, entry, pathto, pathto_len, &error)) {
zend_throw_exception_ex(phar_ce_PharException, 0, zend_throw_exception_ex(phar_ce_PharException, 0,
"Extraction from phar \"%s\" failed: %s", phar_obj->archive->fname, error); "Extraction from phar \"%s\" failed: %s", phar_obj->archive->fname, error);
efree(error); efree(error);
@ -4454,7 +4454,7 @@ PHP_METHOD(Phar, extractTo)
return; return;
} }
if (FAILURE == phar_extract_file(overwrite, entry, pathto, (int)pathto_len, &error)) { if (FAILURE == phar_extract_file(overwrite, entry, pathto, pathto_len, &error)) {
zend_throw_exception_ex(phar_ce_PharException, 0, zend_throw_exception_ex(phar_ce_PharException, 0,
"Extraction from phar \"%s\" failed: %s", phar_obj->archive->fname, error); "Extraction from phar \"%s\" failed: %s", phar_obj->archive->fname, error);
efree(error); efree(error);
@ -4470,7 +4470,7 @@ all_files:
} }
ZEND_HASH_FOREACH_PTR(&phar->manifest, entry) { ZEND_HASH_FOREACH_PTR(&phar->manifest, entry) {
if (FAILURE == phar_extract_file(overwrite, entry, pathto, (int)pathto_len, &error)) { if (FAILURE == phar_extract_file(overwrite, entry, pathto, pathto_len, &error)) {
zend_throw_exception_ex(phar_ce_PharException, 0, zend_throw_exception_ex(phar_ce_PharException, 0,
"Extraction from phar \"%s\" failed: %s", phar->fname, error); "Extraction from phar \"%s\" failed: %s", phar->fname, error);
efree(error); efree(error);

View file

@ -1235,7 +1235,7 @@ FileInfoFunction(isLink, FS_IS_LINK)
SPL_METHOD(SplFileInfo, getLinkTarget) SPL_METHOD(SplFileInfo, getLinkTarget)
{ {
spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis()); spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
int ret; ssize_t ret;
char buff[MAXPATHLEN]; char buff[MAXPATHLEN];
zend_error_handling error_handling; zend_error_handling error_handling;

View file

@ -57,7 +57,7 @@ PHP_FUNCTION(readlink)
char *link; char *link;
size_t link_len; size_t link_len;
char buff[MAXPATHLEN]; char buff[MAXPATHLEN];
int ret; ssize_t ret;
ZEND_PARSE_PARAMETERS_START(1, 1) ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_PATH(link, link_len) Z_PARAM_PATH(link, link_len)

View file

@ -63,7 +63,7 @@ TODO:
PHP_FUNCTION(readlink) PHP_FUNCTION(readlink)
{ {
char *link; char *link;
size_t link_len; ssize_t link_len;
char target[MAXPATHLEN]; char target[MAXPATHLEN];
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &link, &link_len) == FAILURE) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &link, &link_len) == FAILURE) {
@ -74,7 +74,8 @@ PHP_FUNCTION(readlink)
RETURN_FALSE; RETURN_FALSE;
} }
if (php_sys_readlink(link, target, MAXPATHLEN) == -1) { link_len = php_sys_readlink(link, target, MAXPATHLEN);
if (link_len == -1) {
php_error_docref(NULL, E_WARNING, "readlink failed to read the symbolic link (%s), error %d)", link, GetLastError()); php_error_docref(NULL, E_WARNING, "readlink failed to read the symbolic link (%s), error %d)", link, GetLastError());
RETURN_FALSE; RETURN_FALSE;
} }

View file

@ -1559,7 +1559,7 @@ PHP_FUNCTION(stream_resolve_include_path)
Z_PARAM_PATH(filename, filename_len) Z_PARAM_PATH(filename, filename_len)
ZEND_PARSE_PARAMETERS_END(); ZEND_PARSE_PARAMETERS_END();
resolved_path = zend_resolve_path(filename, (int)filename_len); resolved_path = zend_resolve_path(filename, filename_len);
if (resolved_path) { if (resolved_path) {
RETURN_STR(resolved_path); RETURN_STR(resolved_path);

View file

@ -137,18 +137,18 @@ static char * php_zip_make_relative_path(char *path, size_t path_len) /* {{{ */
# define CWD_STATE_FREE(s) efree(s) # define CWD_STATE_FREE(s) efree(s)
/* {{{ php_zip_extract_file */ /* {{{ php_zip_extract_file */
static int php_zip_extract_file(struct zip * za, char *dest, char *file, int file_len) static int php_zip_extract_file(struct zip * za, char *dest, char *file, size_t file_len)
{ {
php_stream_statbuf ssb; php_stream_statbuf ssb;
struct zip_file *zf; struct zip_file *zf;
struct zip_stat sb; struct zip_stat sb;
char b[8192]; char b[8192];
int n, len, ret; int n, ret;
php_stream *stream; php_stream *stream;
char *fullpath; char *fullpath;
char *file_dirname_fullpath; char *file_dirname_fullpath;
char file_dirname[MAXPATHLEN]; char file_dirname[MAXPATHLEN];
size_t dir_len; size_t dir_len, len;
int is_dir_only = 0; int is_dir_only = 0;
char *path_cleaned; char *path_cleaned;
size_t path_cleaned_len; size_t path_cleaned_len;
@ -181,7 +181,7 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int fil
memcpy(file_dirname, path_cleaned, path_cleaned_len); memcpy(file_dirname, path_cleaned, path_cleaned_len);
dir_len = php_dirname(file_dirname, path_cleaned_len); dir_len = php_dirname(file_dirname, path_cleaned_len);
if (dir_len <= 0 || (dir_len == 1 && file_dirname[0] == '.')) { if (!dir_len || (dir_len == 1 && file_dirname[0] == '.')) {
len = spprintf(&file_dirname_fullpath, 0, "%s", dest); len = spprintf(&file_dirname_fullpath, 0, "%s", dest);
} else { } else {
len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file_dirname); len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file_dirname);

View file

@ -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) { while (VCWD_REALPATH(path_tmp, resolved_name) == NULL) {
#if defined(PHP_WIN32) || defined(HAVE_SYMLINK) #if defined(PHP_WIN32) || defined(HAVE_SYMLINK)
if (nesting_level == 0) { if (nesting_level == 0) {
int ret; ssize_t ret;
char buf[MAXPATHLEN]; char buf[MAXPATHLEN];
ret = php_sys_readlink(path_tmp, buf, MAXPATHLEN - 1); ret = php_sys_readlink(path_tmp, buf, MAXPATHLEN - 1);
if (ret < 0) { if (ret == -1) {
/* not a broken symlink, move along.. */ /* not a broken symlink, move along.. */
} else { } else {
/* put the real path into the path buffer */ /* 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 *path_info;
char *filename = NULL; char *filename = NULL;
zend_string *resolved_path = NULL; zend_string *resolved_path = NULL;
int length; size_t length;
zend_bool orig_display_errors; zend_bool orig_display_errors;
path_info = SG(request_info).request_uri; 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); pwbuf = emalloc(pwbuflen);
#endif #endif
length = s - (path_info + 2); length = s - (path_info + 2);
if (length > (int)sizeof(user) - 1) { if (length > sizeof(user) - 1) {
length = sizeof(user) - 1; length = sizeof(user) - 1;
} }
memcpy(user, path_info + 2, length); memcpy(user, path_info + 2, length);
@ -402,9 +402,9 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle)
} }
} else } else
#endif #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)) { 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); filename = emalloc(length + path_len + 2);
memcpy(filename, PG(doc_root), length); memcpy(filename, PG(doc_root), length);
if (!IS_SLASH(filename[length - 1])) { /* length is never 0 */ 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) { if (filename) {
resolved_path = zend_resolve_path(filename, (int)strlen(filename)); resolved_path = zend_resolve_path(filename, strlen(filename));
} }
if (!resolved_path) { if (!resolved_path) {
@ -472,7 +472,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle)
/* {{{ php_resolve_path /* {{{ php_resolve_path
* Returns the realpath for given filename according to include 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 resolved_path[MAXPATHLEN];
char trypath[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); end = strchr(p, DEFAULT_DIR_SEPARATOR);
if (end) { 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; ptr = end + 1;
continue; continue;
} }
@ -543,7 +543,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, int filename_length,
} else { } else {
size_t len = strlen(ptr); 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; break;
} }
memcpy(trypath, ptr, len); 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 *pathbuf, *ptr, *end;
char trypath[MAXPATHLEN]; char trypath[MAXPATHLEN];
FILE *fp; FILE *fp;
int filename_length; size_t filename_length;
zend_string *exec_filename; zend_string *exec_filename;
if (opened_path) { if (opened_path) {
@ -635,7 +635,7 @@ PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const c
return NULL; return NULL;
} }
filename_length = (int)strlen(filename); filename_length = strlen(filename);
#ifndef PHP_WIN32 #ifndef PHP_WIN32
(void) filename_length; (void) filename_length;
#endif #endif
@ -761,14 +761,14 @@ PHPAPI char *expand_filepath_with_mode(const char *filepath, char *real_path, co
{ {
cwd_state new_state; cwd_state new_state;
char cwd[MAXPATHLEN]; char cwd[MAXPATHLEN];
int copy_len; size_t copy_len;
int path_len; size_t path_len;
if (!filepath[0]) { if (!filepath[0]) {
return NULL; return NULL;
} }
path_len = (int)strlen(filepath); path_len = strlen(filepath);
if (IS_ABSOLUTE_PATH(filepath, path_len)) { if (IS_ABSOLUTE_PATH(filepath, path_len)) {
cwd[0] = '\0'; 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 = 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)) { if (virtual_file_ex(&new_state, filepath, NULL, realpath_mode)) {
efree(new_state.cwd); efree(new_state.cwd);

View file

@ -39,7 +39,7 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path
PHPAPI int php_check_safe_mode_include_dir(const char *path); PHPAPI int php_check_safe_mode_include_dir(const char *path);
PHPAPI zend_string *php_resolve_path(const char *filename, int filename_len, const char *path); PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_len, const char *path);
PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const char *path, zend_string **opened_path); PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const char *path, zend_string **opened_path);

View file

@ -1427,7 +1427,7 @@ PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *h
} }
/* }}} */ /* }}} */
static zend_string *php_resolve_path_for_zend(const char *filename, int filename_len) /* {{{ */ static zend_string *php_resolve_path_for_zend(const char *filename, size_t filename_len) /* {{{ */
{ {
return php_resolve_path(filename, filename_len, PG(include_path)); return php_resolve_path(filename, filename_len, PG(include_path));
} }

View file

@ -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 = 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)) { if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)) {
efree(new_state.cwd); efree(new_state.cwd);
@ -216,7 +216,7 @@ PHPAPI const char* php_get_temporary_directory(void)
{ {
char *sys_temp_dir = PG(sys_temp_dir); char *sys_temp_dir = PG(sys_temp_dir);
if (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) { if (len >= 2 && sys_temp_dir[len - 1] == DEFAULT_SLASH) {
PG(php_sys_temp_dir) = estrndup(sys_temp_dir, len - 1); PG(php_sys_temp_dir) = estrndup(sys_temp_dir, len - 1);
return PG(php_sys_temp_dir); return PG(php_sys_temp_dir);
@ -237,7 +237,10 @@ PHPAPI const char* php_get_temporary_directory(void)
wchar_t sTemp[MAXPATHLEN]; wchar_t sTemp[MAXPATHLEN];
char *tmp; char *tmp;
size_t len = GetTempPathW(MAXPATHLEN, sTemp); 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))) { if (NULL == (tmp = php_win32_ioutil_conv_w_to_any(sTemp, len, &len))) {
return NULL; return NULL;
@ -253,7 +256,7 @@ PHPAPI const char* php_get_temporary_directory(void)
{ {
char* s = getenv("TMPDIR"); char* s = getenv("TMPDIR");
if (s && *s) { if (s && *s) {
int len = strlen(s); size_t len = strlen(s);
if (s[len - 1] == DEFAULT_SLASH) { if (s[len - 1] == DEFAULT_SLASH) {
PG(php_sys_temp_dir) = estrndup(s, len - 1); PG(php_sys_temp_dir) = estrndup(s, len - 1);

View file

@ -1996,7 +1996,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
} }
if (options & USE_PATH) { if (options & USE_PATH) {
resolved_path = zend_resolve_path(path, (int)strlen(path)); resolved_path = zend_resolve_path(path, strlen(path));
if (resolved_path) { if (resolved_path) {
path = ZSTR_VAL(resolved_path); path = ZSTR_VAL(resolved_path);
/* we've found this file, don't re-check include_path or run realpath */ /* we've found this file, don't re-check include_path or run realpath */