[Exif] Synchronously checking access to file 56/168856/4
authorPawel Kaczmarczyk <p.kaczmarczy@samsung.com>
Wed, 31 Jan 2018 10:55:58 +0000 (11:55 +0100)
committerPawel Kaczmarczyk <p.kaczmarczy@samsung.com>
Tue, 24 Apr 2018 08:59:05 +0000 (08:59 +0000)
ACR: http://suprem.sec.samsung.net/jira/browse/TWDAPI-187

[Verification] Tested in Chromium console

Change-Id: I4818dd71aaa54ef52bc0d18862f628beedac05f4
Signed-off-by: Pawel Kaczmarczyk <p.kaczmarczy@samsung.com>
src/exif/exif_api.js
src/exif/exif_instance.cc

index 3d2cd510cfd99bc1c69b89012fbd3c4675b0eaae..fc25fa3f4f9d2e58edef6b457056d601e8c1cf16 100644 (file)
@@ -217,7 +217,12 @@ ExifManager.prototype.getExifInfo = function() {
     }
   };
 
-  native_.call('ExifManager_getExifInfo', {'uri': args.uri}, callback);
+  var result = native_.call('ExifManager_getExifInfo', {'uri': args.uri}, callback);
+
+  if (native_.isFailure(result)) {
+    // since tizen 5.0 the only possible error type here is SecurityError
+    throw native_.getErrorObject(result);
+  }
 };
 
 ExifManager.prototype.saveExifInfo = function() {
@@ -263,7 +268,12 @@ ExifManager.prototype.saveExifInfo = function() {
     }
   };
 
-  native_.call('ExifManager_saveExifInfo', json, callback);
+  var result = native_.call('ExifManager_saveExifInfo', json, callback);
+
+  if (native_.isFailure(result)) {
+    // since tizen 5.0 the only possible error type here is SecurityError
+    throw native_.getErrorObject(result);
+  }
 };
 
 ExifManager.prototype.getThumbnail = function() {
@@ -307,7 +317,12 @@ ExifManager.prototype.getThumbnail = function() {
     }
   };
 
-  native_.call('ExifManager_getThumbnail', {'uri': args.uri}, _callback);
+  var result = native_.call('ExifManager_getThumbnail', {'uri': args.uri}, _callback);
+
+  if (native_.isFailure(result)) {
+    // since tizen 5.0 the only possible error type here is SecurityError
+    throw native_.getErrorObject(result);
+  }
 };
 
 tizen.ExifInformation = function(exifInitDict) {
index 121390c1793d8a7f58efc59115175db7ad840077..ff9c4d2e5060fc3d91ad5afeabb3e267d814cb99 100644 (file)
@@ -27,6 +27,7 @@
 #include "common/platform_result.h"
 #include "common/task-queue.h"
 #include "common/tools.h"
+#include "common/filesystem/filesystem_provider.h"
 
 #include "exif/exif_information.h"
 #include "exif/exif_util.h"
@@ -59,15 +60,18 @@ void ExifInstance::ExifManagerGetExifInfo(const picojson::value& args, picojson:
   ScopeLogger();
 
   const std::string& uri = args.get("uri").get<std::string>();
+  const std::string& file_path = ExifUtil::convertUriToPath(uri);
 
   const double callback_id = args.get("callbackId").get<double>();
+  const std::string& real_path = common::FilesystemProvider::Create().GetRealPath(file_path);
+
+  CHECK_STORAGE_ACCESS(real_path, &out);
+
   auto get = [=](const std::shared_ptr<JsonValue>& response) -> void {
     ScopeLogger("Entered into asynchronous function, get");
     JsonValue result = JsonValue(JsonObject());
     PlatformResult status(ErrorCode::NO_ERROR);
 
-    const std::string& file_path = ExifUtil::convertUriToPath(uri);
-
     PlatformResult fileAvailability(common::tools::CheckFileAvailability(file_path));
     if (!fileAvailability) {
       LogAndReportError(fileAvailability, &response->get<picojson::object>());
@@ -99,15 +103,20 @@ void ExifInstance::ExifManagerSaveExifInfo(const picojson::value& args, picojson
   ScopeLogger();
 
   const double callback_id = args.get("callbackId").get<double>();
+
+  const std::string& file_uri = args.get("uri").get<std::string>();
+  const std::string& file_path = ExifUtil::convertUriToPath(file_uri);
+  const std::string& real_path = common::FilesystemProvider::Create().GetRealPath(file_path);
+
+  CHECK_STORAGE_ACCESS(real_path, &out);
+
   auto get = [=](const std::shared_ptr<JsonValue>& response) -> void {
     ScopeLogger("Entered into asynchronous function, get");
     JsonValue result = JsonValue(JsonObject());
     PlatformResult status(ErrorCode::NO_ERROR);
 
     ExifInformationPtr exifInfo(new ExifInformation(args));
-    const std::string& uri = exifInfo->getUri();
-    const std::string& path = ExifUtil::convertUriToPath(uri);
-    status = exifInfo->saveToFile(path);
+    status = exifInfo->saveToFile(file_path);
 
     if (status)
       ReportSuccess(result, response->get<picojson::object>());
@@ -131,12 +140,16 @@ void ExifInstance::ExifManagerGetThumbnail(const picojson::value& args, picojson
   ScopeLogger();
   const std::string& uri = args.get("uri").get<std::string>();
 
+  const std::string& file_path = ExifUtil::ExifUtil::convertUriToPath(uri);
+  const std::string& real_path = common::FilesystemProvider::Create().GetRealPath(file_path);
+
+  CHECK_STORAGE_ACCESS(real_path, &out);
+
   const double callback_id = args.get("callbackId").get<double>();
   auto get = [=](const std::shared_ptr<JsonValue>& response) -> void {
     ScopeLogger("Entered into asynchronous function, get");
     PlatformResult status(ErrorCode::NO_ERROR);
 
-    const std::string& file_path = ExifUtil::convertUriToPath(uri);
     JsonValue result = JsonValue(JsonObject());
     JsonObject& result_obj = result.get<JsonObject>();