From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: michael.d.kinney@intel.com) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by groups.io with SMTP; Wed, 10 Jul 2019 13:10:31 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jul 2019 13:10:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,475,1557212400"; d="scan'208";a="341170561" Received: from orsmsx107.amr.corp.intel.com ([10.22.240.5]) by orsmga005.jf.intel.com with ESMTP; 10 Jul 2019 13:10:30 -0700 Received: from orsmsx125.amr.corp.intel.com (10.22.240.125) by ORSMSX107.amr.corp.intel.com (10.22.240.5) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 10 Jul 2019 13:10:29 -0700 Received: from orsmsx113.amr.corp.intel.com ([169.254.9.128]) by ORSMSX125.amr.corp.intel.com ([169.254.3.92]) with mapi id 14.03.0439.000; Wed, 10 Jul 2019 13:10:29 -0700 From: "Michael D Kinney" To: "Gao, Liming" , "devel@edk2.groups.io" , "leif.lindholm@linaro.org" , "Kinney, Michael D" CC: "Gao, Zhichao" , "Feng, Bob C" , Andrew Fish , Laszlo Ersek Subject: Re: [edk2-devel] [Patch v3] BaseTools: Fix GCC compiler failure in new added tools. Thread-Topic: [edk2-devel] [Patch v3] BaseTools: Fix GCC compiler failure in new added tools. Thread-Index: AQHVNjw4pds8nTxiAUyesXTu0+pnj6bDEGYAgAFDLgD///af0A== Date: Wed, 10 Jul 2019 20:10:28 +0000 Message-ID: References: <1562666013-13188-1-git-send-email-liming.gao@intel.com> <20190709182559.to6n5pifdkegc7yy@bivouac.eciton.net> <4A89E2EF3DFEDB4C8BFDE51014F606A14E4A53C2@SHSMSX104.ccr.corp.intel.com> In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14E4A53C2@SHSMSX104.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action x-originating-ip: [10.22.254.140] MIME-Version: 1.0 Return-Path: michael.d.kinney@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Liming, I agree that edk2-staging is a good place to work on cleaning these tools up. Please revert the commit of these tools today so GCC builds are not broken. Thanks, Mike > -----Original Message----- > From: Gao, Liming > Sent: Wednesday, July 10, 2019 6:43 AM > To: devel@edk2.groups.io; leif.lindholm@linaro.org > Cc: Gao, Zhichao ; Feng, Bob C > ; Andrew Fish ; > Laszlo Ersek ; Kinney, Michael D > > Subject: RE: [edk2-devel] [Patch v3] BaseTools: Fix GCC > compiler failure in new added tools. >=20 > Lefi: >=20 > > -----Original Message----- > > From: devel@edk2.groups.io > [mailto:devel@edk2.groups.io] On Behalf Of > > Leif Lindholm > > Sent: Wednesday, July 10, 2019 2:26 AM > > To: devel@edk2.groups.io; Gao, Liming > > > Cc: Gao, Zhichao ; Feng, Bob C > > ; Andrew Fish ; > Laszlo Ersek > > ; Kinney, Michael D > > > Subject: Re: [edk2-devel] [Patch v3] BaseTools: Fix GCC > compiler failure in new added tools. > > > > Hi Liming, > > > > On Tue, Jul 09, 2019 at 05:53:33PM +0800, Liming Gao > wrote: > > > From: gaozhic > > > > > > GCC 7 or 8 reports some warnings in new added > FCE/FMMT/BlmLib. > > > > Please list the specific warnings addressed. > > (But also see my comments below - I think this utility > needs ripping > > out and rewriting.) > > > > > Signed-off-by: Liming Gao > > > Cc: Bob Feng > > > --- > > > In V2: > > > Fix GCC8 compiler issue. > > > > > > In V3: > > > Fix snprintf wrong replacement. > > > > > > BaseTools/Source/C/BfmLib/BfmLib.c | > 117 +++++++++++---------- > > > BaseTools/Source/C/FCE/BinaryParse.c | > 2 +- > > > BaseTools/Source/C/FMMT/FirmwareModuleManagement.c | > 2 +- > > > BaseTools/Source/C/FMMT/FmmtLib.c | > 117 +++++++++++---------- > > > 4 files changed, 122 insertions(+), 116 deletions(-) > > > > > > diff --git a/BaseTools/Source/C/BfmLib/BfmLib.c > > > b/BaseTools/Source/C/BfmLib/BfmLib.c > > > index 9dedda3da2..8d0ec9038c 100644 > > > --- a/BaseTools/Source/C/BfmLib/BfmLib.c > > > +++ b/BaseTools/Source/C/BfmLib/BfmLib.c > > > @@ -9,6 +9,9 @@ > > > > > > #include "BinFileManager.h" > > > > > > +#define STR_LEN_MAX_4K 4096 > > > +#define STR_LEN_MAX_1K 1024 > > > + > > > > Coding style 3.3.3: "Code files should not contain > #define and typedef > > statements." > > > > Move these to BinFileManager.h? > > > > > #define EFI_TEST_FFS_ATTRIBUTES_BIT(FvbAttributes, > TestAttributes, Bit) \ > > > ( \ > > > (BOOLEAN) ( \ > > > @@ -116,7 +119,7 @@ LibInitializeFvStruct ( > > > > > > for (Index =3D 0; Index < MAX_NUMBER_OF_FILES_IN_FV; > Index ++) { > > > memset (Fv->FfsAttuibutes[Index].FfsName, '\0', > _MAX_PATH); > > > - memset (Fv->FfsAttuibutes[Index].UiName, '\0', > _MAX_PATH); > > > + memset (Fv->FfsAttuibutes[Index].UiName, '\0', > _MAX_PATH * > > > + sizeof (CHAR16)); > > > > > > Fv->FfsAttuibutes[Index].IsLeaf =3D > TRUE; > > > Fv->FfsAttuibutes[Index].TotalSectionNum =3D > 0; > > > @@ -2399,153 +2402,153 @@ LibFvHeaderAttributeToStr ( > > > > > > LocalStr =3D NULL; > > > > > > - LocalStr =3D (CHAR8 *) malloc (1024 * 4); > > > + LocalStr =3D (CHAR8 *) malloc (STR_LEN_MAX_4K); > > > > > > if (LocalStr =3D=3D NULL) { > > > printf ("Out of resource, memory allocation > failed. \n"); > > > return EFI_OUT_OF_RESOURCES; > > > } > > > > > > - memset (LocalStr, '\0', 1024 * 4); > > > + memset (LocalStr, '\0', STR_LEN_MAX_4K); > > > > > > if (Attr =3D=3D 0 || InfFile =3D=3D NULL) { > > > free (LocalStr); > > > return EFI_INVALID_PARAMETER; > > > } > > > > > > - strncat (LocalStr, "[attributes] \n", > sizeof("[attributes] \n")); > > > + strncat (LocalStr, "[attributes] \n", > STR_LEN_MAX_4K - strlen > > > + (LocalStr) - 1); > > > > This is a very inefficient, and difficult to read, way > of doing this. > > It also performs absolutely no error checking (making > any future > > debugging tedious at best). > > > This change is to fix gcc warning -Werror=3Dsizeof-pointer- > memaccess. > strncat is the safe version API. So, it is used here. >=20 > > I have to be honest - looking at this code, I think the > right thing to > > do would be to revert the commit adding it and > reworking the utility > > completely (making sure it gets serious review) before > merging it. > > > > I am not surprised the compilers get upset. > > > > This made me have a closer look at the patches adding > FCE and FMMT, > > and frankly, my opinion of them are similar. These > aren't being > > upstreamed - this is textbook "chuck over the wall". > > > > Don't get me wrong - the code quality of FMMT is > notably higher than > > the code quality of FCE, which is notably higher than > the code quality > > of BfmLib. But even > > > > BfmLib was added with the comment that it is used by > FCE. > > So why do FCE and FMMT both have separate copies of > LibBfmGuidToStr? > > Not just functions doing the same thing, but with the > same name. > > > > There are many other issues with these tools. >=20 > FCE & FMMT both operate the binary FV image. Their > implementation may copy the same logic. I don't think > this is a good way. > I agree to do better design for code sharing and code > quality improvement. >=20 > I suggest to revert them, add current FCE & FMMT into > edk2-staging, then refine them, and send the patch to add > them back into edk2 BaseTools. >=20 > Thanks > Liming > > > > / > > Leif > > > > > > > > if (Attr & EFI_FVB2_READ_DISABLED_CAP) { > > > - strncat (LocalStr, "EFI_READ_DISABLED_CAP =3D TRUE > \n", sizeof ("EFI_READ_DISABLED_CAP =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_READ_DISABLED_CAP =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_READ_ENABLED_CAP) { > > > - strncat (LocalStr, "EFI_READ_ENABLED_CAP =3D TRUE > \n", sizeof ("EFI_READ_ENABLED_CAP =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_READ_ENABLED_CAP =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_READ_STATUS) { > > > - strncat (LocalStr, "EFI_READ_STATUS =3D TRUE \n", > sizeof ("EFI_READ_STATUS =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_READ_STATUS =3D TRUE \n", > STR_LEN_MAX_4K > > > + - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_WRITE_DISABLED_CAP) { > > > - strncat (LocalStr, "EFI_WRITE_DISABLED_CAP =3D > TRUE \n", sizeof ("EFI_WRITE_DISABLED_CAP =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_WRITE_DISABLED_CAP =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_WRITE_ENABLED_CAP) { > > > - strncat (LocalStr, "EFI_WRITE_ENABLED_CAP =3D TRUE > \n", sizeof ("EFI_WRITE_ENABLED_CAP =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_WRITE_ENABLED_CAP =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_WRITE_STATUS) { > > > - strncat (LocalStr, "EFI_WRITE_STATUS =3D TRUE \n", > sizeof ("EFI_WRITE_STATUS =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_WRITE_STATUS =3D TRUE \n", > STR_LEN_MAX_4K > > > + - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_LOCK_CAP) { > > > - strncat (LocalStr, "EFI_LOCK_CAP =3D TRUE \n", > sizeof ("EFI_LOCK_CAP =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_LOCK_CAP =3D TRUE \n", > STR_LEN_MAX_4K - > > > + strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_LOCK_STATUS) { > > > - strncat (LocalStr, "EFI_LOCK_STATUS =3D TRUE \n", > sizeof ("EFI_LOCK_STATUS =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_LOCK_STATUS =3D TRUE \n", > STR_LEN_MAX_4K > > > + - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_STICKY_WRITE) { > > > - strncat (LocalStr, "EFI_STICKY_WRITE =3D TRUE \n", > sizeof ("EFI_STICKY_WRITE =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_STICKY_WRITE =3D TRUE \n", > STR_LEN_MAX_4K > > > + - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_MEMORY_MAPPED) { > > > - strncat (LocalStr, "EFI_MEMORY_MAPPED =3D TRUE > \n", sizeof ("EFI_MEMORY_MAPPED =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_MEMORY_MAPPED =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_ERASE_POLARITY) { > > > - strncat (LocalStr, "EFI_ERASE_POLARITY =3D 1 \n", > sizeof ("EFI_ERASE_POLARITY =3D 1 \n")); > > > + strncat (LocalStr, "EFI_ERASE_POLARITY =3D 1 \n", > STR_LEN_MAX_4K > > > + - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_READ_LOCK_CAP) { > > > - strncat (LocalStr, "EFI_READ_LOCK_CAP =3D TRUE > \n", sizeof ("EFI_READ_LOCK_CAP =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_READ_LOCK_CAP =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_READ_LOCK_STATUS) { > > > - strncat (LocalStr, "EFI_READ_LOCK_STATUS =3D TRUE > \n", sizeof ("EFI_READ_LOCK_STATUS =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_READ_LOCK_STATUS =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_WRITE_LOCK_CAP) { > > > - strncat (LocalStr, "EFI_WRITE_LOCK_CAP =3D TRUE > \n", sizeof ("EFI_WRITE_LOCK_CAP =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_WRITE_LOCK_CAP =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_WRITE_LOCK_STATUS) { > > > - strncat (LocalStr, "EFI_WRITE_LOCK_STATUS =3D TRUE > \n", sizeof ("EFI_WRITE_LOCK_STATUS =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_WRITE_LOCK_STATUS =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_LOCK_STATUS) { > > > - strncat (LocalStr, "EFI_READ_LOCK_STATUS =3D TRUE > \n", sizeof ("EFI_READ_LOCK_STATUS =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_READ_LOCK_STATUS =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > // > > > // Alignment > > > // > > > if (Attr & EFI_FVB2_ALIGNMENT_1) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1 =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_1 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1 =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_2) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2 =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_2 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2 =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_4) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_4 =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_4 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_4 =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_8) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_8 =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_8 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_8 =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_16) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_16 =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_16 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_16 =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_32) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_32 =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_32 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_32 =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_64) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_64 =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_64 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_64 =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_128) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_128 =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_128 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_128 =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_256) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_256 =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_256 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_256 =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_512) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_512 =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_512 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_512 =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_1K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1K =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_1K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1K =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_2K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2K =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_2K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2K =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_4K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_4K =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_4K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_4K =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_8K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_8K =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_8K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_8K =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_16K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_16K =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_16K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_16K =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_32K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_32K =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_32K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_32K =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_64K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_64K =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_64K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_64K =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_128K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_128K =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_128K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_128K =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_256K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_256K =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_256K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_256K =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_512K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_512K =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_512K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_512K =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_1M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1M =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_1M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1M =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_2M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2M =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_2M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2M =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_4M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_4M =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_4M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_4M =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_8M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_8M =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_8M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_8M =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_16M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_16M =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_16M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_16M =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_32M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_32M =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_32M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_32M =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_64M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_64M =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_64M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_64M =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_128M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_128M =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_128M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_128M =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_256M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_256M =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_256M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_256M =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_512M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_512M =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_512M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_512M =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_1G) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1G =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_1G =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1G =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_2G) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2G =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_2G =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2G =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (fwrite (LocalStr, 1, (size_t) strlen > (LocalStr), InfFile) !=3D > > > (size_t) strlen (LocalStr)) { @@ -2592,7 +2595,7 @@ > LibFvHeaderOptionToStr ( > > > // > > > // This section will not over 1024 bytes and each > line will never over 128 bytes. > > > // > > > - LocalStr =3D (CHAR8 *) malloc (1024); > > > + LocalStr =3D (CHAR8 *) malloc (STR_LEN_MAX_1K); > > > BlockSize =3D (CHAR8 *) malloc (128); > > > NumOfBlocks =3D (CHAR8 *) malloc (128); > > > > > > @@ -2611,18 +2614,18 @@ LibFvHeaderOptionToStr ( > > > return EFI_OUT_OF_RESOURCES; > > > } > > > > > > - memset (LocalStr, '\0', 1024); > > > + memset (LocalStr, '\0', STR_LEN_MAX_1K); > > > memset (BlockSize, '\0', 128); > > > memset (NumOfBlocks, '\0', 128); > > > > > > - strncat (LocalStr, "[options] \n", > sizeof("[Options] \n")); > > > + strncat (LocalStr, "[options] \n", STR_LEN_MAX_1K > - strlen > > > + (LocalStr) - 1); > > > > > > sprintf (BlockSize, "EFI_BLOCK_SIZE =3D 0x%x \n", > > > BlockMap->Length); > > > - strncat (LocalStr, BlockSize, strlen(BlockSize)); > > > + strncat (LocalStr, BlockSize, STR_LEN_MAX_1K - > strlen (LocalStr) > > > + - 1); > > > > > > if (IsRootFv) { > > > sprintf (NumOfBlocks, "EFI_NUM_BLOCKS =3D 0x%x \n", > > > BlockMap->NumBlocks); > > > - strncat (LocalStr, NumOfBlocks, > strlen(NumOfBlocks)); > > > + strncat (LocalStr, NumOfBlocks, STR_LEN_MAX_1K - > strlen > > > + (LocalStr) - 1); > > > } > > > > > > if (fwrite (LocalStr, 1, (size_t) strlen > (LocalStr), InfFile) !=3D > > > (size_t) strlen (LocalStr)) { diff --git > > > a/BaseTools/Source/C/FCE/BinaryParse.c > > > b/BaseTools/Source/C/FCE/BinaryParse.c > > > index e9f8ee6826..97d6ecf93b 100644 > > > --- a/BaseTools/Source/C/FCE/BinaryParse.c > > > +++ b/BaseTools/Source/C/FCE/BinaryParse.c > > > @@ -1240,7 +1240,7 @@ Done: > > > ) { > > > continue; > > > } > > > - sprintf (FileNameArry, "%s%c%s", FolderName, > OS_SEP, pDirent->d_name); > > > + snprintf (FileNameArry, MAX_FILENAME_LEN, > "%s%c%s", > > > + FolderName, OS_SEP, pDirent->d_name); > > > FfsFile =3D fopen (FileNameArry, "rb"); > > > Status =3D ReadFfsHeader (FfsFile, (UINT32 > *)&FileSize); > > > if (EFI_ERROR (Status)) { > > > diff --git > a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c > > > b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c > > > index 63ae3c45a4..6648fbd54f 100644 > > > --- > a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c > > > +++ > b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c > > > @@ -1572,7 +1572,7 @@ FmmtImageDelete ( > > > // If decrease operation > executed, we should adjust the ffs list. It will bring in > more complex. > > > // > > > //FvInFd->FfsNumbers > -=3D 1; > > > - memset(FvInFd- > >FfsAttuibutes[Index].UiName, '\0', _MAX_PATH); > > > + memset(FvInFd- > >FfsAttuibutes[Index].UiName, > > > + '\0', _MAX_PATH * sizeof (CHAR16)); > > > if (FvInFd- > >FfsAttuibutes[Index].FvLevel > 1) { > > > for (j =3D Index - 1; j >=3D 0; > j--) { > > > if (FvInFd- > >FfsAttuibutes[j].FvLevel =3D=3D > > > FvInFd->FfsAttuibutes[Index].FvLevel - 1) { diff -- > git > > > a/BaseTools/Source/C/FMMT/FmmtLib.c > > > b/BaseTools/Source/C/FMMT/FmmtLib.c > > > index f87042114b..e236810c59 100644 > > > --- a/BaseTools/Source/C/FMMT/FmmtLib.c > > > +++ b/BaseTools/Source/C/FMMT/FmmtLib.c > > > @@ -9,6 +9,9 @@ > > > > > > #include "FirmwareModuleManagement.h" > > > > > > +#define STR_LEN_MAX_4K 4096 > > > +#define STR_LEN_MAX_1K 1024 > > > + > > > #define EFI_TEST_FFS_ATTRIBUTES_BIT(FvbAttributes, > TestAttributes, Bit) \ > > > ( \ > > > (BOOLEAN) ( \ > > > @@ -155,7 +158,7 @@ LibInitializeFvStruct ( > > > > > > for (Index =3D 0; Index < MAX_NUMBER_OF_FILES_IN_FV; > Index ++) { > > > memset (Fv->FfsAttuibutes[Index].FfsName, '\0', > _MAX_PATH); > > > - memset (Fv->FfsAttuibutes[Index].UiName, '\0', > _MAX_PATH); > > > + memset (Fv->FfsAttuibutes[Index].UiName, '\0', > _MAX_PATH * > > > + sizeof (CHAR16)); > > > memset (&Fv->FfsAttuibutes[Index].GuidName, > '\0', sizeof(EFI_GUID)); > > > Fv->FfsAttuibutes[Index].UiNameSize =3D > 0; > > > Fv->FfsAttuibutes[Index].IsLeaf =3D > TRUE; > > > @@ -2504,153 +2507,153 @@ LibFvHeaderAttributeToStr ( > > > > > > LocalStr =3D NULL; > > > > > > - LocalStr =3D (CHAR8 *) malloc (1024 * 4); > > > + LocalStr =3D (CHAR8 *) malloc (STR_LEN_MAX_4K); > > > > > > if (LocalStr =3D=3D NULL) { > > > printf ("Memory allocate error!\n"); > > > return EFI_OUT_OF_RESOURCES; > > > } > > > > > > - memset (LocalStr, '\0', 1024 * 4); > > > + memset (LocalStr, '\0', STR_LEN_MAX_4K); > > > > > > if (Attr =3D=3D 0 || InfFile =3D=3D NULL) { > > > free (LocalStr); > > > return EFI_INVALID_PARAMETER; > > > } > > > > > > - strncat (LocalStr, "[attributes] \n", > sizeof("[attributes] \n")); > > > + strncat (LocalStr, "[attributes] \n", > STR_LEN_MAX_4K - strlen > > > + (LocalStr) - 1); > > > > > > if (Attr & EFI_FVB2_READ_DISABLED_CAP) { > > > - strncat (LocalStr, "EFI_READ_DISABLED_CAP =3D TRUE > \n", sizeof ("EFI_READ_DISABLED_CAP =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_READ_DISABLED_CAP =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_READ_ENABLED_CAP) { > > > - strncat (LocalStr, "EFI_READ_ENABLED_CAP =3D TRUE > \n", sizeof ("EFI_READ_ENABLED_CAP =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_READ_ENABLED_CAP =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_READ_STATUS) { > > > - strncat (LocalStr, "EFI_READ_STATUS =3D TRUE \n", > sizeof ("EFI_READ_STATUS =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_READ_STATUS =3D TRUE \n", > STR_LEN_MAX_4K > > > + - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_WRITE_DISABLED_CAP) { > > > - strncat (LocalStr, "EFI_WRITE_DISABLED_CAP =3D > TRUE \n", sizeof ("EFI_WRITE_DISABLED_CAP =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_WRITE_DISABLED_CAP =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_WRITE_ENABLED_CAP) { > > > - strncat (LocalStr, "EFI_WRITE_ENABLED_CAP =3D TRUE > \n", sizeof ("EFI_WRITE_ENABLED_CAP =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_WRITE_ENABLED_CAP =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_WRITE_STATUS) { > > > - strncat (LocalStr, "EFI_WRITE_STATUS =3D TRUE \n", > sizeof ("EFI_WRITE_STATUS =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_WRITE_STATUS =3D TRUE \n", > STR_LEN_MAX_4K > > > + - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_LOCK_CAP) { > > > - strncat (LocalStr, "EFI_LOCK_CAP =3D TRUE \n", > sizeof ("EFI_LOCK_CAP =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_LOCK_CAP =3D TRUE \n", > STR_LEN_MAX_4K - > > > + strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_LOCK_STATUS) { > > > - strncat (LocalStr, "EFI_LOCK_STATUS =3D TRUE \n", > sizeof ("EFI_LOCK_STATUS =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_LOCK_STATUS =3D TRUE \n", > STR_LEN_MAX_4K > > > + - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_STICKY_WRITE) { > > > - strncat (LocalStr, "EFI_STICKY_WRITE =3D TRUE \n", > sizeof ("EFI_STICKY_WRITE =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_STICKY_WRITE =3D TRUE \n", > STR_LEN_MAX_4K > > > + - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_MEMORY_MAPPED) { > > > - strncat (LocalStr, "EFI_MEMORY_MAPPED =3D TRUE > \n", sizeof ("EFI_MEMORY_MAPPED =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_MEMORY_MAPPED =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_ERASE_POLARITY) { > > > - strncat (LocalStr, "EFI_ERASE_POLARITY =3D 1 \n", > sizeof ("EFI_ERASE_POLARITY =3D 1 \n")); > > > + strncat (LocalStr, "EFI_ERASE_POLARITY =3D 1 \n", > STR_LEN_MAX_4K > > > + - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_READ_LOCK_CAP) { > > > - strncat (LocalStr, "EFI_READ_LOCK_CAP =3D TRUE > \n", sizeof ("EFI_READ_LOCK_CAP =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_READ_LOCK_CAP =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_READ_LOCK_STATUS) { > > > - strncat (LocalStr, "EFI_READ_LOCK_STATUS =3D TRUE > \n", sizeof ("EFI_READ_LOCK_STATUS =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_READ_LOCK_STATUS =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_WRITE_LOCK_CAP) { > > > - strncat (LocalStr, "EFI_WRITE_LOCK_CAP =3D TRUE > \n", sizeof ("EFI_WRITE_LOCK_CAP =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_WRITE_LOCK_CAP =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_WRITE_LOCK_STATUS) { > > > - strncat (LocalStr, "EFI_WRITE_LOCK_STATUS =3D TRUE > \n", sizeof ("EFI_WRITE_LOCK_STATUS =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_WRITE_LOCK_STATUS =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (Attr & EFI_FVB2_LOCK_STATUS) { > > > - strncat (LocalStr, "EFI_READ_LOCK_STATUS =3D TRUE > \n", sizeof ("EFI_READ_LOCK_STATUS =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_READ_LOCK_STATUS =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > // > > > // Alignment > > > // > > > if (Attr & EFI_FVB2_ALIGNMENT_1) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1 =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_1 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1 =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_2) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2 =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_2 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2 =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_4) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_4 =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_4 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_4 =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_8) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_8 =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_8 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_8 =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_16) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_16 =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_16 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_16 =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_32) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_32 =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_32 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_32 =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_64) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_64 =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_64 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_64 =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_128) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_128 =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_128 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_128 =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_256) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_256 =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_256 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_256 =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_512) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_512 =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_512 =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_512 =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_1K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1K =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_1K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1K =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_2K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2K =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_2K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2K =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_4K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_4K =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_4K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_4K =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_8K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_8K =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_8K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_8K =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_16K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_16K =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_16K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_16K =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_32K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_32K =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_32K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_32K =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_64K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_64K =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_64K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_64K =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_128K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_128K =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_128K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_128K =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_256K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_256K =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_256K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_256K =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_512K) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_512K =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_512K =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_512K =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_1M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1M =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_1M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1M =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_2M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2M =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_2M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2M =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_4M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_4M =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_4M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_4M =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_8M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_8M =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_8M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_8M =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_16M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_16M =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_16M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_16M =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_32M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_32M =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_32M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_32M =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_64M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_64M =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_64M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_64M =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_128M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_128M =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_128M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_128M =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_256M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_256M =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_256M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_256M =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_512M) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_512M =3D > TRUE \n", sizeof ("EFI_FVB2_ALIGNMENT_512M =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_512M =3D > TRUE \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_1G) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1G =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_1G =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_1G =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } else if (Attr & EFI_FVB2_ALIGNMENT_2G) { > > > - strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2G =3D TRUE > \n", sizeof ("EFI_FVB2_ALIGNMENT_2G =3D TRUE \n")); > > > + strncat (LocalStr, "EFI_FVB2_ALIGNMENT_2G =3D TRUE > \n", > > > + STR_LEN_MAX_4K - strlen (LocalStr) - 1); > > > } > > > > > > if (fwrite (LocalStr, 1, (size_t) strlen > (LocalStr), InfFile) !=3D > > > (size_t) strlen (LocalStr)) { @@ -2696,7 +2699,7 @@ > LibFvHeaderOptionToStr ( > > > // > > > // This section will not over 1024 bytes and each > line will never over 128 bytes. > > > // > > > - LocalStr =3D (CHAR8 *) malloc (1024); > > > + LocalStr =3D (CHAR8 *) malloc (STR_LEN_MAX_1K); > > > TempStr =3D (CHAR8 *) malloc (128); > > > > > > if (LocalStr =3D=3D NULL || > > > @@ -2712,18 +2715,18 @@ LibFvHeaderOptionToStr ( > > > } > > > > > > BlockMap =3D FvHeader->BlockMap; > > > - memset (LocalStr, '\0', 1024); > > > + memset (LocalStr, '\0', STR_LEN_MAX_1K); > > > memset (TempStr, '\0', 128); > > > > > > - strncat (LocalStr, "[options] \n", > sizeof("[Options] \n")); > > > + strncat (LocalStr, "[options] \n", STR_LEN_MAX_1K > - strlen > > > + (LocalStr) - 1); > > > > > > > > > snprintf (TempStr, 128, "EFI_BLOCK_SIZE =3D 0x%x > \n", > > > BlockMap->Length); > > > - strncat (LocalStr, TempStr, strlen(TempStr)); > > > + strncat (LocalStr, TempStr, STR_LEN_MAX_1K - > strlen (LocalStr) - > > > + 1); > > > > > > if (IsRootFv) { > > > snprintf (TempStr, 128, "EFI_NUM_BLOCKS =3D 0x%x > \n", > > > BlockMap->NumBlocks); > > > - strncat (LocalStr, TempStr, strlen(TempStr)); > > > + strncat (LocalStr, TempStr, STR_LEN_MAX_1K - > strlen (LocalStr) - > > > + 1); > > > } > > > > > > if (fwrite (LocalStr, 1, (size_t) strlen > (LocalStr), InfFile) !=3D > > > (size_t) strlen (LocalStr)) { > > > -- > > > 2.13.0.windows.1 > > > > > > > > > > > > > > > >=20