From: "cron2 (Code Review)" Date: Tue, 23 Sep 2025 12:42:17 +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="YHghzT7Qc6s="; 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 , plaisthos Cc: openvpn-devel --YHghzT7Qc6s= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#4) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1148?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 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(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/48/1148/4 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: newpatchset --YHghzT7Qc6s= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #4 to the change originally cr= eated by flichtenheld.

View Change

The following approvals got outd= ated and were removed: Code-Review+2 by cron2

Clean up conversion warnings related to base64_{en, =
de}code

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

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

Change-Id: Id7a5b2d8dea0= 1bd532f5bcc8abea0e52b00d1169
Signed-off-by: Frank Lichtenheld <frank@= ...2641...>
Acked-by: Gert Doering <gert@...1296...>
Gerrit = URL: https://gerrit.openvpn.net/c/openvpn/+/1148
Message-Id: <2025092= 3103429.1257-1-gert@...1296...>
URL: https://sourceforge.net/p/openvp= n/mailman/message/59237399/
Signed-off-by: Gert Doering <gert@...1726...= ...>
---
M src/openvpn/base64.c
M src/openvpn/misc.c
M src/o= penvpn/proxy.c
M src/openvpn/ssl_mbedtls.c
4 files changed, 31 insert= ions(+), 28 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/=
openvpn refs/changes/48/1148/4
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)
<= span> {
- 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)
{
<= span> 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 < s= ize)
{
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)
{
- c= har *p;
- for (p =3D= base64_chars; *p; p++)
+ for (char *p =3D base64_chars; *p; p++)
{
if (*p =3D=3D c)
{
= - return p - base64_ch= ars;
+ ret= urn (int)(p - base64_chars);
}
= }
return -1;
@@ -119,16 +118,15 @@
static unsigned int
token_decode(const cha= r *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;<= br> }
- fo= r (i =3D 0; i < 4; i++)
+ for (unsigned int i =3D 0; i < 4; i++)
{=
- val *=3D 64;<= /span>
+ val <<= =3D 6;
if (token[i] =3D=3D '=3D') {
marker++;
@= @ -139,7 +137,12 @@
}
els= e
{
- val +=3D pos(token[i]);
+ int char_pos =3D pos(token[i]);+ if (unlikely(cha= r_pos < 0)) /* caller should check */
+ {
+ return DECODE_ERROR;
+ }
+ val +=3D (unsigned int)char_pos;

}
}
if (ma= rker > 2)
@@ -195,5 +198,5 @@
= *q++ =3D val & 0xff;
}
= }
- return q - (uns= igned char *)data;
+ = return (int)(q - (unsigned char *)data);
}
diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c

in= dex 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-&= gt;password), &pw64) =3D=3D -1
- || openvpn_base64_encode(response,= strlen(response), &resp64) =3D=3D -1)
+ if (openvpn_base64_encode(up= ->password, (int)strlen(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 pass= word/static_response");
}
diff --git a/src/openvpn/proxy.c b/src/openvpn/proxy.c<= br>index 054cc79..9d8fe75 100644
--- a/src/openvpn/pr= oxy.c
+++ b/src/openvpn/proxy.c
@@ -229,7 += 229,7 @@
uint8_t *
make_base64_string(con= st uint8_t *str, struct gc_arena *gc)
{
- return make_base64_string2(str, strl= en((const char *)str), gc);
+ return make_base64_string2(str, (int)strlen((const char *)str),= gc);
}

static const ch= ar *
diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/s= sl_mbedtls.c
index 338de83..b2d511e 100644
= --- a/src/openvpn/ssl_mbedtls.c
+++ b/src/openvpn/ssl_mbedt= ls.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 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: newpatchset
--YHghzT7Qc6s=--