From: "cron2 (Code Review)" Date: Tue, 23 Sep 2025 12:42:19 +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="TfSXwkQ149U="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Clean up conversion warnings related to base64_{en, de}code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: plaisthos , openvpn-devel --TfSXwkQ149U= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/11= 48?usp=3Demail ) Change subject: Clean up conversion warnings related to base64_{en, de}code ...................................................................... Clean up conversion warnings related to base64_{en, de}code It seems unlikely that we can change the API at this point, especially with the integration into the plugin API. So - clean up the functions internally to not throw -Wconversion warnings - clean up any warnings on the caller side Change-Id: Id7a5b2d8dea01bd532f5bcc8abea0e52b00d1169 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1148 Message-Id: <20250923103429.1257-1-gert@...1296...> URL: https://sourceforge.net/p/openvpn/mailman/message/59237399/ Signed-off-by: Gert Doering --- M src/openvpn/base64.c M src/openvpn/misc.c M src/openvpn/proxy.c M src/openvpn/ssl_mbedtls.c 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/openvpn/base64.c b/src/openvpn/base64.c index 54d5b79..7af8976 100644 --- a/src/openvpn/base64.c +++ b/src/openvpn/base64.c @@ -50,32 +50,32 @@ int openvpn_base64_encode(const void *data, int size, char **str) { - char *s, *p; - int i; - int c; - const unsigned char *q; - if (size < 0) { return -1; } - p =3D s =3D (char *)malloc(size * 4 / 3 + 4); + size_t out_size =3D (size_t)size * 4 / 3 + 4; + if (out_size > INT_MAX) + { + return -1; + } + char *p =3D (char *)malloc(out_size); + char *start =3D p; if (p =3D=3D NULL) { return -1; } - q =3D (const unsigned char *)data; - i =3D 0; - for (i =3D 0; i < size;) + const unsigned char *q =3D (const unsigned char *)data; + for (int i =3D 0; i < size;) { - c =3D q[i++]; - c *=3D 256; + unsigned int c =3D q[i++]; + c <<=3D 8; if (i < size) { c +=3D q[i]; } i++; - c *=3D 256; + c <<=3D 8; if (i < size) { c +=3D q[i]; @@ -96,19 +96,18 @@ p +=3D 4; } *p =3D 0; - *str =3D s; - return strlen(s); + *str =3D start; + return (int)strlen(start); } static int pos(char c) { - char *p; - for (p =3D base64_chars; *p; p++) + for (char *p =3D base64_chars; *p; p++) { if (*p =3D=3D c) { - return p - base64_chars; + return (int)(p - base64_chars); } } return -1; @@ -119,16 +118,15 @@ static unsigned int token_decode(const char *token) { - int i; unsigned int val =3D 0; - int marker =3D 0; + unsigned int marker =3D 0; if (!token[0] || !token[1] || !token[2] || !token[3]) { return DECODE_ERROR; } - for (i =3D 0; i < 4; i++) + for (unsigned int i =3D 0; i < 4; i++) { - val *=3D 64; + val <<=3D 6; if (token[i] =3D=3D '=3D') { marker++; @@ -139,7 +137,12 @@ } else { - val +=3D pos(token[i]); + int char_pos =3D pos(token[i]); + if (unlikely(char_pos < 0)) /* caller should check */ + { + return DECODE_ERROR; + } + val +=3D (unsigned int)char_pos; } } if (marker > 2) @@ -195,5 +198,5 @@ *q++ =3D val & 0xff; } } - return q - (unsigned char *)data; + return (int)(q - (unsigned char *)data); } diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c index 59bf52b..e0b5da1 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -420,8 +420,8 @@ } if (!(flags & GET_USER_PASS_STATIC_CHALLENGE_CONCAT)) { - if (openvpn_base64_encode(up->password, strlen(up-= >password), &pw64) =3D=3D -1 - || openvpn_base64_encode(response, strlen(resp= onse), &resp64) =3D=3D -1) + if (openvpn_base64_encode(up->password, (int)strle= n(up->password), &pw64) =3D=3D -1 + || openvpn_base64_encode(response, (int)strlen= (response), &resp64) =3D=3D -1) { msg(M_FATAL, "ERROR: could not base64-encode p= assword/static_response"); } diff --git a/src/openvpn/proxy.c b/src/openvpn/proxy.c index 054cc79..9d8fe75 100644 --- a/src/openvpn/proxy.c +++ b/src/openvpn/proxy.c @@ -229,7 +229,7 @@ uint8_t * make_base64_string(const uint8_t *str, struct gc_arena *gc) { - return make_base64_string2(str, strlen((const char *)str), gc); + return make_base64_string2(str, (int)strlen((const char *)str), gc); } static const char * diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c index 338de83..b2d511e 100644 --- a/src/openvpn/ssl_mbedtls.c +++ b/src/openvpn/ssl_mbedtls.c @@ -754,7 +754,7 @@ char *src_b64 =3D NULL; char *dst_b64 =3D NULL; - if (!management || (openvpn_base64_encode(src, src_len, &src_b64) <=3D= 0)) + if (!management || (openvpn_base64_encode(src, (int)src_len, &src_b64)= <=3D 0)) { goto cleanup; } @@ -768,7 +768,7 @@ goto cleanup; } - if (openvpn_base64_decode(dst_b64, dst, dst_len) !=3D dst_len) + if (openvpn_base64_decode(dst_b64, dst, (int)dst_len) !=3D dst_len) { goto cleanup; } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1148?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Id7a5b2d8dea01bd532f5bcc8abea0e52b00d1169 Gerrit-Change-Number: 1148 Gerrit-PatchSet: 4 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --TfSXwkQ149U= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

