public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] BaseTools: Add check for VOID* PCD Max Size
@ 2018-08-03  8:14 Yonghong Zhu
  0 siblings, 0 replies; only message in thread
From: Yonghong Zhu @ 2018-08-03  8:14 UTC (permalink / raw)
  To: edk2-devel

Per spec VOID* PCD max size should be a UINT16 value. so this patch
add the value check whether it is in range 0x0 .. 0xFFFF.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
---
 BaseTools/Source/Python/Workspace/DscBuildData.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index e8b36a3..c7f07f4 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -1534,10 +1534,17 @@ class DscBuildData(PlatformBuildClassObject):
         for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdSet:
             Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid, SkuName]
             if Setting is None:
                 continue
             PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
+            if MaxDatumSize:
+                if int(MaxDatumSize, 0) > 0xFFFF:
+                    EdkLogger.error('build', FORMAT_INVALID, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid, PcdCName)),
+                                    File=self.MetaFile, Line=Dummy4)
+                if int(MaxDatumSize, 0) < 0:
+                    EdkLogger.error('build', FORMAT_INVALID, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid, PcdCName)),
+                                    File=self.MetaFile, Line=Dummy4)
             if (PcdCName, TokenSpaceGuid) in PcdValueDict:
                 PcdValueDict[PcdCName, TokenSpaceGuid][SkuName] = (PcdValue, DatumType, MaxDatumSize)
             else:
                 PcdValueDict[PcdCName, TokenSpaceGuid] = {SkuName:(PcdValue, DatumType, MaxDatumSize)}
 
@@ -2379,10 +2386,17 @@ class DscBuildData(PlatformBuildClassObject):
             Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]
             if Setting is None:
                 continue
 
             PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
+            if MaxDatumSize:
+                if int(MaxDatumSize, 0) > 0xFFFF:
+                    EdkLogger.error('build', FORMAT_INVALID, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid, PcdCName)),
+                                    File=self.MetaFile, Line=Dummy4)
+                if int(MaxDatumSize, 0) < 0:
+                    EdkLogger.error('build', FORMAT_INVALID, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid, PcdCName)),
+                                    File=self.MetaFile, Line=Dummy4)
             SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName][0], '', '', '', '', '', PcdValue)
             if (PcdCName, TokenSpaceGuid) in Pcds:
                 pcdObject = Pcds[PcdCName, TokenSpaceGuid]
                 pcdObject.SkuInfoList[SkuName] = SkuInfo
                 if MaxDatumSize.strip():
@@ -2712,10 +2726,17 @@ class DscBuildData(PlatformBuildClassObject):
             # For the Integer & Boolean type, the optional data can only be InitialValue.
             # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
             # until the DEC parser has been called.
             #
             VpdOffset, MaxDatumSize, InitialValue = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
+            if MaxDatumSize:
+                if int(MaxDatumSize, 0) > 0xFFFF:
+                    EdkLogger.error('build', FORMAT_INVALID, "The size value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid, PcdCName)),
+                                    File=self.MetaFile, Line=Dummy4)
+                if int(MaxDatumSize, 0) < 0:
+                    EdkLogger.error('build', FORMAT_INVALID, "The size value can't be set to negative value for %s." % ".".join((TokenSpaceGuid, PcdCName)),
+                                    File=self.MetaFile, Line=Dummy4)
             SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName][0], '', '', '', '', VpdOffset, InitialValue)
             if (PcdCName, TokenSpaceGuid) in Pcds:
                 pcdObject = Pcds[PcdCName, TokenSpaceGuid]
                 pcdObject.SkuInfoList[SkuName] = SkuInfo
                 if MaxDatumSize.strip():
-- 
2.6.1.windows.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-08-03  8:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-03  8:14 [Patch] BaseTools: Add check for VOID* PCD Max Size Yonghong Zhu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox