Change file permissions for directories and respect umask for written files. (#828)

Fixes #548
Fixes #819
This commit is contained in:
Simon Wisselink
2022-11-22 22:31:54 +01:00
committed by GitHub
parent 613c5d691c
commit 773b3b4b7c
2 changed files with 5 additions and 5 deletions
@@ -29,7 +29,6 @@ class Smarty_Internal_Runtime_WriteFile
{
$_error_reporting = error_reporting();
error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
$old_umask = umask(0);
$_dirpath = dirname($_filepath);
// if subdirs, create dir structure
if ($_dirpath !== '.') {
@@ -37,7 +36,7 @@ class Smarty_Internal_Runtime_WriteFile
// loop if concurrency problem occurs
// see https://bugs.php.net/bug.php?id=35326
while (!is_dir($_dirpath)) {
if (@mkdir($_dirpath, 0771, true)) {
if (@mkdir($_dirpath, 0777, true)) {
break;
}
clearstatcache();
@@ -85,8 +84,7 @@ class Smarty_Internal_Runtime_WriteFile
throw new SmartyException("unable to write file {$_filepath}");
}
// set file permissions
chmod($_filepath, 0644);
umask($old_umask);
@chmod($_filepath, 0666 & ~umask());
error_reporting($_error_reporting);
return true;
}