From: Kamil Lysik Date: Mon, 9 Mar 2015 15:22:43 +0000 (+0100) Subject: [Filesystem] Add detection to invalid virtual paths. X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~303 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d88e5db8a11124de064ce9a56a4e203a92ea4c25;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Filesystem] Add detection to invalid virtual paths. 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 --- diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index 36fa5203..c54be7d1 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -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(); const std::string& originPath = args.get("originFilePath").get(); const std::string& destinationPath = args.get("destinationFilePath").get(); diff --git a/src/filesystem/js/common.js b/src/filesystem/js/common.js index b6eb5a35..870d18f1 100644 --- a/src/filesystem/js/common.js +++ b/src/filesystem/js/common.js @@ -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; diff --git a/src/filesystem/js/file.js b/src/filesystem/js/file.js index 6f536f61..dfcf49ab 100644 --- a/src/filesystem/js/file.js +++ b/src/filesystem/js/file.js @@ -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));