[edk2-devel] [PATCH v2] BaseTools: Fix parse PCD GUID expression issue

Feng, YunhuaX posted 1 patch 3 years, 11 months ago
Failed in applying to current master (apply log)
BaseTools/Source/Python/Common/Misc.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
[edk2-devel] [PATCH v2] BaseTools: Fix parse PCD GUID expression issue
Posted by Feng, YunhuaX 3 years, 11 months ago
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2686

The build tool will give an incorrect GUID value if the GUID includes character ' or " ASCII value.
This patch is going to fix this issue.

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
---
 BaseTools/Source/Python/Common/Misc.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index da5fb380f0..ad55671080 100755
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -37,10 +37,11 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
 from Common.LongFilePathSupport import CopyLongFilePath as CopyLong
 from Common.LongFilePathSupport import LongFilePath as LongFilePath
 from Common.MultipleWorkspace import MultipleWorkspace as mws
 from CommonDataClass.Exceptions import BadExpression
 from Common.caching import cached_property
+import struct

 ArrayIndex = re.compile("\[\s*[0-9a-fA-FxX]*\s*\]")
 ## Regular expression used to find out place holders in string template
 gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)

@@ -1153,17 +1154,16 @@ def ParseFieldValue (Value):
                 raise BadExpression("Invalid GUID value string %s" % Value)
             Value = TmpValue
         if Value[0] == '"' and Value[-1] == '"':
             Value = Value[1:-1]
         try:
-            Value = str(uuid.UUID(Value).bytes_le)
-            if Value.startswith("b'"):
-                Value = Value[2:-1]
-            Value = "'" + Value + "'"
+            Value = uuid.UUID(Value).bytes_le
+            ValueL, ValueH = struct.unpack('2Q', Value)
+            Value = (ValueH << 64 ) | ValueL
+
         except ValueError as Message:
             raise BadExpression(Message)
-        Value, Size = ParseFieldValue(Value)
         return Value, 16
     if Value.startswith('L"') and Value.endswith('"'):
         # Unicode String
         # translate escape character
         Value = Value[1:]
--
2.12.2.windows.2


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#58921): https://edk2.groups.io/g/devel/message/58921
Mute This Topic: https://groups.io/mt/74087168/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH v2] BaseTools: Fix parse PCD GUID expression issue
Posted by Bob Feng 3 years, 11 months ago
Reviewed-by: Bob Feng <bob.c.feng@intel.com>

-----Original Message-----
From: Feng, YunhuaX <yunhuax.feng@intel.com> 
Sent: Saturday, May 9, 2020 8:15 AM
To: devel@edk2.groups.io
Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [PATCH v2] BaseTools: Fix parse PCD GUID expression issue

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2686

The build tool will give an incorrect GUID value if the GUID includes character ' or " ASCII value.
This patch is going to fix this issue.

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
---
 BaseTools/Source/Python/Common/Misc.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index da5fb380f0..ad55671080 100755
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -37,10 +37,11 @@ from Common.LongFilePathSupport import OpenLongFilePath as open  from Common.LongFilePathSupport import CopyLongFilePath as CopyLong  from Common.LongFilePathSupport import LongFilePath as LongFilePath  from Common.MultipleWorkspace import MultipleWorkspace as mws  from CommonDataClass.Exceptions import BadExpression  from Common.caching import cached_property
+import struct
 
 ArrayIndex = re.compile("\[\s*[0-9a-fA-FxX]*\s*\]")
 ## Regular expression used to find out place holders in string template  gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)
 
@@ -1153,17 +1154,16 @@ def ParseFieldValue (Value):
                 raise BadExpression("Invalid GUID value string %s" % Value)
             Value = TmpValue
         if Value[0] == '"' and Value[-1] == '"':
             Value = Value[1:-1]
         try:
-            Value = str(uuid.UUID(Value).bytes_le)
-            if Value.startswith("b'"):
-                Value = Value[2:-1]
-            Value = "'" + Value + "'"
+            Value = uuid.UUID(Value).bytes_le
+            ValueL, ValueH = struct.unpack('2Q', Value)
+            Value = (ValueH << 64 ) | ValueL
+
         except ValueError as Message:
             raise BadExpression(Message)
-        Value, Size = ParseFieldValue(Value)
         return Value, 16
     if Value.startswith('L"') and Value.endswith('"'):
         # Unicode String
         # translate escape character
         Value = Value[1:]
--
2.12.2.windows.2


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#59393): https://edk2.groups.io/g/devel/message/59393
Mute This Topic: https://groups.io/mt/74087168/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-