summaryrefslogtreecommitdiff
path: root/BaseTools
diff options
context:
space:
mode:
authorBobCF <bob.c.feng@intel.com>2017-12-01 14:15:59 +0800
committerLiming Gao <liming.gao@intel.com>2017-12-25 11:05:53 +0800
commit520365decb26e5176ec2bb614f11ddeaa495de54 (patch)
tree1158924ffcf13583712beaa296d181ff1b81ffe7 /BaseTools
parent67e63e9a7b3620fc5fdd3df61b4477a8cd5bc944 (diff)
downloadedk2-520365decb26e5176ec2bb614f11ddeaa495de54.zip
edk2-520365decb26e5176ec2bb614f11ddeaa495de54.tar.gz
edk2-520365decb26e5176ec2bb614f11ddeaa495de54.tar.bz2
BaseTools: Check PCD DataType and the maxsize.
Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Feng Bob C <bob.c.feng@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'BaseTools')
-rw-r--r--BaseTools/Source/Python/Common/Misc.py24
-rw-r--r--BaseTools/Source/Python/Workspace/DscBuildData.py15
2 files changed, 33 insertions, 6 deletions
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index a2c6a6a..549c879 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1611,6 +1611,12 @@ def AnalyzeDscPcd(Setting, PcdType, DataType=''):
else:
IsValid = (len(FieldList) <= 3)
# Value, Size = ParseFieldValue(Value)
+ if Size:
+ try:
+ int(Size,16) if Size.upper().startswith("0X") else int(Size)
+ except:
+ IsValid = False
+ Size = -1
return [str(Value), '', str(Size)], IsValid, 0
elif PcdType in (MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_EX_DEFAULT):
Value = FieldList[0]
@@ -1633,7 +1639,14 @@ def AnalyzeDscPcd(Setting, PcdType, DataType=''):
IsValid = (len(FieldList) <= 1)
else:
IsValid = (len(FieldList) <= 3)
- return [Value, Type, Size], IsValid, 0
+
+ if Size:
+ try:
+ int(Size,16) if Size.upper().startswith("0X") else int(Size)
+ except:
+ IsValid = False
+ Size = -1
+ return [Value, Type, str(Size)], IsValid, 0
elif PcdType in (MODEL_PCD_DYNAMIC_VPD, MODEL_PCD_DYNAMIC_EX_VPD):
VpdOffset = FieldList[0]
Value = Size = ''
@@ -1649,8 +1662,13 @@ def AnalyzeDscPcd(Setting, PcdType, DataType=''):
IsValid = (len(FieldList) <= 1)
else:
IsValid = (len(FieldList) <= 3)
-
- return [VpdOffset, Size, Value], IsValid, 2
+ if Size:
+ try:
+ int(Size,16) if Size.upper().startswith("0X") else int(Size)
+ except:
+ IsValid = False
+ Size = -1
+ return [VpdOffset, str(Size), Value], IsValid, 2
elif PcdType in (MODEL_PCD_DYNAMIC_HII, MODEL_PCD_DYNAMIC_EX_HII):
HiiString = FieldList[0]
Guid = Offset = Value = Attribute = ''
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 7594b45..23c2c0d 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -806,9 +806,14 @@ class DscBuildData(PlatformBuildClassObject):
"Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TokenSpaceGuid, PcdCName, self._Arch),
File=self.MetaFile, Line=LineNo)
ValueList, IsValid, Index = AnalyzeDscPcd(Setting, PcdType, self._DecPcds[PcdCName, TokenSpaceGuid].DatumType)
- if not IsValid and PcdType not in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:
- EdkLogger.error('build', FORMAT_INVALID, "Pcd format incorrect.", File=self.MetaFile, Line=LineNo,
- ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))
+ if not IsValid:
+ if PcdType not in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:
+ EdkLogger.error('build', FORMAT_INVALID, "Pcd format incorrect.", File=self.MetaFile, Line=LineNo,
+ ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))
+ else:
+ if ValueList[2] == '-1':
+ EdkLogger.error('build', FORMAT_INVALID, "Pcd format incorrect.", File=self.MetaFile, Line=LineNo,
+ ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))
if ValueList[Index] and PcdType not in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:
try:
ValueList[Index] = ValueExpression(ValueList[Index], GlobalData.gPlatformPcds)(True)
@@ -836,6 +841,10 @@ class DscBuildData(PlatformBuildClassObject):
if not Valid:
EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile, Line=LineNo,
ExtraData="%s.%s" % (TokenSpaceGuid, PcdCName))
+ if PcdType in (MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_EX_DEFAULT):
+ if self._DecPcds[PcdCName, TokenSpaceGuid].DatumType.strip() != ValueList[1].strip():
+ EdkLogger.error('build', FORMAT_INVALID, ErrStr , File=self.MetaFile, Line=LineNo,
+ ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))
return ValueList
def _FilterPcdBySkuUsage(self,Pcds):