| Message ID | 20260121121830.27244-1-frank@lichtenheld.com |
|---|---|
| State | New |
| Headers | show |
| Series | [Openvpn-devel,v4] Silence compiler truncation warning by checking snprintf return value | expand |
Compilers... but yeah, the change won't do harm, and might catch something
unexpected with a proper error message. Doesn't change the actual code
flow, so not tested beyond "is the compiler fine with it".
Your patch has been applied to the master branch.
commit 1fe958183fa5877d9e00cbfbe0d29477adff7187
Author: Arne Schwabe
Date: Wed Jan 21 13:18:30 2026 +0100
Silence compiler truncation warning by checking snprintf return value
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1272
Message-Id: <20260121121830.27244-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35367.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
--
kind regards,
Gert Doering
diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 0399b4a..e38df3e 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -3558,7 +3558,13 @@ msg(M_FATAL, "Error enumerating registry subkeys of key: %s", ADAPTER_KEY); } - snprintf(unit_string, sizeof(unit_string), "%s\\%s", ADAPTER_KEY, enum_name); + int ret = snprintf(unit_string, sizeof(unit_string), "%s\\%s", ADAPTER_KEY, enum_name); + + if (ret < 0 || ret >= sizeof(unit_string)) + { + msg(M_WARN, "Error constructing unit string for %s", enum_name); + continue; + } status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, unit_string, 0, KEY_READ, &unit_key); @@ -3667,8 +3673,15 @@ msg(M_FATAL, "Error enumerating registry subkeys of key: %s", NETWORK_CONNECTIONS_KEY); } - snprintf(connection_string, sizeof(connection_string), "%s\\%s\\Connection", - NETWORK_CONNECTIONS_KEY, enum_name); + int ret = snprintf(connection_string, sizeof(connection_string), "%s\\%s\\Connection", + NETWORK_CONNECTIONS_KEY, enum_name); + + if (ret < 0 || ret >= sizeof(connection_string)) + { + msg(M_WARN, "Error constructing connection string for %s", enum_name); + continue; + } + status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, connection_string, 0, KEY_READ, &connection_key);