From: "plaisthos (Code Review)" Date: Tue, 14 Oct 2025 11:50:52 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <239197ec395a6d9ab5ce31635b27b41ae94c4a9f-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="oaZUoRodlRs="; 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: flichtenheld Cc: openvpn-devel --oaZUoRodlRs= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld,=20 I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1272?usp=3Demail to look at the new patch set (#2). 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 --- M src/openvpn/tun.c 1 file changed, 14 insertions(+), 3 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/72/1272/2 diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 06b7ae5..8b2d5f4 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -3803,7 +3803,12 @@ 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_FATAL, "Error constructing unit string for %s", enum_nam= e); + } status =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, unit_string, 0, KEY_RE= AD, &unit_key); @@ -3912,8 +3917,14 @@ 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_FATAL, "Error constructing connection string for %s", en= um_name); + } + 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: 2 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld --oaZUoRodlRs= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: flichtenheld.

plaisthos uploaded patch set #2 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/1272?usp=3Demail">View Chan= ge

Silence compiler truncation warning by checking snp=
rintf return value

On the more recent mingw compilers (homebrew ming= w 13.0.0, GCC 15.2.0) the
compiler complains about a potential truncatio= n in these two places.

src/openvpn/tun.c:3806:57:
error: '= ;%s' directive output may be truncated writing up
to 255 bytes int= o a region of size 178
[-Werror=3Dformat-truncation=3D]

This no= t very helpful but checking the snprintf return value
will make the comp= iler not warn about this.

Change-Id: I54b11a5540fb236580a3b80c6d1e86= 78b24bd852
Signed-off-by: Arne Schwabe <arne@...1227...>
---M src/openvpn/tun.c
1 file changed, 14 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn re=
fs/changes/72/1272/2
diff --git a/src/openvpn/tun.c b/src/openvpn/t=
un.c
index 06b7ae5..8b2d5f4 100644
--- a/sr= c/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ = -3803,7 +3803,12 @@
msg(M_FATAL, "Error e= numerating registry subkeys of key: %s", ADAPTER_KEY);
}

- snprintf(unit_string, sizeof(unit_string), "%s\\%s&quo= t;, ADAPTER_KEY, enum_name);
+ int ret =3D snprintf(unit_string, sizeof(unit_string), &qu= ot;%s\\%s", ADAPTER_KEY, enum_name);
+
+ {
+ msg(M_FATAL, "Error cons= tructing unit string for %s", enum_name);
+ }

= status =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, unit_string, 0, KEY_READ, = &unit_key);

@@ -3912,8 +3917,14 @@
msg(M_FATAL, "Error enumerating registry su= bkeys of key: %s", NETWORK_CONNECTIONS_KEY);
= }

- = snprintf(connection_string, sizeof(connection_string), "%s\\%s\\= Connection",
- = NETWORK_CONNECTIONS_KEY, enum_name);
+ int ret =3D snprintf(connection_strin= g, sizeof(connection_string), "%s\\%s\\Connection",
+ NETWOR= K_CONNECTIONS_KEY, enum_name);

+
+ = if (ret < 0 || ret >=3D sizeof(connection_string))
+ {
+ msg(M_FATAL, "Error constructin= g connection string for %s", enum_name);
+ }
+

status =3D RegO= penKeyEx(HKEY_LOCAL_MACHINE, connection_string, 0, KEY_READ, &connectio= n_key);


To view, visi= t change= 1272. To unsubscribe, or for 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: 2
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
= --oaZUoRodlRs=--