[Openvpn-devel] Fix possibly uninitialized return value in GetOpenvpnSettings()

Message ID 1582159777-2437-1-git-send-email-selva.nair@gmail.com
State Accepted
Headers show
Series
  • [Openvpn-devel] Fix possibly uninitialized return value in GetOpenvpnSettings()
Related show

Commit Message

Selva Nair Feb. 20, 2020, 12:49 a.m.
From: Selva Nair <selva.nair@gmail.com>

Compile time warning for openvpnserv.exe
common.c:90:11: warning: ‘error’ may be used uninitialized in this
function [-Wmaybe-uninitialized];

Uninitialized value gets returned if install-path is not found
in the registry. Fix by setting it to the return value of
GetRegString().

Signed-off-by: Selva Nair <selva.nair@gmail.com>
---
Behaviour change: previously, on not finding the install_path
in registry, the service logged an error and often continued
as the uninitialized value of error could be zero. With
this change it will consistently exit with error.

 src/openvpnserv/common.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Lev Stipakov Feb. 20, 2020, 9:15 a.m. | #1
Hi,

Compiled with MSVC and MinGW, warning is gone.

Acked-by: Lev Stipakov <lstipakov@gmail.com>

Patch

diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c
index fd51776..958643d 100644
--- a/src/openvpnserv/common.c
+++ b/src/openvpnserv/common.c
@@ -118,8 +118,10 @@  GetOpenvpnSettings(settings_t *s)
     }
 
     /* The default value of REG_KEY is the install path */
-    if (GetRegString(key, NULL, install_path, sizeof(install_path), NULL) != ERROR_SUCCESS)
+    status = GetRegString(key, NULL, install_path, sizeof(install_path), NULL);
+    if (status != ERROR_SUCCESS)
     {
+        error = status;
         goto out;
     }