Skip to content

Commit a7f1269

Browse files
committed
Files: also check if the source path is valid when doing a rename or copy operation
1 parent 7ae0e38 commit a7f1269

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

lib/files/view.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,13 @@ public function touch($path, $mtime = null) {
245245
if (!is_null($mtime) and !is_numeric($mtime)) {
246246
$mtime = strtotime($mtime);
247247
}
248-
248+
249249
$hooks = array('touch');
250-
250+
251251
if (!$this->file_exists($path)) {
252252
$hooks[] = 'write';
253253
}
254-
254+
255255
return $this->basicOperation('touch', $path, $hooks, $mtime);
256256
}
257257

@@ -263,11 +263,12 @@ public function file_put_contents($path, $data) {
263263
if (is_resource($data)) { //not having to deal with streams in file_put_contents makes life easier
264264
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
265265
if (\OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data)
266-
&& Filesystem::isValidPath($path)) {
266+
&& Filesystem::isValidPath($path)
267+
) {
267268
$path = $this->getRelativePath($absolutePath);
268269
$exists = $this->file_exists($path);
269270
$run = true;
270-
if ($this->fakeRoot == Filesystem::getRoot() && ! Cache\Scanner::isIgnoredFile($path) ) {
271+
if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isIgnoredFile($path)) {
271272
if (!$exists) {
272273
\OC_Hook::emit(
273274
Filesystem::CLASSNAME,
@@ -295,7 +296,7 @@ public function file_put_contents($path, $data) {
295296
list ($count, $result) = \OC_Helper::streamCopy($data, $target);
296297
fclose($target);
297298
fclose($data);
298-
if ($this->fakeRoot == Filesystem::getRoot() && ! Cache\Scanner::isIgnoredFile($path) ) {
299+
if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isIgnoredFile($path)) {
299300
if (!$exists) {
300301
\OC_Hook::emit(
301302
Filesystem::CLASSNAME,
@@ -335,8 +336,11 @@ public function rename($path1, $path2) {
335336
$postFix2 = (substr($path2, -1, 1) === '/') ? '/' : '';
336337
$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
337338
$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
338-
if (\OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2)
339-
and Filesystem::isValidPath($path2)) {
339+
if (
340+
\OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2)
341+
and Filesystem::isValidPath($path2)
342+
and Filesystem::isValidPath($path1)
343+
) {
340344
$path1 = $this->getRelativePath($absolutePath1);
341345
$path2 = $this->getRelativePath($absolutePath2);
342346

@@ -396,7 +400,11 @@ public function copy($path1, $path2) {
396400
$postFix2 = (substr($path2, -1, 1) === '/') ? '/' : '';
397401
$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
398402
$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
399-
if (\OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and Filesystem::isValidPath($path2)) {
403+
if (
404+
\OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2)
405+
and Filesystem::isValidPath($path2)
406+
and Filesystem::isValidPath($path1)
407+
) {
400408
$path1 = $this->getRelativePath($absolutePath1);
401409
$path2 = $this->getRelativePath($absolutePath2);
402410

@@ -627,7 +635,7 @@ private function basicOperation($operation, $path, $hooks = array(), $extraParam
627635
private function runHooks($hooks, $path, $post = false) {
628636
$prefix = ($post) ? 'post_' : '';
629637
$run = true;
630-
if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot() && ! Cache\Scanner::isIgnoredFile($path) ) {
638+
if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isIgnoredFile($path)) {
631639
foreach ($hooks as $hook) {
632640
if ($hook != 'read') {
633641
\OC_Hook::emit(
@@ -930,11 +938,11 @@ private function searchCommon($query, $method) {
930938
}
931939

932940
/**
933-
* Get the owner for a file or folder
934-
*
935-
* @param string $path
936-
* @return string
937-
*/
941+
* Get the owner for a file or folder
942+
*
943+
* @param string $path
944+
* @return string
945+
*/
938946
public function getOwner($path) {
939947
return $this->basicOperation('getOwner', $path);
940948
}

0 commit comments

Comments
 (0)