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.126; helo=mga18.intel.com; envelope-from=bob.c.feng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (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 9E13F21163272 for ; Wed, 24 Oct 2018 00:24:56 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Oct 2018 00:24:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,419,1534834800"; d="scan'208";a="90793183" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by FMSMGA003.fm.intel.com with ESMTP; 24 Oct 2018 00:24:55 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 24 Oct 2018 00:24:55 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.102]) by shsmsx102.ccr.corp.intel.com ([169.254.2.84]) with mapi id 14.03.0415.000; Wed, 24 Oct 2018 15:24:53 +0800 From: "Feng, Bob C" To: "Zhao, ZhiqiangX" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [PATCH] BaseTools: add ASSERT checker for array buffer in fdf and command line Thread-Index: AQHUaeKRrdYXskKjmk65IsX8KgX/J6UuAX0w Date: Wed, 24 Oct 2018 07:24:53 +0000 Message-ID: <08650203BA1BD64D8AD9B6D5D74A85D15FFE5ECB@SHSMSX101.ccr.corp.intel.com> References: <20181022083743.92736-1-zhiqiangx.zhao@intel.com> In-Reply-To: <20181022083743.92736-1-zhiqiangx.zhao@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYmNhZmIwODUtOTc5NC00NTg2LTgwMjYtOWYyMzA5NTc5ZDQyIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiRXN3MTdvdkFyVHVwZjZSMkdHREd6b3RHNjhGaUFtRVBBcU5TTHZpYzczekR0TEtnRUhPdWZNUW8xYURRUU5PZCJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] BaseTools: add ASSERT checker for array buffer in fdf and command line 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: Wed, 24 Oct 2018 07:24:56 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Bob Feng -----Original Message----- From: Zhao, ZhiqiangX=20 Sent: Monday, October 22, 2018 4:38 PM To: edk2-devel@lists.01.org Cc: Zhao, ZhiqiangX ; Gao, Liming ; Zhu, Yonghong ; Feng, Bob C Subject: [PATCH] BaseTools: add ASSERT checker for array buffer in fdf and = command line For structure PCD in fdf file and command line, 1. use compiler time assert= to check the array index, report error if array index exceeds the array nu= mber. 2. use compiler time assert to check the array size, report error if the us= er declared size in header file is smaller than the user used in fdf file a= nd command line. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: ZhiqiangX Zhao Cc: Liming Gao Cc: Yonghong Zhu Cc: Bob Feng --- BaseTools/Source/Python/Workspace/DscBuildData.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/= Source/Python/Workspace/DscBuildData.py index b0e88a93ce..01a565aa08 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -2013,8 +2013,12 @@ class DscBuildData(PlatformBuildClassObject): # CApp =3D CApp + ' FieldSize =3D __FIELD_SIZE(%s, %s);= \n' % (Pcd.DatumType, FieldName) CApp =3D CApp + ' Value =3D %s; // From %s Line %= d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[Fie= ldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) + CApp =3D CApp + ' __STATIC_ASSERT((__FIELD_SIZE(%s,=20 + %s) >=3D %d) || (__FIELD_SIZE(%s, %s) =3D=3D 0), "Input buffer exceeds th= e=20 + buffer array"); // From %s Line %d Value %s\n' % (Pcd.DatumType,=20 + FieldName, ValueSize, Pcd.DatumType, FieldName,=20 + FieldList[FieldName][1], FieldList[FieldName][2],=20 + FieldList[FieldName][0]) CApp =3D CApp + ' memcpy (&Pcd->%s, Value, (FieldSize= > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, Valu= eSize) else: + if '[' in FieldName and ']' in FieldName: + Index =3D int(FieldName.split('[')[1].split(']')[0= ]) + CApp =3D CApp + ' __STATIC_ASSERT((%d <=20 + __ARRAY_SIZE(Pcd->%s)) || (__ARRAY_SIZE(Pcd->%s) =3D=3D 0), "array index= =20 + exceeds the array number"); // From %s Line %d Index of %s\n' %=20 + (Index, FieldName.split('[')[0], FieldName.split('[')[0],=20 + FieldList[FieldName][1], FieldList[FieldName][2], FieldName) if ValueSize > 4: CApp =3D CApp + ' Pcd->%s =3D %dULL; // From %s L= ine %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[= FieldName][2], FieldList[FieldName][0]) else: @@ -2077,8 +2081,12 @@ class DscBuildData(PlatformBuildClassObject): # CApp =3D CApp + ' FieldSize =3D __FIELD_SIZE(%s, %s);= \n' % (Pcd.DatumType, FieldName) CApp =3D CApp + ' Value =3D %s; // From %s Line %= d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[Fie= ldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) + CApp =3D CApp + ' __STATIC_ASSERT((__FIELD_SIZE(%s,=20 + %s) >=3D %d) || (__FIELD_SIZE(%s, %s) =3D=3D 0), "Input buffer exceeds th= e=20 + buffer array"); // From %s Line %d Value %s\n' % (Pcd.DatumType,=20 + FieldName, ValueSize, Pcd.DatumType, FieldName,=20 + FieldList[FieldName][1], FieldList[FieldName][2],=20 + FieldList[FieldName][0]) CApp =3D CApp + ' memcpy (&Pcd->%s, Value, (FieldSize= > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, Valu= eSize) else: + if '[' in FieldName and ']' in FieldName: + Index =3D int(FieldName.split('[')[1].split(']')[0= ]) + CApp =3D CApp + ' __STATIC_ASSERT((%d <=20 + __ARRAY_SIZE(Pcd->%s)) || (__ARRAY_SIZE(Pcd->%s) =3D=3D 0), "array index= =20 + exceeds the array number"); // From %s Line %d Index of %s\n' %=20 + (Index, FieldName.split('[')[0], FieldName.split('[')[0],=20 + FieldList[FieldName][1], FieldList[FieldName][2], FieldName) if ValueSize > 4: CApp =3D CApp + ' Pcd->%s =3D %dULL; // From %s L= ine %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[= FieldName][2], FieldList[FieldName][0]) else: -- 2.14.1.windows.1