Skip to content

Commit 5d15fdc

Browse files
committed
Fixed bug #74923 Crash when crawling through network share
1 parent 3b60af9 commit 5d15fdc

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

@@ -163,6 +167,8 @@ __forceinline static wchar_t *php_win32_ioutil_conv_any_to_w(const char* in, siz
163167

164168
/* Only prefix with long if it's needed. */
165169
if (mb_len > _MAX_PATH) {
170+
size_t new_mb_len;
171+
166172
ret = (wchar_t *) malloc((mb_len + PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW + 1) * sizeof(wchar_t));
167173
if (!ret) {
168174
free(mb);
@@ -174,9 +180,19 @@ __forceinline static wchar_t *php_win32_ioutil_conv_any_to_w(const char* in, siz
174180
Partial normalization could still do a better job further. And
175181
otherwise, the path might be unchanged which is ok if the path
176182
was valid long one. */
177-
(void)php_win32_ioutil_normalize_path_w(&mb, mb_len, &mb_len);
183+
(void)php_win32_ioutil_normalize_path_w(&mb, mb_len, &new_mb_len);
184+
185+
if (new_mb_len > mb_len) {
186+
wchar_t *tmp = (wchar_t *) realloc(ret, (new_mb_len + 1) * sizeof(wchar_t));
187+
if (!tmp) {
188+
free(ret);
189+
return NULL;
190+
}
191+
ret = tmp;
192+
mb_len = new_mb_len;
193+
}
178194

179-
if (PHP_WIN32_IOUTIL_IS_LONG_PATHW(mb, mb_len)) {
195+
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)) {
180196
memmove(ret, mb, mb_len * sizeof(wchar_t));
181197
ret[mb_len] = L'\0';
182198
} else {

0 commit comments

Comments
 (0)