Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change file permissions for directories and respect umask for files #828

Merged
merged 1 commit into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Include docs and demo in the releases [#799](https://github.com/smarty-php/smarty/issues/799)
- Using PHP functions as modifiers now triggers a deprecation notice because we will drop support for this in the next major release [#813](https://github.com/smarty-php/smarty/issues/813)
- Dropped remaining references to removed PHP-support in Smarty 4 from docs, lexer and security class. [#816](https://github.com/smarty-php/smarty/issues/816)

- Support umask when writing (template) files and set dir permissions to 777 [#548](https://github.com/smarty-php/smarty/issues/548) [#819](https://github.com/smarty-php/smarty/issues/819)

### Fixed
- Output buffer is now cleaned for internal PHP errors as well, not just for Exceptions [#514](https://github.com/smarty-php/smarty/issues/514)
- Fixed recursion and out of memory errors when caching in complicated template set-ups using inheritance and includes [#801](https://github.com/smarty-php/smarty/pull/801)
Expand All @@ -24,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Adapt Smarty upper/lower functions to be codesafe (e.g. for Turkish locale) [#586](https://github.com/smarty-php/smarty/pull/586)
- Bug fix for underscore and limited length in template name in custom resources [#581](https://github.com/smarty-php/smarty/pull/581)


## [4.2.1] - 2022-09-14

### Security
Expand Down
6 changes: 2 additions & 4 deletions libs/sysplugins/smarty_internal_runtime_writefile.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ public function writeFile($_filepath, $_contents, Smarty $smarty)
{
$_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 !== '.') {
$i = 0;
// 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();
Expand Down Expand Up @@ -85,8 +84,7 @@ public function writeFile($_filepath, $_contents, Smarty $smarty)
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;
}
Expand Down