@@ -458,12 +458,22 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle)
458
458
}
459
459
/* }}} */
460
460
461
+ static zend_string * tsrm_realpath_str (const char * path ) {
462
+ char * realpath = tsrm_realpath (path , NULL );
463
+ if (!realpath ) {
464
+ return NULL ;
465
+ }
466
+ zend_string * realpath_str = zend_string_init (realpath , strlen (realpath ), 0 );
467
+ efree (realpath );
468
+ return realpath_str ;
469
+ }
470
+
461
471
/* {{{ php_resolve_path
462
472
* Returns the realpath for given filename according to include path
463
473
*/
464
474
PHPAPI zend_string * php_resolve_path (const char * filename , size_t filename_length , const char * path )
465
475
{
466
- char resolved_path [ MAXPATHLEN ] ;
476
+ zend_string * resolved_path ;
467
477
char trypath [MAXPATHLEN ];
468
478
const char * ptr , * end , * p ;
469
479
const char * actual_path ;
@@ -479,8 +489,8 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
479
489
if ((* p == ':' ) && (p - filename > 1 ) && (p [1 ] == '/' ) && (p [2 ] == '/' )) {
480
490
wrapper = php_stream_locate_url_wrapper (filename , & actual_path , STREAM_OPEN_FOR_INCLUDE );
481
491
if (wrapper == & php_plain_files_wrapper ) {
482
- if (tsrm_realpath ( actual_path , resolved_path )) {
483
- return zend_string_init ( resolved_path , strlen ( resolved_path ), 0 ) ;
492
+ if (( resolved_path = tsrm_realpath_str ( actual_path ) )) {
493
+ return resolved_path ;
484
494
}
485
495
}
486
496
return NULL ;
@@ -499,11 +509,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
499
509
#endif
500
510
!path ||
501
511
!* path ) {
502
- if (tsrm_realpath (filename , resolved_path )) {
503
- return zend_string_init (resolved_path , strlen (resolved_path ), 0 );
504
- } else {
505
- return NULL ;
506
- }
512
+ return tsrm_realpath_str (filename );
507
513
}
508
514
509
515
ptr = path ;
@@ -559,8 +565,8 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
559
565
continue ;
560
566
}
561
567
}
562
- if (tsrm_realpath ( actual_path , resolved_path )) {
563
- return zend_string_init ( resolved_path , strlen ( resolved_path ), 0 ) ;
568
+ if (( resolved_path = tsrm_realpath_str ( actual_path ) )) {
569
+ return resolved_path ;
564
570
}
565
571
} /* end provided path */
566
572
@@ -600,9 +606,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
600
606
}
601
607
}
602
608
603
- if (tsrm_realpath (actual_path , resolved_path )) {
604
- return zend_string_init (resolved_path , strlen (resolved_path ), 0 );
605
- }
609
+ return tsrm_realpath_str (actual_path );
606
610
}
607
611
}
608
612
0 commit comments