[Filesystem] Add detection to invalid virtual paths.
authorKamil Lysik <k.lysik@samsung.com>
Mon, 9 Mar 2015 15:22:43 +0000 (16:22 +0100)
committerRafal Galka <r.galka@samsung.com>
Tue, 10 Mar 2015 14:48:36 +0000 (23:48 +0900)
Not all cases of invalid virtual path was handled.
This commit introduces detection of invalid path
and updates to all virtual path resolve occurences.

[Verification]
Test File_moveTo_with_path_invalid should pass.

Change-Id: I9be07699737a7f30b8db63c86084dc2f150108bb
Signed-off-by: Kamil Lysik <k.lysik@samsung.com>
src/filesystem/filesystem_instance.cc
src/filesystem/js/common.js
src/filesystem/js/file.js

index 36fa52036caa5d6a94040571bf00caf3918c8374..c54be7d1a8acbb2c4d105c9c0f8b2b95ccbd0ce2 100644 (file)
@@ -535,6 +535,11 @@ void FilesystemInstance::RemoveDirectory(const picojson::value& args,
 void FilesystemInstance::CopyTo(const picojson::value& args,
                                   picojson::object& out) {
   LoggerD("enter");
+  CHECK_EXIST(args, "callbackId", out)
+  CHECK_EXIST(args, "originFilePath", out)
+  CHECK_EXIST(args, "destinationFilePath", out)
+  CHECK_EXIST(args, "overwrite", out)
+
   double callback_id = args.get("callbackId").get<double>();
   const std::string& originPath = args.get("originFilePath").get<std::string>();
   const std::string& destinationPath = args.get("destinationFilePath").get<std::string>();
index b6eb5a35f8498df131e9ce16c891541ae427fb35..870d18f119c6297bf7977b994ae2ed0caedc901e 100644 (file)
@@ -103,6 +103,9 @@ CommonFS.prototype.getFileInfo = function(aPath, aStatObj, secondIter, aMode) {
 };
 
 CommonFS.prototype.isLocationAllowed = function(aPath) {
+  if (!aPath) {
+      return false;
+  }
   if (aPath.indexOf(this.cacheVirtualToReal.ringtones.path) === 0) {
     return false;
   }
@@ -144,8 +147,10 @@ CommonFS.prototype.toRealPath = function(aPath) {
       for (i = 1; i < _pathTokens.length; ++i) {
         _fileRealPath += '/' + _pathTokens[i];
       }
+      this.cacheRealToVirtual[_fileRealPath] = aPath;
     } else {
-      _fileRealPath = aPath;
+      //If path token is not present in cache then it is invalid
+      _fileRealPath = undefined;
     }
   } else {
     _fileRealPath = aPath;
index 6f536f6123569df4277a280594dc11732c92b0cd..dfcf49ab2709357db6b1b51448b34738d168fab2 100644 (file)
@@ -352,6 +352,24 @@ File.prototype.copyTo = function(originFilePath, destinationFilePath, overwrite,
   var _realOriginalPath = commonFS_.toRealPath(args.originFilePath);
   var _realDestinationPath = commonFS_.toRealPath(args.destinationFilePath);
 
+  if (!_realOriginalPath) {
+      setTimeout(function() {
+        native_.callIfPossible(args.onerror,
+            new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR,
+            'Source path is not valid'));
+      }, 0);
+      return;
+  }
+
+  if (!_realDestinationPath) {
+      setTimeout(function() {
+        native_.callIfPossible(args.onerror,
+            new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR,
+            'Destination path is not valid'));
+      }, 0);
+      return;
+  }
+
   var resultOldPath = native_.callSync('File_statSync', {location: _realOriginalPath});
   if (native_.isFailure(resultOldPath)) {
     setTimeout(function() {
@@ -408,6 +426,24 @@ File.prototype.moveTo = function(originFilePath, destinationFilePath, overwrite,
   var _realOriginalPath = commonFS_.toRealPath(args.originFilePath);
   var _realDestinationPath = commonFS_.toRealPath(args.destinationFilePath);
 
+  if (!_realOriginalPath) {
+      setTimeout(function() {
+        native_.callIfPossible(args.onerror,
+            new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR,
+            'Source path is not valid'));
+      }, 0);
+      return;
+  }
+
+  if (!_realDestinationPath) {
+      setTimeout(function() {
+        native_.callIfPossible(args.onerror,
+            new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR,
+            'Destination path is not valid'));
+      }, 0);
+      return;
+  }
+
   var resultOldPath = native_.callSync('File_statSync', {location: _realOriginalPath});
   if (native_.isFailure(resultOldPath)) {
     setTimeout(function() {
@@ -483,6 +519,15 @@ File.prototype.createDirectory = function(dirPath) {
           _fileInfo,
           _realNewPath = commonFS_.toRealPath(_newPath);
 
+  if (!_realNewPath) {
+    setTimeout(function() {
+      native_.callIfPossible(args.onerror,
+          new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+          'Path is not valid'));
+    }, 0);
+    return;
+  }
+
   if (this.isDirectory) {
     if (this.mode === 'r') {
       throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
@@ -532,6 +577,14 @@ File.prototype.createFile = function(relativeFilePath) {
 
   var _outputPath = this.fullPath + '/' + args.relativeFilePath;
   var _outputRealPath = commonFS_.toRealPath(_outputPath);
+  if (!_outputRealPath) {
+    setTimeout(function() {
+      native_.callIfPossible(args.onerror,
+          new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+          'Path is not valid'));
+    }, 0);
+    return;
+  }
   var _resultExist = native_.callSync('File_statSync', {location: _outputRealPath});
 
   if (native_.isSuccess(_resultExist)) {
@@ -571,6 +624,14 @@ File.prototype.resolve = function(filePath) {
 
   var _newPath = this.fullPath + '/' + args.filePath;
   var _realPath = commonFS_.toRealPath(_newPath);
+  if (!_realPath) {
+    setTimeout(function() {
+      native_.callIfPossible(args.onerror,
+          new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+          'Path is not valid'));
+    }, 0);
+    return;
+  }
   var _result = native_.callSync('File_statSync', {location: _realPath});
   if (native_.isFailure(_result)) {
     throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR, native_.getErrorObject(_result));