]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/VrfCompile: Fix uninitialized field from unnamed field
authorMichael D Kinney <michael.d.kinney@intel.com>
Mon, 4 Oct 2021 23:04:41 +0000 (16:04 -0700)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 3 Nov 2021 23:43:46 +0000 (23:43 +0000)
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 <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp

index 2b9b5dbb1ca59b7eb93360f3e5f9744f12437b49..11470de45ccef4641800a4c72d7aa84534a57249 100644 (file)
@@ -1135,6 +1135,8 @@ CVfrVarDataTypeDB::DataTypeAddBitField (
   if (FieldName != NULL) {\r
     strncpy (pNewField->mFieldName, FieldName, MAX_NAME_LEN - 1);\r
     pNewField->mFieldName[MAX_NAME_LEN - 1] = 0;\r
+  } else {\r
+    strncpy (pNewField->mFieldName, "", MAX_NAME_LEN - 1);\r
   }\r
   pNewField->mFieldType    = pFieldType;\r
   pNewField->mIsBitField   = TRUE;\r
@@ -3916,5 +3918,3 @@ CVfrStringDB::GetUnicodeStringTextSize (
 CVfrVarDataTypeDB gCVfrVarDataTypeDB;\r
 CVfrDefaultStore  gCVfrDefaultStore;\r
 CVfrDataStorage  gCVfrDataStorage;\r
-\r
-\r