From nobody Tue May 7 14:42:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1519892535242960.415157025947; Thu, 1 Mar 2018 00:22:15 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A41622242385F; Thu, 1 Mar 2018 00:16:04 -0800 (PST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7C21622423840 for ; Thu, 1 Mar 2018 00:16:03 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Mar 2018 00:22:11 -0800 Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga004.fm.intel.com with ESMTP; 01 Mar 2018 00:22:11 -0800 Received: from fmsmsx114.amr.corp.intel.com (10.18.116.8) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 1 Mar 2018 00:22:10 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX114.amr.corp.intel.com (10.18.116.8) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 1 Mar 2018 00:22:10 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.124]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.116]) with mapi id 14.03.0319.002; Thu, 1 Mar 2018 16:22:09 +0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=yunhuax.feng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,407,1515484800"; d="dat'59?scan'59,208,59";a="33785367" From: "Feng, YunhuaX" To: "edk2-devel@lists.01.org" Thread-Topic: [PATCH] BaseTools: report error if flag in LABEL() invalid Thread-Index: AdOxNmNmwnFg/1ooRHai1Jnf+QkauA== Date: Thu, 1 Mar 2018 08:22:08 +0000 Message-ID: <47C64442C08CCD4089DC43B6B5E46BC482C852@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: <47C64442C08CCD4089DC43B6B5E46BC482C852@shsmsx102.ccr.corp.intel.com> x-originating-ip: [10.239.127.40] MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.23 Subject: [edk2] [PATCH] BaseTools: report error if flag in LABEL() invalid X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Gao, Liming" Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Flag in LABEL() is not valid C variable name, will report error Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng Reviewed-by: Yonghong Zhu --- BaseTools/Source/Python/Common/Expression.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Sourc= e/Python/Common/Expression.py index f1516d5c7b..40e6d32280 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -117,10 +117,16 @@ def SplitPcdValueString(String): raise BadExpression(ERR_STRING_TOKEN % Item) if Item: RetList.append(Item) return RetList =20 +def IsValidCString(Str): + ValidString =3D 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 =3D None): StrList =3D SplitString(String) for i, String in enumerate(StrList): @@ -883,17 +889,17 @@ class ValueExpressionEx(ValueExpression): ReOffset =3D re.compile('OFFSET_OF\((\w+)\)') LabelOffset =3D 0 for Index, Item in enumerate(PcdValueList): # compute byte offset of every LABEL Item =3D Item.strip() - try: - LabelList =3D ReLabel.findall(Item) + LabelList =3D ReLabel.findall(Item) + if LabelList: for Label in LabelList: + if not IsValidCString(Label): + raise BadExpression('%s is invalid= c variable string' % Label) if Label not in LabelDict.keys(): LabelDict[Label] =3D str(LabelOffs= et) - except: - pass if Item.startswith('UINT8'): LabelOffset =3D LabelOffset + 1 elif Item.startswith('UINT16'): LabelOffset =3D LabelOffset + 2 elif Item.startswith('UINT32'): --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel