From b258f12889c09555e99c9cebf56dba45190c5dc2 Mon Sep 17 00:00:00 2001 From: Michael D Kinney Date: Mon, 4 Oct 2021 16:04:41 -0700 Subject: BaseTools/VrfCompile: Fix uninitialized field from unnamed field REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3687 If a C structure parsed by the VFR compiler contains an unnamed field, then mFieldName is left uninitialized, which generates random data in the VFR compiler output file. If the FieldName is NULL, then initialize pNewField->mFieldName to a Null-terminated empty string. Cc: Bob Feng Cc: Liming Gao Cc: Yuwei Chen Signed-off-by: Michael D Kinney Reviewed-by: Liming Gao Reviewed-by: Bob Feng --- BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'BaseTools/Source') diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp index 2b9b5db..11470de 100644 --- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp +++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp @@ -1135,6 +1135,8 @@ CVfrVarDataTypeDB::DataTypeAddBitField ( if (FieldName != NULL) { strncpy (pNewField->mFieldName, FieldName, MAX_NAME_LEN - 1); pNewField->mFieldName[MAX_NAME_LEN - 1] = 0; + } else { + strncpy (pNewField->mFieldName, "", MAX_NAME_LEN - 1); } pNewField->mFieldType = pFieldType; pNewField->mIsBitField = TRUE; @@ -3916,5 +3918,3 @@ CVfrStringDB::GetUnicodeStringTextSize ( CVfrVarDataTypeDB gCVfrVarDataTypeDB; CVfrDefaultStore gCVfrDefaultStore; CVfrDataStorage gCVfrDataStorage; - - -- cgit v1.1