Skip to content
Snippets Groups Projects
Commit 3c90625e authored by Robin Appelman's avatar Robin Appelman
Browse files

Files: also check if the source path is valid when doing a rename or copy operation

parent 2314067e
No related branches found
No related tags found
No related merge requests found
...@@ -245,13 +245,13 @@ class View { ...@@ -245,13 +245,13 @@ class View {
if (!is_null($mtime) and !is_numeric($mtime)) { if (!is_null($mtime) and !is_numeric($mtime)) {
$mtime = strtotime($mtime); $mtime = strtotime($mtime);
} }
$hooks = array('touch'); $hooks = array('touch');
if (!$this->file_exists($path)) { if (!$this->file_exists($path)) {
$hooks[] = 'write'; $hooks[] = 'write';
} }
return $this->basicOperation('touch', $path, $hooks, $mtime); return $this->basicOperation('touch', $path, $hooks, $mtime);
} }
...@@ -263,11 +263,12 @@ class View { ...@@ -263,11 +263,12 @@ class View {
if (is_resource($data)) { //not having to deal with streams in file_put_contents makes life easier if (is_resource($data)) { //not having to deal with streams in file_put_contents makes life easier
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
if (\OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) if (\OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data)
&& Filesystem::isValidPath($path)) { && Filesystem::isValidPath($path)
) {
$path = $this->getRelativePath($absolutePath); $path = $this->getRelativePath($absolutePath);
$exists = $this->file_exists($path); $exists = $this->file_exists($path);
$run = true; $run = true;
if ($this->fakeRoot == Filesystem::getRoot() && ! Cache\Scanner::isIgnoredFile($path) ) { if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isIgnoredFile($path)) {
if (!$exists) { if (!$exists) {
\OC_Hook::emit( \OC_Hook::emit(
Filesystem::CLASSNAME, Filesystem::CLASSNAME,
...@@ -295,7 +296,7 @@ class View { ...@@ -295,7 +296,7 @@ class View {
list ($count, $result) = \OC_Helper::streamCopy($data, $target); list ($count, $result) = \OC_Helper::streamCopy($data, $target);
fclose($target); fclose($target);
fclose($data); fclose($data);
if ($this->fakeRoot == Filesystem::getRoot() && ! Cache\Scanner::isIgnoredFile($path) ) { if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isIgnoredFile($path)) {
if (!$exists) { if (!$exists) {
\OC_Hook::emit( \OC_Hook::emit(
Filesystem::CLASSNAME, Filesystem::CLASSNAME,
...@@ -335,8 +336,11 @@ class View { ...@@ -335,8 +336,11 @@ class View {
$postFix2 = (substr($path2, -1, 1) === '/') ? '/' : ''; $postFix2 = (substr($path2, -1, 1) === '/') ? '/' : '';
$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1)); $absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2)); $absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
if (\OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2) if (
and Filesystem::isValidPath($path2)) { \OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2)
and Filesystem::isValidPath($path2)
and Filesystem::isValidPath($path1)
) {
$path1 = $this->getRelativePath($absolutePath1); $path1 = $this->getRelativePath($absolutePath1);
$path2 = $this->getRelativePath($absolutePath2); $path2 = $this->getRelativePath($absolutePath2);
...@@ -396,7 +400,11 @@ class View { ...@@ -396,7 +400,11 @@ class View {
$postFix2 = (substr($path2, -1, 1) === '/') ? '/' : ''; $postFix2 = (substr($path2, -1, 1) === '/') ? '/' : '';
$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1)); $absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2)); $absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
if (\OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and Filesystem::isValidPath($path2)) { if (
\OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2)
and Filesystem::isValidPath($path2)
and Filesystem::isValidPath($path1)
) {
$path1 = $this->getRelativePath($absolutePath1); $path1 = $this->getRelativePath($absolutePath1);
$path2 = $this->getRelativePath($absolutePath2); $path2 = $this->getRelativePath($absolutePath2);
...@@ -627,7 +635,7 @@ class View { ...@@ -627,7 +635,7 @@ class View {
private function runHooks($hooks, $path, $post = false) { private function runHooks($hooks, $path, $post = false) {
$prefix = ($post) ? 'post_' : ''; $prefix = ($post) ? 'post_' : '';
$run = true; $run = true;
if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot() && ! Cache\Scanner::isIgnoredFile($path) ) { if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isIgnoredFile($path)) {
foreach ($hooks as $hook) { foreach ($hooks as $hook) {
if ($hook != 'read') { if ($hook != 'read') {
\OC_Hook::emit( \OC_Hook::emit(
...@@ -931,11 +939,11 @@ class View { ...@@ -931,11 +939,11 @@ class View {
} }
/** /**
* Get the owner for a file or folder * Get the owner for a file or folder
* *
* @param string $path * @param string $path
* @return string * @return string
*/ */
public function getOwner($path) { public function getOwner($path) {
return $this->basicOperation('getOwner', $path); return $this->basicOperation('getOwner', $path);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment