[Openvpn-devel,v1] win32: pass the buffer size in bytes to get_openvpn_reg_value()

Message ID 20261027130054.2283-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v1] win32: pass the buffer size in bytes to get_openvpn_reg_value() |

Commit Message

Gert Doering Oct. 27, 2026, 1 p.m. UTC
  From: Heiko Hund <heiko@ist.eigentlich.net>

get_openvpn_reg_value() expects the size of the value buffer in bytes,
as documented and as RegGetValueW() expects it. All callers passed the
number of characters instead, so only half of the buffer was used.

Pass sizeof() of the buffers instead of _countof().

Change-Id: Ifa4497963989c2d6ba68d75942d368c112ac6f67
Signed-off-by: Heiko Hund <heiko@ist.eigentlich.net>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2038
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2038
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <frank@lichtenheld.com>
  

Patch

diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c
index fde6412..3af58ed 100644
--- a/src/openvpn/win32.c
+++ b/src/openvpn/win32.c
@@ -1491,7 +1491,7 @@ 
 set_openssl_env_vars(void)
 {
     WCHAR install_path[MAX_PATH] = { 0 };
-    if (!get_openvpn_reg_value(NULL, install_path, _countof(install_path)))
+    if (!get_openvpn_reg_value(NULL, install_path, sizeof(install_path)))
     {
         const WCHAR *ssl_fallback_dir = L"C:\\Windows\\System32";
         /* if we cannot find installation path from the registry,
@@ -1585,8 +1585,8 @@ 
 
     /* Attempt to retrieve the trusted plugin directory path from the registry,
      * using installation path as a fallback */
-    if (!get_openvpn_reg_value(L"plugin_dir", plugin_dir, _countof(plugin_dir))
-        && !get_openvpn_reg_value(NULL, plugin_dir, _countof(plugin_dir)))
+    if (!get_openvpn_reg_value(L"plugin_dir", plugin_dir, sizeof(plugin_dir))
+        && !get_openvpn_reg_value(NULL, plugin_dir, sizeof(plugin_dir)))
     {
         msg(M_WARN, "Installation path could not be determined.");
     }