From: "flichtenheld (Code Review)" Date: Thu, 21 Aug 2025 16:21:11 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <8565ae6847620f6a727012c4dcd2863f731e2790-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="afEAGcuDa3k="; 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: plaisthos Cc: openvpn-devel --afEAGcuDa3k= 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/+/1148?usp=3Demail to review the following change. 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 --- 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(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/48/1148/1 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 17f7706..ae5a438 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -441,8 +441,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 635b53c..23c1e78 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: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-MessageType: newchange --afEAGcuDa3k= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

V= iew Change

Clean up conversion warnings related to base64_{en,de}code
It seems unlikely that we can change the API at this point,
especi= ally 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: Id7a5b2d8dea01bd532f5b= cc8abea0e52b00d1169
Signed-off-by: Frank Lichtenheld <frank@...2723...= .>
---
M src/openvpn/base64.c
M src/openvpn/misc.c
M src/ope= nvpn/proxy.c
M src/openvpn/ssl_mbedtls.c
4 files changed, 31 insertio= ns(+), 28 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/op=
envpn refs/changes/48/1148/1
diff --git a/src/openvpn/base64.c b/sr=
c/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;<= br>+ if (out_size > INT_M= AX)
+ {
= + return -1;
<= span style=3D"color: hsl(120, 100%, 40%);">+ }
+ char *p =3D (char *)malloc(out_size);

+ char *start =3D p;<= /span>
if (p =3D=3D NULL)
{
return -1;

}
- q =3D (const unsigned char *)data;
<= span style=3D"color: hsl(0, 100%, 40%);">- 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];
}<= /span>
i++;
- c *=3D 256;
+ c <<=3D 8;
if (i < size)<= /span>
{
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);
}<= br>
static int
pos(char c)<= br> {
- char *= p;
- for (p =3D base= 64_chars; *p; p++)
+ = for (char *p =3D base64_chars; *p; p++)
{ if (*p =3D=3D c)
{
- return p - base64_chars;<= /span>
+ return (= int)(p - base64_chars);
}
}
return -1;
@@ -119,16 +118,15 @@=
static unsigned int
token_decode(const char *to= ken)
{
- 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++;
@@ -13= 9,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 &g= t; 2)
@@ -195,5 +198,5 @@
*q++= =3D val & 0xff;
}
}
- return q - (unsigned c= har *)data;
+ retu= rn (int)(q - (unsigned char *)data);
}
dif= f --git a/src/openvpn/misc.c b/src/openvpn/misc.c
index 17f= 7706..ae5a438 100644
--- a/src/openvpn/misc.c
+++ b/src/openvpn/misc.c

@@ -441,8 +441,8 @@
<= span> }

if (!(flag= s & GET_USER_PASS_STATIC_CHALLENGE_CONCAT))
= {
- = if (openvpn_base64_encode(up->password, strlen(up->pass= word), &pw64) =3D=3D -1
- || openvpn_base64_encode(response, strlen= (response), &resp64) =3D=3D -1)
+ if (openvpn_base64_encode(up->pa= ssword, (int)strlen(up->password), &pw64) =3D=3D -1
+ || openv= pn_base64_encode(response, (int)strlen(response), &resp64) =3D=3D -1)
{
= msg(M_FATAL, "ERROR: could not base64-encode password/stat= ic_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 @@<= /span>
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_mbedtl= s.c
index 635b53c..23c1e78 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_en= code(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_d= ecode(dst_b64, dst, (int)dst_len) !=3D dst_len)
{
goto cleanup;
}
<= /span>

To view, visit change 1148. To unsubscribe, or for help writ= ing mail filters, visit sett= ings.

<= link itemprop=3D"url" href=3D"http://gerrit.openvpn.net/c/openvpn/+/1148?us= p=3Demail"/>
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id7a5b2d8dea01bd532f5bcc8abe= a0e52b00d1169
Gerrit-Change-Number: 1148
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...>
Gerrit-MessageType: newchange
--afEAGcuDa3k=--