View Issue Details

IDProjectCategoryView StatusLast Update
0015357mantisbtbugtrackerpublic2014-09-23 18:05
ReporterAbsolutelyFreeWeb Assigned Todregad  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
PlatformwindowsOS2003 
Product Version1.2.8 
Target Version1.2.15Fixed in Version1.2.15 
Summary0015357: uninitialized library path
Description

in core.php the library path is given with:

define ( 'BASE_PATH' , realpath( dirname(FILE) ) );
$mantisLibrary = BASE_PATH . DIRECTORY_SEPARATOR . 'library';

However realpath may fail and return blank. Which results in that library path in the include path will not be valid and a number of required_once inclusions will fail.

please check if realpath is returning usable data before using it.

TagsNo tags attached.

Relationships

related to 0005137 closeddregad Problems wth dirname( FILE) instructions and symlinks 
related to 0015721 closedgrangeway Functionality to consider porting to master-2.0.x 

Activities

dregad

dregad

2013-01-10 11:15

developer   ~0034752

Considering that FILE will by definition contain an absolute path of the core.php file, I fail to see in which scenario realpath could possibly return NULL. Am I missing something ?

Do you have a real case where this actually happened to you ?

atrol

atrol

2013-01-10 13:14

developer   ~0034756

Might explain the behaviour
Note from http://de3.php.net/manual/en/function.realpath.php

The running script must have executable permissions on ALL DIRECTORIES IN THE HIERARCHY, otherwise realpath() will return FALSE.

AbsolutelyFreeWeb

AbsolutelyFreeWeb

2013-01-11 04:02

reporter   ~0034765

yes, on shared hosting on windows environment you may get that.

Here is a simple fix:

$thisfolder = realpath( dirname(FILE) );
if ($thisfolder == '') {$thisfolder = dirname(FILE);};
define ( 'BASE_PATH' , $thisfolder );

dregad

dregad

2013-01-11 07:16

developer   ~0034773

Last edited: 2013-01-11 07:17

OK I get it now.

That being said, your proposed fix is probably unnecessary... Since Mantis has a minimum req of 5.1, I believe we in fact do not even need to call realpath() at all as we'll always have an absolute path (based on PHP doc for magic constants[1]) :

FILE The full path and filename of the file. [...] Since PHP 4.0.2, FILE always contains an absolute path with symlinks resolved [..]

So I would propose the following code change.


-define ( 'BASE_PATH' , realpath( dirname(FILE) ) );
+define( 'BASE_PATH', dirname( FILE ) );

Thoughts ?

[1] http://php.net/manual/en/language.constants.predefined.php

dregad

dregad

2013-01-29 03:38

developer   ~0034944

@AbsolutelyFreeWeb can you please confirm if my earlier suggestion fixes your problem ?

AbsolutelyFreeWeb

AbsolutelyFreeWeb

2013-01-30 00:01

reporter   ~0034959

yes it should be fine. thank you

dregad

dregad

2013-01-30 04:08

developer   ~0034964

Fixed.

This issue does not need to be ported to 1.3 as the logic to include APIs is different and does not rely on realpath().

grangeway

grangeway

2013-04-05 17:56

reporter   ~0036102

Marking as 'acknowledged' not resolved/closed to track that change gets ported to master-2.0.x branch

Related Changesets

MantisBT: master-1.2.x 4ea08bf0

2013-01-30 04:05

dregad


Details Diff
Remove call to realpath() when setting BASE_PATH in core.php

Per PHP documentation [1], since version 4.0.2 __FILE__ always contains
an absolute path with symlinks resolved; considering that MantisBT's
minimum requirement is PHP 5.1 we therefore do not need to call
realpath().

This avoids problems with the function returning FALSE when the running
script does not have executable permissions on all directories in the
hierarchy, which can happen e.g. with shared hosting on Windows.

Fixes 0015357

[1] http://php.net/language.constants.predefined.php
Affected Issues
0015357
mod - core.php Diff File