[Filesystem][Alarm] Fix coverity/SVACE issues 10/178110/2
authorPiotr Kosko <p.kosko@samsung.com>
Tue, 8 May 2018 05:53:49 +0000 (07:53 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Tue, 8 May 2018 06:46:42 +0000 (08:46 +0200)
[Bug] Fixed Coverity issues: 119865, 119863.
  Fixed SVACE issue: 345864

  Issues were related to not reachable code (invalid returned value was checked)
  in Alarm module and not checking returned values in Filesystem module.
  SVACE issue 345864 is related to the same problem as Coverity 119863.

[Verification] Code compiles without errors.
  TCT passrate for Alarm and Filesystem - 100%.

Change-Id: I315d0aed94f8efef13d37a73b313ef455fb3b00e
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/alarm/alarm_manager.cc
src/filesystem/filesystem_manager.cc

index 1669bb6fd6d4bb4ad1d95aaea1070aa436c468ac..7a27dfcca66319165af8c923a6ba5e53456ea515 100644 (file)
@@ -630,7 +630,7 @@ PlatformResult AlarmManager::GetAlarm(int id, picojson::object& obj) {
     }
 
     int ret_app = app_control_get_extra_data(app_control, kAlarmRelativeDelayKey, &delay_string);
-    if (APP_CONTROL_ERROR_NONE != ret) {
+    if (APP_CONTROL_ERROR_NONE != ret_app) {
       return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Failed to get data.",
                                 ("Failed to get data: %d (%s)", ret_app, get_error_message(ret_app)));
     }
index ad518b07e6764955e034bddf14c86058ed69326d..755defb57cb4e7707165219e5a6d7f5cff4e0b02 100644 (file)
@@ -327,14 +327,20 @@ void FilesystemManager::Rename(const std::string oldPath, const std::string& new
     ret |= chown(newPath.c_str(), fileStat.st_uid, fileStat.st_gid);
     if (0 != ret) {
       LoggerE("Error while changing ownership/permissions [%s]", GetErrorString(errno).c_str());
-      remove(newPath.c_str());
+      if (0 != remove(newPath.c_str())) {
+        LoggerW("Error during rollback [%s], some of copied files may still exist",
+                GetErrorString(errno).c_str());
+      }
       error_cb(FilesystemError::Other);
       return;
     }
 
     if (0 != remove(oldPath.c_str())) {
       LoggerE("Error while removing file [%s]", GetErrorString(errno).c_str());
-      remove(newPath.c_str());
+      if (0 != remove(newPath.c_str())) {
+        LoggerW("Error during rollback [%s], some of copied files may still exist",
+                GetErrorString(errno).c_str());
+      }
       error_cb(FilesystemError::Other);
       return;
     }