From nobody Thu Apr 25 13:53:21 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; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1533708867108777.1434455086439; Tue, 7 Aug 2018 23:14:27 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A6F4D210DF757; Tue, 7 Aug 2018 23:14:25 -0700 (PDT) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 C2FDE210DF741 for ; Tue, 7 Aug 2018 23:14:24 -0700 (PDT) Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Aug 2018 23:14:24 -0700 Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga007.fm.intel.com with ESMTP; 07 Aug 2018 23:14:23 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 7 Aug 2018 23:14:23 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.226]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.240]) with mapi id 14.03.0319.002; Wed, 8 Aug 2018 14:14:21 +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=192.55.52.93; helo=mga11.intel.com; envelope-from=yunhuax.feng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,456,1526367600"; d="dat'59?scan'59,208,59";a="60754810" From: "Feng, YunhuaX" To: "edk2-devel@lists.01.org" Thread-Topic: [PATCH] BaseTools: Check GUID C structure format Thread-Index: AdQu3wselrGgmCn1S3uC3yrdoyN0fQ== Date: Wed, 8 Aug 2018 06:14:20 +0000 Message-ID: <47C64442C08CCD4089DC43B6B5E46BC48B69DA@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: <47C64442C08CCD4089DC43B6B5E46BC48B69DA@shsmsx102.ccr.corp.intel.com> x-originating-ip: [10.239.127.40] MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.27 Subject: [edk2] [PATCH] BaseTools: Check GUID C structure format X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 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: RDMRC_1 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" GUID C format must conform to {8,4,4,{2,2,2,2,2,2,2,2}} Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng --- 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/Sourc= e/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 =3D re.compile(r'{}{{4}}'.format(_HexChar)) gHexPattern =3D re.compile(r'0[xX]{}+'.format(_HexChar)) gHexPatternAll =3D re.compile(r'0[xX]{}+$'.format(_HexChar)) =20 ## Regular expressions for string identifier checking gIdentifierPattern =3D re.compile('^[a-zA-Z][a-zA-Z0-9_]*$', re.UNICODE) +## Regular expression for GUID c structure format +_GuidCFormatPattern =3D 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=3D_HexChar) +gGuidCFormatPattern =3D re.compile(r"{}".format(_GuidCFormatPattern)) =20 # # A global variable for whether current build in AutoGen phase or not. # gAutoGenPhase =3D False diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Pyth= on/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-xxxx= xxxxxxxx format # def GuidStructureStringToGuidString(GuidValue): + if not GlobalData.gGuidCFormatPattern.match(GuidValue): + return '' guidValueString =3D GuidValue.lower().replace("{", "").replace("}", ""= ).replace(" ", "").replace(";", "") guidValueList =3D guidValueString.split(",") if len(guidValueList) !=3D 11: return '' #EdkLogger.error(None, None, "Invalid GUID value string %s" % Guid= Value) @@ -1325,11 +1327,11 @@ def ParseFieldValue (Value): return Value, 8 if Value.startswith(TAB_GUID) and Value.endswith(')'): Value =3D Value.split('(', 1)[1][:-1].strip() if Value[0] =3D=3D '{' and Value[-1] =3D=3D '}': TmpValue =3D GuidStructureStringToGuidString(Value) - if len(TmpValue) =3D=3D 0: + if not TmpValue: raise BadExpression("Invalid GUID value string %s" % Value) Value =3D TmpValue if Value[0] =3D=3D '"' and Value[-1] =3D=3D '"': Value =3D Value[1:-1] try: --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel