From: "flichtenheld (Code Review)" Date: Fri, 24 Oct 2025 16:52:47 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <7cfc68a081d9125a65bc5d3f94c2ee6ffd9d838c-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="9gH0UVhGepM="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: pkcs11: Avoid some conversion warnings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --9gH0UVhGepM= 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/+/1296?usp=3Demail to review the following change. Change subject: pkcs11: Avoid some conversion warnings ...................................................................... pkcs11: Avoid some conversion warnings Since we translate between different APIs casts are unavoidable. Make sure they are safe. Change-Id: If3331a2d0477634af077b4c29963dbec6d04e17b Signed-off-by: Frank Lichtenheld --- M src/openvpn/pkcs11.c 1 file changed, 13 insertions(+), 12 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/1296/1 diff --git a/src/openvpn/pkcs11.c b/src/openvpn/pkcs11.c index ce64135..a253503 100644 --- a/src/openvpn/pkcs11.c +++ b/src/openvpn/pkcs11.c @@ -53,18 +53,17 @@ } #endif -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - static void -__mysleep(const unsigned long usec) +__mysleep(unsigned long usec) { #if defined(_WIN32) Sleep(usec / 1000); #else - usleep(usec); + if (usec > UINT_MAX) + { + usec =3D UINT_MAX; + } + usleep((useconds_t)usec); #endif } @@ -531,7 +530,13 @@ goto cleanup; } - if (openvpn_base64_encode(certificate_blob, certificate_blob_size, &in= ternal_base64) =3D=3D -1) + if (certificate_blob_size > INT_MAX) + { + msg(M_WARN, "PKCS#11: Invalid certificate size %zu", certificate_b= lob_size); + goto cleanup; + } + + if (openvpn_base64_encode(certificate_blob, (int)certificate_blob_size= , &internal_base64) =3D=3D -1) { msg(M_WARN, "PKCS#11: Cannot encode certificate"); goto cleanup; @@ -563,10 +568,6 @@ return success; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - int tls_ctx_use_pkcs11(struct tls_root_ctx *const ssl_ctx, bool pkcs11_id_mana= gement, const char *const pkcs11_id) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1296?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: If3331a2d0477634af077b4c29963dbec6d04e17b Gerrit-Change-Number: 1296 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --9gH0UVhGepM= 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

pkcs11: Avoid some conversion warnings
<= br>Since we translate between different APIs
casts are unavoidable. Make= sure they are safe.

Change-Id: If3331a2d0477634af077b4c29963dbec6d0= 4e17b
Signed-off-by: Frank Lichtenheld <frank@...2641...>
---M src/openvpn/pkcs11.c
1 file changed, 13 insertions(+), 12 deletions(= -)

git pull ssh://gerrit.openvpn.net:29418/openv=
pn refs/changes/96/1296/1
diff --git a/src/openvpn/pkcs11.c b/src/o=
penvpn/pkcs11.c
index ce64135..a253503 100644
--- a/src/openvpn/pkcs11.c
+++ b/src/openvpn/pkcs11.c
@@ -53,18 +53,17 @@
}
#endi= f

-#i= f defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion= "
-#endif-
static void<= /span>
-__mysleep(const unsign= ed long usec)
+__mysl= eep(unsigned long usec)
{
#if defined(_WI= N32)
Sleep(usec / 1000);
#else=
- usleep(usec);
= + if (usec > UINT_MAX)
+ {
+ usec =3D UINT_MAX;+ }
+ usleep((useconds_t)usec);
<= span> #endif

}

@@ -531,7= +530,13 @@
goto cleanup;
}

- i= f (openvpn_base64_encode(certificate_blob, certificate_blob_size, &inte= rnal_base64) =3D=3D -1)
+ if (certificate_blob_size > INT_MAX)
+ {
+ msg(M_WARN, "PKCS#11: Invalid certificate size %= zu", certificate_blob_size);
+ goto cleanup;
+ }
+
+ if (openvpn_b= ase64_encode(certificate_blob, (int)certificate_blob_size, &internal_ba= se64) =3D=3D -1)
{
msg(M_WARN= , "PKCS#11: Cannot encode certificate");
= goto cleanup;
@@ -563,10 +568,6 @@
re= turn success;
}

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic p= op
-#endif
-

int
tls_ctx_use_pkcs11(struct tls_root_ctx *const ssl_ctx, bool pkcs11_id_= management,

const char *const pkcs11_id= )

To view, visit change 1296. To unsubscrib= e, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If3331a2d0477634af077b4c2996= 3dbec6d04e17b
Gerrit-Change-Number: 1296
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...>
= --9gH0UVhGepM=--