Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- Test rmdir() function : variation: various valid and invalid paths --CREDITS-- Da..

Decoded Output download

--TEST--
Test rmdir() function : variation: various valid and invalid paths
--CREDITS--
Dave Kelsey <[email protected]>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) != "WIN")
  die("skip Only valid for Windows");
?>
--FILE--
<?php
echo "*** Testing rmdir() : variation ***
";

$workDir = "rmdirVar3.tmp";
$subDir = "aSubDir";
mkdir($workDir);
$cwd = getcwd();

$unixifiedDir = '/'.substr(str_replace('\','/',$cwd).'/'.$workDir.'/'.$subDir, 3);

$dirs = array(
             // relative
             $workDir.'\'.$subDir,
             '.\'.$workDir.'\'.$subDir,
             $workDir.'\..\'.$workDir.'\'.$subDir,

             // relative bad path
             $workDir.'\..\BADDIR\'.$subDir,
             'BADDIR\'.$subDir,

             //absolute
             $cwd.'\'.$workDir.'\'.$subDir,
             $cwd.'\.\'.$workDir.'\'.$subDir,
             $cwd.'\'.$workDir.'\..\'.$workDir.'\'.$subDir,

             //absolute bad path
             $cwd.'\BADDIR\'.$subDir,

             //trailing separators
             $workDir.'\'.$subDir.'\',
             $cwd.'\'.$workDir.'\'.$subDir.'\',

             // multiple separators
             $workDir.'\\'.$subDir,
             $cwd.'\\'.$workDir.'\\'.$subDir,

             // Unixified Dir
             $unixifiedDir,

             );


foreach($dirs as $dir) {
   mkdir($workDir.'/'.$subDir);
   echo "-- removing $dir --
";
   $res = rmdir($dir);
   if ($res === true) {
      echo "Directory removed
";
   }
   else {
      rmdir($workDir.'/'.$subDir);
   }
}

rmdir($workDir);

?>
--EXPECTF--
*** Testing rmdir() : variation ***
-- removing rmdirVar3.tmpSubDir --
Directory removed
-- removing .
mdirVar3.tmpSubDir --
Directory removed
-- removing rmdirVar3.tmp\..
mdirVar3.tmpSubDir --
Directory removed
-- removing rmdirVar3.tmp\..\BADDIRSubDir --

Warning: rmdir(rmdirVar3.tmp\..\BADDIRSubDir): No such file or directory in %s on line %d
-- removing BADDIRSubDir --

Warning: rmdir(BADDIRSubDir): No such file or directory in %s on line %d
-- removing %s
mdirVar3.tmpSubDir --
Directory removed
-- removing %s\.
mdirVar3.tmpSubDir --
Directory removed
-- removing %s
mdirVar3.tmp\..
mdirVar3.tmpSubDir --
Directory removed
-- removing %s\BADDIRSubDir --

Warning: rmdir(%s\BADDIRSubDir): No such file or directory in %s on line %d
-- removing rmdirVar3.tmpSubDir\ --
Directory removed
-- removing %s
mdirVar3.tmpSubDir\ --
Directory removed
-- removing rmdirVar3.tmp\aSubDir --
Directory removed
-- removing %s\rmdirVar3.tmp\aSubDir --
Directory removed
-- removing /%s/rmdirVar3.tmp/aSubDir --
Directory removed

Did this file decode correctly?

Original Code

--TEST--
Test rmdir() function : variation: various valid and invalid paths
--CREDITS--
Dave Kelsey <[email protected]>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) != "WIN")
  die("skip Only valid for Windows");
?>
--FILE--
<?php
echo "*** Testing rmdir() : variation ***\n";

$workDir = "rmdirVar3.tmp";
$subDir = "aSubDir";
mkdir($workDir);
$cwd = getcwd();

$unixifiedDir = '/'.substr(str_replace('\\','/',$cwd).'/'.$workDir.'/'.$subDir, 3);

$dirs = array(
             // relative
             $workDir.'\\'.$subDir,
             '.\\'.$workDir.'\\'.$subDir,
             $workDir.'\\..\\'.$workDir.'\\'.$subDir,

             // relative bad path
             $workDir.'\\..\\BADDIR\\'.$subDir,
             'BADDIR\\'.$subDir,

             //absolute
             $cwd.'\\'.$workDir.'\\'.$subDir,
             $cwd.'\\.\\'.$workDir.'\\'.$subDir,
             $cwd.'\\'.$workDir.'\\..\\'.$workDir.'\\'.$subDir,

             //absolute bad path
             $cwd.'\\BADDIR\\'.$subDir,

             //trailing separators
             $workDir.'\\'.$subDir.'\\',
             $cwd.'\\'.$workDir.'\\'.$subDir.'\\',

             // multiple separators
             $workDir.'\\\\'.$subDir,
             $cwd.'\\\\'.$workDir.'\\\\'.$subDir,

             // Unixified Dir
             $unixifiedDir,

             );


foreach($dirs as $dir) {
   mkdir($workDir.'/'.$subDir);
   echo "-- removing $dir --\n";
   $res = rmdir($dir);
   if ($res === true) {
      echo "Directory removed\n";
   }
   else {
      rmdir($workDir.'/'.$subDir);
   }
}

rmdir($workDir);

?>
--EXPECTF--
*** Testing rmdir() : variation ***
-- removing rmdirVar3.tmp\aSubDir --
Directory removed
-- removing .\rmdirVar3.tmp\aSubDir --
Directory removed
-- removing rmdirVar3.tmp\..\rmdirVar3.tmp\aSubDir --
Directory removed
-- removing rmdirVar3.tmp\..\BADDIR\aSubDir --

Warning: rmdir(rmdirVar3.tmp\..\BADDIR\aSubDir): No such file or directory in %s on line %d
-- removing BADDIR\aSubDir --

Warning: rmdir(BADDIR\aSubDir): No such file or directory in %s on line %d
-- removing %s\rmdirVar3.tmp\aSubDir --
Directory removed
-- removing %s\.\rmdirVar3.tmp\aSubDir --
Directory removed
-- removing %s\rmdirVar3.tmp\..\rmdirVar3.tmp\aSubDir --
Directory removed
-- removing %s\BADDIR\aSubDir --

Warning: rmdir(%s\BADDIR\aSubDir): No such file or directory in %s on line %d
-- removing rmdirVar3.tmp\aSubDir\ --
Directory removed
-- removing %s\rmdirVar3.tmp\aSubDir\ --
Directory removed
-- removing rmdirVar3.tmp\\aSubDir --
Directory removed
-- removing %s\\rmdirVar3.tmp\\aSubDir --
Directory removed
-- removing /%s/rmdirVar3.tmp/aSubDir --
Directory removed

Function Calls

None

Variables

None

Stats

MD5 9f9a72160f2cec887a2f489a521375d8
Eval Count 0
Decode Time 87 ms