[common] Handle nullptr output args in platform_enum. 66/208166/1
authorMichal Michalski <m.michalski2@partner.samsung.com>
Wed, 19 Jun 2019 06:18:38 +0000 (08:18 +0200)
committerMichal Michalski <m.michalski2@partner.samsung.com>
Wed, 19 Jun 2019 06:18:38 +0000 (08:18 +0200)
Methods in platform_enum were not handling a nullptr output argument
case. This could lead to dereferencing of nullptr and to a crash.
Now they will return InvalidValuesError.

[Verification] No verification.

Change-Id: I756cf1495369143eaca78d249fd83229383907fc
Signed-off-by: Michal Michalski <m.michalski2@partner.samsung.com>
src/common/platform_enum.h

index 6c6269547c44c9b1304283abe2ad12ccf9022925..aad4d3c2249cd70ef9164e2bd72aea7917f2b0ea 100644 (file)
@@ -44,15 +44,24 @@ public:
   }
 
   PlatformResult getName(NativeEnumType value, std::string* name) const {
+    if (nullptr == name) {
+      return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "output argument cannnot be nullptr");
+    }
+
     auto it = rev_mapping_.find(value);
     if (it != rev_mapping_.end()) {
       *name = it->second;
       return PlatformResult(ErrorCode::NO_ERROR);
     }
+
     return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "enum value not registered");
   }
 
   PlatformResult getValue(std::string name, NativeEnumType* value) const {
+    if (nullptr == value) {
+      return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "output argument cannnot be nullptr");
+    }
+
     auto it = mapping_.find(name);
     if (it != mapping_.end()) {
       *value = it->second;