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

Commit 1905cba

Browse files
clerodawagner
authored andcommitted
Add check for inclusive criterion overflow
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]>
1 parent 7501513 commit 1905cba

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

parameter/SelectionCriterionType.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2014, Intel Corporation
2+
* Copyright (c) 2011-2015, Intel Corporation
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without modification,
@@ -30,6 +30,8 @@
3030
#include "SelectionCriterionType.h"
3131
#include "Tokenizer.h"
3232

33+
#include <climits>
34+
3335
#define base CElement
3436

3537
const std::string CSelectionCriterionType::_strDelimiter = "|";
@@ -51,6 +53,16 @@ std::string CSelectionCriterionType::getKind() const
5153
// From ISelectionCriterionTypeInterface
5254
bool CSelectionCriterionType::addValuePair(int iValue, const std::string& strValue)
5355
{
56+
// As signed integer has a bit reserved for sign, there is one value which is not available
57+
static const size_t inclusiveCriterionMaxValue = sizeof(int32_t) * CHAR_BIT - 1;
58+
if (_bInclusive && _numToLitMap.size() >= inclusiveCriterionMaxValue) {
59+
60+
log_warning("Rejecting value pair association: 0x%X - %s "
61+
"because inclusive criterion can't have more than '%u' values",
62+
iValue, strValue.c_str(), inclusiveCriterionMaxValue);
63+
return false;
64+
}
65+
5466
// Check 1 bit set only for inclusive types
5567
if (_bInclusive && (!iValue || (iValue & (iValue - 1)))) {
5668

test/test-platform/TestPlatform.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2014, Intel Corporation
2+
* Copyright (c) 2011-2015, Intel Corporation
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without modification,
@@ -333,14 +333,6 @@ bool CTestPlatform::createInclusiveSelectionCriterionFromStateList(
333333
assert(pCriterionType != NULL);
334334

335335
uint32_t uiNbStates = remoteCommand.getArgumentCount() - 1;
336-
337-
if (uiNbStates > 32) {
338-
339-
strResult = "Maximum number of states for inclusive criterion is 32";
340-
341-
return false;
342-
}
343-
344336
uint32_t uiState;
345337

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

400-
if (uiNbStates > 32) {
401-
402-
strResult = "Maximum number of states for inclusive criterion is 32";
403-
404-
return false;
405-
}
406-
407392
uint32_t uiState;
408393

409394
for (uiState = 0; uiState < uiNbStates; uiState++) {

0 commit comments

Comments
 (0)