Clean up conversion warnings related to base6=
4_{en, de}code

It seems unlikely that we can change the API at this = point,
especially with the integration into the plugin API.

So - clean up the functions internally to not throw -Wconversion
warni= ngs
- clean up any warnings on the caller side

Change-Id: Id7a5b= 2d8dea01bd532f5bcc8abea0e52b00d1169
Signed-off-by: Frank Lichtenheld <= ;frank@...2641...>
Acked-by: Gert Doering <gert@...1296...>
= Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1148
Message-Id: <= 20250923103429.1257-1-gert@...1296...>
URL: https://sourceforge.net/p= /openvpn/mailman/message/59237399/
Signed-off-by: Gert Doering <gert@= ...1296...>
---
M src/openvpn/base64.c
M src/openvpn/misc.c
= M src/openvpn/proxy.c
M src/openvpn/ssl_mbedtls.c
4 files changed, 31= insertions(+), 28 deletions(-)

diff --git a/src/openvpn/base64.c b/src/openvpn/base64.c
index 54d5b79..7af8976 100644
--- a/src/openvpn/base64.c
+++ b/src/openvpn/base64.c
@@ -50,32 +50,32 = @@
int
openvpn_base64_encode(const void *= data, int size, char **str)
{
- char *s, *p;
- int i;
- int c;
- = const unsigned char *q;
-
if (size < 0)
{ return -1;
}
- p =3D s =3D (char *)malloc(size * 4 / 3 + 4= );
+ size_t out_si= ze =3D (size_t)size * 4 / 3 + 4;
+ if (out_size > INT_MAX)
+ {
+ return -1;
+ }
+ c= har *p =3D (char *)malloc(out_size);
+ char *start =3D p;
if (p =3D=3D N= ULL)
{
return -1;
<= span> }

- q =3D = (const unsigned char *)data;
- i =3D 0;
- = for (i =3D 0; i < size;)
+ const unsigned char *q =3D (const unsigned char *)data;

+ for (int i =3D 0; i &= lt; size;)
{
- c =3D q[i++];
- c *=3D 256;
+ unsigned int c =3D q[i++];
+ c <<=3D 8;
= if (i < size)
{
= c +=3D q[i];
}
i++;
- c *=3D 256;<= br>+ c <<=3D 8;
if (i < size)
{ c +=3D q[i];
@@ -96,19 +96,18 @@
p +=3D 4;
}
*= p =3D 0;
- *str =3D = s;
- return strlen(s= );
+ *str =3D star= t;
+ return (int)s= trlen(start);
}

static = int
pos(char c)
{
- char *p;
- for (p =3D base64_chars; *p; p++)
+ for (char *p =3D base64_chars;= *p; p++)

{
if (*p =3D=3D c)<= /span>
{
- return p - base64_chars;
+ return (int)(p - base64_chars); }
}
return -1;
@@ -119,16 +118,15 @@
static unsigned int
token_decode(const char *token)
{- int i;
= unsigned int val =3D 0;
+ unsigned int marker =3D 0;
if (!token[0] || != token[1] || !token[2] || !token[3])
{
= return DECODE_ERROR;
}
- for (i =3D 0; i < 4; i++)
= + for (unsigned int i =3D 0;= i < 4; i++)
{
- val *=3D 64;
+ val <<=3D 6;
if (t= oken[i] =3D=3D '=3D')
{
= marker++;
@@ -139,7 +137,12 @@
= }
else
{- val +=3D pos(token= [i]);
+ in= t char_pos =3D pos(token[i]);
+ if (unlikely(char_pos < 0)) /* caller should check= */
+ {
+ return= DECODE_ERROR;
+ = }
+ = val +=3D (unsigned int)char_pos;
}
}

if (marker > 2)
@@ -195,5 = +198,5 @@
*q++ =3D val & 0xff;
<= span> }

}
- return q - (unsigned char *)data;
+ return (int)(q - (unsigned char *)da= ta);
}
diff --git a/src/openvpn/misc.c b/s= rc/openvpn/misc.c
index 59bf52b..e0b5da1 100644
<= span>--- a/src/openvpn/misc.c

