From c1a869902b93e6d88cb5df7701ef0fd010276448 Mon Sep 17 00:00:00 2001 From: Michal Michalski Date: Wed, 19 Jun 2019 08:18:38 +0200 Subject: [PATCH] [common] Handle nullptr output args in platform_enum. 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 --- src/common/platform_enum.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/common/platform_enum.h b/src/common/platform_enum.h index 6c626954..aad4d3c2 100644 --- a/src/common/platform_enum.h +++ b/src/common/platform_enum.h @@ -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; -- 2.34.1