From 0166c3728b30446f2ed63204f2e4278275c9ecff Mon Sep 17 00:00:00 2001
From: "Edward Z. Yang"
Date: Fri, 1 Jul 2016 16:04:11 -0400
Subject: [PATCH] Stop trying to chmod if SerializerPermissions is null, fixes
#71
Signed-off-by: Edward Z. Yang
---
configdoc/usage.xml | 2 +-
library/HTMLPurifier/ConfigSchema/schema.ser | Bin 15525 -> 15526 bytes
.../schema/Cache.SerializerPermissions.txt | 7 ++++-
.../DefinitionCache/Serializer.php | 28 ++++++++++++------
4 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/configdoc/usage.xml b/configdoc/usage.xml
index b4d0d863..d59b6b1c 100644
--- a/configdoc/usage.xml
+++ b/configdoc/usage.xml
@@ -424,7 +424,7 @@
200
- 218
+ 219
+
+ In HTML Purifier 4.8.0, this also supports NULL
,
+ which means that no chmod'ing or directory creation shall
+ occur.
+
--# vim: et sw=4 sts=4
diff --git a/library/HTMLPurifier/DefinitionCache/Serializer.php b/library/HTMLPurifier/DefinitionCache/Serializer.php
index 4686fcff..f930c6b9 100644
--- a/library/HTMLPurifier/DefinitionCache/Serializer.php
+++ b/library/HTMLPurifier/DefinitionCache/Serializer.php
@@ -198,11 +198,12 @@ class HTMLPurifier_DefinitionCache_Serializer extends HTMLPurifier_DefinitionCac
if ($result !== false) {
// set permissions of the new file (no execute)
$chmod = $config->get('Cache.SerializerPermissions');
- if (!$chmod) {
- $chmod = 0644; // invalid config or simpletest
+ if ($chmod === null) {
+ // don't do anything
+ } else {
+ $chmod = $chmod & 0666;
+ chmod($file, $chmod);
}
- $chmod = $chmod & 0666;
- chmod($file, $chmod);
}
return $result;
}
@@ -216,9 +217,6 @@ class HTMLPurifier_DefinitionCache_Serializer extends HTMLPurifier_DefinitionCac
{
$directory = $this->generateDirectoryPath($config);
$chmod = $config->get('Cache.SerializerPermissions');
- if (!$chmod) {
- $chmod = 0755; // invalid config or simpletest
- }
if (!is_dir($directory)) {
$base = $this->generateBaseDirectoryPath($config);
if (!is_dir($base)) {
@@ -231,7 +229,19 @@ class HTMLPurifier_DefinitionCache_Serializer extends HTMLPurifier_DefinitionCac
} elseif (!$this->_testPermissions($base, $chmod)) {
return false;
}
- mkdir($directory, $chmod);
+ if ($chmod === null) {
+ trigger_error(
+ 'Base directory ' . $base . ' does not exist,
+ please create or change using %Cache.SerializerPath',
+ E_USER_WARNING
+ );
+ return false;
+ }
+ if ($chmod !== null) {
+ mkdir($directory, $chmod);
+ } else {
+ mkdir($directory);
+ }
if (!$this->_testPermissions($directory, $chmod)) {
trigger_error(
'Base directory ' . $base . ' does not exist,
@@ -268,7 +278,7 @@ class HTMLPurifier_DefinitionCache_Serializer extends HTMLPurifier_DefinitionCac
);
return false;
}
- if (function_exists('posix_getuid')) {
+ if (function_exists('posix_getuid') && $chmod !== null) {
// POSIX system, we can give more specific advice
if (fileowner($dir) === posix_getuid()) {
// we can chmod it ourselves