From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=195.135.221.5; helo=smtp.nue.novell.com; envelope-from=glin@suse.com; receiver=edk2-devel@lists.01.org Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (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 06F6F2096AEF9 for ; Wed, 9 May 2018 01:20:22 -0700 (PDT) Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Wed, 09 May 2018 10:20:21 +0200 Received: from GaryWorkstation (nwb-a10-snat.microfocus.com [10.120.13.201]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Wed, 09 May 2018 09:20:13 +0100 Date: Wed, 9 May 2018 16:20:09 +0800 From: Gary Lin To: Dandan Bi Cc: edk2-devel@lists.01.org, Eric Dong , Liming Gao Message-ID: <20180509082009.uotkzgubbm2qtg2b@GaryWorkstation> References: <20180509050211.76104-1-dandan.bi@intel.com> MIME-Version: 1.0 In-Reply-To: <20180509050211.76104-1-dandan.bi@intel.com> User-Agent: NeoMutt/20170912 (1.9.0) Subject: Re: [patch v2] BaseTools/VfrCompile: Avoid using uninitialized pointer X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 May 2018 08:20:23 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, May 09, 2018 at 01:02:11PM +0800, Dandan Bi wrote: > V2: > Add function _INIT_OPHDR_COND () for variable initialization. > Make code logic more clean. > > Previously _CLEAR_SAVED_OPHDR () is used for variable > initialization, and we updated it to clean memory. > But _CLEAR_SAVED_OPHDR () is still called for variable > initialization. This will cause uninitialized pointer > will be checked to free and cause unexpected issue. > > This patch is to add new function for variable initialization > and keep _CLEAR_SAVED_OPHDR () to clean memory which is > aligned with its function name. > This patch fixes the build errors I had :) Tested-by: Gary Lin > Cc: Eric Dong > Cc: Liming Gao > Cc: Gary Lin > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Dandan Bi > --- > BaseTools/Source/C/VfrCompile/VfrSyntax.g | 23 ++++++++++++++++++++--- > 1 file changed, 20 insertions(+), 3 deletions(-) > > diff --git a/BaseTools/Source/C/VfrCompile/VfrSyntax.g b/BaseTools/Source/C/VfrCompile/VfrSyntax.g > index 4b0a43606ea..84dd2c3ed3f 100644 > --- a/BaseTools/Source/C/VfrCompile/VfrSyntax.g > +++ b/BaseTools/Source/C/VfrCompile/VfrSyntax.g > @@ -4084,11 +4084,19 @@ vfrStatementInvalidSaveRestoreDefaults : > > // > // Root expression extension function called by other function. > // > vfrStatementExpression [UINT32 RootLevel, UINT32 ExpOpCount = 0] : > - << if ($RootLevel == 0) {mCIfrOpHdrIndex ++; if (mCIfrOpHdrIndex >= MAX_IFR_EXPRESSION_DEPTH) _PCATCH (VFR_RETURN_INVALID_PARAMETER, 0, "The depth of expression exceeds the max supported level 8!"); _CLEAR_SAVED_OPHDR ();} >> > + << > + if ($RootLevel == 0) { > + mCIfrOpHdrIndex ++; > + if (mCIfrOpHdrIndex >= MAX_IFR_EXPRESSION_DEPTH) { > + _PCATCH (VFR_RETURN_INVALID_PARAMETER, 0, "The depth of expression exceeds the max supported level 8!"); > + } > + _INIT_OPHDR_COND (); > + } > + >> > andTerm[$RootLevel, $ExpOpCount] > ( > L:OR andTerm[$RootLevel, $ExpOpCount] << $ExpOpCount++; CIfrOr OObj(L->getLine()); >> > )* > << > @@ -4988,10 +4996,11 @@ private: > CIfrOpHeader * mCIfrOpHdr[MAX_IFR_EXPRESSION_DEPTH]; > UINT32 mCIfrOpHdrLineNo[MAX_IFR_EXPRESSION_DEPTH]; > UINT8 mCIfrOpHdrIndex; > VOID _SAVE_OPHDR_COND (IN CIfrOpHeader &, IN BOOLEAN, UINT32 LineNo = 0); > VOID _CLEAR_SAVED_OPHDR (VOID); > + VOID _INIT_OPHDR_COND (VOID); > BOOLEAN _SET_SAVED_OPHDR_SCOPE (VOID); > > > EFI_VARSTORE_INFO mCurrQestVarInfo; > EFI_GUID *mOverrideClassGuid; > @@ -5077,20 +5086,28 @@ EfiVfrParser::_SAVE_OPHDR_COND ( > mCIfrOpHdr[mCIfrOpHdrIndex] = new CIfrOpHeader(OpHdr); > mCIfrOpHdrLineNo[mCIfrOpHdrIndex] = LineNo; > } > } > > +VOID > +EfiVfrParser::_INIT_OPHDR_COND ( > + VOID > + ) > +{ > + mCIfrOpHdr[mCIfrOpHdrIndex] = NULL; > + mCIfrOpHdrLineNo[mCIfrOpHdrIndex] = 0; > +} > + > VOID > EfiVfrParser::_CLEAR_SAVED_OPHDR ( > VOID > ) > { > if (mCIfrOpHdr[mCIfrOpHdrIndex] != NULL) { > delete mCIfrOpHdr[mCIfrOpHdrIndex]; > - mCIfrOpHdr[mCIfrOpHdrIndex] = NULL; > + mCIfrOpHdr[mCIfrOpHdrIndex] = NULL; > } > - mCIfrOpHdrLineNo[mCIfrOpHdrIndex] = 0; > } > > BOOLEAN > EfiVfrParser::_SET_SAVED_OPHDR_SCOPE ( > VOID > -- > 2.14.3.windows.1 > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel >