summaryrefslogtreecommitdiff
path: root/BaseTools
diff options
context:
space:
mode:
authorFeng, YunhuaX </o=Intel/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=Feng, YunhuaX4e1>2018-03-01 16:22:08 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2018-03-02 10:18:50 +0800
commit5ac0a5450bb87ccefa9f847d3d5bf579cb13925e (patch)
treea33d07bb3dddd94545faec676e1d870556f69ea6 /BaseTools
parent6ee9c68912324b4053cfa15fd06b02af1c1c74d9 (diff)
downloadedk2-5ac0a5450bb87ccefa9f847d3d5bf579cb13925e.zip
edk2-5ac0a5450bb87ccefa9f847d3d5bf579cb13925e.tar.gz
edk2-5ac0a5450bb87ccefa9f847d3d5bf579cb13925e.tar.bz2
BaseTools: report error if flag in LABEL() invalid
Flag in LABEL() is not valid C variable name, will report error. 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> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Diffstat (limited to 'BaseTools')
-rw-r--r--BaseTools/Source/Python/Common/Expression.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py
index f1516d5..5a0ade9 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -119,6 +119,12 @@ def SplitPcdValueString(String):
RetList.append(Item)
return RetList
+def IsValidCString(Str):
+ ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')
+ if not ValidString.match(Str):
+ return False
+ return True
+
## ReplaceExprMacro
#
def ReplaceExprMacro(String, Macros, ExceptionList = None):
@@ -885,13 +891,13 @@ class ValueExpressionEx(ValueExpression):
for Index, Item in enumerate(PcdValueList):
# compute byte offset of every LABEL
Item = Item.strip()
- try:
- LabelList = ReLabel.findall(Item)
+ LabelList = ReLabel.findall(Item)
+ if LabelList:
for Label in LabelList:
+ if not IsValidCString(Label):
+ raise BadExpression('%s is not a valid c variable name' % Label)
if Label not in LabelDict.keys():
LabelDict[Label] = str(LabelOffset)
- except:
- pass
if Item.startswith('UINT8'):
LabelOffset = LabelOffset + 1
elif Item.startswith('UINT16'):