From nobody Mon Dec 23 05:44:09 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 1519870574131713.6673352175258; Wed, 28 Feb 2018 18:16:14 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 28DAD223522B8; Wed, 28 Feb 2018 18:10:05 -0800 (PST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 C7599209574F7 for ; Wed, 28 Feb 2018 18:10:03 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Feb 2018 18:16:11 -0800 Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by FMSMGA003.fm.intel.com with ESMTP; 28 Feb 2018 18:16:10 -0800 Received: from fmsmsx126.amr.corp.intel.com (10.18.125.43) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 28 Feb 2018 18:16:10 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX126.amr.corp.intel.com (10.18.125.43) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 28 Feb 2018 18:16:10 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.124]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.125]) with mapi id 14.03.0319.002; Thu, 1 Mar 2018 10:16:08 +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.31; helo=mga06.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="30555384" From: "Feng, YunhuaX" To: "edk2-devel@lists.01.org" Thread-Topic: [PATCH] BaseTools: Fix eval parse string issue Thread-Index: AdOxA0HAUP6BTkP2QaGvDKjnx2Mfxg== Date: Thu, 1 Mar 2018 02:16:07 +0000 Message-ID: <47C64442C08CCD4089DC43B6B5E46BC482C790@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: <47C64442C08CCD4089DC43B6B5E46BC482C790@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: Fix eval parse string issue 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" eval argument start with " or ', but it is unicode string, will encounter error: List =3D list(eval(Value)) # translate escape character File "", line 1 'j=C3=83=C2=A0=3D=C3=83=C2=AE=C3=82=C2=B5=C3=82=C2=A2=C3=83"F=C3=83=C2= =A0 ^ SyntaxError: EOL while scanning string literal Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng Reviewed-by: Yonghong Zhu =20 --- BaseTools/Source/Python/Common/Misc.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Pyth= on/Common/Misc.py index a7e7797d04..af374d804d 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -1552,37 +1552,59 @@ def ParseFieldValue (Value): raise BadExpression('%s' % Message) Value, Size =3D ParseFieldValue(Value) return Value, 16 if Value.startswith('L"') and Value.endswith('"'): # Unicode String - List =3D list(eval(Value[1:])) # translate escape character + # translate escape character + Value =3D Value[1:] + try: + Value =3D eval(Value) + except: + Value =3D Value[1:-1] + List =3D list(Value) List.reverse() Value =3D 0 for Char in List: Value =3D (Value << 16) | ord(Char) return Value, (len(List) + 1) * 2 if Value.startswith('"') and Value.endswith('"'): # ASCII String - List =3D list(eval(Value)) # translate escape character + # translate escape character + try: + Value =3D eval(Value) + except: + Value =3D Value[1:-1] + List =3D list(Value) List.reverse() Value =3D 0 for Char in List: Value =3D (Value << 8) | ord(Char) return Value, len(List) + 1 if Value.startswith("L'") and Value.endswith("'"): # Unicode Character Constant - List =3D list(eval(Value[1:])) # translate escape character + # translate escape character + Value =3D Value[1:] + try: + Value =3D eval(Value) + except: + Value =3D Value[1:-1] + List =3D list(Value) if len(List) =3D=3D 0: raise BadExpression('Length %s is %s' % (Value, len(List))) List.reverse() Value =3D 0 for Char in List: Value =3D (Value << 16) | ord(Char) return Value, len(List) * 2 if Value.startswith("'") and Value.endswith("'"): # Character constant - List =3D list(eval(Value)) # translate escape character + # translate escape character + try: + Value =3D eval(Value) + except: + Value =3D Value[1:-1] + List =3D list(Value) if len(List) =3D=3D 0: raise BadExpression('Length %s is %s' % (Value, len(List))) List.reverse() Value =3D 0 for Char in List: --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel