From: "cron2 (Code Review)" Date: Sun, 16 Nov 2025 18:32:46 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="ZSaJqRrVk+o="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: tls_crypt: Avoid some conversion warnings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos Cc: openvpn-devel --ZSaJqRrVk+o= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#2) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1379?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: tls_crypt: Avoid some conversion warnings ...................................................................... tls_crypt: Avoid some conversion warnings The casts should be safe, since one is a constant (but got type from sizeof()) and the other is limited by the buffer length. While here make the code in tls_crypt_v2_wrap_client_key as little easier to follow. Change-Id: I3f11423834814bab5d653f160fc2326dae4c0e8e Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1379 Message-Id: <20251116140754.17177-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34= 466.html Signed-off-by: Gert Doering --- M src/openvpn/tls_crypt.c 1 file changed, 6 insertions(+), 14 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/79/1379/2 diff --git a/src/openvpn/tls_crypt.c b/src/openvpn/tls_crypt.c index a808de3..ab719b3 100644 --- a/src/openvpn/tls_crypt.c +++ b/src/openvpn/tls_crypt.c @@ -205,11 +205,6 @@ return false; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - bool tls_crypt_unwrap(const struct buffer *src, struct buffer *dst, struct cryp= to_options *opt) { @@ -246,7 +241,7 @@ CRYPT_ERROR("cipher reset failed"); } if (!cipher_ctx_update(ctx->cipher, BPTR(dst), &outlen, BPTR(src) = + TLS_CRYPT_OFF_CT, - BLEN(src) - TLS_CRYPT_OFF_CT)) + BLEN(src) - (int)TLS_CRYPT_OFF_CT)) { CRYPT_ERROR("cipher update failed"); } @@ -381,8 +376,9 @@ msg(M_WARN, "ERROR: could not write tag"); return false; } - uint16_t net_len =3D htons(sizeof(src_key->keys) + BLEN(src_metadata) = + TLS_CRYPT_V2_TAG_SIZE - + sizeof(uint16_t)); + const int data_len =3D BLEN(src_metadata) + sizeof(src_key->keys) + si= zeof(uint16_t); + const int tagged_len =3D data_len + TLS_CRYPT_TAG_SIZE; + const uint16_t net_len =3D htons((uint16_t)tagged_len); hmac_ctx_t *hmac_ctx =3D server_key->hmac; hmac_ctx_reset(hmac_ctx); hmac_ctx_update(hmac_ctx, (void *)&net_len, sizeof(net_len)); @@ -396,8 +392,8 @@ ASSERT(cipher_ctx_reset(cipher_ctx, tag)); /* Overflow check (OpenSSL requires an extra block in the dst buffer) = */ - if (buf_forward_capacity(&work) < (sizeof(src_key->keys) + BLEN(src_me= tadata) + sizeof(net_len) - + cipher_ctx_block_size(cipher_ctx)= )) + const int padded_len =3D data_len + cipher_ctx_block_size(cipher_ctx); + if (buf_forward_capacity(&work) < padded_len) { msg(M_WARN, "ERROR: could not crypt: insufficient space in dst"); return false; @@ -418,10 +414,6 @@ return buf_copy(wkc, &work); } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - static bool tls_crypt_v2_unwrap_client_key(struct key2 *client_key, struct buffer *met= adata, struct buffer wrapped_client_key, struct ke= y_ctx *server_key) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1379?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: I3f11423834814bab5d653f160fc2326dae4c0e8e Gerrit-Change-Number: 1379 Gerrit-PatchSet: 2 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --ZSaJqRrVk+o= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #2 to the change originally created by flichtenhel= d.

View Change

The following approvals got outdated and were remove= d: Code-Review+2 by cron2

tls_crypt: Avoid some conversion wa=
rnings

The casts should be safe, since one is a constant
(but got= type from sizeof()) and the other is
limited by the buffer length.
<= br>While here make the code in tls_crypt_v2_wrap_client_key
as little ea= sier to follow.

