From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CA8CC81CF3 for ; Thu, 3 Nov 2016 00:23:53 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 03 Nov 2016 00:23:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,585,1473145200"; d="scan'208";a="897185187" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.34]) by orsmga003.jf.intel.com with ESMTP; 03 Nov 2016 00:23:53 -0700 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Liming Gao , Yonghong Zhu , Eric Dong , Dandan Bi Date: Thu, 3 Nov 2016 15:22:38 +0800 Message-Id: <1478157783-9368-29-git-send-email-hao.a.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1478157783-9368-1-git-send-email-hao.a.wu@intel.com> References: <1478157783-9368-1-git-send-email-hao.a.wu@intel.com> Subject: [PATCH v2 28/53] BaseTools/VfrCompile: Avoid freeing freed memory in classes X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Nov 2016 07:23:53 -0000 For classes that contain dynamically allocated data members, copy constructor and assignment operator should be implemented or both operations should be prohibited to avoid freeing freed memory caused by shallow copy. This commit declares both copy constructor and assignment operator as 'private' for classes that contain dynamically allocated data members. This will prevent freeing already freed memory. Cc: Liming Gao Cc: Yonghong Zhu Cc: Eric Dong Cc: Dandan Bi Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu --- BaseTools/Source/C/VfrCompile/Pccts/h/DLexerBase.h | 3 ++ BaseTools/Source/C/VfrCompile/VfrError.h | 10 +++- BaseTools/Source/C/VfrCompile/VfrFormPkg.h | 12 +++++ BaseTools/Source/C/VfrCompile/VfrUtilityLib.h | 55 ++++++++++++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/C/VfrCompile/Pccts/h/DLexerBase.h b/BaseTools/Source/C/VfrCompile/Pccts/h/DLexerBase.h index db6cc18..667ecfd 100644 --- a/BaseTools/Source/C/VfrCompile/Pccts/h/DLexerBase.h +++ b/BaseTools/Source/C/VfrCompile/Pccts/h/DLexerBase.h @@ -119,6 +119,9 @@ public: /* user must subclass this */ class DllExportPCCTS DLGLexerBase : public ANTLRTokenStream { +private: + DLGLexerBase(const DLGLexerBase&); // Prevent copy-construction + DLGLexerBase& operator=(const DLGLexerBase&); // Prevent assignment public: virtual ANTLRTokenType erraction(); diff --git a/BaseTools/Source/C/VfrCompile/VfrError.h b/BaseTools/Source/C/VfrCompile/VfrError.h index 8241ce2..4dbc54c 100644 --- a/BaseTools/Source/C/VfrCompile/VfrError.h +++ b/BaseTools/Source/C/VfrCompile/VfrError.h @@ -2,7 +2,7 @@ VfrCompiler Error definition -Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -73,6 +73,10 @@ struct SVfrFileScopeRecord { SVfrFileScopeRecord (IN CHAR8 *, IN UINT32); ~SVfrFileScopeRecord(); + +private: + SVfrFileScopeRecord (IN CONST SVfrFileScopeRecord&); // Prevent copy-construction + SVfrFileScopeRecord& operator= (IN CONST SVfrFileScopeRecord&); // Prevent assignment }; class CVfrErrorHandle { @@ -95,6 +99,10 @@ public: UINT8 HandleError (IN EFI_VFR_RETURN_CODE, IN UINT32 LineNum = 0, IN CHAR8 *TokName = NULL); UINT8 HandleWarning (IN EFI_VFR_WARNING_CODE, IN UINT32 LineNum = 0, IN CHAR8 *TokName = NULL); VOID PrintMsg (IN UINT32 LineNum = 0, IN CHAR8 *TokName = NULL, IN CONST CHAR8 *MsgType = "Error", IN CONST CHAR8 *ErrorMsg = ""); + +private: + CVfrErrorHandle (IN CONST CVfrErrorHandle&); // Prevent copy-construction + CVfrErrorHandle& operator= (IN CONST CVfrErrorHandle&); // Prevent assignment }; #define CHECK_ERROR_RETURN(f, v) do { EFI_VFR_RETURN_CODE r; if ((r = (f)) != (v)) { return r; } } while (0) diff --git a/BaseTools/Source/C/VfrCompile/VfrFormPkg.h b/BaseTools/Source/C/VfrCompile/VfrFormPkg.h index 3c7964a..17ab14c 100644 --- a/BaseTools/Source/C/VfrCompile/VfrFormPkg.h +++ b/BaseTools/Source/C/VfrCompile/VfrFormPkg.h @@ -87,6 +87,10 @@ struct SPendingAssign { VOID SetAddrAndLen (IN VOID *, IN UINT32); VOID AssignValue (IN VOID *, IN UINT32); CHAR8 * GetKey (VOID); + +private: + SPendingAssign (IN CONST SPendingAssign&); // Prevent copy-construction + SPendingAssign& operator= (IN CONST SPendingAssign&); // Prevent assignment }; struct SBufferNode { @@ -139,6 +143,10 @@ public: EFI_VFR_RETURN_CODE BuildPkg (OUT PACKAGE_DATA &); EFI_VFR_RETURN_CODE GenCFile (IN CHAR8 *, IN FILE *, IN PACKAGE_DATA *PkgData = NULL); +private: + CFormPkg (IN CONST CFormPkg&); // Prevent copy-construction + CFormPkg& operator= (IN CONST CFormPkg&); // Prevent assignment + public: EFI_VFR_RETURN_CODE AssignPending (IN CHAR8 *, IN VOID *, IN UINT32, IN UINT32, IN CONST CHAR8 *Msg = NULL); VOID DoPendingAssign (IN CHAR8 *, IN VOID *, IN UINT32); @@ -237,6 +245,10 @@ public: VOID IfrCreateDefaultForQuestion (IN SIfrRecord *, IN QuestionDefaultRecord *); VOID IfrParseDefaulInfoInQuestion (IN SIfrRecord *, OUT QuestionDefaultRecord *); VOID IfrAddDefaultToBufferConfig (IN UINT16, IN SIfrRecord *,IN EFI_IFR_TYPE_VALUE); + +private: + CIfrRecordInfoDB (IN CONST CIfrRecordInfoDB&); // Prevent copy-construction + CIfrRecordInfoDB& operator= (IN CONST CIfrRecordInfoDB&); // Prevent assignment }; extern CIfrRecordInfoDB gCIfrRecordInfoDB; diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h index 2e06e4f..59509c3 100644 --- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h +++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h @@ -55,6 +55,10 @@ struct SConfigInfo { SConfigInfo (IN UINT8, IN UINT16, IN UINT32, IN EFI_IFR_TYPE_VALUE); ~SConfigInfo (VOID); + +private: + SConfigInfo (IN CONST SConfigInfo&); // Prevent copy-construction + SConfigInfo& operator= (IN CONST SConfigInfo&); // Prevent assignment }; struct SConfigItem { @@ -68,6 +72,10 @@ public: SConfigItem (IN CHAR8 *, IN EFI_GUID *, IN CHAR8 *); SConfigItem (IN CHAR8 *, IN EFI_GUID *, IN CHAR8 *, IN UINT8, IN UINT16, IN UINT16, IN EFI_IFR_TYPE_VALUE); virtual ~SConfigItem (); + +private: + SConfigItem (IN CONST SConfigItem&); // Prevent copy-construction + SConfigItem& operator= (IN CONST SConfigItem&); // Prevent assignment }; class CVfrBufferConfig { @@ -90,6 +98,10 @@ public: #endif virtual VOID Close (VOID); virtual VOID OutputCFile (IN FILE *, IN CHAR8 *); + +private: + CVfrBufferConfig (IN CONST CVfrBufferConfig&); // Prevent copy-construction + CVfrBufferConfig& operator= (IN CONST CVfrBufferConfig&); // Prevent assignment }; extern CVfrBufferConfig gCVfrBufferConfig; @@ -157,6 +169,10 @@ struct SVfrPackStackNode { return FALSE; } } + +private: + SVfrPackStackNode (IN CONST SVfrPackStackNode&); // Prevent copy-construction + SVfrPackStackNode& operator= (IN CONST SVfrPackStackNode&); // Prevent assignment }; class CVfrVarDataTypeDB { @@ -210,6 +226,10 @@ public: #ifdef CVFR_VARDATATYPEDB_DEBUG VOID ParserDB (); #endif + +private: + CVfrVarDataTypeDB (IN CONST CVfrVarDataTypeDB&); // Prevent copy-construction + CVfrVarDataTypeDB& operator= (IN CONST CVfrVarDataTypeDB&); // Prevent assignment }; extern CVfrVarDataTypeDB gCVfrVarDataTypeDB; @@ -251,6 +271,10 @@ public: SVfrVarStorageNode (IN EFI_GUID *, IN CHAR8 *, IN EFI_VARSTORE_ID, IN SVfrDataType *, IN BOOLEAN Flag = TRUE); SVfrVarStorageNode (IN CHAR8 *, IN EFI_VARSTORE_ID); ~SVfrVarStorageNode (VOID); + +private: + SVfrVarStorageNode (IN CONST SVfrVarStorageNode&); // Prevent copy-construction + SVfrVarStorageNode& operator= (IN CONST SVfrVarStorageNode&); // Prevent assignment }; struct EFI_VARSTORE_INFO { @@ -332,6 +356,10 @@ public: EFI_VFR_RETURN_CODE GetNameVarStoreInfo (IN EFI_VARSTORE_INFO *, IN UINT32); EFI_VFR_RETURN_CODE AddBufferVarStoreFieldInfo (IN EFI_VARSTORE_INFO *); EFI_VFR_RETURN_CODE GetBufferVarStoreFieldInfo (IN OUT EFI_VARSTORE_INFO *); + +private: + CVfrDataStorage (IN CONST CVfrDataStorage&); // Prevent copy-construction + CVfrDataStorage& operator= (IN CONST CVfrDataStorage&); // Prevent assignment }; extern CVfrDataStorage gCVfrDataStorage; @@ -357,6 +385,10 @@ struct SVfrQuestionNode { SVfrQuestionNode (IN CHAR8 *, IN CHAR8 *, IN UINT32 BitMask = 0); ~SVfrQuestionNode (); + +private: + SVfrQuestionNode (IN CONST SVfrQuestionNode&); // Prevent copy-construction + SVfrQuestionNode& operator= (IN CONST SVfrQuestionNode&); // Prevent assignment }; class CVfrQuestionDB { @@ -390,6 +422,10 @@ public: VOID SetCompatibleMode (IN BOOLEAN Mode) { VfrCompatibleMode = Mode; } + +private: + CVfrQuestionDB (IN CONST CVfrQuestionDB&); // Prevent copy-construction + CVfrQuestionDB& operator= (IN CONST CVfrQuestionDB&); // Prevent assignment }; struct SVfrDefaultStoreNode { @@ -402,6 +438,10 @@ struct SVfrDefaultStoreNode { SVfrDefaultStoreNode (IN EFI_IFR_DEFAULTSTORE *, IN CHAR8 *, IN EFI_STRING_ID, IN UINT16); ~SVfrDefaultStoreNode(); + +private: + SVfrDefaultStoreNode (IN CONST SVfrDefaultStoreNode&); // Prevent copy-construction + SVfrDefaultStoreNode& operator= (IN CONST SVfrDefaultStoreNode&); // Prevent assignment }; class CVfrDefaultStore { @@ -417,6 +457,10 @@ public: BOOLEAN DefaultIdRegistered (IN UINT16); EFI_VFR_RETURN_CODE GetDefaultId (IN CHAR8 *, OUT UINT16 *); EFI_VFR_RETURN_CODE BufferVarStoreAltConfigAdd (IN EFI_VARSTORE_ID, IN EFI_VARSTORE_INFO &, IN CHAR8 *, IN EFI_GUID *, IN UINT8, IN EFI_IFR_TYPE_VALUE); + +private: + CVfrDefaultStore (IN CONST CVfrDefaultStore&); // Prevent copy-construction + CVfrDefaultStore& operator= (IN CONST CVfrDefaultStore&); // Prevent assignment }; extern CVfrDefaultStore gCVfrDefaultStore; @@ -431,6 +475,10 @@ struct SVfrRuleNode { SVfrRuleNode(IN CHAR8 *, IN UINT8); ~SVfrRuleNode(); + +private: + SVfrRuleNode (IN CONST SVfrRuleNode&); // Prevent copy-construction + SVfrRuleNode& operator= (IN CONST SVfrRuleNode&); // Prevent assignment }; class CVfrRulesDB { @@ -444,6 +492,10 @@ public: VOID RegisterRule (IN CHAR8 *); UINT8 GetRuleId (IN CHAR8 *); + +private: + CVfrRulesDB (IN CONST CVfrRulesDB&); // Prevent copy-construction + CVfrRulesDB& operator= (IN CONST CVfrRulesDB&); // Prevent assignment }; class CVfrStringDB { @@ -478,6 +530,9 @@ public: IN EFI_STRING_ID StringId ); +private: + CVfrStringDB (IN CONST CVfrStringDB&); // Prevent copy-construction + CVfrStringDB& operator= (IN CONST CVfrStringDB&); // Prevent assignment }; #endif -- 1.9.5.msysgit.0