* [patch v2] BaseTools/VfrCompile: Avoid using uninitialized pointer @ 2018-05-09 5:02 Dandan Bi 2018-05-09 8:20 ` Gary Lin 2018-05-09 8:22 ` Dong, Eric 0 siblings, 2 replies; 5+ messages in thread From: Dandan Bi @ 2018-05-09 5:02 UTC (permalink / raw) To: edk2-devel; +Cc: Eric Dong, Liming Gao, Gary Lin 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 <eric.dong@intel.com> 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> --- 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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [patch v2] BaseTools/VfrCompile: Avoid using uninitialized pointer 2018-05-09 5:02 [patch v2] BaseTools/VfrCompile: Avoid using uninitialized pointer Dandan Bi @ 2018-05-09 8:20 ` Gary Lin 2018-05-10 3:34 ` Ni, Ruiyu 2018-05-09 8:22 ` Dong, Eric 1 sibling, 1 reply; 5+ messages in thread From: Gary Lin @ 2018-05-09 8:20 UTC (permalink / raw) To: Dandan Bi; +Cc: edk2-devel, Eric Dong, Liming Gao 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 <glin@suse.com> > Cc: Eric Dong <eric.dong@intel.com> > 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> > --- > 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 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch v2] BaseTools/VfrCompile: Avoid using uninitialized pointer 2018-05-09 8:20 ` Gary Lin @ 2018-05-10 3:34 ` Ni, Ruiyu 2018-05-10 3:45 ` Bi, Dandan 0 siblings, 1 reply; 5+ messages in thread From: Ni, Ruiyu @ 2018-05-10 3:34 UTC (permalink / raw) To: Gary Lin, Bi, Dandan; +Cc: edk2-devel@lists.01.org, Dong, Eric, Gao, Liming Dandan, Can you describe the build failure met by Gary Lin in final commit message? The current commit message is not very clear about which issue it may fix. Thanks/Ray > -----Original Message----- > From: edk2-devel <edk2-devel-bounces@lists.01.org> On Behalf Of Gary Lin > Sent: Wednesday, May 9, 2018 4:20 PM > To: Bi, Dandan <dandan.bi@intel.com> > Cc: edk2-devel@lists.01.org; Dong, Eric <eric.dong@intel.com>; Gao, Liming > <liming.gao@intel.com> > Subject: Re: [edk2] [patch v2] BaseTools/VfrCompile: Avoid using > uninitialized pointer > > 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 <glin@suse.com> > > > Cc: Eric Dong <eric.dong@intel.com> > > 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> > > --- > > 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 > > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch v2] BaseTools/VfrCompile: Avoid using uninitialized pointer 2018-05-10 3:34 ` Ni, Ruiyu @ 2018-05-10 3:45 ` Bi, Dandan 0 siblings, 0 replies; 5+ messages in thread From: Bi, Dandan @ 2018-05-10 3:45 UTC (permalink / raw) To: Ni, Ruiyu, Gary Lin; +Cc: edk2-devel@lists.01.org, Dong, Eric, Gao, Liming Hi Ray, Thanks for your suggestion. But we have committed this patch yesterday. :( I will pay more attention to the commit message in the future work. Thanks, Dandan -----Original Message----- From: Ni, Ruiyu Sent: Thursday, May 10, 2018 11:34 AM To: Gary Lin <glin@suse.com>; Bi, Dandan <dandan.bi@intel.com> Cc: edk2-devel@lists.01.org; Dong, Eric <eric.dong@intel.com>; Gao, Liming <liming.gao@intel.com> Subject: RE: [edk2] [patch v2] BaseTools/VfrCompile: Avoid using uninitialized pointer Dandan, Can you describe the build failure met by Gary Lin in final commit message? The current commit message is not very clear about which issue it may fix. Thanks/Ray > -----Original Message----- > From: edk2-devel <edk2-devel-bounces@lists.01.org> On Behalf Of Gary > Lin > Sent: Wednesday, May 9, 2018 4:20 PM > To: Bi, Dandan <dandan.bi@intel.com> > Cc: edk2-devel@lists.01.org; Dong, Eric <eric.dong@intel.com>; Gao, > Liming <liming.gao@intel.com> > Subject: Re: [edk2] [patch v2] BaseTools/VfrCompile: Avoid using > uninitialized pointer > > 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 <glin@suse.com> > > > Cc: Eric Dong <eric.dong@intel.com> > > 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> > > --- > > 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 > > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch v2] BaseTools/VfrCompile: Avoid using uninitialized pointer 2018-05-09 5:02 [patch v2] BaseTools/VfrCompile: Avoid using uninitialized pointer Dandan Bi 2018-05-09 8:20 ` Gary Lin @ 2018-05-09 8:22 ` Dong, Eric 1 sibling, 0 replies; 5+ messages in thread From: Dong, Eric @ 2018-05-09 8:22 UTC (permalink / raw) To: Bi, Dandan, edk2-devel@lists.01.org; +Cc: Gao, Liming, Gary Lin Reviewed-by: Eric Dong <eric.dong@intel.com> -----Original Message----- From: Bi, Dandan Sent: Wednesday, May 9, 2018 1:02 PM To: edk2-devel@lists.01.org Cc: Dong, Eric <eric.dong@intel.com>; Gao, Liming <liming.gao@intel.com>; Gary Lin <glin@suse.com> Subject: [patch v2] 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: Eric Dong <eric.dong@intel.com> 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> --- 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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-05-10 3:45 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-05-09 5:02 [patch v2] BaseTools/VfrCompile: Avoid using uninitialized pointer Dandan Bi 2018-05-09 8:20 ` Gary Lin 2018-05-10 3:34 ` Ni, Ruiyu 2018-05-10 3:45 ` Bi, Dandan 2018-05-09 8:22 ` Dong, Eric
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox