Skip to content

Commit b5fd99b

Browse files
committed
Merge branch 'PHP-7.1'
* PHP-7.1: Fixed bug #74923 Crash when crawling through network share
2 parents b280ba8 + 5d15fdc commit b5fd99b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

win32/ioutil.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ typedef enum {
112112

113113
#define PHP_WIN32_IOUTIL_IS_LONG_PATHW(pathw, path_lenw) (path_lenw >= PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW \
114114
&& 0 == wcsncmp((pathw), PHP_WIN32_IOUTIL_LONG_PATH_PREFIXW, PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW))
115+
#define PHP_WIN32_IOUTIL_IS_UNC_PATHW(pathw, path_lenw) (path_lenw >= PHP_WIN32_IOUTIL_UNC_PATH_PREFIX_LENW \
116+
&& 0 == wcsncmp((pathw), PHP_WIN32_IOUTIL_UNC_PATH_PREFIXW, PHP_WIN32_IOUTIL_UNC_PATH_PREFIX_LENW))
117+
#define PHP_WIN32_IOUTIL_IS_JUNCTION_PATHW(pathw, path_lenw) (path_lenw >= PHP_WIN32_IOUTIL_JUNCTION_PREFIX_LENW \
118+
&& 0 == wcsncmp((pathw), PHP_WIN32_IOUTIL_JUNCTION_PREFIXW, PHP_WIN32_IOUTIL_JUNCTION_PREFIX_LENW))
115119
#define PHP_WIN32_IOUTIL_IS_ABSOLUTEW(pathw, path_lenw) (PHP_WIN32_IOUTIL_IS_LONG_PATHW(pathw, path_lenw) \
116120
|| path_lenw >= 3 && PHP_WIN32_IOUTIL_IS_LETTERW(pathw[0]) && L':' == pathw[1] && IS_SLASHW(pathw[2]))
117121
#define PHP_WIN32_IOUTIL_IS_UNC(pathw, path_lenw) (path_lenw >= 2 && PHP_WIN32_IOUTIL_IS_SLASHW(pathw[0]) && PHP_WIN32_IOUTIL_IS_SLASHW(pathw[1]) \
@@ -165,6 +169,8 @@ __forceinline static wchar_t *php_win32_ioutil_conv_any_to_w(const char* in, siz
165169

166170
/* Only prefix with long if it's needed. */
167171
if (mb_len > _MAX_PATH) {
172+
size_t new_mb_len;
173+
168174
ret = (wchar_t *) malloc((mb_len + PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW + 1) * sizeof(wchar_t));
169175
if (!ret) {
170176
free(mb);
@@ -176,9 +182,19 @@ __forceinline static wchar_t *php_win32_ioutil_conv_any_to_w(const char* in, siz
176182
Partial normalization could still do a better job further. And
177183
otherwise, the path might be unchanged which is ok if the path
178184
was valid long one. */
179-
(void)php_win32_ioutil_normalize_path_w(&mb, mb_len, &mb_len);
185+
(void)php_win32_ioutil_normalize_path_w(&mb, mb_len, &new_mb_len);
186+
187+
if (new_mb_len > mb_len) {
188+
wchar_t *tmp = (wchar_t *) realloc(ret, (new_mb_len + 1) * sizeof(wchar_t));
189+
if (!tmp) {
190+
free(ret);
191+
return NULL;
192+
}
193+
ret = tmp;
194+
mb_len = new_mb_len;
195+
}
180196

181-
if (PHP_WIN32_IOUTIL_IS_LONG_PATHW(mb, mb_len)) {
197+
if (PHP_WIN32_IOUTIL_IS_LONG_PATHW(mb, mb_len) || PHP_WIN32_IOUTIL_IS_JUNCTION_PATHW(mb, mb_len) || PHP_WIN32_IOUTIL_IS_UNC_PATHW(mb, mb_len)) {
182198
memmove(ret, mb, mb_len * sizeof(wchar_t));
183199
ret[mb_len] = L'\0';
184200
} else {

0 commit comments

Comments
 (0)