From: "cron2 (Code Review)" Date: Wed, 8 Oct 2025 09:44:33 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., max@...2606... Message-ID: <674dffec64147fee1a66500788d79a830b240591-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="MoWyfeMBT7E="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: crypto: Make some casts to int explicit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: MaxF , plaisthos , openvpn-devel --MoWyfeMBT7E= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/12= 17?usp=3Demail ) Change subject: crypto: Make some casts to int explicit ...................................................................... crypto: Make some casts to int explicit In all of these cases the cast is safe to do since we have limits imposed in other ways. And we want those values as int, so no alternative to casting. Change-Id: I3b8dd8d5671e31dba2a23a0a78f36d9dda034b88 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1217 Message-Id: <20251008092859.875-1-gert@...1296...> URL: https://sourceforge.net/p/openvpn/mailman/message/59243794/ Signed-off-by: Gert Doering --- M src/openvpn/crypto.c 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index 6376c11..307d1ee 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -186,11 +186,6 @@ return; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - static void openvpn_encrypt_v1(struct buffer *buf, struct buffer work, struct crypto_o= ptions *opt) { @@ -302,7 +297,7 @@ if (ctx->hmac) { hmac_ctx_reset(ctx->hmac); - hmac_ctx_update(ctx->hmac, hmac_start, BEND(&work) - hmac_star= t); + hmac_ctx_update(ctx->hmac, hmac_start, (int)(BEND(&work) - hma= c_start)); hmac_ctx_final(ctx->hmac, mac_out); dmsg(D_PACKET_CONTENT, "ENCRYPT HMAC: %s", format_hex(mac_out, hmac_ctx_size(ctx->hmac), 80, &gc)); @@ -533,7 +528,7 @@ } } - const int ad_size =3D BPTR(buf) - ad_start; + const int ad_size =3D (int)(BPTR(buf) - ad_start); uint8_t *tag_ptr =3D NULL; int data_len =3D 0; @@ -1366,8 +1361,8 @@ int state =3D PARSE_INITIAL; /* constants */ - const int hlen =3D strlen(static_key_head); - const int flen =3D strlen(static_key_foot); + const int hlen =3D (int)strlen(static_key_head); + const int flen =3D (int)strlen(static_key_foot); const int onekeylen =3D sizeof(key2->keys[0]); CLEAR(*key2); @@ -1378,7 +1373,9 @@ */ if (flags & RKF_INLINE) /* 'file' is a string containing ascii represe= ntation of key */ { - size =3D strlen(file) + 1; + size_t buf_size =3D strlen(file) + 1; + ASSERT(buf_size <=3D INT_MAX); + size =3D (int)buf_size; buf_set_read(&in, (const uint8_t *)file, size); } else /* 'file' is a filename which refers to a file containing the asc= ii key */ @@ -1537,10 +1534,6 @@ gc_free(&gc); } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - int write_key_file(const int nkeys, const char *filename) { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1217?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: merged Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I3b8dd8d5671e31dba2a23a0a78f36d9dda034b88 Gerrit-Change-Number: 1217 Gerrit-PatchSet: 5 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: MaxF Gerrit-CC: openvpn-devel --MoWyfeMBT7E= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

crypto: Make some casts to int explicit

I= n all of these cases the cast is safe to do
since we have limits imposed= in other ways.

And we want those values as int, so no
alternativ= e to casting.

Change-Id: I3b8dd8d5671e31dba2a23a0a78f36d9dda034b88Signed-off-by: Frank Lichtenheld <frank@...2641...>
Acked-by: Ge= rt Doering <gert@...1296...>
Gerrit URL: https://gerrit.openvpn.ne= t/c/openvpn/+/1217
Message-Id: <20251008092859.875-1-gert@...1296...&= gt;
URL: https://sourceforge.net/p/openvpn/mailman/message/59243794/
= Signed-off-by: Gert Doering <gert@...1296...>
---
M src/openvpn= /crypto.c
1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index 6376c11..307d1ee 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -186,11 +186,6= @@
return;
}

-#if defined(__GNUC__) || de= fined(__clang__)
-#prag= ma GCC diagnostic push
= -#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
static void
openvpn_= encrypt_v1(struct buffer *buf, struct buffer work, struct crypto_options *o= pt)
{
@@ -302,7 +297,7 @@
= if (ctx->hmac)
{
= hmac_ctx_reset(ctx->hmac);
- hmac_ctx_update(ctx->hmac, hmac_start, BEND(= &work) - hmac_start);
+ hmac_ctx_update(ctx->hmac, hmac_start, (int)(BEND(&= ;work) - hmac_start));
hmac_ctx_final(ctx->= hmac, mac_out);
dmsg(D_PACKET_CONTENT, "E= NCRYPT HMAC: %s",
format_hex(mac_out= , hmac_ctx_size(ctx->hmac), 80, &gc));
@@ -533,7 +52= 8,7 @@
}
}
<= /span>
- const int ad_size = =3D BPTR(buf) - ad_start;
+ const int ad_size =3D (int)(BPTR(buf) - ad_start);

uint8_t *tag_ptr =3D NULL;
in= t data_len =3D 0;
@@ -1366,8 +1361,8 @@
= int state =3D PARSE_INITIAL;

/* co= nstants */
- const i= nt hlen =3D strlen(static_key_head);
- const int flen =3D strlen(static_key_foot);
+ const int hlen =3D (int)strl= en(static_key_head);
= + const int flen =3D (int)strlen(static_key_foot);
= const int onekeylen =3D sizeof(key2->keys[0]);
<= br> CLEAR(*key2);
@@ -1378,7 +1373,9 @@ */
if (flags & RKF_INLINE) /* 'fi= le' is a string containing ascii representation of key */
{
- size= =3D strlen(file) + 1;
+ ASSERT(buf_size <=3D INT_MAX);
+ size =3D (int)bu= f_size;
buf_set_read(&in, (const uint8_t *)fil= e, size);
}
else /* 'file'= ; is a filename which refers to a file containing the ascii key */@@ -1537,10 +1534,6 @@
gc_free(&gc);
}

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
int
write_key_file= (const int nkeys, const char *filename)
{
=

To view, visit change 1217. To unsubscribe, or for help wri= ting mail filters, visit settings.

=
Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I3b8dd8d5671e31dba2a23a0a78f= 36d9dda034b88
Gerrit-Change-Number: 1217
Gerrit-PatchSet: 5
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: MaxF <max@...2606...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --MoWyfeMBT7E=--