@@ -225,10 +225,32 @@ static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, const cha
225
225
* opened_path = zend_string_init (path , strlen (path ), 0 );
226
226
}
227
227
}
228
+ const char * pattern = path ;
229
+ #ifdef ZTS
230
+ char cwd [MAXPATHLEN ];
231
+ char work_pattern [MAXPATHLEN ];
232
+ char * result ;
233
+ size_t cwd_skip = 0 ;
234
+ if (!IS_ABSOLUTE_PATH (path , strlen (path ))) {
235
+ result = VCWD_GETCWD (cwd , MAXPATHLEN );
236
+ if (!result ) {
237
+ cwd [0 ] = '\0' ;
238
+ }
239
+ # ifdef PHP_WIN32
240
+ if (IS_SLASH (* path )) {
241
+ cwd [2 ] = '\0' ;
242
+ }
243
+ # endif
244
+ cwd_skip = strlen (cwd )+ 1 ;
245
+
246
+ snprintf (work_pattern , MAXPATHLEN , "%s%c%s" , cwd , DEFAULT_SLASH , path );
247
+ pattern = work_pattern ;
248
+ }
249
+ #endif
228
250
229
251
pglob = ecalloc (1 , sizeof (* pglob ));
230
252
231
- if (0 != (ret = glob (path , pglob -> flags & GLOB_FLAGMASK , NULL , & pglob -> glob ))) {
253
+ if (0 != (ret = glob (pattern , pglob -> flags & GLOB_FLAGMASK , NULL , & pglob -> glob ))) {
232
254
#ifdef GLOB_NOMATCH
233
255
if (GLOB_NOMATCH != ret )
234
256
#endif
@@ -238,6 +260,21 @@ static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, const cha
238
260
}
239
261
}
240
262
263
+ #ifdef ZTS
264
+ if (cwd_skip > 0 ) {
265
+ /* strip prepended CWD */
266
+ for (i = 0 ; i < pglob -> glob .gl_pathc ; i ++ ) {
267
+ char * p = pglob -> glob .gl_pathv [i ];
268
+ char * q = p + cwd_skip ;
269
+ char * e = p + strlen (pglob -> glob .gl_pathv [i ]) - 1 ;
270
+ while (q <= e ) {
271
+ * p ++ = * q ++ ;
272
+ }
273
+ * p = '\0' ;
274
+ }
275
+ }
276
+ #endif
277
+
241
278
/* if open_basedir in use, check and filter restricted paths */
242
279
if ((options & STREAM_DISABLE_OPEN_BASEDIR ) == 0 ) {
243
280
pglob -> open_basedir_used = true;
0 commit comments