From: "flichtenheld (Code Review)" Date: Thu, 7 Sep 2023 08:45:05 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="MwHpnSXOx00="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Various fixes for -Wconversion errors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --MwHpnSXOx00= 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/+/267?usp=3Demail to review the following change. Change subject: Various fixes for -Wconversion errors ...................................................................... Various fixes for -Wconversion errors These are all fixes I considered "safe". They either - Have sufficient checks/shifts for a cast to be safe - Fix the type of a variable without requiring code changes - Are in non-critical unittest code v2: - add min_size instead of abusing min_int Change-Id: I6818b153bdeb1eed65870af99b0531e95807fe0f Signed-off-by: Frank Lichtenheld --- M src/openvpn/buffer.c M src/openvpn/crypto.c M src/openvpn/integer.h M src/openvpn/mss.c M src/openvpn/otime.c M src/openvpn/otime.h M src/openvpn/packet_id.c M src/openvpn/reliable.c M src/openvpn/socket.h M src/openvpn/tls_crypt.c M src/openvpn/xkey_helper.c M tests/unit_tests/openvpn/mock_get_random.c M tests/unit_tests/openvpn/test_crypto.c M tests/unit_tests/openvpn/test_packet_id.c M tests/unit_tests/openvpn/test_provider.c M tests/unit_tests/openvpn/test_tls_crypt.c 16 files changed, 50 insertions(+), 36 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/67/267/3 diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index 24f1ef2..a32e7d2 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -352,7 +352,7 @@ return false; } - const int size =3D write(fd, BPTR(buf), BLEN(buf)); + const ssize_t size =3D write(fd, BPTR(buf), BLEN(buf)); if (size !=3D BLEN(buf)) { msg(M_ERRNO, "Write error on file '%s'", filename); @@ -889,7 +889,7 @@ { break; } - line[n++] =3D c; + line[n++] =3D (char)c; } while (c); diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index a77b5a1..3152060 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -26,6 +26,8 @@ #include "config.h" #endif +#include + #include "syshead.h" #include "crypto.h" @@ -1275,8 +1277,8 @@ hex_byte[hb_index++] =3D c; if (hb_index =3D=3D 2) { - unsigned int u; - ASSERT(sscanf((const char *)hex_byte, "%x", &u) = =3D=3D 1); + uint8_t u; + ASSERT(sscanf((const char *)hex_byte, "%" SCNx8, &= u) =3D=3D 1); *out++ =3D u; hb_index =3D 0; if (++count =3D=3D keylen) @@ -1538,13 +1540,13 @@ ASSERT(cipher_kt_key_size(kt->cipher) <=3D MAX_CIPHER_KEY_LENGTH && md_kt_size(kt->digest) <=3D MAX_HMAC_KEY_LENGTH); - const uint8_t cipher_length =3D cipher_kt_key_size(kt->cipher); + const uint8_t cipher_length =3D (uint8_t)cipher_kt_key_size(kt->cipher= ); if (!buf_write(buf, &cipher_length, 1)) { return false; } - uint8_t hmac_length =3D md_kt_size(kt->digest); + uint8_t hmac_length =3D (uint8_t)md_kt_size(kt->digest); if (!buf_write(buf, &hmac_length, 1)) { diff --git a/src/openvpn/integer.h b/src/openvpn/integer.h index 215c159..30b9ecf 100644 --- a/src/openvpn/integer.h +++ b/src/openvpn/integer.h @@ -28,12 +28,12 @@ #ifndef htonll #define htonll(x) ((1=3D=3Dhtonl(1)) ? (x) : \ - ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >= > 32)) + ((uint64_t)htonl((uint32_t)((x) & 0xFFFFFFFF)) << 32) |= htonl((uint32_t)((x) >> 32))) #endif #ifndef ntohll #define ntohll(x) ((1=3D=3Dntohl(1)) ? (x) : \ - ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >= > 32)) + ((uint64_t)ntohl((uint32_t)((x) & 0xFFFFFFFF)) << 32) |= ntohl((uint32_t)((x) >> 32))) #endif /* @@ -65,6 +65,19 @@ } } +static inline size_t +min_size(size_t x, size_t y) +{ + if (x < y) + { + return x; + } + else + { + return y; + } +} + static inline int max_int(int x, int y) { diff --git a/src/openvpn/mss.c b/src/openvpn/mss.c index 816e65b..dbd3681 100644 --- a/src/openvpn/mss.c +++ b/src/openvpn/mss.c @@ -165,7 +165,7 @@ return; } - for (olen =3D hlen - sizeof(struct openvpn_tcphdr), + for (olen =3D hlen - (int) sizeof(struct openvpn_tcphdr), opt =3D (uint8_t *)(tc + 1); olen > 1; olen -=3D optlen, opt +=3D optlen) diff --git a/src/openvpn/otime.c b/src/openvpn/otime.c index b28a90f..e751246 100644 --- a/src/openvpn/otime.c +++ b/src/openvpn/otime.c @@ -105,7 +105,7 @@ /* format a time_t as ascii, or use current time if 0 */ const char * -time_string(time_t t, int usec, bool show_usec, struct gc_arena *gc) +time_string(time_t t, long usec, bool show_usec, struct gc_arena *gc) { struct buffer out =3D alloc_buf_gc(64, gc); struct timeval tv; diff --git a/src/openvpn/otime.h b/src/openvpn/otime.h index c27be89..d795c3c 100644 --- a/src/openvpn/otime.h +++ b/src/openvpn/otime.h @@ -43,7 +43,7 @@ bool frequency_limit_event_allowed(struct frequency_limit *f); /* format a time_t as ascii, or use current time if 0 */ -const char *time_string(time_t t, int usec, bool show_usec, struct gc_aren= a *gc); +const char *time_string(time_t t, long usec, bool show_usec, struct gc_are= na *gc); /* struct timeval functions */ diff --git a/src/openvpn/packet_id.c b/src/openvpn/packet_id.c index ef83248..3d6f3ee 100644 --- a/src/openvpn/packet_id.c +++ b/src/openvpn/packet_id.c @@ -588,14 +588,14 @@ } else { - diff =3D (int) prev_now - v; + diff =3D (int)(prev_now - v); if (diff < 0) { c =3D 'N'; } else if (diff < 10) { - c =3D '0' + diff; + c =3D (char)('0' + diff); } else { diff --git a/src/openvpn/reliable.c b/src/openvpn/reliable.c index e7d4d5f..0e26f98 100644 --- a/src/openvpn/reliable.c +++ b/src/openvpn/reliable.c @@ -257,8 +257,7 @@ struct buffer *buf, const struct session_id *sid, int max, bool prepend) { - int i, j; - uint8_t n; + int i, j, n; struct buffer sub; n =3D ack->len; @@ -270,9 +269,9 @@ copy_acks_to_mru(ack, ack_mru, n); /* Number of acks we can resend that still fit into the packet */ - uint8_t total_acks =3D min_int(max, ack_mru->len); + uint8_t total_acks =3D (uint8_t)min_int(max, ack_mru->len); - sub =3D buf_sub(buf, ACK_SIZE(total_acks), prepend); + sub =3D buf_sub(buf, (int)ACK_SIZE(total_acks), prepend); if (!BDEF(&sub)) { goto error; diff --git a/src/openvpn/socket.h b/src/openvpn/socket.h index bfc1253..a4acc5d 100644 --- a/src/openvpn/socket.h +++ b/src/openvpn/socket.h @@ -1181,7 +1181,7 @@ } /* write a TCP or UDP packet to link */ -static inline int +static inline size_t link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to) @@ -1198,7 +1198,7 @@ else { ASSERT(0); - return -1; /* NOTREACHED */ + return 0; /* NOTREACHED */ } } diff --git a/src/openvpn/tls_crypt.c b/src/openvpn/tls_crypt.c index 975d31f..f0946cb 100644 --- a/src/openvpn/tls_crypt.c +++ b/src/openvpn/tls_crypt.c @@ -634,7 +634,7 @@ memcpy(&net_len, BEND(&wrapped_client_key) - sizeof(net_len), sizeof(net_len)); - size_t wkc_len =3D ntohs(net_len); + uint16_t wkc_len =3D ntohs(net_len); if (!buf_advance(&wrapped_client_key, BLEN(&wrapped_client_key) - wkc_= len)) { msg(D_TLS_ERRORS, "Can not locate tls-crypt-v2 client key"); diff --git a/src/openvpn/xkey_helper.c b/src/openvpn/xkey_helper.c index 40839f2..fcf8c2e 100644 --- a/src/openvpn/xkey_helper.c +++ b/src/openvpn/xkey_helper.c @@ -292,7 +292,7 @@ * @return false on error, true on success * * On return enc_len is set to actual size of the result. - * enc is NULL or enc_len is not enough to store the result, it is set + * If enc is NULL or enc_len is not enough to store the result, it is set * to the required size and false is returned. */ bool @@ -337,8 +337,8 @@ MAKE_DI(sha512), MAKE_DI(sha224), MAKE_DI(sha512_2= 24), MAKE_DI(sha512_256), {0, NULL, 0}}; - int out_len =3D 0; - int ret =3D 0; + size_t out_len =3D 0; + bool ret =3D false; int nid =3D OBJ_sn2nid(mdname); if (nid =3D=3D NID_undef) @@ -354,7 +354,7 @@ if (tbslen !=3D EVP_MD_size(EVP_get_digestbyname(mdname))) { - msg(M_WARN, "Error: encode_pkcs11: invalid input length <%d>", (in= t)tbslen); + msg(M_WARN, "Error: encode_pkcs11: invalid input length <%zu>", tb= slen); goto done; } @@ -383,13 +383,13 @@ out_len =3D tbslen + di->sz; - if (enc && (out_len <=3D (int) *enc_len)) + if (enc && (out_len <=3D *enc_len)) { /* combine header and digest */ memcpy(enc, di->header, di->sz); memcpy(enc + di->sz, tbs, tbslen); - dmsg(D_XKEY, "encode_pkcs1: digest length =3D %d encoded length = =3D %d", - (int) tbslen, (int) out_len); + dmsg(D_XKEY, "encode_pkcs1: digest length =3D %zu encoded length = =3D %zu", + tbslen, out_len); ret =3D true; } diff --git a/tests/unit_tests/openvpn/mock_get_random.c b/tests/unit_tests/= openvpn/mock_get_random.c index 787b5e3..dfc7287 100644 --- a/tests/unit_tests/openvpn/mock_get_random.c +++ b/tests/unit_tests/openvpn/mock_get_random.c @@ -41,6 +41,6 @@ { for (int i =3D 0; i < len; i++) { - output[i] =3D rand(); + output[i] =3D (uint8_t)rand(); } } diff --git a/tests/unit_tests/openvpn/test_crypto.c b/tests/unit_tests/open= vpn/test_crypto.c index 58eebc0..d765a4e 100644 --- a/tests/unit_tests/openvpn/test_crypto.c +++ b/tests/unit_tests/openvpn/test_crypto.c @@ -97,8 +97,8 @@ for (int i =3D 0; i < strlen(ciphername); i++) { - upper[i] =3D toupper(ciphername[i]); - lower[i] =3D tolower(ciphername[i]); + upper[i] =3D (char)toupper((unsigned char)ciphername[i]); + lower[i] =3D (char)tolower((unsigned char)ciphername[i]); if (rand() & 0x1) { random_case[i] =3D upper[i]; @@ -160,7 +160,7 @@ uint8_t out[32]; - ssl_tls1_PRF(seed, seed_len, secret, secret_len, out, sizeof(out)); + ssl_tls1_PRF(seed, (int)seed_len, secret, (int)secret_len, out, sizeof= (out)); assert_memory_equal(good_prf, out, sizeof(out)); } diff --git a/tests/unit_tests/openvpn/test_packet_id.c b/tests/unit_tests/o= penvpn/test_packet_id.c index 90c67ac..c351858 100644 --- a/tests/unit_tests/openvpn/test_packet_id.c +++ b/tests/unit_tests/openvpn/test_packet_id.c @@ -94,7 +94,7 @@ assert(data->pis.id =3D=3D 1); assert(data->pis.time =3D=3D now); assert_true(data->test_buf_data.buf_id =3D=3D htonl(1)); - assert_true(data->test_buf_data.buf_time =3D=3D htonl(now)); + assert_true(data->test_buf_data.buf_time =3D=3D htonl((uint32_t)now)); } static void @@ -121,7 +121,7 @@ assert(data->pis.id =3D=3D 1); assert(data->pis.time =3D=3D now); assert_true(data->test_buf_data.buf_id =3D=3D htonl(1)); - assert_true(data->test_buf_data.buf_time =3D=3D htonl(now)); + assert_true(data->test_buf_data.buf_time =3D=3D htonl((uint32_t)now)); } static void @@ -152,7 +152,7 @@ assert(data->pis.id =3D=3D 1); assert(data->pis.time =3D=3D now); assert_true(data->test_buf_data.buf_id =3D=3D htonl(1)); - assert_true(data->test_buf_data.buf_time =3D=3D htonl(now)); + assert_true(data->test_buf_data.buf_time =3D=3D htonl((uint32_t)now)); } static void diff --git a/tests/unit_tests/openvpn/test_provider.c b/tests/unit_tests/op= envpn/test_provider.c index 335fca2..5e57f33 100644 --- a/tests/unit_tests/openvpn/test_provider.c +++ b/tests/unit_tests/openvpn/test_provider.c @@ -365,7 +365,7 @@ } /* return a predefined string as sig */ - memcpy(sig, good_sig, min_int(sizeof(good_sig), *siglen)); + memcpy(sig, good_sig, min_size(sizeof(good_sig), *siglen)); return 1; } diff --git a/tests/unit_tests/openvpn/test_tls_crypt.c b/tests/unit_tests/o= penvpn/test_tls_crypt.c index ed7c794..3b885ab 100644 --- a/tests/unit_tests/openvpn/test_tls_crypt.c +++ b/tests/unit_tests/openvpn/test_tls_crypt.c @@ -138,7 +138,7 @@ { for (int i =3D 0; i < len; i++) { - output[i] =3D i; + output[i] =3D (uint8_t)i; } return true; } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/267?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: I6818b153bdeb1eed65870af99b0531e95807fe0f Gerrit-Change-Number: 267 Gerrit-PatchSet: 3 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-MessageType: newchange --MwHpnSXOx00= 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.

