From: "flichtenheld (Code Review)"
Date: Mon, 16 Mar 2026 11:56:47 +0000
In-Reply-To:
References:
Reply-To: frank@...2641..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net, gert@...1296...
Message-ID:
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="nCD9YuWbjmE="; charset=UTF-8
Subject: [Openvpn-devel] [S] Change in openvpn[master]: ssl_mbedtls: Avoid
conversion and sign-compare warnings
List-Id:
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
To: plaisthos
Cc: openvpn-devel
--nCD9YuWbjmE=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: flichtenheld, plaisthos.
Hello cron2, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1559?usp=3Demail
to look at the new patch set (#5).
The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied=
now.
Change subject: ssl_mbedtls: Avoid conversion and sign-compare warnings
......................................................................
ssl_mbedtls: Avoid conversion and sign-compare warnings
Change-Id: I777a3a5f4f137432a19746972e2aad1732184feb
Signed-off-by: Frank Lichtenheld
---
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_verify_mbedtls.c
2 files changed, 17 insertions(+), 31 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/59/1559/5
diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c
index a9506ef..d0c481e 100644
--- a/src/openvpn/ssl_mbedtls.c
+++ b/src/openvpn/ssl_mbedtls.c
@@ -624,12 +624,6 @@
return 0;
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
#if MBEDTLS_VERSION_NUMBER < 0x04000000
/**
* external_pkcs1_sign implements a mbed TLS rsa_sign_func callback, that =
uses
@@ -656,7 +650,6 @@
{
struct external_context *const ctx =3D ctx_voidptr;
int rv;
- uint8_t *to_sign =3D NULL;
size_t asn_len =3D 0, oid_size =3D 0;
const char *oid =3D NULL;
@@ -688,11 +681,13 @@
asn_len =3D 10 + oid_size;
}
- if ((SIZE_MAX - hashlen) < asn_len || ctx->signature_length < (asn_len=
+ hashlen))
+ if (ctx->signature_length < (asn_len + hashlen)
+ || (asn_len + hashlen) > UINT8_MAX)
{
return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
}
=20
+ uint8_t *to_sign =3D NULL;
ALLOC_ARRAY_CLEAR(to_sign, uint8_t, asn_len + hashlen);
uint8_t *p =3D to_sign;
if (md_alg !=3D MBEDTLS_MD_NONE)
@@ -707,20 +702,20 @@
* Digest ::=3D OCTET STRING
*/
*p++ =3D MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
- *p++ =3D (unsigned char)(0x08 + oid_size + hashlen);
+ *p++ =3D (uint8_t)(0x08 + oid_size + hashlen);
*p++ =3D MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
- *p++ =3D (unsigned char)(0x04 + oid_size);
+ *p++ =3D (uint8_t)(0x04 + oid_size);
*p++ =3D MBEDTLS_ASN1_OID;
- *p++ =3D oid_size & 0xFF;
+ *p++ =3D (uint8_t)oid_size;
memcpy(p, oid, oid_size);
p +=3D oid_size;
*p++ =3D MBEDTLS_ASN1_NULL;
*p++ =3D 0x00;
*p++ =3D MBEDTLS_ASN1_OCTET_STRING;
- *p++ =3D hashlen;
+ *p++ =3D (uint8_t)hashlen;
/* Double-check ASN length */
- ASSERT(asn_len =3D=3D p - to_sign);
+ ASSERT(asn_len =3D=3D (uintptr_t)(p - to_sign));
}
/* Copy the hash to be signed */
@@ -810,7 +805,7 @@
goto cleanup;
}
- if (openvpn_base64_decode(dst_b64, dst, (int)dst_len) !=3D dst_len)
+ if (openvpn_base64_decode(dst_b64, dst, (int)dst_len) !=3D (int)dst_le=
n)
{
goto cleanup;
}
@@ -923,6 +918,8 @@
{
size_t read_len =3D 0;
+ ASSERT(out_len <=3D INT_MAX);
+
if (in->first_block =3D=3D NULL)
{
return MBEDTLS_ERR_SSL_WANT_READ;
@@ -930,7 +927,7 @@
while (in->first_block !=3D NULL && read_len < out_len)
{
- int block_len =3D in->first_block->length - in->data_start;
+ size_t block_len =3D in->first_block->length - in->data_start;
if (block_len <=3D out_len - read_len)
{
buffer_entry *cur_entry =3D in->first_block;
@@ -956,7 +953,7 @@
}
}
- return read_len;
+ return (int)read_len;
}
static int
@@ -975,6 +972,8 @@
return MBEDTLS_ERR_NET_SEND_FAILED;
}
+ ASSERT(len <=3D INT_MAX);
+
new_block->length =3D len;
new_block->next_block =3D NULL;
@@ -992,7 +991,7 @@
out->last_block =3D new_block;
- return len;
+ return (int)len;
}
static int
@@ -1012,7 +1011,7 @@
static void
my_debug(void *ctx, int level, const char *file, int line, const char *str)
{
- int my_loglevel =3D (level < 3) ? D_TLS_DEBUG_MED : D_TLS_DEBUG;
+ msglvl_t my_loglevel =3D (level < 3) ? D_TLS_DEBUG_MED : D_TLS_DEBUG;
msg(my_loglevel, "mbed TLS msg (%s:%d): %s", file, line, str);
}
@@ -1048,10 +1047,6 @@
#endif /* MBEDTLS_VERSION_NUMBER < 0x040000 */
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
int
tls_version_max(void)
{
diff --git a/src/openvpn/ssl_verify_mbedtls.c b/src/openvpn/ssl_verify_mbed=
tls.c
index 7495085..ad5479c 100644
--- a/src/openvpn/ssl_verify_mbedtls.c
+++ b/src/openvpn/ssl_verify_mbedtls.c
@@ -565,11 +565,6 @@
gc_free(&gc);
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
/*
* Save X509 fields to environment, using the naming convention:
*
@@ -678,10 +673,6 @@
return fFound;
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
result_t
x509_verify_cert_eku(mbedtls_x509_crt *cert, const char *const expected_oi=
d)
{
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1559?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: I777a3a5f4f137432a19746972e2aad1732184feb
Gerrit-Change-Number: 1559
Gerrit-PatchSet: 5
Gerrit-Owner: flichtenheld
Gerrit-Reviewer: cron2
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-Attention: plaisthos
Gerrit-Attention: flichtenheld
--nCD9YuWbjmE=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is cur=
rently required from: flichtenheld, plaisthos.
flichtenheld uploaded patch set #5 to this change.
<=
p>View C=
hange
The change is no longer submittable: checks~ChecksSubmitRul=
e is unsatisfied now.
ssl_mbedtls: Avoid conversion and si=
gn-compare warnings
Change-Id: I777a3a5f4f137432a19746972e2aad173218=
4feb
Signed-off-by: Frank Lichtenheld <frank@...2641...>
---
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_verify_mbedtls.c
2 fil=
es changed, 17 insertions(+), 31 deletions(-)
gi=
t pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/59/1559/5
<=
pre style=3D"font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c=
index a9506ef..d0c481e 100644
--- a/src/openvpn/s=
sl_mbedtls.c
+++ b/src/openvpn/ssl_mbedtls.c
@@ -624,12 +624,6 @@
return 0;
}
-#if de=
fined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion&quo=
t;
-#pragma GCC diagnos=
tic ignored "-Wsign-compare"
-#endif
-
#if MBEDTLS_VERSION_NUMBER < 0x04000000
/**
* external_pkcs1_sign implements a mbed TLS rsa_=
sign_func callback, that uses
@@ -656,7 +650,6 @@
{
struct external_context *const ctx =3D ctx_v=
oidptr;
int rv;
- uint8_t *to_sign =3D NULL;
size_t a=
sn_len =3D 0, oid_size =3D 0;
const char *oid =3D NULL=
;
@@ -688,11 +681,13 @@
=
asn_len =3D 10 + oid_size;
}
=
- if ((SIZE_MAX - h=
ashlen) < asn_len || ctx->signature_length < (asn_len + hashlen))<=
/span>
+ if (ctx->sign=
ature_length < (asn_len + hashlen)
+ || (asn_len + hashlen) > UINT8_MAX)
=
{
return MBEDTLS_ERR_RSA_BAD_INPUT_DATA=
;
}
+ uint8_t *to_sign =3D NULL;
=
ALLOC_ARRAY_CLEAR(to_sign, uint8_t, asn_len + hashlen);
=
uint8_t *p =3D to_sign;
if (md_alg !=3D MBEDTLS_MD_N=
ONE)
@@ -707,20 +702,20 @@
* Dige=
st ::=3D OCTET STRING
*/
=
*p++ =3D MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
- *p++ =3D (unsigned char)(0x08=
+ oid_size + hashlen);
+ *p++ =3D (uint8_t)(0x08 + oid_size + hashlen);
=
*p++ =3D MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;<=
br>- *p++ =3D (unsigned ch=
ar)(0x04 + oid_size);
+ *p++ =3D (uint8_t)(0x04 + oid_size);
*p+=
+ =3D MBEDTLS_ASN1_OID;
- *p++ =3D oid_size & 0xFF;
+ *p++ =3D (uint8_t)oid_size;
=
memcpy(p, oid, oid_size);
p +=3D oid_size;=
span>
*p++ =3D MBEDTLS_ASN1_NULL;
=
*p++ =3D 0x00;
*p++ =3D MBEDTLS_ASN1_OCTET_STRIN=
G;
- *p++ =3D ha=
shlen;
+ *p++ =
=3D (uint8_t)hashlen;
/* Double-=
check ASN length */
- =
ASSERT(asn_len =3D=3D p - to_sign);
+ ASSERT(asn_len =3D=3D (uintptr_t)(p - to_sign=
));
}
/* Copy t=
he hash to be signed */
@@ -810,7 +805,7 @@
goto cleanup;
}
=
- if (openvpn_base64_decode(ds=
t_b64, dst, (int)dst_len) !=3D dst_len)
+ if (openvpn_base64_decode(dst_b64, dst, (int)dst_le=
n) !=3D (int)dst_len)
{
goto =
cleanup;
}
@@ -923,6 +918,8 @@<=
br> {
size_t read_len =3D 0;
=
span>
+ ASSERT(out_len &l=
t;=3D INT_MAX);
+
if (in->first_block =3D=3D NULL)
=
{
return MBEDTLS_ERR_SSL_WANT_READ;
@@ -930,7 +927,7 @@
while (in->=
first_block !=3D NULL && read_len < out_len)
=
{
- int block_=
len =3D in->first_block->length - in->data_start;
+ size_t block_len =3D in->=
first_block->length - in->data_start;
if (bl=
ock_len <=3D out_len - read_len)
{
buffer_entry *cur_entry =3D in->first_block;
=
@@ -956,7 +953,7 @@
}
}=
- =
return read_len;
+ =
return (int)read_len;
}
static int
@@ -975,6 +972,8 @@
=
return MBEDTLS_ERR_NET_SEND_FAILED;
}
=
+ ASSERT(len <=
;=3D INT_MAX);
+
new_block->length =3D len;
new_blo=
ck->next_block =3D NULL;
@@ -992,7 +99=
1,7 @@
out->last_block =3D new_bl=
ock;
=
- return len;
+ =
return (int)len;
}
sta=
tic int
@@ -1012,7 +1011,7 @@
static void<=
/span>
my_debug(void *ctx, int level, const char *file, int line,=
const char *str)
{
- int my_loglevel =3D (level < 3) ? D_TLS_DEBUG_MED : D=
_TLS_DEBUG;
+ msgl=
vl_t my_loglevel =3D (level < 3) ? D_TLS_DEBUG_MED : D_TLS_DEBUG;=
msg(my_loglevel, "mbed TLS msg (%s:%d): %s", file,=
line, str);
}
@@ -1048,=
10 +1047,6 @@
#endif /* MBEDTLS_VERSION_NUMBER < 0x0400=
00 */
}
-#if defined(__GNUC__) || defined(__clang__)
=
-#pragma GCC diagnostic pop
-#endif
-
int
tls=
_version_max(void)
{
diff --git a/src/open=
vpn/ssl_verify_mbedtls.c b/src/openvpn/ssl_verify_mbedtls.c
index 7495085..ad5479c 100644
--- a/src/openvpn/ssl_verify=
_mbedtls.c
+++ b/src/openvpn/ssl_verify_mbedtls.c
@@ -565,11 +565,6 @@
gc_free(&gc); }
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Ws=
ign-compare"
-#end=
if
-
/=
*
* Save X509 fields to environment, using the naming con=
vention:
*
@@ -678,10 +673,6 @@
return fFound;
}
<=
span style=3D"color: hsl(0, 100%, 40%);">-#if defined(__GNUC__) || defined(=
__clang__)
-#pragma GCC=
diagnostic pop
-#endif=
-
res=
ult_t
x509_verify_cert_eku(mbedtls_x509_crt *cert, const c=
har *const expected_oid)
{
To view, visit change 1559. To unsubscribe, or for help writing mail filte=
rs, visit settin=
gs.
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I777a3a5f4f137432a19746972e2=
aad1732184feb
Gerrit-Change-Number: 1559
Gerrit-PatchSet: 5
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>
Gerrit-Attention: plaisthos <arne-openvpn@...220...=
..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...=
41...>
=
--nCD9YuWbjmE=--