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=yonghong.zhu@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 A9BEC2117FD61 for ; Tue, 30 Oct 2018 06:27:50 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2018 06:27:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,444,1534834800"; d="scan'208";a="275671037" Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.127]) by fmsmga005.fm.intel.com with ESMTP; 30 Oct 2018 06:27:48 -0700 From: Yonghong Zhu To: edk2-devel@lists.01.org Cc: zhijufan , Liming Gao Date: Tue, 30 Oct 2018 21:27:44 +0800 Message-Id: <1540906064-15080-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [Patch] BaseTools: Add special handle for '\' use in Pcd Value X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Oct 2018 13:27:50 -0000 From: zhijufan Case: gEfiOzmosisPkgTokenSpaceGuid.PcdBootLogFolderPath|L"\\Logs\\"|VOID*|12 Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=1287 Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan --- BaseTools/Source/Python/Common/Expression.py | 13 ++++++++++++- BaseTools/Source/Python/Common/Misc.py | 9 ++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py index 05459b9..6eec0de 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -20,10 +20,11 @@ from CommonDataClass.Exceptions import WrnExpression from .Misc import GuidStringToGuidStructureString, ParseFieldValue import Common.EdkLogger as EdkLogger import copy from Common.DataType import * import sys +import random, string ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].' ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].' ERR_MATCH = 'No matching right parenthesis.' ERR_STRING_TOKEN = 'Bad string token: [%s].' @@ -53,10 +54,12 @@ PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$') # Split string to list according double quote # For example: abc"de\"f"ghi"jkl"mn will be: ['abc', '"de\"f"', 'ghi', '"jkl"', 'mn'] # def SplitString(String): # There might be escaped quote: "abc\"def\\\"ghi", 'abc\'def\\\'ghi' + RanStr = ''.join(random.sample(string.ascii_letters + string.digits, 8)) + String = String.replace('\\\\', RanStr).strip() RetList = [] InSingleQuote = False InDoubleQuote = False Item = '' for i, ch in enumerate(String): @@ -85,15 +88,20 @@ def SplitString(String): Item += String[i] if InSingleQuote or InDoubleQuote: raise BadExpression(ERR_STRING_TOKEN % Item) if Item: RetList.append(Item) + for i, ch in enumerate(RetList): + if RanStr in ch: + RetList[i] = ch.replace(RanStr,'\\\\') return RetList def SplitPcdValueString(String): # There might be escaped comma in GUID() or DEVICE_PATH() or " " # or ' ' or L' ' or L" " + RanStr = ''.join(random.sample(string.ascii_letters + string.digits, 8)) + String = String.replace('\\\\', RanStr).strip() RetList = [] InParenthesis = 0 InSingleQuote = False InDoubleQuote = False Item = '' @@ -122,10 +130,13 @@ def SplitPcdValueString(String): Item += String[i] if InSingleQuote or InDoubleQuote or InParenthesis: raise BadExpression(ERR_STRING_TOKEN % Item) if Item: RetList.append(Item) + for i, ch in enumerate(RetList): + if RanStr in ch: + RetList[i] = ch.replace(RanStr,'\\\\') return RetList def IsValidCName(Str): return True if __ValidString.match(Str) else False @@ -388,11 +399,11 @@ class ValueExpression(BaseExpression): if Val == 'L""': Val = False elif not Val: Val = False RealVal = '""' - elif not Val.startswith('L"') and not Val.startswith('{') and not Val.startswith("L'"): + elif not Val.startswith('L"') and not Val.startswith('{') and not Val.startswith("L'") and not Val.startswith("'"): Val = True RealVal = '"' + RealVal + '"' # The expression has been parsed, but the end of expression is not reached # It means the rest does not comply EBNF of diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index b32b7cd..b27268a 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -15,11 +15,11 @@ # Import Modules # from __future__ import absolute_import import Common.LongFilePathOs as os import sys -import string +import random, string import threading import time import re import pickle import array @@ -1234,11 +1234,12 @@ def IsFieldValueAnArray (Value): if Value[0] == "'" and Value[-1] == "'" and len(list(Value[1:-1])) > 1: return True return False def AnalyzePcdExpression(Setting): - Setting = Setting.strip() + RanStr = ''.join(random.sample(string.ascii_letters + string.digits, 8)) + Setting = Setting.replace('\\\\', RanStr).strip() # There might be escaped quote in a string: \", \\\" , \', \\\' Data = Setting # There might be '|' in string and in ( ... | ... ), replace it with '-' NewStr = '' InSingleQuoteStr = False @@ -1267,11 +1268,13 @@ def AnalyzePcdExpression(Setting): if Pos < 0: FieldList.append(Setting[StartPos:].strip()) break FieldList.append(Setting[StartPos:Pos].strip()) StartPos = Pos + 1 - + for i, ch in enumerate(FieldList): + if RanStr in ch: + FieldList[i] = ch.replace(RanStr,'\\\\') return FieldList def ParseDevPathValue (Value): if '\\' in Value: Value.replace('\\', '/').replace(' ', '') -- 2.6.1.windows.1