Vi= ew Change

Various fixes for -Wconversion errors

These are all fi= xes I considered "safe". They either

- Have sufficient che= cks/shifts for a cast to be safe
- Fix the type of a variable without re= quiring code changes
- Are in non-critical unittest code

v2:
= - add min_size instead of abusing min_int

Change-Id: I6818b153bdeb1e= ed65870af99b0531e95807fe0f
Signed-off-by: Frank Lichtenheld <frank@...1186...= .2641...>
---
M src/openvpn/buffer.c
M src/openvpn/crypto.c
= M src/openvpn/integer.h
M src/openvpn/mss.c
M src/openvpn/otime.c
= M src/openvpn/otime.h
M src/openvpn/packet_id.c
M src/openvpn/reliabl= e.c
M src/openvpn/socket.h
M src/openvpn/tls_crypt.c
M src/openvpn= /xkey_helper.c
M tests/unit_tests/openvpn/mock_get_random.c
M tests/u= nit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_packet_i= d.c
M tests/unit_tests/openvpn/test_provider.c
M tests/unit_tests/ope= nvpn/test_tls_crypt.c
16 files changed, 50 insertions(+), 36 deletions(-= )

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/67=
/267/3
diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c
index 24f1ef2..a32e7d2 100644
--- a/src/openvp= n/buffer.c
+++ b/src/openvpn/buffer.c
@@ -3= 52,7 +352,7 @@
return false;
= }

