@@ -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
#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
165
169
166
170
/* Only prefix with long if it's needed. */
167
171
if (mb_len > _MAX_PATH ) {
172
+ size_t new_mb_len ;
173
+
168
174
ret = (wchar_t * ) malloc ((mb_len + PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW + 1 ) * sizeof (wchar_t ));
169
175
if (!ret ) {
170
176
free (mb );
@@ -176,9 +182,19 @@ __forceinline static wchar_t *php_win32_ioutil_conv_any_to_w(const char* in, siz
176
182
Partial normalization could still do a better job further. And
177
183
otherwise, the path might be unchanged which is ok if the path
178
184
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
+ }
180
196
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 ) ) {
182
198
memmove (ret , mb , mb_len * sizeof (wchar_t ));
183
199
ret [mb_len ] = L'\0' ;
184
200
} else {
0 commit comments