Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
Add check for inclusive criterion overflow
Browse files Browse the repository at this point in the history
Inclusive criteria have a limited value number due to their internal state
representation. Currently, the only check made for this is at test-platform
level.

This patch adds a new check to make addValuePair API fail if too many values
are added to an inclusive criterion type.  A log has also been added to warn
the client.  The check at test-platform level has been removed.

Change-Id: Ie9c9ec8fb8561f949bb62adbab127bc900aa254b
Signed-off-by: Jules Clero <[email protected]>
  • Loading branch information
clero authored and dawagner committed Jul 9, 2015
1 parent 7501513 commit 1905cba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
14 changes: 13 additions & 1 deletion parameter/SelectionCriterionType.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2014, Intel Corporation
* Copyright (c) 2011-2015, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -30,6 +30,8 @@
#include "SelectionCriterionType.h"
#include "Tokenizer.h"

#include <climits>

#define base CElement

const std::string CSelectionCriterionType::_strDelimiter = "|";
Expand All @@ -51,6 +53,16 @@ std::string CSelectionCriterionType::getKind() const
// From ISelectionCriterionTypeInterface
bool CSelectionCriterionType::addValuePair(int iValue, const std::string& strValue)
{
// As signed integer has a bit reserved for sign, there is one value which is not available
static const size_t inclusiveCriterionMaxValue = sizeof(int32_t) * CHAR_BIT - 1;
if (_bInclusive && _numToLitMap.size() >= inclusiveCriterionMaxValue) {

log_warning("Rejecting value pair association: 0x%X - %s "
"because inclusive criterion can't have more than '%u' values",
iValue, strValue.c_str(), inclusiveCriterionMaxValue);
return false;
}

// Check 1 bit set only for inclusive types
if (_bInclusive && (!iValue || (iValue & (iValue - 1)))) {

Expand Down
17 changes: 1 addition & 16 deletions test/test-platform/TestPlatform.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2014, Intel Corporation
* Copyright (c) 2011-2015, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -333,14 +333,6 @@ bool CTestPlatform::createInclusiveSelectionCriterionFromStateList(
assert(pCriterionType != NULL);

uint32_t uiNbStates = remoteCommand.getArgumentCount() - 1;

if (uiNbStates > 32) {

strResult = "Maximum number of states for inclusive criterion is 32";

return false;
}

uint32_t uiState;

for (uiState = 0; uiState < uiNbStates; uiState++) {
Expand Down Expand Up @@ -397,13 +389,6 @@ bool CTestPlatform::createInclusiveSelectionCriterion(const string& strName,
ISelectionCriterionTypeInterface* pCriterionType =
_pParameterMgrPlatformConnector->createSelectionCriterionType(true);

if (uiNbStates > 32) {

strResult = "Maximum number of states for inclusive criterion is 32";

return false;
}

uint32_t uiState;

for (uiState = 0; uiState < uiNbStates; uiState++) {
Expand Down

0 comments on commit 1905cba

Please sign in to comment.