Skip to content

Commit

Permalink
Handle basedir restrictions in php8
Browse files Browse the repository at this point in the history
Signed by Shawn Bulen, [email protected]
  • Loading branch information
sbulen committed May 3, 2023
1 parent a738fe5 commit 075b0fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Sources/Packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -2304,6 +2304,10 @@ function fetchPerms__recursive($path, &$data, $level)
$dh = opendir($path);
while ($entry = readdir($dh))
{
// Bypass directory abbreviations altogether...
if ($entry == '.' || $entry == '..')
continue;

// Some kind of file?
if (is_file($path . '/' . $entry))
{
Expand All @@ -2315,7 +2319,7 @@ function fetchPerms__recursive($path, &$data, $level)
$foundData['files'][$entry] = true;
}
// It's a directory - we're interested one way or another, probably...
elseif ($entry != '.' && $entry != '..')
else
{
// Going further?
if ((!empty($data['type']) && $data['type'] == 'dir_recursive') || (isset($data['contents'][$entry]) && (!empty($data['contents'][$entry]['list_contents']) || (!empty($data['contents'][$entry]['type']) && $data['contents'][$entry]['type'] == 'dir_recursive'))))
Expand Down
12 changes: 9 additions & 3 deletions Sources/Subs-Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,11 @@ function read_tgz_data($data, $destination, $single_file = false, $overwrite = f
$current['data'] = substr($data, ++$offset << 9, $current['size']);
$offset += $size;

// If hunting for a file in subdirectories, pass to subsequent write test...
if ($single_file && $destination !== null && (substr($destination, 0, 2) == '*/'))
$write_this = true;
// Not a directory and doesn't exist already...
if (substr($current['filename'], -1, 1) != '/' && $destination !== null && !file_exists($destination . '/' . $current['filename']))
elseif (substr($current['filename'], -1, 1) != '/' && $destination !== null && !file_exists($destination . '/' . $current['filename']))
$write_this = true;
// File exists... check if it is newer.
elseif (substr($current['filename'], -1, 1) != '/')
Expand Down Expand Up @@ -230,7 +233,7 @@ function read_tgz_data($data, $destination, $single_file = false, $overwrite = f
function read_zip_data($data, $destination, $single_file = false, $overwrite = false, $files_to_extract = null)
{
umask(0);
if ($destination !== null && !file_exists($destination) && !$single_file)
if ($destination !== null && (substr($destination, 0, 2) != '*/') && !file_exists($destination) && !$single_file)
mktree($destination, 0777);

// Search for the end of directory signature 0x06054b50.
Expand Down Expand Up @@ -291,8 +294,11 @@ function read_zip_data($data, $destination, $single_file = false, $overwrite = f
$write_this = false;
if ($destination !== null)
{
// If hunting for a file in subdirectories, pass to subsequent write test...
if ($single_file && $destination !== null && (substr($destination, 0, 2) == '*/'))
$write_this = true;
// If this is a file, and it doesn't exist.... happy days!
if ($is_file)
elseif ($is_file)
$write_this = !file_exists($destination . '/' . $file_info['filename']) || $overwrite;
// This is a directory, so we're gonna want to create it. (probably...)
elseif (!$single_file)
Expand Down

0 comments on commit 075b0fd

Please sign in to comment.