[edk2-devel] [edk2-libc Patch v2 1/1] edk2-libc/StdLib: Uninitialized global variable

Jayaprakash, N n.jayaprakash at intel.com
Fri Jul 21 15:47:52 UTC 2023


REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4506

res_init() is called from different places in sockets library.
It depends on global _res variable containing a state.
The problem is that if __BIND_RES_TEXT macro is not defined, _res is not initialized.
Depending on compiler and build optimization this can fill
the variable with garbage that is later used by res_init().
Fix is trivial - explicitly initialize _res

Cc: Rebecca Cran <rebecca at nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney at intel.com>
Co-authored-by: Kloper Dimitry <dimitry.kloper at intel.com>
Signed-off-by: Jayaprakash N <n.jayaprakash at intel.com>
---
 StdLib/BsdSocketLib/res_init.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/StdLib/BsdSocketLib/res_init.c b/StdLib/BsdSocketLib/res_init.c
index 613a76a..6421d9a 100644
--- a/StdLib/BsdSocketLib/res_init.c
+++ b/StdLib/BsdSocketLib/res_init.c
@@ -122,9 +122,10 @@ static u_int32_t net_mask __P((struct in_addr));
 
 struct __res_state _res
 # if defined(__BIND_RES_TEXT)
-    = { RES_TIMEOUT, }  /* Motorola, et al. */
-# endif
-    ;
+    = { RES_TIMEOUT, }; /* Motorola, et al. */
+#else
+    = {0};
+#endif
 
 
 /*
-- 
2.40.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107130): https://edk2.groups.io/g/devel/message/107130
Mute This Topic: https://groups.io/mt/100279095/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