summaryrefslogtreecommitdiffstats
path: root/parameter/EnumParameterType.cpp
diff options
context:
space:
mode:
authorFrédéric Boisnard <fredericx.boisnard@intel.com>2012-07-27 11:32:30 +0200
committerDavid Wagner <david.wagner@intel.com>2014-02-12 17:03:12 +0100
commit7bd615ba9b4d44d78aa745a10e836d2e02f6a995 (patch)
tree5167cf25a73a639cec19b623dc7c463ddc25055e /parameter/EnumParameterType.cpp
parent951478881581670ae7d63e16b2aa2e4d2d1fdd66 (diff)
downloadexternal_parameter-framework-7bd615ba9b4d44d78aa745a10e836d2e02f6a995.zip
external_parameter-framework-7bd615ba9b4d44d78aa745a10e836d2e02f6a995.tar.gz
external_parameter-framework-7bd615ba9b4d44d78aa745a10e836d2e02f6a995.tar.bz2
PFW: Verification of Enum size compatibility
BZ: 30283 No verification is made on the compatibility of the numerical Enum with the declared size. This patch aims to fix this issue. Change-Id: I03dea88d1b3e482eecb92a92169537d51c44c2a7 Signed-off-by: Frédéric Boisnard <fredericx.boisnard@intel.com> Reviewed-on: http://android.intel.com:8080/59242 Reviewed-by: Rocard, KevinX <kevinx.rocard@intel.com> Reviewed-by: Benavoli, Patrick <patrick.benavoli@intel.com> Reviewed-by: De Chivre, Renaud <renaud.de.chivre@intel.com> Tested-by: Mendi, EduardoX <eduardox.mendi@intel.com> Reviewed-by: buildbot <buildbot@intel.com> Tested-by: buildbot <buildbot@intel.com>
Diffstat (limited to 'parameter/EnumParameterType.cpp')
-rw-r--r--parameter/EnumParameterType.cpp56
1 files changed, 47 insertions, 9 deletions
diff --git a/parameter/EnumParameterType.cpp b/parameter/EnumParameterType.cpp
index 863db64..c89aaf4 100644
--- a/parameter/EnumParameterType.cpp
+++ b/parameter/EnumParameterType.cpp
@@ -90,7 +90,7 @@ bool CEnumParameterType::toBlackboard(const string& strValue, uint32_t& uiValue,
if (isNumber(strValue)) {
- // Numerical value provided
+ /// Numerical value provided
// Hexa
bool bValueProvidedAsHexa = !strValue.compare(0, 2, "0x");
@@ -104,11 +104,8 @@ bool CEnumParameterType::toBlackboard(const string& strValue, uint32_t& uiValue,
// Conversion error when the input string does not contain any digit or the number is out of range (int32_t type)
bool bConversionSucceeded = !errno && (strValue.c_str() != pcStrEnd);
-
- if (!bConversionSucceeded || !isEncodable((uint64_t)iData, !bValueProvidedAsHexa)) {
-
- // Illegal value provided
- parameterAccessContext.setError("Provided value out of bound");
+ // Check validity against type
+ if (!checkValueAgainstRange(strValue, iData, parameterAccessContext, bValueProvidedAsHexa, bConversionSucceeded)) {
return false;
}
@@ -118,7 +115,8 @@ bool CEnumParameterType::toBlackboard(const string& strValue, uint32_t& uiValue,
// Sign extend
signExtend(iData);
}
- // Check validity
+
+ // Check validity against lexical space
string strError;
if (!isValid(iData, parameterAccessContext)) {
@@ -127,9 +125,9 @@ bool CEnumParameterType::toBlackboard(const string& strValue, uint32_t& uiValue,
return false;
}
} else {
- // Literal value provided
+ /// Literal value provided
- // Check validity
+ // Check validity against lexical space
int iNumerical;
if (!getNumerical(strValue, iNumerical)) {
@@ -138,6 +136,12 @@ bool CEnumParameterType::toBlackboard(const string& strValue, uint32_t& uiValue,
return false;
}
iData = iNumerical;
+
+ // Check validity against type
+ if (!checkValueAgainstRange(strValue, iData, parameterAccessContext, false, isEncodable((uint64_t)iData, true))) {
+
+ return false;
+ }
}
// Return data
@@ -146,6 +150,40 @@ bool CEnumParameterType::toBlackboard(const string& strValue, uint32_t& uiValue,
return true;
}
+// Range checking
+bool CEnumParameterType::checkValueAgainstRange(const string& strValue, int64_t value, CParameterAccessContext& parameterAccessContext, bool bHexaValue, bool bConversionSucceeded) const
+{
+ // Enums are always signed, it means we have one less util bit
+ int64_t maxValue = (1 << (getSize() * 8 - 1)) - 1;
+ int64_t minValue = -maxValue - 1;
+
+ if (!bConversionSucceeded || value < minValue || value > maxValue) {
+
+ ostringstream strStream;
+
+ strStream << "Value " << strValue << " standing out of admitted range [";
+
+ if (bHexaValue) {
+
+ // Format Min
+ strStream << "0x" << hex << uppercase << setw(getSize()*2) << setfill('0') << makeEncodable(minValue);
+ // Format Max
+ strStream << ", 0x" << hex << uppercase << setw(getSize()*2) << setfill('0') << makeEncodable(maxValue);
+
+ } else {
+
+ strStream << minValue << ", " << maxValue;
+ }
+
+ strStream << "] for " << getKind();
+
+ parameterAccessContext.setError(strStream.str());
+
+ return false;
+ }
+ return true;
+}
+
bool CEnumParameterType::fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const
{
// Take care of format