From: Hao Wu <hao.a.wu@intel.com>
To: edk2-devel@lists.01.org
Cc: Hao Wu <hao.a.wu@intel.com>, Liming Gao <liming.gao@intel.com>,
Yonghong Zhu <yonghong.zhu@intel.com>,
Eric Dong <eric.dong@intel.com>, Dandan Bi <dandan.bi@intel.com>
Subject: [PATCH v2 28/53] BaseTools/VfrCompile: Avoid freeing freed memory in classes
Date: Thu, 3 Nov 2016 15:22:38 +0800 [thread overview]
Message-ID: <1478157783-9368-29-git-send-email-hao.a.wu@intel.com> (raw)
In-Reply-To: <1478157783-9368-1-git-send-email-hao.a.wu@intel.com>
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 <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
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.<BR>
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
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
next prev parent reply other threads:[~2016-11-03 7:23 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-03 7:22 [PATCH v2 00/53] Resolve issues for C source codes in BaseTools Hao Wu
2016-11-03 7:22 ` [PATCH v2 01/53] BaseTools/C/Common: Avoid possible NULL pointer dereference Hao Wu
2016-11-03 7:22 ` [PATCH v2 02/53] BaseTools/EfiRom: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 03/53] BaseTools/GenFfs: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 04/53] BaseTools/GenFv: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 05/53] BaseTools/GenFw: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 06/53] BaseTools/GenPage: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 07/53] BaseTools/GenSec: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 08/53] BaseTools/GenVtf: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 09/53] BaseTools/TianoCompress: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 10/53] BaseTools/VfrCompile: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 11/53] BaseTools/VolInfo: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 12/53] BaseTools/TianoCompress: Initialize local variables before being used Hao Wu
2016-11-03 7:22 ` [PATCH v2 13/53] BaseTools/VfrCompile: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 14/53] BaseTools/GenBootSector: Fix parameter format mismatch in printf functions Hao Wu
2016-11-03 7:22 ` [PATCH v2 15/53] BaseTools/VolInfo: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 16/53] BaseTools/C/Common: Fix parameter format mismatch in scanf functions Hao Wu
2016-11-03 7:22 ` [PATCH v2 17/53] BaseTools/GenFv: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 18/53] BaseTools/GenFw: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 19/53] BaseTools/GenVtf: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 20/53] BaseTools/C/Common: Add checks for array access Hao Wu
2016-11-03 7:22 ` [PATCH v2 21/53] BaseTools/TianoCompress: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 22/53] BaseTools/VfrCompile: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 23/53] BaseTools/EfiRom: Add checks for user/file inputs Hao Wu
2016-11-03 7:22 ` [PATCH v2 24/53] BaseTools/GenFv: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 25/53] BaseTools/VfrCompile: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 26/53] BaseTools/VfrCompile: Avoid freeing memory with mismatched functions Hao Wu
2016-11-03 7:22 ` [PATCH v2 27/53] BaseTools/VfrCompile: Add assignment operator definition for some classes Hao Wu
2016-11-03 7:22 ` Hao Wu [this message]
2016-11-03 7:22 ` [PATCH v2 29/53] BaseTools/VfrCompile: Remove unused local variables Hao Wu
2016-11-03 7:22 ` [PATCH v2 30/53] BaseTools/C/Common: Fix potential memory leak Hao Wu
2016-11-03 7:22 ` [PATCH v2 31/53] BaseTools/EfiRom: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 32/53] BaseTools/GenFv: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 33/53] BaseTools/GenPage: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 34/53] BaseTools/GenSec: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 35/53] BaseTools/GenVtf: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 36/53] BaseTools/Split: Fix potential memory and resource leak Hao Wu
2016-11-03 7:22 ` [PATCH v2 37/53] BaseTools/TianoCompress: Fix potential memory leak Hao Wu
2016-11-03 7:22 ` [PATCH v2 38/53] BaseTools/VfrCompile: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 39/53] BaseTools/VolInfo: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 40/53] BaseTools/EfiRom: Fix file handles not being closed Hao Wu
2016-11-03 7:22 ` [PATCH v2 41/53] BaseTools/GenBootSector: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 42/53] BaseTools/GenCrc32: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 43/53] BaseTools/GenFv: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 44/53] BaseTools/GenVtf: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 45/53] BaseTools/LzmaCompress: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 46/53] BaseTools/TianoCompress: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 47/53] BaseTools/VolInfo: " Hao Wu
2016-11-03 7:22 ` [PATCH v2 48/53] BaseTools/GenVtf: Provide string width in '%s' specifier in format string Hao Wu
2016-11-03 7:22 ` [PATCH v2 49/53] BaseTools/VolInfo: " Hao Wu
2016-11-03 7:23 ` [PATCH v2 50/53] BaseTools/VfrCompile: Explicitly state format string for DebugMsg() Hao Wu
2016-11-03 7:23 ` [PATCH v2 51/53] BaseTools/VolInfo: Add definitions for command format strings Hao Wu
2016-11-03 7:23 ` [PATCH v2 52/53] BaseTools/VfrCompile/Pccts: Add virtual destructor for class DLGInputStream Hao Wu
2016-11-03 7:23 ` [PATCH v2 53/53] BaseTools/VfrCompile/Pccts: Make assignment operator not returning void Hao Wu
2016-11-08 1:05 ` [PATCH v2 00/53] Resolve issues for C source codes in BaseTools Gao, Liming
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1478157783-9368-29-git-send-email-hao.a.wu@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox