From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 0CFC221142FF5 for ; Sat, 29 Sep 2018 18:49:46 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Sep 2018 18:49:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,322,1534834800"; d="scan'208";a="77222419" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga007.jf.intel.com with ESMTP; 29 Sep 2018 18:49:46 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sat, 29 Sep 2018 18:49:45 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.245]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.27]) with mapi id 14.03.0319.002; Sun, 30 Sep 2018 09:49:43 +0800 From: "Zhu, Yonghong" To: "Zhu, Yonghong" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [edk2] [Patch] BaseTools: refactor the error for PCD value is negative or exceed max Thread-Index: AQHUV6GubQ53s2C8rkqkyloWuTKPoKUIEFMQ Date: Sun, 30 Sep 2018 01:49:43 +0000 Message-ID: References: <1538190493-18412-1-git-send-email-yonghong.zhu@intel.com> In-Reply-To: <1538190493-18412-1-git-send-email-yonghong.zhu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch] BaseTools: refactor the error for PCD value is negative or exceed max 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: Sun, 30 Sep 2018 01:49:47 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yonghong Zhu =20 Best Regards, Zhu Yonghong -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Yong= hong Zhu Sent: Saturday, September 29, 2018 11:08 AM To: edk2-devel@lists.01.org Cc: Gao, Liming Subject: [edk2] [Patch] BaseTools: refactor the error for PCD value is nega= tive or exceed max From: zhijufan refactor the error handling for the PCD value that is negative or it exceed= the max value. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan --- BaseTools/Source/Python/AutoGen/GenC.py | 57 ++++++++---------------------= ---- BaseTools/Source/Python/BPDG/GenVpd.py | 44 ++++++++----------------= - BaseTools/Source/Python/Common/Misc.py | 4 +++ 3 files changed, 30 insertions(+), 75 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Pyt= hon/AutoGen/GenC.py index f455f83..09626d0 100644 --- a/BaseTools/Source/Python/AutoGen/GenC.py +++ b/BaseTools/Source/Python/AutoGen/GenC.py @@ -1013,54 +1013,23 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, P= cd): ValueNumber =3D int (Value, 0) except: EdkLogger.error("build", AUTOGEN_ERROR, "PCD value is not valid dec or hex number = for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName= , TokenCName), ExtraData=3D"[%s]" % str(Info)) - if Pcd.DatumType =3D=3D TAB_UINT64: - if ValueNumber < 0: - EdkLogger.error("build", AUTOGEN_ERROR, - "PCD can't be set to negative value fo= r datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, = TokenCName), - ExtraData=3D"[%s]" % str(Info)) - elif ValueNumber >=3D 0x10000000000000000: - EdkLogger.error("build", AUTOGEN_ERROR, - "Too large PCD value for datum type [%= s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), - ExtraData=3D"[%s]" % str(Info)) - if not Value.endswith('ULL'): - Value +=3D 'ULL' - elif Pcd.DatumType =3D=3D TAB_UINT32: - if ValueNumber < 0: - EdkLogger.error("build", AUTOGEN_ERROR, - "PCD can't be set to negative value fo= r datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, = TokenCName), - ExtraData=3D"[%s]" % str(Info)) - elif ValueNumber >=3D 0x100000000: - EdkLogger.error("build", AUTOGEN_ERROR, - "Too large PCD value for datum type [%= s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), - ExtraData=3D"[%s]" % str(Info)) - if not Value.endswith('U'): - Value +=3D 'U' - elif Pcd.DatumType =3D=3D TAB_UINT16: - if ValueNumber < 0: - EdkLogger.error("build", AUTOGEN_ERROR, - "PCD can't be set to negative value fo= r datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, = TokenCName), - ExtraData=3D"[%s]" % str(Info)) - elif ValueNumber >=3D 0x10000: - EdkLogger.error("build", AUTOGEN_ERROR, - "Too large PCD value for datum type [%= s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), - ExtraData=3D"[%s]" % str(Info)) - if not Value.endswith('U'): - Value +=3D 'U' - elif Pcd.DatumType =3D=3D TAB_UINT8: - if ValueNumber < 0: - EdkLogger.error("build", AUTOGEN_ERROR, - "PCD can't be set to negative value fo= r datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, = TokenCName), - ExtraData=3D"[%s]" % str(Info)) - elif ValueNumber >=3D 0x100: - EdkLogger.error("build", AUTOGEN_ERROR, - "Too large PCD value for datum type [%= s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), - ExtraData=3D"[%s]" % str(Info)) - if not Value.endswith('U'): - Value +=3D 'U' + if ValueNumber < 0: + EdkLogger.error("build", AUTOGEN_ERROR, + "PCD can't be set to negative value for da= tum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Toke= nCName), + ExtraData=3D"[%s]" % str(Info)) + elif ValueNumber > MAX_VAL_TYPE[Pcd.DatumType]: + EdkLogger.error("build", AUTOGEN_ERROR, + "Too large PCD value for datum type [%s] o= f PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), + ExtraData=3D"[%s]" % str(Info)) + if Pcd.DatumType =3D=3D TAB_UINT64 and not Value.endswith('ULL= '): + Value +=3D 'ULL' + elif Pcd.DatumType !=3D TAB_UINT64 and not Value.endswith('U')= : + Value +=3D 'U' + if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES: if not Pcd.MaxDatumSize: EdkLogger.error("build", AUTOGEN_ERROR, "Unknown [MaxDatumSize] of PCD [%s.%s]" % = (Pcd.TokenSpaceGuidCName, TokenCName), ExtraData=3D"[%s]" % str(Info)) diff --git= a/BaseTools/Source/Python/BPDG/GenVpd.py b/BaseTools/Source/Python/BPDG/Ge= nVpd.py index c5e91a3..d7852d2 100644 --- a/BaseTools/Source/Python/BPDG/GenVpd.py +++ b/BaseTools/Source/Python/BPDG/GenVpd.py @@ -19,10 +19,11 @@ from io import BytesIO from . import StringTable as st= import array import re from Common.LongFilePathSupport import OpenLongF= ilePath as open from struct import * +from Common.DataType import MAX_SIZE_TYPE, MAX_VAL_TYPE import Common.EdkLogger as EdkLogger import Common.BuildToolError as BuildToolError =20 _FORMAT_CHAR =3D {1: 'B', 2: 'H', @@ -123,41 +124,22 @@ class PcdEntry: def _PackIntValue(self, IntValue, Size): if Size not in _FORMAT_CHAR: EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid size %d for PCD %s in integer datum s= ize(File: %s Line: %s)." % (Size, self.PcdCName, self.FileName, self.Lineno= )) =20 - if Size =3D=3D 1: - if IntValue < 0: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "PCD can't be set to negative value %d for= PCD %s in UINT8 datum type(File: %s Line: %s)." % (IntValue, self.PcdCName= , self.FileName, self.Lineno)) - elif IntValue >=3D 0x100: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "Too large PCD value %d for datum type UIN= T8 for PCD %s(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileNam= e, self.Lineno)) - elif Size =3D=3D 2: - if IntValue < 0: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "PCD can't be set to negative value %d for= PCD %s in UINT16 datum type(File: %s Line: %s)." % (IntValue, self.PcdCNam= e, self.FileName, self.Lineno)) - elif IntValue >=3D 0x10000: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "Too large PCD value %d for datum type UIN= T16 for PCD %s(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileNa= me, self.Lineno)) - elif Size =3D=3D 4: - if IntValue < 0: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "PCD can't be set to negative value %d for= PCD %s in UINT32 datum type(File: %s Line: %s)." % (IntValue, self.PcdCNam= e, self.FileName, self.Lineno)) - elif IntValue >=3D 0x100000000: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "Too large PCD value %d for datum type UIN= T32 for PCD %s(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileNa= me, self.Lineno)) - elif Size =3D=3D 8: - if IntValue < 0: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "PCD can't be set to negative value %d for= PCD %s in UINT32 datum type(File: %s Line: %s)." % (IntValue, self.PcdCNam= e, self.FileName, self.Lineno)) - elif IntValue >=3D 0x10000000000000000: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "Too large PCD value %d for datum type UIN= T32 for PCD %s(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileNa= me, self.Lineno)) - else: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "Invalid size %d for PCD %s in integer datum s= ize(File: %s Line: %s)." % (Size, self.PcdCName, self.FileName, self.Lineno= )) + for Type, MaxSize in MAX_SIZE_TYPE.items(): + if Type =3D=3D 'BOOLEAN': + continue + if Size =3D=3D MaxSize: + if IntValue < 0: + EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, + "PCD can't be set to negative value %d= for PCD %s in %s datum type(File: %s Line: %s)." % ( + IntValue, self.PcdCName, Type, self.Fi= leName, self.Lineno)) + elif IntValue > MAX_VAL_TYPE[Type]: + EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, + "Too large PCD value %d for datum type= %s for PCD %s(File: %s Line: %s)." % ( + IntValue, Type, self.PcdCName,=20 + self.FileName, self.Lineno)) =20 try: self.PcdValue =3D pack(_FORMAT_CHAR[Size], IntValue) except: EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, diff --= git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Comm= on/Misc.py index fb6a844..0efd8b0 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -1587,12 +1587,16 @@ def CheckPcdDatum(Type, Value): elif Type =3D=3D 'BOOLEAN': if Value not in ['TRUE', 'True', 'true', '0x1', '0x01', '1', 'FALS= E', 'False', 'false', '0x0', '0x00', '0']: return False, "Invalid value [%s] of type [%s]; must be one of= TRUE, True, true, 0x1, 0x01, 1"\ ", FALSE, False, false, 0x0, 0x00, 0" % (Value, = Type) elif Type in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64]: + if Value and int(Value, 0) < 0: + return False, "PCD can't be set to negative value[%s] for=20 + datum type [%s]" % (Value, Type) try: Value =3D long(Value, 0) + if Value > MAX_VAL_TYPE[Type]: + return False, "Too large PCD value[%s] for datum type=20 + [%s]" % (Value, Type) except: return False, "Invalid value [%s] of type [%s];"\ " must be a hexadecimal, decimal or octal in C l= anguage format." % (Value, Type) else: return True, "StructurePcd" -- 2.6.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel