summaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Storage/Common.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-11-09 10:58:11 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2016-11-21 09:23:37 +0100
commit558f169671208fb349bb40de7b6e0abb02097832 (patch)
tree716c3e8e0ea965c4a592cfe60618019d7554a57f /lib/private/Files/Storage/Common.php
parent4652d203e37d06b427872888ccb17227c1e0818b (diff)
downloadnextcloud-server-558f169671208fb349bb40de7b6e0abb02097832.tar.gz
nextcloud-server-558f169671208fb349bb40de7b6e0abb02097832.zip
Move the validation into one place only
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Files/Storage/Common.php')
-rw-r--r--lib/private/Files/Storage/Common.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php
index c975791295d..5561f6a889b 100644
--- a/lib/private/Files/Storage/Common.php
+++ b/lib/private/Files/Storage/Common.php
@@ -45,8 +45,10 @@ use OC\Files\Cache\Scanner;
use OC\Files\Cache\Updater;
use OC\Files\Filesystem;
use OC\Files\Cache\Watcher;
+use OCP\Files\EmptyFileNameException;
use OCP\Files\FileNameTooLongException;
use OCP\Files\InvalidCharacterInPathException;
+use OCP\Files\InvalidDirectoryException;
use OCP\Files\InvalidPathException;
use OCP\Files\ReservedWordException;
use OCP\Files\Storage\ILockingStorage;
@@ -487,8 +489,31 @@ abstract class Common implements Storage, ILockingStorage {
/**
* @inheritdoc
+ * @throws InvalidPathException
*/
public function verifyPath($path, $fileName) {
+
+ // verify empty and dot files
+ $trimmed = trim($fileName);
+ if ($trimmed === '') {
+ throw new EmptyFileNameException();
+ }
+
+ if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) {
+ throw new InvalidDirectoryException();
+ }
+
+ if (!\OC::$server->getDatabaseConnection()->supports4ByteText()) {
+ // verify database - e.g. mysql only 3-byte chars
+ if (preg_match('%(?:
+ \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
+ | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
+ | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
+)%xs', $fileName)) {
+ throw new InvalidCharacterInPathException();
+ }
+ }
+
if (isset($fileName[255])) {
throw new FileNameTooLongException();
}