Harden issubdirectory()

realpath() may return false in case the directory does not exist since we can not be sure how different PHP versions may behave here we do an additional check whether realpath returned false
This commit is contained in:
Lukas Reschke 2014-05-11 15:49:19 +02:00 committed by Morris Jobke
parent 8c1eff8f52
commit 1e6b4576c2

View file

@ -716,9 +716,21 @@ class OC_Helper {
* @return bool
*/
public static function issubdirectory($sub, $parent) {
if (strpos(realpath($sub), realpath($parent)) === 0) {
$realpathSub = realpath($sub);
$realpathParent = realpath($parent);
// realpath() may return false in case the directory does not exist
// since we can not be sure how different PHP versions may behave here
// we do an additional check whether realpath returned false
if($realpathSub === false || $realpathParent === false) {
return false;
}
// Check whether $sub is a subdirectory of $parent
if (strpos($realpathSub, $realpathParent) === 0) {
return true;
}
return false;
}