[edk2] [PATCH] BaseTools: Report error GUID format if incorrectly

Feng, YunhuaX posted 1 patch 6 years, 2 months ago
Failed in applying to current master (apply log)
BaseTools/Source/Python/Common/Misc.py | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
[edk2] [PATCH] BaseTools: Report error GUID format if incorrectly
Posted by Feng, YunhuaX 6 years, 2 months ago
Flexible GUID format support like these:
1. { GUID("11E13869-1896-4A07-8B21-D8B23DD2A2B4") }
2. { GUID({ 0x11e13869, 0x1896, 0x4a07,{
    0x8b, 0x21, 0xd8, 0xb2, 0x3d, 0xd2, 0xa2, 0xb4 } }) }
3. { GUID(gEfiBlockIoProtocolGuid) }

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
---
 BaseTools/Source/Python/Common/Misc.py | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index b8c2ce1ddc..5a0bcd9bf7 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1535,16 +1535,10 @@ def ParseFieldValue (Value):
     if Value.startswith('GUID') and Value.endswith(')'):
         Value = Value.split('(', 1)[1][:-1].strip()
         if Value[0] == '{' and Value[-1] == '}':
-            Value = Value[1:-1].strip()
-            Value = Value.split('{', 1)
-            Value = ['%02x' % int(Item, 16) for Item in (Value[0] + Value[1][:-1]).split(',')]
-            if len(Value[0]) != 8:
-                Value[0] = '%08X' % int(Value[0], 16)
-            if len(Value[1]) != 4:
-                Value[1] = '%04X' % int(Value[1], 16)
-            if len(Value[2]) != 4:
-                Value[2] = '%04X' % int(Value[2], 16)
-            Value = '-'.join(Value[0:3]) + '-' + ''.join(Value[3:5]) + '-' + ''.join(Value[5:11])
+            TmpValue = GuidStructureStringToGuidString(Value)
+            if len(TmpValue) == 0:
+                raise BadExpression("Invalid GUID value string %s" % Value)
+            Value = TmpValue
         if Value[0] == '"' and Value[-1] == '"':
             Value = Value[1:-1]
         try:
-- 
2.12.2.windows.2

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] BaseTools: Report error GUID format if incorrectly
Posted by Zhu, Yonghong 6 years, 2 months ago
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com> 

Best Regards,
Zhu Yonghong


-----Original Message-----
From: Feng, YunhuaX 
Sent: Monday, February 05, 2018 11:43 AM
To: edk2-devel@lists.01.org
Cc: Zhu, Yonghong <yonghong.zhu@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [PATCH] BaseTools: Report error GUID format if incorrectly

Flexible GUID format support like these:
1. { GUID("11E13869-1896-4A07-8B21-D8B23DD2A2B4") } 2. { GUID({ 0x11e13869, 0x1896, 0x4a07,{
    0x8b, 0x21, 0xd8, 0xb2, 0x3d, 0xd2, 0xa2, 0xb4 } }) } 3. { GUID(gEfiBlockIoProtocolGuid) }

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
---
 BaseTools/Source/Python/Common/Misc.py | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index b8c2ce1ddc..5a0bcd9bf7 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1535,16 +1535,10 @@ def ParseFieldValue (Value):
     if Value.startswith('GUID') and Value.endswith(')'):
         Value = Value.split('(', 1)[1][:-1].strip()
         if Value[0] == '{' and Value[-1] == '}':
-            Value = Value[1:-1].strip()
-            Value = Value.split('{', 1)
-            Value = ['%02x' % int(Item, 16) for Item in (Value[0] + Value[1][:-1]).split(',')]
-            if len(Value[0]) != 8:
-                Value[0] = '%08X' % int(Value[0], 16)
-            if len(Value[1]) != 4:
-                Value[1] = '%04X' % int(Value[1], 16)
-            if len(Value[2]) != 4:
-                Value[2] = '%04X' % int(Value[2], 16)
-            Value = '-'.join(Value[0:3]) + '-' + ''.join(Value[3:5]) + '-' + ''.join(Value[5:11])
+            TmpValue = GuidStructureStringToGuidString(Value)
+            if len(TmpValue) == 0:
+                raise BadExpression("Invalid GUID value string %s" % Value)
+            Value = TmpValue
         if Value[0] == '"' and Value[-1] == '"':
             Value = Value[1:-1]
         try:
--
2.12.2.windows.2

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel