[SystemSetting] Synchronously checking access to file 59/168859/3
authorSzymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
Wed, 31 Jan 2018 12:59:13 +0000 (13:59 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Wed, 25 Apr 2018 12:31:29 +0000 (12:31 +0000)
[Verificaton] SystemSetting TCT 100% pass rate

ACR: http://suprem.sec.samsung.net/jira/browse/TWDAPI-187

Change-Id: Ic7df53247ce575790f428d6338bfdb23ee00e997
Signed-off-by: Szymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
src/systemsetting/systemsetting_instance.cc

index 8b28ba7cc2e1c9269a8cb0e771c24dcf3c94e7fc..e791bc2c82ac8f01e812e602e6f5ab25d9ef2a68 100644 (file)
@@ -21,6 +21,7 @@
 #include "common/filesystem/filesystem_provider.h"
 #include "common/logger.h"
 #include "common/picojson.h"
+#include "common/scope_exit.h"
 #include "common/task-queue.h"
 #include "common/tools.h"
 
@@ -109,11 +110,15 @@ PlatformResult SystemSettingInstance::getPlatformPropertyValue(const std::string
   // other values (not specified in the documentation) are handled in JS
 
   switch (ret) {
-    case SYSTEM_SETTINGS_ERROR_NONE:
+    case SYSTEM_SETTINGS_ERROR_NONE: {
+      SCOPE_EXIT {
+        free(value);
+      };
       LoggerD("ret == SYSTEM_SETTINGS_ERROR_NONE");
+      CHECK_STORAGE_ACCESS_AND_RETURN(value);
       result_obj.insert(std::make_pair("value", picojson::value(value ? value : "")));
-      free(value);
       return PlatformResult(ErrorCode::NO_ERROR);
+    }
     case SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED:
       return LogAndCreateResult(
           ErrorCode::NOT_SUPPORTED_ERR, "This property is not supported.",
@@ -137,10 +142,12 @@ void SystemSettingInstance::setProperty(const picojson::value& args, picojson::o
   const std::string& value = args.get("value").get<std::string>();
   LoggerD("Value to set: %s ", value.c_str());
 
-  auto get = [this, type, value,
+  std::string real_path = common::FilesystemProvider::Create().GetRealPath(value);
+  CHECK_STORAGE_ACCESS(real_path, &out);
+
+  auto get = [this, type, real_path,
               callback_id](const std::shared_ptr<picojson::value>& response) -> void {
     ScopeLogger("Entered into asynchronous function, get");
-    std::string real_path = common::FilesystemProvider::Create().GetRealPath(value);
     PlatformResult status = setPlatformPropertyValue(type, real_path);
     picojson::object& obj = response->get<picojson::object>();
     if (status.IsSuccess()) {