diff options
author | Frederic Boisnard <fredericx.boisnard@intel.com> | 2012-03-21 14:47:00 +0100 |
---|---|---|
committer | David Wagner <david.wagner@intel.com> | 2014-02-12 17:03:10 +0100 |
commit | 8b01852701d50869318663f568270f977d93dbdf (patch) | |
tree | b26462e5ae9e3b7cb10a9ed0511da6c2a7e6cd75 /parameter/EnumParameterType.cpp | |
parent | 170f0a44b8309a954cd4802e85ac3dd6944a35fa (diff) | |
download | external_parameter-framework-8b01852701d50869318663f568270f977d93dbdf.zip external_parameter-framework-8b01852701d50869318663f568270f977d93dbdf.tar.gz external_parameter-framework-8b01852701d50869318663f568270f977d93dbdf.tar.bz2 |
PFW: overflow not detected for int parameters
BZ: 26285
The following errors were not detected by the PFW when setting parameters
of type (U)INT8, (U)INT16, (U)INT32:
- When setting a value out of the int32 range (ex: 999999999999999), the
strtol/strtoul functions return the value -1 which was then assumed correct
by the PFW. Now the errno value is checked to ensure that no range error
was encountered by strtol/strtoul.
- When the input string does not contain any digits, the strtol/strtoul
functions return 0 which was assumed correct by the PFW. Now the endptr
argument is checked to make sure that at least a part of the string was
parsed.
In any case an error message is displayed and the original value is not
updated.
Made the change compliant to 64-bit OSes.
Applied the same corrections to Enum and FixedPoint types.
Change-Id: I135538def791208a6eb6143444a3fc30337137e1
Orig-Change-Id: I1519dbf798228a9be579aaf612f456d5eb1b41b5
Signed-off-by: Frederic Boisnard <fredericx.boisnard@intel.com>
Reviewed-on: http://android.intel.com:8080/55443
Reviewed-by: Mendi, EduardoX <eduardox.mendi@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.cpp | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/parameter/EnumParameterType.cpp b/parameter/EnumParameterType.cpp index 60c937c..fc2123a 100644 --- a/parameter/EnumParameterType.cpp +++ b/parameter/EnumParameterType.cpp @@ -36,6 +36,7 @@ #include <assert.h> #include "ParameterAccessContext.h" #include "EnumValuePair.h" +#include <errno.h> #define base CParameterType @@ -91,7 +92,7 @@ bool CEnumParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingC // Conversion (tuning) bool CEnumParameterType::toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const { - int32_t iData; + int64_t iData; if (isNumber(strValue)) { @@ -100,18 +101,34 @@ bool CEnumParameterType::toBlackboard(const string& strValue, uint32_t& uiValue, // Hexa bool bValueProvidedAsHexa = !strValue.compare(0, 2, "0x"); + errno = 0; + char *pcStrEnd; + // Get value - iData = strtol(strValue.c_str(), NULL, 0); + iData = strtoll(strValue.c_str(), &pcStrEnd, 0); + + // 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"); - if (bValueProvidedAsHexa && isEncodable(iData)) { + return false; + } + + if (bValueProvidedAsHexa) { // Sign extend signExtend(iData); } // Check validity - if (!isValid(iData)) { + string strError; + if (!isValid(iData, parameterAccessContext)) { - parameterAccessContext.setError("Provided value not part of numerical space"); + parameterAccessContext.setError(strError); return false; } @@ -119,16 +136,18 @@ bool CEnumParameterType::toBlackboard(const string& strValue, uint32_t& uiValue, // Literal value provided // Check validity - if (!getNumerical(strValue, iData)) { + int iNumerical; + if (!getNumerical(strValue, iNumerical)) { parameterAccessContext.setError("Provided value not part of lexical space"); return false; } + iData = iNumerical; } // Return data - uiValue = iData; + uiValue = (uint32_t)iData; return true; } @@ -177,9 +196,7 @@ bool CEnumParameterType::fromBlackboard(string& strValue, const uint32_t& uiValu // Value access bool CEnumParameterType::toBlackboard(int32_t iUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const { - if (!isValid(iUserValue)) { - - parameterAccessContext.setError("Invalid value"); + if (!isValid(iUserValue, parameterAccessContext)) { return false; } @@ -243,7 +260,7 @@ bool CEnumParameterType::getLiteral(int32_t iNumerical, string& strLiteral) cons return false; } -bool CEnumParameterType::getNumerical(const string& strLiteral, int32_t& iNumerical) const +bool CEnumParameterType::getNumerical(const string& strLiteral, int& iNumerical) const { uint32_t uiChild; uint32_t uiNbChildren = getNbChildren(); @@ -263,9 +280,10 @@ bool CEnumParameterType::getNumerical(const string& strLiteral, int32_t& iNumeri return false; } -// Numerical validity -bool CEnumParameterType::isValid(int32_t iNumerical) const +// Numerical validity of the enum value +bool CEnumParameterType::isValid(int iNumerical, CParameterAccessContext& parameterAccessContext) const { + // Check that the value is part of the allowed values for this kind of enum uint32_t uiChild; uint32_t uiNbChildren = getNbChildren(); @@ -279,5 +297,7 @@ bool CEnumParameterType::isValid(int32_t iNumerical) const } } + parameterAccessContext.setError("Provided value not part of numerical space"); + return false; } |