Fix zero-initialization of class members 38/245138/2
authorMateusz Cegielka <m.cegielka@samsung.com>
Fri, 2 Oct 2020 13:40:40 +0000 (15:40 +0200)
committerMateusz Cegielka <m.cegielka@samsung.com>
Mon, 5 Oct 2020 07:37:19 +0000 (09:37 +0200)
Some class members are not zero-initialized, which can cause seemingly
innocent initializations to result in uninitialized memory, which can
cause UB. While unlikely, this shows up as a critical issue in SVACE.

I have changed the constructors so that they explicitly initialize
members in order to fix the issue.

Change-Id: I16e1f253985e1c37f3b5ee67d3d9c91696706054

src/common/types/MonitorEntry.h
src/common/types/PolicyKey.h

index cb0def666f414e78adda99a1f6e6f68e10b0948f..447f27ea92cf6c8b7b75eabe5897c9e8ffbb8a21 100644 (file)
 
 #include <time.h>
 
+#include <cynara-error.h>
 #include "PolicyKey.h"
 
 namespace Cynara {
 
 class MonitorEntry {
 public:
-    MonitorEntry() = default;
+    MonitorEntry()
+        : m_result(CYNARA_API_ACCESS_DENIED), m_timestamp{0, 0} {}
     MonitorEntry(PolicyKey key, const int &result, const struct timespec &timestamp)
         : m_key(std::move(key)), m_result(result), m_timestamp(timestamp) {}
 
index 4862cae795ddb724c0b39dbec664fd7f2a6cac44..7a56752608d79585ffa57b0dfa02bb671aca5d30 100644 (file)
@@ -41,7 +41,8 @@ class PolicyKeyFeature {
 friend class PolicyKey;
 
 public:
-    PolicyKeyFeature() = default;
+    PolicyKeyFeature()
+        : m_isAny(false) {}
 
     typedef std::string ValueType;