[edk2-devel] [Patch 1/1] BaseTools/VrfCompile: Fix uninitialized field from unnamed field

Bob Feng bob.c.feng at intel.com
Tue Nov 2 05:10:44 UTC 2021


This patch is good to me.

Reviewed-by: Bob Feng <bob.c.feng at intel.com>

-----Original Message-----
From: Kinney, Michael D <michael.d.kinney at intel.com> 
Sent: Tuesday, November 2, 2021 1:45 AM
To: devel at edk2.groups.io
Cc: Feng, Bob C <bob.c.feng at intel.com>; Liming Gao <gaoliming at byosoft.com.cn>; Chen, Christine <yuwei.chen at intel.com>
Subject: [Patch 1/1] 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 <bob.c.feng at intel.com>
Cc: Liming Gao <gaoliming at byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen at intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney at intel.com>
---
 BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
index 2b9b5dbb1ca5..11470de45cce 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;
-
-
--
2.32.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#83089): https://edk2.groups.io/g/devel/message/83089
Mute This Topic: https://groups.io/mt/86747261/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-






More information about the edk2-devel-archive mailing list