* [PATCH] BaseTools: Check GUID C structure format
@ 2018-08-08 6:14 Feng, YunhuaX
0 siblings, 0 replies; only message in thread
From: Feng, YunhuaX @ 2018-08-08 6:14 UTC (permalink / raw)
To: edk2-devel@lists.01.org; +Cc: Zhu, Yonghong, Gao, Liming
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 | 7 +++++++
BaseTools/Source/Python/Common/Misc.py | 4 +++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/BaseTools/Source/Python/Common/GlobalData.py b/BaseTools/Source/Python/Common/GlobalData.py
index fac7cde708..57048bcae6 100644
--- a/BaseTools/Source/Python/Common/GlobalData.py
+++ b/BaseTools/Source/Python/Common/GlobalData.py
@@ -64,10 +64,17 @@ g4HexChar = re.compile(r'{}{{4}}'.format(_HexChar))
gHexPattern = re.compile(r'0[xX]{}+'.format(_HexChar))
gHexPatternAll = re.compile(r'0[xX]{}+$'.format(_HexChar))
## Regular expressions for string identifier checking
gIdentifierPattern = re.compile('^[a-zA-Z][a-zA-Z0-9_]*$', re.UNICODE)
+## Regular expression for GUID c structure format
+_GuidCFormatPattern = r"{{\s*0[xX]{Hex}{{1,8}}\s*,\s*0[xX]{Hex}{{1,4}}\s*,\s*0[xX]{Hex}{{1,4}}" \
+ r"\s*,\s*{{\s*0[xX]{Hex}{{1,2}}\s*,\s*0[xX]{Hex}{{1,2}}" \
+ r"\s*,\s*0[xX]{Hex}{{1,2}}\s*,\s*0[xX]{Hex}{{1,2}}" \
+ r"\s*,\s*0[xX]{Hex}{{1,2}}\s*,\s*0[xX]{Hex}{{1,2}}" \
+ r"\s*,\s*0[xX]{Hex}{{1,2}}\s*,\s*0[xX]{Hex}{{1,2}}\s*}}\s*}}".format(Hex=_HexChar)
+gGuidCFormatPattern = re.compile(r"{}".format(_GuidCFormatPattern))
#
# A global variable for whether current build in AutoGen phase or not.
#
gAutoGenPhase = False
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index 74a5f0bca5..a92d2d69a8 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -358,10 +358,12 @@ def GuidStructureByteArrayToGuidString(GuidValue):
# @param GuidValue The GUID value in C structure format
#
# @retval string The GUID value in xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format
#
def GuidStructureStringToGuidString(GuidValue):
+ if not GlobalData.gGuidCFormatPattern.match(GuidValue):
+ return ''
guidValueString = GuidValue.lower().replace("{", "").replace("}", "").replace(" ", "").replace(";", "")
guidValueList = guidValueString.split(",")
if len(guidValueList) != 11:
return ''
#EdkLogger.error(None, None, "Invalid GUID value string %s" % GuidValue)
@@ -1325,11 +1327,11 @@ def ParseFieldValue (Value):
return Value, 8
if Value.startswith(TAB_GUID) and Value.endswith(')'):
Value = Value.split('(', 1)[1][:-1].strip()
if Value[0] == '{' and Value[-1] == '}':
TmpValue = GuidStructureStringToGuidString(Value)
- if len(TmpValue) == 0:
+ if not TmpValue:
raise BadExpression("Invalid GUID value string %s" % Value)
Value = TmpValue
if Value[0] == '"' and Value[-1] == '"':
Value = Value[1:-1]
try:
--
2.12.2.windows.2
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-08-08 6:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-08 6:14 [PATCH] BaseTools: Check GUID C structure format Feng, YunhuaX
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox