Change in openvpn[master]: Clean up conversion warnings related to base64_{en, de}code
A message that is not in the archive (sent off-list or not yet received): gerrit.1755793268000.Id7a5b2d8dea01bd532f5bcc8abea0e52b00d1169@...2715...
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=email
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
---
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
src/openvpn/base64.c +26 -23
@@ -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 = s = (char *)malloc (size *4 /3 +4 ); +size_t out_size = (size_t )size *4 /3 +4 ; +if (out_size >INT_MAX ) + { +return -1 ; + } +char *p = (char *)malloc (out_size); +char *start = p;if (p ==NULL ) {return -1 ; } - q = (const unsigned char *)data; - i =0 ; -for (i =0 ; i < size;) +const unsigned char *q = (const unsigned char *)data; +for (int i =0 ; i < size;) { - c = q[i++]; - c *=256 ; +unsigned int c = q[i++]; + c <<=8 ;if (i < size) { c += q[i]; } i++; - c *=256 ; + c <<=8 ;if (i < size) { c += q[i];
@@ -96,19 +96,18 @@ p +=4 ; } *p =0 ; - *str = s; -return strlen (s); + *str = start; +return (int )strlen (start); }static int pos (char c) { -char *p; -for (p = base64_chars; *p; p++) +for (char *p = base64_chars; *p; p++) {if (*p == 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 =0 ; -int marker =0 ; +unsigned int marker =0 ;if (!token[0 ] || !token[1 ] || !token[2 ] || !token[3 ]) {return DECODE_ERROR ; } -for (i =0 ; i <4 ; i++) +for (unsigned int i =0 ; i <4 ; i++) { - val *=64 ; + val <<=6 ;if (token[i] =='=' ) { marker++;
@@ -139,7 +137,12 @@ }else { - val +=pos (token[i]); +int char_pos =pos (token[i]); +if (unlikely (char_pos <0 ))/* caller should check */ + { +return DECODE_ERROR ; + } + val += (unsigned int )char_pos; } }if (marker >2 )
@@ -195,5 +198,5 @@ *q++ = val &0xff ; } } -return q - (unsigned char *)data; +return (int )(q - (unsigned char *)data); }
src/openvpn/misc.c +2 -2
@@ -441,8 +441,8 @@ }if (!(flags &GET_USER_PASS_STATIC_CHALLENGE_CONCAT )) { -if (openvpn_base64_encode (up->password,strlen (up->password), &pw64) ==-1 - ||openvpn_base64_encode (response,strlen (response), &resp64) ==-1 ) +if (openvpn_base64_encode (up->password, (int )strlen (up->password), &pw64) ==-1 + ||openvpn_base64_encode (response, (int )strlen (response), &resp64) ==-1 ) {msg (M_FATAL ,"ERROR: could not base64-encode password/static_response" ); }
src/openvpn/proxy.c +1 -1
@@ -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 *
src/openvpn/ssl_mbedtls.c +2 -2
@@ -754,7 +754,7 @@char *src_b64 =NULL ;char *dst_b64 =NULL ; -if (!management || (openvpn_base64_encode (src, src_len, &src_b64) <=0 )) +if (!management || (openvpn_base64_encode (src, (int )src_len, &src_b64) <=0 )) { goto cleanup; }
@@ -768,7 +768,7 @@ goto cleanup; } -if (openvpn_base64_decode (dst_b64, dst, dst_len) != dst_len) +if (openvpn_base64_decode (dst_b64, dst, (int )dst_len) != dst_len) { goto cleanup; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1148?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id7a5b2d8dea01bd532f5bcc8abea0e52b00d1169
Gerrit-Change-Number: 1148
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: flichtenheld, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1148?usp=email )
Change subject: Clean up conversion warnings related to base64_{en,de}code
......................................................................
Patch Set 3: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1148?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id7a5b2d8dea01bd532f5bcc8abea0e52b00d1169
Gerrit-Change-Number: 1148
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 23 Sep 2025 10:34:13 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH v3 1/1 Clean up conversion warnings related to base64_{en, de}code
In reply to a message not in the archiveFrom: Frank Lichtenheld <[email protected]...>
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
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1148
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1148
This mail reflects revision 3 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
src/openvpn/base64.c +26 -23
@@ -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 = s = (char *)malloc (size *4 /3 +4 ); +size_t out_size = (size_t )size *4 /3 +4 ; +if (out_size >INT_MAX ) + { +return -1 ; + } +char *p = (char *)malloc (out_size); +char *start = p;if (p ==NULL ) {return -1 ; } - q = (const unsigned char *)data; - i =0 ; -for (i =0 ; i < size;) +const unsigned char *q = (const unsigned char *)data; +for (int i =0 ; i < size;) { - c = q[i++]; - c *=256 ; +unsigned int c = q[i++]; + c <<=8 ;if (i < size) { c += q[i]; } i++; - c *=256 ; + c <<=8 ;if (i < size) { c += q[i];
@@ -96,19 +96,18 @@ p +=4 ; } *p =0 ; - *str = s; -return strlen (s); + *str = start; +return (int )strlen (start); }static int pos (char c) { -char *p; -for (p = base64_chars; *p; p++) +for (char *p = base64_chars; *p; p++) {if (*p == 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 =0 ; -int marker =0 ; +unsigned int marker =0 ;if (!token[0 ] || !token[1 ] || !token[2 ] || !token[3 ]) {return DECODE_ERROR ; } -for (i =0 ; i <4 ; i++) +for (unsigned int i =0 ; i <4 ; i++) { - val *=64 ; + val <<=6 ;if (token[i] =='=' ) { marker++;
@@ -139,7 +137,12 @@ }else { - val +=pos (token[i]); +int char_pos =pos (token[i]); +if (unlikely (char_pos <0 ))/* caller should check */ + { +return DECODE_ERROR ; + } + val += (unsigned int )char_pos; } }if (marker >2 )
@@ -195,5 +198,5 @@ *q++ = val &0xff ; } } -return q - (unsigned char *)data; +return (int )(q - (unsigned char *)data); }
src/openvpn/misc.c +2 -2
@@ -420,8 +420,8 @@ }if (!(flags &GET_USER_PASS_STATIC_CHALLENGE_CONCAT )) { -if (openvpn_base64_encode (up->password,strlen (up->password), &pw64) ==-1 - ||openvpn_base64_encode (response,strlen (response), &resp64) ==-1 ) +if (openvpn_base64_encode (up->password, (int )strlen (up->password), &pw64) ==-1 + ||openvpn_base64_encode (response, (int )strlen (response), &resp64) ==-1 ) {msg (M_FATAL ,"ERROR: could not base64-encode password/static_response" ); }
src/openvpn/proxy.c +1 -1
@@ -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 *
src/openvpn/ssl_mbedtls.c +2 -2
@@ -754,7 +754,7 @@char *src_b64 =NULL ;char *dst_b64 =NULL ; -if (!management || (openvpn_base64_encode (src, src_len, &src_b64) <=0 )) +if (!management || (openvpn_base64_encode (src, (int )src_len, &src_b64) <=0 )) { goto cleanup; }
@@ -768,7 +768,7 @@ goto cleanup; } -if (openvpn_base64_decode (dst_b64, dst, dst_len) != dst_len) +if (openvpn_base64_decode (dst_b64, dst, (int )dst_len) != dst_len) { goto cleanup; }
[Openvpn-devel] [PATCH applied] Re: Clean up conversion warnings related to base64_{en, de}code
This is a bit bigger than "just int", and the functions are not that easy to understand... so I stared a bit longer, and also ran all the t_server self tests (because there's plugins that use username/password and auth-token, so, base64 should better work - it does).
Reference link to sf.net...
Your patch has been applied to the master branch.
commit f32844b25c3b3b352bad0b250fd8721656ae9bc0
Author: Frank Lichtenheld Date: Tue Sep 23 12:34:23 2025 +0200
Clean up conversion warnings related to base64_{en, de}code
Signed-off-by: Frank Lichtenheld <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1148
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59237399/
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#4) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1148?usp=email )
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
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1148
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59237399/
---
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
src/openvpn/base64.c +26 -23
@@ -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 = s = (char *)malloc (size *4 /3 +4 ); +size_t out_size = (size_t )size *4 /3 +4 ; +if (out_size >INT_MAX ) + { +return -1 ; + } +char *p = (char *)malloc (out_size); +char *start = p;if (p ==NULL ) {return -1 ; } - q = (const unsigned char *)data; - i =0 ; -for (i =0 ; i < size;) +const unsigned char *q = (const unsigned char *)data; +for (int i =0 ; i < size;) { - c = q[i++]; - c *=256 ; +unsigned int c = q[i++]; + c <<=8 ;if (i < size) { c += q[i]; } i++; - c *=256 ; + c <<=8 ;if (i < size) { c += q[i];
@@ -96,19 +96,18 @@ p +=4 ; } *p =0 ; - *str = s; -return strlen (s); + *str = start; +return (int )strlen (start); }static int pos (char c) { -char *p; -for (p = base64_chars; *p; p++) +for (char *p = base64_chars; *p; p++) {if (*p == 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 =0 ; -int marker =0 ; +unsigned int marker =0 ;if (!token[0 ] || !token[1 ] || !token[2 ] || !token[3 ]) {return DECODE_ERROR ; } -for (i =0 ; i <4 ; i++) +for (unsigned int i =0 ; i <4 ; i++) { - val *=64 ; + val <<=6 ;if (token[i] =='=' ) { marker++;
@@ -139,7 +137,12 @@ }else { - val +=pos (token[i]); +int char_pos =pos (token[i]); +if (unlikely (char_pos <0 ))/* caller should check */ + { +return DECODE_ERROR ; + } + val += (unsigned int )char_pos; } }if (marker >2 )
@@ -195,5 +198,5 @@ *q++ = val &0xff ; } } -return q - (unsigned char *)data; +return (int )(q - (unsigned char *)data); }
src/openvpn/misc.c +2 -2
@@ -420,8 +420,8 @@ }if (!(flags &GET_USER_PASS_STATIC_CHALLENGE_CONCAT )) { -if (openvpn_base64_encode (up->password,strlen (up->password), &pw64) ==-1 - ||openvpn_base64_encode (response,strlen (response), &resp64) ==-1 ) +if (openvpn_base64_encode (up->password, (int )strlen (up->password), &pw64) ==-1 + ||openvpn_base64_encode (response, (int )strlen (response), &resp64) ==-1 ) {msg (M_FATAL ,"ERROR: could not base64-encode password/static_response" ); }
src/openvpn/proxy.c +1 -1
@@ -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 *
src/openvpn/ssl_mbedtls.c +2 -2
@@ -754,7 +754,7 @@char *src_b64 =NULL ;char *dst_b64 =NULL ; -if (!management || (openvpn_base64_encode (src, src_len, &src_b64) <=0 )) +if (!management || (openvpn_base64_encode (src, (int )src_len, &src_b64) <=0 )) { goto cleanup; }
@@ -768,7 +768,7 @@ goto cleanup; } -if (openvpn_base64_decode (dst_b64, dst, dst_len) != dst_len) +if (openvpn_base64_decode (dst_b64, dst, (int )dst_len) != dst_len) { goto cleanup; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1148?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id7a5b2d8dea01bd532f5bcc8abea0e52b00d1169
Gerrit-Change-Number: 1148
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1148?usp=email )
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
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1148
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59237399/
---
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(-)
src/openvpn/base64.c +26 -23
@@ -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 = s = (char *)malloc (size *4 /3 +4 ); +size_t out_size = (size_t )size *4 /3 +4 ; +if (out_size >INT_MAX ) + { +return -1 ; + } +char *p = (char *)malloc (out_size); +char *start = p;if (p ==NULL ) {return -1 ; } - q = (const unsigned char *)data; - i =0 ; -for (i =0 ; i < size;) +const unsigned char *q = (const unsigned char *)data; +for (int i =0 ; i < size;) { - c = q[i++]; - c *=256 ; +unsigned int c = q[i++]; + c <<=8 ;if (i < size) { c += q[i]; } i++; - c *=256 ; + c <<=8 ;if (i < size) { c += q[i];
@@ -96,19 +96,18 @@ p +=4 ; } *p =0 ; - *str = s; -return strlen (s); + *str = start; +return (int )strlen (start); }static int pos (char c) { -char *p; -for (p = base64_chars; *p; p++) +for (char *p = base64_chars; *p; p++) {if (*p == 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 =0 ; -int marker =0 ; +unsigned int marker =0 ;if (!token[0 ] || !token[1 ] || !token[2 ] || !token[3 ]) {return DECODE_ERROR ; } -for (i =0 ; i <4 ; i++) +for (unsigned int i =0 ; i <4 ; i++) { - val *=64 ; + val <<=6 ;if (token[i] =='=' ) { marker++;
@@ -139,7 +137,12 @@ }else { - val +=pos (token[i]); +int char_pos =pos (token[i]); +if (unlikely (char_pos <0 ))/* caller should check */ + { +return DECODE_ERROR ; + } + val += (unsigned int )char_pos; } }if (marker >2 )
@@ -195,5 +198,5 @@ *q++ = val &0xff ; } } -return q - (unsigned char *)data; +return (int )(q - (unsigned char *)data); }
src/openvpn/misc.c +2 -2
@@ -420,8 +420,8 @@ }if (!(flags &GET_USER_PASS_STATIC_CHALLENGE_CONCAT )) { -if (openvpn_base64_encode (up->password,strlen (up->password), &pw64) ==-1 - ||openvpn_base64_encode (response,strlen (response), &resp64) ==-1 ) +if (openvpn_base64_encode (up->password, (int )strlen (up->password), &pw64) ==-1 + ||openvpn_base64_encode (response, (int )strlen (response), &resp64) ==-1 ) {msg (M_FATAL ,"ERROR: could not base64-encode password/static_response" ); }
src/openvpn/proxy.c +1 -1
@@ -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 *
src/openvpn/ssl_mbedtls.c +2 -2
@@ -754,7 +754,7 @@char *src_b64 =NULL ;char *dst_b64 =NULL ; -if (!management || (openvpn_base64_encode (src, src_len, &src_b64) <=0 )) +if (!management || (openvpn_base64_encode (src, (int )src_len, &src_b64) <=0 )) { goto cleanup; }
@@ -768,7 +768,7 @@ goto cleanup; } -if (openvpn_base64_decode (dst_b64, dst, dst_len) != dst_len) +if (openvpn_base64_decode (dst_b64, dst, (int )dst_len) != dst_len) { goto cleanup; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1148?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id7a5b2d8dea01bd532f5bcc8abea0e52b00d1169
Gerrit-Change-Number: 1148
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged