From nobody Sat May 4 09:13:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1525842152028177.75155957572952; Tue, 8 May 2018 22:02:32 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6E48B2096108F; Tue, 8 May 2018 22:02:30 -0700 (PDT) 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 CB4C620945D95 for ; Tue, 8 May 2018 22:02:29 -0700 (PDT) Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 May 2018 22:02:29 -0700 Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.135]) by fmsmga007.fm.intel.com with ESMTP; 08 May 2018 22:02:28 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=dandan.bi@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,380,1520924400"; d="scan'208";a="37913434" From: Dandan Bi To: edk2-devel@lists.01.org Date: Wed, 9 May 2018 13:02:11 +0800 Message-Id: <20180509050211.76104-1-dandan.bi@intel.com> X-Mailer: git-send-email 2.14.3.windows.1 Subject: [edk2] [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: , Cc: Gary Lin , Eric Dong , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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. Cc: Eric Dong Cc: Liming Gao Cc: Gary Lin Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Dandan Bi Reviewed-by: Eric Dong Tested-by: Gary Lin --- 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 : =20 // // Root expression extension function called by other function. // vfrStatementExpression [UINT32 RootLevel, UINT32 ExpOpCount =3D 0] : - << if ($RootLevel =3D=3D 0) {mCIfrOpHdrIndex ++; if (mCIfrOpHdrIndex >= =3D MAX_IFR_EXPRESSION_DEPTH) _PCATCH (VFR_RETURN_INVALID_PARAMETER, 0, "Th= e depth of expression exceeds the max supported level 8!"); _CLEAR_SAVED_OP= HDR ();} >> + << + if ($RootLevel = =3D=3D 0) { + mCIfrOpHdrInde= x ++; + if (mCIfrOpHdr= Index >=3D MAX_IFR_EXPRESSION_DEPTH) { + _PCATCH (VFR= _RETURN_INVALID_PARAMETER, 0, "The depth of expression exceeds the max supp= orted level 8!"); + } + _INIT_OPHDR_CO= ND (); + } + >> andTerm[$RootLevel, $ExpOpCount] ( L:OR andTerm[$RootLevel, $ExpOpCount] << $ExpOpCount++; C= IfrOr 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, UIN= T32 LineNo =3D 0); VOID _CLEAR_SAVED_OPHDR (VOID); + VOID _INIT_OPHDR_COND (VOID); BOOLEAN _SET_SAVED_OPHDR_SCOPE (VOID); =20 =20 EFI_VARSTORE_INFO mCurrQestVarInfo; EFI_GUID *mOverrideClassGuid; @@ -5077,20 +5086,28 @@ EfiVfrParser::_SAVE_OPHDR_COND ( mCIfrOpHdr[mCIfrOpHdrIndex] =3D new CIfrOpHeader(OpHdr); mCIfrOpHdrLineNo[mCIfrOpHdrIndex] =3D LineNo; } } =20 +VOID +EfiVfrParser::_INIT_OPHDR_COND ( + VOID + ) +{ + mCIfrOpHdr[mCIfrOpHdrIndex] =3D NULL; + mCIfrOpHdrLineNo[mCIfrOpHdrIndex] =3D 0; +} + VOID EfiVfrParser::_CLEAR_SAVED_OPHDR ( VOID ) { if (mCIfrOpHdr[mCIfrOpHdrIndex] !=3D NULL) { delete mCIfrOpHdr[mCIfrOpHdrIndex]; - mCIfrOpHdr[mCIfrOpHdrIndex] =3D NULL; + mCIfrOpHdr[mCIfrOpHdrIndex] =3D NULL; } - mCIfrOpHdrLineNo[mCIfrOpHdrIndex] =3D 0; } =20 BOOLEAN EfiVfrParser::_SET_SAVED_OPHDR_SCOPE ( VOID --=20 2.14.3.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel