CKM: Prevent exceptions in gc. Fix buffer comparison. 86/41986/5
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 19 Jun 2015 12:34:14 +0000 (14:34 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 26 Jun 2015 11:48:06 +0000 (13:48 +0200)
[Problem] Garbage collector destructor may throw exceptions. Buffers can be
different even if sizes match.
[Solution] Destructor protected with try catch. Buffer comparison fixed.

[Verification] Run tests

Change-Id: Iae33de10ee9e9b2bde6aa427a4f17b49eed6955e

src/ckm/ckm-common.cpp

index 47b4012..9b5cb77 100644 (file)
@@ -209,8 +209,12 @@ GarbageCollector::~GarbageCollector()
 {
     for(auto & item : m_garbage)
     {
-        ScopedAccessProvider ap(item.owner_label, item.owner_uid, item.owner_gid);
-        check_remove_allowed(item.item_alias.c_str());
+        try {
+            ScopedAccessProvider ap(item.owner_label, item.owner_uid, item.owner_gid);
+            check_remove_allowed(item.item_alias.c_str());
+        } catch (...) {
+            // prevent exceptions in destructor
+        }
     }
 }
 
@@ -542,7 +546,7 @@ void assert_buffers_equal(const ckmc_raw_buffer_s b1, const ckmc_raw_buffer_s b2
         RUNNER_ASSERT_MSG(b1.size == b2.size, "Buffer size differs: " << b1.size << "!=" << b2.size);
         RUNNER_ASSERT_MSG(0 == memcmp(b1.data, b2.data, b1.size), "Buffer contents differ");
     } else {
-        RUNNER_ASSERT_MSG(b1.size != b2.size, "Buffer sizes equal: " << b1.size << "==" << b2.size);
-        RUNNER_ASSERT_MSG(0 != memcmp(b1.data, b2.data, b1.size), "Buffer contents are identical");
+        RUNNER_ASSERT_MSG(b1.size != b2.size || 0 != memcmp(b1.data, b2.data, b1.size),
+                          "Buffers should be different");
     }
 }