From: "cron2 (Code Review)" Date: Sat, 24 Jan 2026 15:49:52 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <36fddac46eb4999de6de5a0e28105601d0463eb3-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="/g90c4FA4Yc="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Silence compiler truncation warning by checking snprintf return value List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --/g90c4FA4Yc= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#5) to the change originally created by= plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1272?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by flichtenheld Change subject: Silence compiler truncation warning by checking snprintf re= turn value ...................................................................... Silence compiler truncation warning by checking snprintf return value On the more recent mingw compilers (homebrew mingw 13.0.0, GCC 15.2.0) the compiler complains about a potential truncation in these two places. src/openvpn/tun.c:3806:57: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 178 [-Werror=3Dformat-truncation=3D] This not very helpful but checking the snprintf return value will make the compiler not warn about this. Change-Id: I54b11a5540fb236580a3b80c6d1e8678b24bd852 Signed-off-by: Arne Schwabe Acked-by: Frank Lichtenheld Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1272 Message-Id: <20260121121830.27244-1-frank@...2641...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35= 367.html Signed-off-by: Gert Doering --- M src/openvpn/tun.c 1 file changed, 16 insertions(+), 3 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/72/1272/5 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 =3D snprintf(unit_string, sizeof(unit_string), "%s\\%s", A= DAPTER_KEY, enum_name); + + if (ret < 0 || ret >=3D sizeof(unit_string)) + { + msg(M_WARN, "Error constructing unit string for %s", enum_name= ); + continue; + } status =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, unit_string, 0, KEY_RE= AD, &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\\Co= nnection", - NETWORK_CONNECTIONS_KEY, enum_name); + int ret =3D snprintf(connection_string, sizeof(connection_string),= "%s\\%s\\Connection", + NETWORK_CONNECTIONS_KEY, enum_name); + + if (ret < 0 || ret >=3D sizeof(connection_string)) + { + msg(M_WARN, "Error constructing connection string for %s", enu= m_name); + continue; + } + status =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, connection_string, 0, = KEY_READ, &connection_key); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1272?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I54b11a5540fb236580a3b80c6d1e8678b24bd852 Gerrit-Change-Number: 1272 Gerrit-PatchSet: 5 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel --/g90c4FA4Yc= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #5 to the change originally created by plaisthos.<= /p>

Vi= ew Change

The following approvals got outdated and were removed: Code-Review+2 by flichtenheld

Silence compiler truncation =
warning by checking snprintf return value

On the more recent mingw c= ompilers (homebrew mingw 13.0.0, GCC 15.2.0) the
compiler complains abou= t a potential truncation in these two places.

src/openvpn/tun.c:38= 06:57:
error: '%s' directive output may be truncated writing u= p
to 255 bytes into a region of size 178
[-Werror=3Dformat-trunca= tion=3D]

This not very helpful but checking the snprintf return valu= e
will make the compiler not warn about this.

Change-Id: I54b11a5= 540fb236580a3b80c6d1e8678b24bd852
Signed-off-by: Arne Schwabe <arne@...220...= ..1227...>
Acked-by: Frank Lichtenheld <frank@...2641...>
Ge= rrit URL: https://gerrit.openvpn.net/c/openvpn/+/1272
Message-Id: <20= 260121121830.27244-1-frank@...2641...>
URL: https://www.mail-archive.= com/openvpn-devel@lists.sourceforge.net/msg35367.html
Signed-off-by: Ger= t Doering <gert@...1296...>
---
M src/openvpn/tun.c
1 file c= hanged, 16 insertions(+), 3 deletions(-)

git pul=
l ssh://gerrit.openvpn.net:29418/openvpn refs/changes/72/1272/5
dif=
f --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index 0399b= 4a..e38df3e 100644
--- a/src/openvpn/tun.c
= +++ b/src/openvpn/tun.c
@@ -3558,7 +3558,13 @@
msg(M_FATAL, "Error enumerating registry subkeys of k= ey: %s", ADAPTER_KEY);
}

- snprintf(unit_st= ring, sizeof(unit_string), "%s\\%s", ADAPTER_KEY, enum_name);
+ int ret =3D snp= rintf(unit_string, sizeof(unit_string), "%s\\%s", ADAPTER_KEY, en= um_name);
++ if (ret < 0 || ret= >=3D sizeof(unit_string))
+ {
+= msg(M_WARN, "Error constructing unit string for %s", = enum_name);
+ = continue;
+ = }

status =3D 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_C= ONNECTIONS_KEY);
}

- snprintf(connection_string,= sizeof(connection_string), "%s\\%s\\Connection",

- NETWORK_CONNECTIONS_= KEY, enum_name);
+ = int ret =3D snprintf(connection_string, sizeof(connection_string), &qu= ot;%s\\%s\\Connection",
+ NETWORK_CONNECTIONS_KEY, enum_name);
+
+ if (ret < 0 || ret >=3D siz= eof(connection_string))
+ {
+ = msg(M_WARN, "Error constructing connection string for %s", = enum_name);
+ = continue;
+ = }
+

status =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, con= nection_string, 0, KEY_READ, &connection_key);
=

To view, visit change 1272. To unsubscribe, or fo= r help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I54b11a5540fb236580a3b80c6d1= e8678b24bd852
Gerrit-Change-Number: 1272
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --/g90c4FA4Yc=--