From: "flichtenheld (Code Review)" Date: Fri, 24 Oct 2025 16:52:51 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <6afd005d8c5e7eda1a917810219007636f8133bb-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="bg+v8sdVfFY="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: ssl: Clean up type handling in write_string() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --bg+v8sdVfFY= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1300?usp=3Demail to review the following change. Change subject: ssl: Clean up type handling in write_string() ...................................................................... ssl: Clean up type handling in write_string() Make better checks for the maxlen input value. Change-Id: I3309265edf8d6bea7bd73b21eef589a92ede6e0a Signed-off-by: Frank Lichtenheld --- M src/openvpn/ssl.c 1 file changed, 9 insertions(+), 8 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/00/1300/1 diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 925c5af..39abb59 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -1781,20 +1781,16 @@ return true; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - static bool write_string(struct buffer *buf, const char *str, const int maxlen) { - const int len =3D strlen(str) + 1; - if (len < 1 || (maxlen >=3D 0 && len > maxlen)) + const size_t len =3D strlen(str) + 1; + const size_t real_maxlen =3D (maxlen >=3D 0 && maxlen <=3D UINT16_MAX)= ? (size_t)maxlen : UINT16_MAX; + if (len < 2 || len > real_maxlen) { return false; } - if (!buf_write_u16(buf, len)) + if (!buf_write_u16(buf, (uint16_t)len)) { return false; } @@ -1834,6 +1830,11 @@ return len; } +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + static char * read_string_alloc(struct buffer *buf) { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1300?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I3309265edf8d6bea7bd73b21eef589a92ede6e0a Gerrit-Change-Number: 1300 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --bg+v8sdVfFY= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

V= iew Change

ssl: Clean up type handling in write_string=
()

Make better checks for the maxlen input value.

Change-Id: = I3309265edf8d6bea7bd73b21eef589a92ede6e0a
Signed-off-by: Frank Lichtenhe= ld <frank@...2641...>
---
M src/openvpn/ssl.c
1 file changed= , 9 insertions(+), 8 deletions(-)

git pull ssh:=
//gerrit.openvpn.net:29418/openvpn refs/changes/00/1300/1
diff --=
git a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index 925c5af..= 39abb59 100644
--- a/src/openvpn/ssl.c
+++ = b/src/openvpn/ssl.c
@@ -1781,20 +1781,16 @@
return true;
}

-#if defined(__GNUC__) || defined(__clang_= _)
-#pragma GCC diagnos= tic push
-#pragma GCC d= iagnostic ignored "-Wconversion"
-#endif
-
static bool
write_string(struct bu= ffer *buf, const char *str, const int maxlen)
{
= - const int len =3D strlen(str= ) + 1;
- if (len <= ; 1 || (maxlen >=3D 0 && len > maxlen))
+ const size_t len =3D strlen(str) + 1;=
+ const size_t re= al_maxlen =3D (maxlen >=3D 0 && maxlen <=3D UINT16_MAX) ? (si= ze_t)maxlen : UINT16_MAX;
+ if (len < 2 || len > real_maxlen)
{
return false;
}
- if (!buf_write_u16(buf, len))
+ if (!buf_write_u16(= buf, (uint16_t)len))
{
return= false;
}
@@ -1834,6 +1830,11 @@

return len;
}

= +#if defined(__GNUC__) || defin= ed(__clang__)
+#pragm= a GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion"
+#endif
+
static char *
r= ead_string_alloc(struct buffer *buf)
{

To view, visit change 1300. To unsubscribe, or for help writin= g mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I3309265edf8d6bea7bd73b21eef= 589a92ede6e0a
Gerrit-Change-Number: 1300
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
= --bg+v8sdVfFY=--