@@ -112,6 +112,10 @@ typedef enum {
112
112
113
113
#define PHP_WIN32_IOUTIL_IS_LONG_PATHW (pathw , path_lenw ) (path_lenw >= PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW \
114
114
&& 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))
115
119
#define PHP_WIN32_IOUTIL_IS_ABSOLUTEW (pathw , path_lenw ) (PHP_WIN32_IOUTIL_IS_LONG_PATHW(pathw, path_lenw) \
116
120
|| path_lenw >= 3 && PHP_WIN32_IOUTIL_IS_LETTERW(pathw[0]) && L':' == pathw[1] && IS_SLASHW(pathw[2]))
117
121
@@ -163,6 +167,8 @@ __forceinline static wchar_t *php_win32_ioutil_conv_any_to_w(const char* in, siz
163
167
164
168
/* Only prefix with long if it's needed. */
165
169
if (mb_len > _MAX_PATH ) {
170
+ size_t new_mb_len ;
171
+
166
172
ret = (wchar_t * ) malloc ((mb_len + PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW + 1 ) * sizeof (wchar_t ));
167
173
if (!ret ) {
168
174
free (mb );
@@ -174,9 +180,19 @@ __forceinline static wchar_t *php_win32_ioutil_conv_any_to_w(const char* in, siz
174
180
Partial normalization could still do a better job further. And
175
181
otherwise, the path might be unchanged which is ok if the path
176
182
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
+ }
178
194
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 ) ) {
180
196
memmove (ret , mb , mb_len * sizeof (wchar_t ));
181
197
ret [mb_len ] = L'\0' ;
182
198
} else {
0 commit comments