Change-Id: I3f11423834814bab5d653f160fc2326dae4c0e8e=
Signed-off-by: Frank Lichtenheld <frank@...2641...>
Acked-by: = Gert Doering <gert@...1296...>
Gerrit URL: https://gerrit.openvpn.= net/c/openvpn/+/1379
Message-Id: <20251116140754.17177-1-gert@...1726...= ...>
URL: https://www.mail-archive.com/openvpn-devel@...1483...= e.net/msg34466.html
Signed-off-by: Gert Doering <gert@...1296...><= br>---
M src/openvpn/tls_crypt.c
1 file changed, 6 insertions(+), 14 = deletions(-)

git pull ssh://gerrit.openvpn.net:2=
9418/openvpn refs/changes/79/1379/2
diff --git a/src/openvpn/tls_cr=
ypt.c b/src/openvpn/tls_crypt.c
index a808de3..ab719b3 1006= 44
--- a/src/openvpn/tls_crypt.c
+++ b/src/= openvpn/tls_crypt.c
@@ -205,11 +205,6 @@
= return false;
}

-#if defined(__GNUC__) || defined(__clang__)=
-#pragma GCC diagnosti= c push
-#pragma GCC dia= gnostic ignored "-Wconversion"
-#endif
-
bool
tls_crypt_unwrap(const struct b= uffer *src, struct buffer *dst, struct crypto_options *opt)
{
@@ -246,7 +241,7 @@
CRYPT_= ERROR("cipher reset failed");
} if (!cipher_ctx_update(ctx->cipher, BPTR(dst), &out= len, BPTR(src) + TLS_CRYPT_OFF_CT,
- BLEN(src) - TLS_CRYPT_OFF_CT))<= /span>
+ = BLEN(src) - (int)TLS_CRYPT_OFF_CT))
{
CRYPT_ERROR("cipher update failed");<= /span>
}
@@ -381,8 +376,9 @@
msg(M_WARN, "ERROR: could not write tag");
return false;
}
- uint16_t net_len =3D htons(sizeof(src_k= ey->keys) + BLEN(src_metadata) + TLS_CRYPT_V2_TAG_SIZE
- + sizeof(u= int16_t));
+ const= int data_len =3D BLEN(src_metadata) + sizeof(src_key->keys) + sizeof(ui= nt16_t);
+ const i= nt tagged_len =3D data_len + TLS_CRYPT_TAG_SIZE;
+ const uint16_t net_len =3D htons((uint16_t= )tagged_len);
hmac_ctx_t *hmac_ctx =3D server_key->= hmac;
hmac_ctx_reset(hmac_ctx);
h= mac_ctx_update(hmac_ctx, (void *)&net_len, sizeof(net_len));
= @@ -396,8 +392,8 @@
ASSERT(cipher_ctx_reset(ciph= er_ctx, tag));

/* Overflow check (Op= enSSL requires an extra block in the dst buffer) */
- if (buf_forward_capacity(&work) <= ; (sizeof(src_key->keys) + BLEN(src_metadata) + sizeof(net_len)- = + cipher_ctx_block_size(cipher_ctx)))
+ const int padded_len =3D data_len + cipher_c= tx_block_size(cipher_ctx);
+ if (buf_forward_capacity(&work) < padded_len)
<= span> {

msg(M_WARN, "ERROR: could not cry= pt: insufficient space in dst");
return false= ;
@@ -418,10 +414,6 @@
return buf_copy= (wkc, &work);
}

-#if defined(__GNUC__) || defined(__clang__= )
-#pragma GCC diagnost= ic pop
-#endif-
static bool<= /span>
tls_crypt_v2_unwrap_client_key(struct key2 *client_key, st= ruct buffer *metadata,
stru= ct buffer wrapped_client_key, struct key_ctx *server_key)
<= /span>

To view, visit change 1379. To unsubscribe, or for help writ= ing mail filters, visit settings.

=
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I3f11423834814bab5d653f160fc= 2326dae4c0e8e
Gerrit-Change-Number: 1379
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --ZSaJqRrVk+o=--