From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 427F22255D6FE for ; Thu, 1 Mar 2018 18:09:35 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Mar 2018 18:15:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,409,1515484800"; d="scan'208";a="35299376" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga001.jf.intel.com with ESMTP; 01 Mar 2018 18:15:44 -0800 Received: from fmsmsx124.amr.corp.intel.com (10.18.125.39) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 1 Mar 2018 18:15:44 -0800 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by fmsmsx124.amr.corp.intel.com (10.18.125.39) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 1 Mar 2018 18:15:43 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.116]) by shsmsx102.ccr.corp.intel.com ([169.254.2.124]) with mapi id 14.03.0319.002; Fri, 2 Mar 2018 10:15:42 +0800 From: "Zhu, Yonghong" To: "Feng, YunhuaX" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [PATCH] BaseTools: report error if flag in LABEL() invalid Thread-Index: AdOxNmNmwnFg/1ooRHai1Jnf+QkauAAle71g Date: Fri, 2 Mar 2018 02:15:41 +0000 Message-ID: References: <47C64442C08CCD4089DC43B6B5E46BC482C852@shsmsx102.ccr.corp.intel.com> In-Reply-To: <47C64442C08CCD4089DC43B6B5E46BC482C852@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [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: , X-List-Received-Date: Fri, 02 Mar 2018 02:09:36 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yonghong Zhu Best Regards, Zhu Yonghong -----Original Message----- From: Feng, YunhuaX=20 Sent: Thursday, March 01, 2018 4:22 PM To: edk2-devel@lists.01.org Cc: Zhu, Yonghong ; Gao, Liming Subject: [PATCH] BaseTools: report error if flag in LABEL() invalid 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 --- 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=20 + 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'): -- 2.12.2.windows.2