Attention is currently required from: Arne Schwabe.
Hello Arne Schwabe,
I'd like you to do a code review.
Please visit
https://gerrit.openvpn.net/c/openvpn/+/2003?usp=email
to review the following change.
Change subject: crypto_mbedtls_legacy: Sync code with crypto_mbedtls to remove
warnings
......................................................................
crypto_mbedtls_legacy: Sync code with crypto_mbedtls to remove warnings
Generally take the solutions we chose in crypto_mbedtls.c
to avoid conversion warnings and apply them to
crypto_mbedtls_legacy.c.
Change-Id: Ia57c539ede73ca4d0fe08b7b03f8bf8652b89ca4
Signed-off-by: Frank Lichtenheld <[email protected]>
---
M src/openvpn/crypto_mbedtls.c
M src/openvpn/crypto_mbedtls_legacy.c
2 files changed, 25 insertions(+), 30 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/03/2003/1
diff --git a/src/openvpn/crypto_mbedtls.c b/src/openvpn/crypto_mbedtls.c
index 05bb60d..81f1a37 100644
--- a/src/openvpn/crypto_mbedtls.c
+++ b/src/openvpn/crypto_mbedtls.c
@@ -872,7 +872,7 @@
hmac_ctx_reset(ctx_tmp);
hmac_ctx_update(ctx, A1, A1_len);
hmac_ctx_update(ctx_tmp, A1, A1_len);
- hmac_ctx_update(ctx, seed, (int)seed_len);
+ hmac_ctx_update(ctx, seed, seed_len);
if (olen > chunk)
{
diff --git a/src/openvpn/crypto_mbedtls_legacy.c
b/src/openvpn/crypto_mbedtls_legacy.c
index f46d8bf..ed18d30 100644
--- a/src/openvpn/crypto_mbedtls_legacy.c
+++ b/src/openvpn/crypto_mbedtls_legacy.c
@@ -225,11 +225,6 @@
"available\n");
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
bool
crypto_pem_encode(const char *name, struct buffer *dst, const struct buffer
*src,
struct gc_arena *gc)
@@ -259,7 +254,7 @@
*dst = alloc_buf_gc(out_len, gc);
if (!mbed_ok(mbedtls_pem_write_buffer(header, footer, CBPTR(src),
BLEN(src), BPTR(dst),
BCAP(dst), &out_len))
- || !buf_inc_len(dst, out_len - 1))
+ || !buf_inc_len(dst, (int)out_len - 1))
{
CLEAR(*dst);
return false;
@@ -365,7 +360,7 @@
while (len > 0)
{
- const size_t blen = min_int(len, MBEDTLS_CTR_DRBG_MAX_REQUEST);
+ const int blen = min_int(len, MBEDTLS_CTR_DRBG_MAX_REQUEST);
if (0 != mbedtls_ctr_drbg_random(rng_ctx, output, blen))
{
return 0;
@@ -447,7 +442,7 @@
return 0;
}
- return mbedtls_cipher_info_get_key_bitlen(cipher_kt) / 8;
+ return (unsigned int)mbedtls_cipher_info_get_key_bitlen(cipher_kt) / 8;
}
unsigned int
@@ -459,7 +454,7 @@
{
return 0;
}
- return mbedtls_cipher_info_get_iv_size(cipher_kt);
+ return (unsigned int)mbedtls_cipher_info_get_iv_size(cipher_kt);
}
unsigned int
@@ -470,7 +465,7 @@
{
return 0;
}
- return mbedtls_cipher_info_get_block_size(cipher_kt);
+ return (unsigned int)mbedtls_cipher_info_get_block_size(cipher_kt);
}
unsigned int
@@ -694,7 +689,11 @@
return 0;
}
- *dst_len = s_dst_len;
+ if (s_dst_len > INT_MAX)
+ {
+ return 0;
+ }
+ *dst_len = (int)s_dst_len;
return 1;
}
@@ -709,7 +708,11 @@
return 0;
}
- *dst_len = s_dst_len;
+ if (s_dst_len > INT_MAX)
+ {
+ return 0;
+ }
+ *dst_len = (int)s_dst_len;
return 1;
}
@@ -740,7 +743,7 @@
{
return 0;
}
- *dst_len = olen;
+ *dst_len = (int)olen;
if (!mbed_ok(mbedtls_cipher_check_tag(ctx, (const unsigned char *)tag,
tag_len)))
{
@@ -750,10 +753,6 @@
return 1;
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
/*
*
* Generic message digest information functions
@@ -966,11 +965,6 @@
return diff;
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
/*
* Generate the hash required by for the \c tls1_PRF function.
*
@@ -984,7 +978,7 @@
*/
static void
tls1_P_hash(const mbedtls_md_info_t *md_kt, const uint8_t *sec, size_t
sec_len, const uint8_t *seed,
- size_t seed_len, uint8_t *out, size_t olen)
+ int seed_len, uint8_t *out, size_t olen)
{
struct gc_arena gc = gc_new();
uint8_t A1[MAX_HMAC_KEY_LENGTH];
@@ -1077,6 +1071,11 @@
const md_kt_t *md5 = md_get("MD5");
const md_kt_t *sha1 = md_get("SHA1");
+ if (label_len > (size_t)INT_MAX)
+ {
+ return false;
+ }
+
uint8_t *out2 = (uint8_t *)gc_malloc(olen, false, &gc);
size_t len = slen / 2;
@@ -1084,8 +1083,8 @@
const uint8_t *S2 = &(sec[len]);
len += (slen & 1); /* add for odd, make longer */
- tls1_P_hash(md5, S1, len, label, label_len, out1, olen);
- tls1_P_hash(sha1, S2, len, label, label_len, out2, olen);
+ tls1_P_hash(md5, S1, len, label, (int)label_len, out1, olen);
+ tls1_P_hash(sha1, S2, len, label, (int)label_len, out2, olen);
for (size_t i = 0; i < olen; i++)
{
@@ -1100,9 +1099,5 @@
return true;
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
#endif /* MBEDTLS_VERSION_NUMBER < 0x040000 */
#endif /* ENABLE_CRYPTO_MBEDTLS */
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2003?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia57c539ede73ca4d0fe08b7b03f8bf8652b89ca4
Gerrit-Change-Number: 2003
Gerrit-PatchSet: 1
Gerrit-Owner: Frank Lichtenheld <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel