BaseTools/VfrCompile: Avoid using uninitialized pointer

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: Liming Gao <liming.gao@intel.com>
Cc: Gary Lin <glin@suse.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
This commit is contained in:
Bi, Dandan 2018-05-09 13:02:11 +08:00 committed by Eric Dong
parent e91797885a
commit 13e3f8c033
1 changed files with 20 additions and 3 deletions

View File

@ -4086,7 +4086,15 @@ 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()); >>
@ -4990,6 +4998,7 @@ private:
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);
@ -5079,6 +5088,15 @@ EfiVfrParser::_SAVE_OPHDR_COND (
}
}
VOID
EfiVfrParser::_INIT_OPHDR_COND (
VOID
)
{
mCIfrOpHdr[mCIfrOpHdrIndex] = NULL;
mCIfrOpHdrLineNo[mCIfrOpHdrIndex] = 0;
}
VOID
EfiVfrParser::_CLEAR_SAVED_OPHDR (
VOID
@ -5086,9 +5104,8 @@ EfiVfrParser::_CLEAR_SAVED_OPHDR (
{
if (mCIfrOpHdr[mCIfrOpHdrIndex] != NULL) {
delete mCIfrOpHdr[mCIfrOpHdrIndex];
mCIfrOpHdr[mCIfrOpHdrIndex] = NULL;
mCIfrOpHdr[mCIfrOpHdrIndex] = NULL;
}
mCIfrOpHdrLineNo[mCIfrOpHdrIndex] = 0;
}
BOOLEAN