]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Check GUID C structure format
authorFeng, YunhuaX <yunhuax.feng@intel.com>
Wed, 8 Aug 2018 06:14:20 +0000 (14:14 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Fri, 14 Sep 2018 05:41:07 +0000 (13:41 +0800)
GUID C format must conform to {8,4,4,{2,2,2,2,2,2,2,2}}

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
BaseTools/Source/Python/Common/GlobalData.py
BaseTools/Source/Python/Common/Misc.py

index fac7cde708f6d63e7ffec3c8d7d075489b486969..57048bcae64052e85d309b951879ff6a078eabf7 100644 (file)
@@ -66,6 +66,13 @@ gHexPatternAll = re.compile(r'0[xX]{}+$'.format(_HexChar))
 \r
 ## Regular expressions for string identifier checking\r
 gIdentifierPattern = re.compile('^[a-zA-Z][a-zA-Z0-9_]*$', re.UNICODE)\r
+## Regular expression for GUID c structure format\r
+_GuidCFormatPattern = r"{{\s*0[xX]{Hex}{{1,8}}\s*,\s*0[xX]{Hex}{{1,4}}\s*,\s*0[xX]{Hex}{{1,4}}" \\r
+                      r"\s*,\s*{{\s*0[xX]{Hex}{{1,2}}\s*,\s*0[xX]{Hex}{{1,2}}" \\r
+                      r"\s*,\s*0[xX]{Hex}{{1,2}}\s*,\s*0[xX]{Hex}{{1,2}}" \\r
+                      r"\s*,\s*0[xX]{Hex}{{1,2}}\s*,\s*0[xX]{Hex}{{1,2}}" \\r
+                      r"\s*,\s*0[xX]{Hex}{{1,2}}\s*,\s*0[xX]{Hex}{{1,2}}\s*}}\s*}}".format(Hex=_HexChar)\r
+gGuidCFormatPattern = re.compile(r"{}".format(_GuidCFormatPattern))\r
 \r
 #\r
 # A global variable for whether current build in AutoGen phase or not.\r
index 430bf6bcdabf07a1f45f55116c21edcd1863e849..fc90ccb2c86efe5d9f23e0c0f198200c2604c949 100644 (file)
@@ -360,6 +360,8 @@ def GuidStructureByteArrayToGuidString(GuidValue):
 #   @retval     string      The GUID value in xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format\r
 #\r
 def GuidStructureStringToGuidString(GuidValue):\r
+    if not GlobalData.gGuidCFormatPattern.match(GuidValue):\r
+        return ''\r
     guidValueString = GuidValue.lower().replace("{", "").replace("}", "").replace(" ", "").replace(";", "")\r
     guidValueList = guidValueString.split(",")\r
     if len(guidValueList) != 11:\r
@@ -1327,7 +1329,7 @@ def ParseFieldValue (Value):
         Value = Value.split('(', 1)[1][:-1].strip()\r
         if Value[0] == '{' and Value[-1] == '}':\r
             TmpValue = GuidStructureStringToGuidString(Value)\r
-            if len(TmpValue) == 0:\r
+            if not TmpValue:\r
                 raise BadExpression("Invalid GUID value string %s" % Value)\r
             Value = TmpValue\r
         if Value[0] == '"' and Value[-1] == '"':\r