+++ b/src/openvpn/misc.c
@@ -420,8 +420,8 @@
}
if (!(flags & GET_USER_PASS_STATIC_CHA= LLENGE_CONCAT))
{
- if (openvpn_base64= _encode(up->password, strlen(up->password), &pw64) =3D=3D -1
- = || openvpn_base64_encode(response, strlen(response), &resp64) =3D=3D = -1)
+ = if (openvpn_base64_encode(up->password, (int)strlen(up->passw= ord), &pw64) =3D=3D -1
+ || openvpn_base64_encode(response, (int)= strlen(response), &resp64) =3D=3D -1)
= {
msg(M_FATAL, "E= RROR: could not base64-encode password/static_response");
}

diff --git a/src/openvpn/pro= xy.c b/src/openvpn/proxy.c
index 054cc79..9d8fe75 100644
--- a/src/openvpn/proxy.c
+++ b/src/openvpn/p= roxy.c
@@ -229,7 +229,7 @@
uint8_t *
make_base64_string(const uint8_t *str, struct gc_arena *gc)

{
- re= turn make_base64_string2(str, strlen((const char *)str), gc);
+ return make_base64_string2(st= r, (int)strlen((const char *)str), gc);
}
=
static const char *
diff --git a/src/ope= nvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c
index 338de8= 3..b2d511e 100644
--- a/src/openvpn/ssl_mbedtls.c+++ b/src/openvpn/ssl_mbedtls.c
@@ -754,7 +754,7 @@<= /span>
char *src_b64 =3D NULL;
char *dst= _b64 =3D NULL;

- if (!management || (openvpn_base64_encode(src, src_len, &= ;src_b64) <=3D 0))
+ if (!management || (openvpn_base64_encode(src, (int)src_len, &src= _b64) <=3D 0))
{
goto clea= nup;
}
@@ -768,7 +768,7 @@
<= span> goto cleanup;

}
=
- if (openvpn_base64_decod= e(dst_b64, dst, dst_len) !=3D dst_len)
+ if (openvpn_base64_decode(dst_b64, dst, (int)dst_len= ) !=3D dst_len)
{
goto cleanu= p;
}

To view, visi= t change= 1148. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id7a5b2d8dea01bd532f5bcc8abe= a0e52b00d1169
Gerrit-Change-Number: 1148
Gerrit-PatchSet: 4
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-MessageType: merged
--TfSXwkQ149U=--