From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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) X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False 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 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,407,1515484800"; d="dat'59?scan'59,208,59";a="30555384" 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 From: "Feng, YunhuaX" To: "edk2-devel@lists.01.org" CC: "Zhu, Yonghong" , "Gao, Liming" 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 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: [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: , X-List-Received-Date: Thu, 01 Mar 2018 02:10:04 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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=A0=3D=C3=AE=C2=B5=C2=A2=C3"F=C3=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 --- 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