- = const int size =3D write(fd, BPTR(buf), BLEN(buf));
+ const ssize_t size =3D write(fd, BPTR= (buf), BLEN(buf));
if (size !=3D BLEN(buf))
= {
msg(M_ERRNO, "Write error on fil= e '%s'", filename);
@@ -889,7 +889,7 @@=
{
break;
= }
- line[= n++] =3D c;
+ = line[n++] =3D (char)c;
}
while (c= );

diff --git a/src/openvpn/crypto.c b/sr= c/openvpn/crypto.c
index a77b5a1..3152060 100644
= --- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c=
@@ -26,6 +26,8 @@
#include "config.h= "
#endif

+#include <inttypes.h>
+
#include "syshe= ad.h"

#include "crypto.h"=
@@ -1275,8 +1277,8 @@
= hex_byte[hb_index++] =3D c;
if (hb_in= dex =3D=3D 2)
{
- unsigned int u;
- A= SSERT(sscanf((const char *)hex_byte, "%x", &u) =3D=3D 1);
+ = uint8_t u;
+ = ASSERT(sscanf((const char *)hex_byte, "%" SCNx8, = &u) =3D=3D 1);
*out++ =3D u;
hb_index =3D 0;
= if (++count =3D=3D keylen)
@@ -1538,1= 3 +1540,13 @@
ASSERT(cipher_kt_key_size(kt->cipher)= <=3D MAX_CIPHER_KEY_LENGTH
&& md_kt= _size(kt->digest) <=3D MAX_HMAC_KEY_LENGTH);
=
- const uint8_t cipher_len= gth =3D cipher_kt_key_size(kt->cipher);
+ const uint8_t cipher_length =3D (uint8_t)cipher_= kt_key_size(kt->cipher);
if (!buf_write(buf, &c= ipher_length, 1))
{
return fa= lse;
}

- uint8_t hmac_length =3D md_kt_size(kt->diges= t);
+ uint8_t hmac= _length =3D (uint8_t)md_kt_size(kt->digest);
if (!buf_write(buf, &hmac_length, 1))
= {
diff --git a/src/openvpn/integer.h b/src/openvpn/integer.= h
index 215c159..30b9ecf 100644
--- a/src/o= penvpn/integer.h
+++ b/src/openvpn/integer.h
@@ -28,12 +28,12 @@


#ifndef htonll
#define htonll(x) ((1=3D=3Dhtonl(1)) ? (x) : \
- ((uint64_t)htonl(= (x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))

+ ((uint64_t)hton= l((uint32_t)((x) & 0xFFFFFFFF)) << 32) | htonl((uint32_t)((x) >= ;> 32)))

#endif

#ifn= def ntohll
#define ntohll(x) ((1=3D=3Dntohl(1)) ? (x) : \<= /span>
- ((u= int64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))<= /span>
+ (= (uint64_t)ntohl((uint32_t)((x) & 0xFFFFFFFF)) << 32) | ntohl((uin= t32_t)((x) >> 32)))
#endif
<= br> /*
@@ -65,6 +65,19 @@
}
}

+static inline size_t
+min_size(size_t x, size_t y)
+{
+ if (x < y)
+ ret= urn x;
+ }<= br>+ else
+ {
+ return y;
+ }
+}
+
= static inline int
max_int(int x, int y)
<= span> {

diff --git a/src/openvpn/mss.c b/src/openvpn/mss.c<= /span>
index 816e65b..dbd3681 100644
--- a/src/ope= nvpn/mss.c
+++ b/src/openvpn/mss.c
@@ -165,= 7 +165,7 @@
return;
}<= br>
- for (ol= en =3D hlen - sizeof(struct openvpn_tcphdr),
+ for (olen =3D hlen - (int) sizeof(struct openv= pn_tcphdr),
opt =3D (uint8_t *)(tc + 1); olen > 1;
olen -=3D optlen, = opt +=3D optlen)
diff --git a/src/openvpn/otime.c b/src/ope= nvpn/otime.c
index b28a90f..e751246 100644
= --- a/src/openvpn/otime.c
+++ b/src/openvpn/otime.c<= br>@@ -105,7 +105,7 @@
/* format a time_t as ascii, = or use current time if 0 */

const char *=
-time_string(time_t t,= int usec, bool show_usec, struct gc_arena *gc)
+time_string(time_t t, long usec, bool show_usec= , struct gc_arena *gc)
{
struct buffe= r out =3D alloc_buf_gc(64, gc);
struct timeval tv;
diff --git a/src/openvpn/otime.h b/src/openvpn/otime.h<= br>index c27be89..d795c3c 100644
--- a/src/openvpn/ot= ime.h
+++ b/src/openvpn/otime.h
@@ -43,7 +4= 3,7 @@
bool frequency_limit_event_allowed(struct frequency= _limit *f);

/* format a time_t as ascii,= or use current time if 0 */
-const char *time_string(time_t t, int usec, bool show_usec, struct g= c_arena *gc);
+const = char *time_string(time_t t, long usec, bool show_usec, struct gc_arena *gc)= ;

/* struct timeval functions */<= br>
diff --git a/src/openvpn/packet_id.c b/src/openv= pn/packet_id.c
index ef83248..3d6f3ee 100644
--- a/src/openvpn/packet_id.c

+++ b/src/openvpn/packet_id= .c
@@ -588,14 +588,14 @@
}<= br> else
{
- diff =3D (int) prev_now - v;=
+ diff =3D (int)= (prev_now - v);
if (diff < 0)
{

c =3D 'N';
}
else if (diff < 1= 0)
{
- c =3D '0' + diff;
+ c =3D (char)('0' = + diff);
}
else
{
diff --git a/src/openvpn/reli= able.c b/src/openvpn/reliable.c
index e7d4d5f..0e26f98 1006= 44
--- a/src/openvpn/reliable.c
+++ b/src/o= penvpn/reliable.c
@@ -257,8 +257,7 @@
= struct buffer *buf,
cons= t struct session_id *sid, int max, bool prepend)
{<= br>- int i, j;
- uint8_t n;

+ int i, j, n;
str= uct buffer sub;

n =3D ack->len;
@@ -270,9 +269,9 @@
copy_acks_to_mru(ac= k, ack_mru, n);

/* Number of acks we= can resend that still fit into the packet */
- uint8_t total_acks =3D min_int(max, ack_mru->= ;len);
+ uint8_t t= otal_acks =3D (uint8_t)min_int(max, ack_mru->len);

- sub =3D buf_sub(buf, = ACK_SIZE(total_acks), prepend);
+ sub =3D buf_sub(buf, (int)ACK_SIZE(total_acks), prepend);
if (!BDEF(&sub))
{
<= span> goto error;

diff --git a/src/openvpn/socket.h= b/src/openvpn/socket.h
index bfc1253..a4acc5d 100644
--- a/src/openvpn/socket.h
+++ b/src/openvpn/soc= ket.h
@@ -1181,7 +1181,7 @@
}

/* write a TCP or UDP packet to link */
-static inline int

+static inline size_t
link_socket_write(struct link_socket *sock,

= struct buffer *buf,
struct link_so= cket_actual *to)
@@ -1198,7 +1198,7 @@
= else
{
ASSERT(0);
= - return -1; /* NOTREACHED= */
+ return 0= ; /* NOTREACHED */
}
}

diff --git a/src/openvpn/tls_crypt.c b/src/openvpn/tls_= crypt.c
index 975d31f..f0946cb 100644
--- a= /src/openvpn/tls_crypt.c
+++ b/src/openvpn/tls_crypt.c
@@ -634,7 +634,7 @@
memcpy(&net_len, B= END(&wrapped_client_key) - sizeof(net_len),
= sizeof(net_len));

- size_t wkc_len =3D ntohs(net_len);
+ uint16_t wkc_len =3D ntohs(net_len);<= /span>
if (!buf_advance(&wrapped_client_key, BLEN(&wr= apped_client_key) - wkc_len))
{
= msg(D_TLS_ERRORS, "Can not locate tls-crypt-v2 client key");
diff --git a/src/openvpn/xkey_helper.c b/src/openvpn/xkey_he= lper.c
index 40839f2..fcf8c2e 100644
--- a/= src/openvpn/xkey_helper.c
+++ b/src/openvpn/xkey_helper.c
@@ -292,7 +292,7 @@
* @return = false on error, true on success
*
* O= n return enc_len is set to actual size of the result.
- * enc is NULL or enc_len is not enough to= store the result, it is set
+ * If enc is NULL or enc_len is not enough to store the result, it= is set
* to the required size and false is returned.
*/
bool
@@ -337,8 +337,8 @@=
MAKE_DI(sha512), MAKE_DI(sha224),= MAKE_DI(sha512_224),
MAKE_DI(sha5= 12_256), {0, NULL, 0}};

- int out_len =3D 0;
- int ret =3D 0;
+ size_t out_len =3D 0;
+ bool ret =3D false;
<= br> int nid =3D OBJ_sn2nid(mdname);
if (nid = =3D=3D NID_undef)
@@ -354,7 +354,7 @@

if (tbslen !=3D EVP_MD_size(EVP_get_digestbyname(mdname))= )
{
+ msg(M_WARN, "Error: encode_pkcs11: invalid input leng= th <%zu>", tbslen);
goto done; }

@@ -383,13 +383,13 @@

out_len =3D tbslen + di->sz;
- if (enc = && (out_len <=3D (int) *enc_len))
+ if (enc && (out_len <=3D *enc_len))=
{
/* combine header and dige= st */
memcpy(enc, di->header, di->sz);
memcpy(enc + di->sz, tbs, tbslen);
- dmsg(D_XKEY, "encode_pkcs1= : digest length =3D %d encoded length =3D %d",
- (int) tbslen, (int) out_len);<= /span>
+ dmsg(D_XKEY,= "encode_pkcs1: digest length =3D %zu encoded length =3D %zu",
+ tbslen, o= ut_len);
ret =3D true;
}

diff --git a/tests/unit_tests/openvpn/mock_ge= t_random.c b/tests/unit_tests/openvpn/mock_get_random.c
ind= ex 787b5e3..dfc7287 100644
--- a/tests/unit_tests/openvpn/m= ock_get_random.c
+++ b/tests/unit_tests/openvpn/mock_get_ra= ndom.c
@@ -41,6 +41,6 @@
{
for (int i =3D 0; i < len; i++)

{
<= span style=3D"color: hsl(0, 100%, 40%);">- output[i] =3D rand();
+ output[i] =3D (= uint8_t)rand();
}
}
d= iff --git a/tests/unit_tests/openvpn/test_crypto.c b/tests/unit_tests/openv= pn/test_crypto.c
index 58eebc0..d765a4e 100644
--- a/tests/unit_tests/openvpn/test_crypto.c

+++ b/test= s/unit_tests/openvpn/test_crypto.c
@@ -97,8 +97,8 @@=

for (int i =3D 0; i < strlen(ciphername= ); i++)
{
- upper[i] =3D toupper(ciphername[i]);
- lower[i] =3D tolower(ciphername[i])= ;
+ upper[i] = =3D (char)toupper((unsigned char)ciphername[i]);
+ lower[i] =3D (char)tolower((unsigned c= har)ciphername[i]);
if (rand() & 0x1) {
random_case[i] =3D upper[i]= ;
@@ -160,7 +160,7 @@


uint8_t out[32];
- ssl_tls1_PRF(seed, seed_len, secret, secret_len, out, si= zeof(out));
+ ssl_= tls1_PRF(seed, (int)seed_len, secret, (int)secret_len, out, sizeof(out));

assert_memory_equal(good_prf, out, si= zeof(out));
}
diff --git a/tests/unit_test= s/openvpn/test_packet_id.c b/tests/unit_tests/openvpn/test_packet_id.c
index 90c67ac..c351858 100644
--- a/tests/unit_= tests/openvpn/test_packet_id.c
+++ b/tests/unit_tests/openv= pn/test_packet_id.c
@@ -94,7 +94,7 @@
= assert(data->pis.id =3D=3D 1);
assert(data->pis.= time =3D=3D now);
assert_true(data->test_buf_data.b= uf_id =3D=3D htonl(1));
- assert_true(data->test_buf_data.buf_time =3D=3D htonl(now));
+ assert_true(data->= test_buf_data.buf_time =3D=3D htonl((uint32_t)now));
}

static void
@@ -121,7 +121,= 7 @@
assert(data->pis.id =3D=3D 1);
assert(data->pis.time =3D=3D now);

assert_tru= e(data->test_buf_data.buf_id =3D=3D htonl(1));
- assert_true(data->test_buf_data.buf_time= =3D=3D htonl(now));
= + assert_true(data->test_buf_data.buf_time =3D=3D htonl((uint32_t)now= ));
}

static void
@@ -152,7 +152,7 @@
assert(data->pis.id = =3D=3D 1);
assert(data->pis.time =3D=3D now);
assert_true(data->test_buf_data.buf_id =3D=3D htonl(1));=
- assert_true(data-= >test_buf_data.buf_time =3D=3D htonl(now));
+ assert_true(data->test_buf_data.buf_time = =3D=3D htonl((uint32_t)now));
}
static void
diff --git a/tests/unit_tests/openvpn/= test_provider.c b/tests/unit_tests/openvpn/test_provider.c
= index 335fca2..5e57f33 100644
--- a/tests/unit_tests/openvp= n/test_provider.c
+++ b/tests/unit_tests/openvpn/test_provi= der.c
@@ -365,7 +365,7 @@
}
=
/* return a predefined string as sig */=
- memcpy(sig, good_sig, mi= n_int(sizeof(good_sig), *siglen));
+ memcpy(sig, good_sig, min_size(sizeof(good_sig), *siglen= ));

return 1;
}
diff --git a/tests/unit_tests/openvpn/test_tls_crypt.c b/tests= /unit_tests/openvpn/test_tls_crypt.c
index ed7c794..3b885ab= 100644
--- a/tests/unit_tests/openvpn/test_tls_crypt.c
+++ b/tests/unit_tests/openvpn/test_tls_crypt.c
@@ -138,7 +138,7 @@

{
for (int i = =3D 0; i < len; i++)
{
- output[i] =3D i;
+ output[i] =3D (uint8_t)i;
<= span> }

return true;
}
=

To view, visit change 267. To unsubscribe, or for help= writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6818b153bdeb1eed65870af99b0= 531e95807fe0f
Gerrit-Change-Number: 267
Gerrit-PatchSet: 3
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
--MwHpnSXOx00=--