Attention is currently required from: Arne Schwabe.

Hello Arne Schwabe, 

I'd like you to reexamine a change. Please visit

    https://gerrit.openvpn.net/c/openvpn/+/2157?usp=email

to look at the new patch set (#2).


Change subject: Various trivial -Wsign-conversion fixes
......................................................................

Various trivial -Wsign-conversion fixes

* Continue BLEN -> BLENZ replacement
* Remove some unneeded casts
* Some trivial type fixes

Change-Id: I02f8df01f8f33cb9cd04cd844d1f1893688f51e8
Signed-off-by: Frank Lichtenheld <[email protected]>
---
M src/openvpn/acc.c
M src/openvpn/auth_token.c
M src/openvpn/base64.h
M src/openvpn/console_builtin.c
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_epoch.c
M src/openvpn/manage.c
M src/openvpn/ssl_mbedtls.c
9 files changed, 34 insertions(+), 53 deletions(-)


  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/2157/2

diff --git a/src/openvpn/acc.c b/src/openvpn/acc.c
index e21891d..b8d7c3d 100644
--- a/src/openvpn/acc.c
+++ b/src/openvpn/acc.c
@@ -148,11 +148,6 @@
     return parse_acc_message_flags(flags, err_reason, gc);
 }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
 void
 receive_acc_message(struct context *c, const struct buffer *buffer)
 {
@@ -236,15 +231,10 @@
     msg(D_PUSH_ERRORS, "WARNING: Received malformed custom app control channel 
"
                        "message (%s): %s",
         err_reason,
-        format_hex(CBPTR(buffer), BLEN(buffer), 80, &gc));
+        format_hex(CBPTR(buffer), BLENZ(buffer), 80, &gc));
     gc_free(&gc);
 }

-
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 bool
 send_acc_message(struct context *c,
                  struct tls_multi *multi,
diff --git a/src/openvpn/auth_token.c b/src/openvpn/auth_token.c
index 211af90..b69092c 100644
--- a/src/openvpn/auth_token.c
+++ b/src/openvpn/auth_token.c
@@ -36,11 +36,6 @@
  * padding */
 static_assert(TOKEN_DATA_LEN % 3 == 0, "TOKEN_DATA_LEN is not a multiple of 
3");

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
 bool
 is_auth_token(const char *password)
 {
@@ -67,7 +62,7 @@
         return;
     }

-    int auth_token_state_flags = 
session->key[KS_PRIMARY].auth_token_state_flags;
+    unsigned int auth_token_state_flags = 
session->key[KS_PRIMARY].auth_token_state_flags;

     const char *state;

@@ -188,7 +183,7 @@
 {
     struct gc_arena gc = gc_new();

-    int64_t timestamp = htonll((uint64_t)now);
+    int64_t timestamp = (int64_t)htonll((uint64_t)now);
     int64_t initial_timestamp = timestamp;

     hmac_ctx_t *ctx = multi->opt.auth_token_key.hmac;
@@ -273,7 +268,7 @@
         alloc_buf_gc(strlen(SESSION_ID_PREFIX) + strlen(b64output) + 1, &gc);

     ASSERT(buf_write(&session_token, SESSION_ID_PREFIX, 
strlen(SESSION_ID_PREFIX)));
-    ASSERT(buf_write(&session_token, b64output, (int)strlen(b64output)));
+    ASSERT(buf_write(&session_token, b64output, strlen(b64output)));
     ASSERT(buf_write_u8(&session_token, 0));

     free(b64output);
@@ -296,10 +291,6 @@
     gc_free(&gc);
 }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 static bool
 check_hmac_token(hmac_ctx_t *ctx, const uint8_t *b64decoded, const char 
*username)
 {
diff --git a/src/openvpn/base64.h b/src/openvpn/base64.h
index be7aa64..800e569 100644
--- a/src/openvpn/base64.h
+++ b/src/openvpn/base64.h
@@ -35,7 +35,7 @@
 #define _BASE64_H_

 /** Compute resulting base64 length.  6 bits per byte, padded to 4 bytes. */
-#define OPENVPN_BASE64_LENGTH(binary_length) ((((8 * binary_length) / 6) + 3) 
& ~3)
+#define OPENVPN_BASE64_LENGTH(binary_length) ((((8 * binary_length) / 6) + 3) 
& ~3u)

 /** Compute the maximal number of bytes encoded in a base64 string. */
 #define OPENVPN_BASE64_DECODED_LENGTH(base64_length) ((base64_length / 4) * 3)
diff --git a/src/openvpn/console_builtin.c b/src/openvpn/console_builtin.c
index dc71d12..0353ade 100644
--- a/src/openvpn/console_builtin.c
+++ b/src/openvpn/console_builtin.c
@@ -234,7 +234,7 @@
     if (!echo && (tcgetattr(fileno(fp), &tty_tmp) == 0))
     {
         tty_save = tty_tmp;
-        tty_tmp.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ISIG);
+        tty_tmp.c_lflag &= ~(unsigned int)(ECHO | ECHOE | ECHOK | ECHONL | 
ISIG);
         restore_tty = (tcsetattr(fileno(fp), TCSAFLUSH, &tty_tmp) == 0);
     }

diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index 88c2c52..ffdf8c4 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -139,7 +139,7 @@
         ASSERT(cipher_ctx_reset(ctx->cipher, iv));
     }

-    dmsg(D_PACKET_CONTENT, "ENCRYPT FROM: %s", format_hex(BPTR(buf), 
BLEN(buf), 80, &gc));
+    dmsg(D_PACKET_CONTENT, "ENCRYPT FROM: %s", format_hex(BPTR(buf), 
BLENZ(buf), 80, &gc));

     /* Buffer overflow check */
     if (!buf_safe(&work, buf->len + mac_len + 
cipher_ctx_block_size(ctx->cipher)))
@@ -151,7 +151,7 @@

     /* For AEAD ciphers, authenticate Additional Data, including opcode */
     ASSERT(cipher_ctx_update_ad(ctx->cipher, BPTR(&work), BLEN(&work)));
-    dmsg(D_PACKET_CONTENT, "ENCRYPT AD: %s", format_hex(BPTR(&work), 
BLEN(&work), 0, &gc));
+    dmsg(D_PACKET_CONTENT, "ENCRYPT AD: %s", format_hex(BPTR(&work), 
BLENZ(&work), 0, &gc));

     if (!use_epoch_data_format)
     {
@@ -170,8 +170,8 @@

     /* update number of plaintext blocks encrypted. Use the (x + (n-1))/n trick
      * to round up the result to the number of blocks used */
-    const int blocksize = AEAD_LIMIT_BLOCKSIZE;
-    opt->key_ctx_bi.encrypt.plaintext_blocks += (BLEN(&work) + (blocksize - 
1)) / blocksize;
+    const unsigned int blocksize = AEAD_LIMIT_BLOCKSIZE;
+    opt->key_ctx_bi.encrypt.plaintext_blocks += (BLENZ(&work) + (blocksize - 
1)) / blocksize;

     /* if the tag is at end the end, allocate it now */
     if (use_epoch_data_format)
@@ -186,7 +186,7 @@

     *buf = work;

-    dmsg(D_PACKET_CONTENT, "ENCRYPT TO: %s", format_hex(BPTR(buf), BLEN(buf), 
80, &gc));
+    dmsg(D_PACKET_CONTENT, "ENCRYPT TO: %s", format_hex(BPTR(buf), BLENZ(buf), 
80, &gc));

     gc_free(&gc);
     return;
@@ -257,13 +257,13 @@
             ASSERT(buf_write(&work, iv_buf, iv_size));
             dmsg(D_PACKET_CONTENT, "ENCRYPT IV: %s", format_hex(iv_buf, 
iv_size, 0, &gc));

-            dmsg(D_PACKET_CONTENT, "ENCRYPT FROM: %s", format_hex(BPTR(buf), 
BLEN(buf), 80, &gc));
+            dmsg(D_PACKET_CONTENT, "ENCRYPT FROM: %s", format_hex(BPTR(buf), 
BLENZ(buf), 80, &gc));

             /* cipher_ctx was already initialized with key & keylen */
             ASSERT(cipher_ctx_reset(ctx->cipher, iv_buf));

             /* Buffer overflow check */
-            if (!buf_safe(&work, buf->len + 
cipher_ctx_block_size(ctx->cipher)))
+            if (!buf_safe(&work, BLENZ(buf) + 
cipher_ctx_block_size(ctx->cipher)))
             {
                 msg(D_CRYPT_ERRORS,
                     "ENCRYPT: buffer size error, bc=%d bo=%d bl=%d wc=%d wo=%d 
wl=%d cbs=%u",
@@ -317,7 +317,7 @@

         *buf = work;

-        dmsg(D_PACKET_CONTENT, "ENCRYPT TO: %s", format_hex(BPTR(&work), 
BLEN(&work), 80, &gc));
+        dmsg(D_PACKET_CONTENT, "ENCRYPT TO: %s", format_hex(BPTR(&work), 
BLENZ(&work), 80, &gc));
     }

     gc_free(&gc);
@@ -460,7 +460,7 @@
     ASSERT(buf->len > 0);
     ASSERT(ctx->cipher);

-    dmsg(D_PACKET_CONTENT, "DECRYPT FROM: %s", format_hex(BPTR(buf), 
BLEN(buf), 80, &gc));
+    dmsg(D_PACKET_CONTENT, "DECRYPT FROM: %s", format_hex(BPTR(buf), 
BLENZ(buf), 80, &gc));

     ASSERT(ad_start >= buf->data && ad_start <= BPTR(buf));

@@ -558,10 +558,10 @@
     }

     dmsg(D_PACKET_CONTENT, "DECRYPT MAC: %s", format_hex(tag_ptr, tag_size, 0, 
&gc));
-    dmsg(D_PACKET_CONTENT, "DECRYPT FROM: %s", format_hex(BPTR(buf), 
BLEN(buf), 0, &gc));
+    dmsg(D_PACKET_CONTENT, "DECRYPT FROM: %s", format_hex(BPTR(buf), 
BLENZ(buf), 0, &gc));

     /* Buffer overflow check (should never fail) */
-    if (!buf_safe(&work, buf->len + cipher_ctx_block_size(ctx->cipher)))
+    if (!buf_safe(&work, BLENZ(buf) + cipher_ctx_block_size(ctx->cipher)))
     {
         CRYPT_ERROR("potential buffer overflow");
     }
@@ -585,7 +585,7 @@
     }
     ASSERT(buf_inc_len(&work, outlen));

-    dmsg(D_PACKET_CONTENT, "DECRYPT TO: %s", format_hex(BPTR(&work), 
BLEN(&work), 80, &gc));
+    dmsg(D_PACKET_CONTENT, "DECRYPT TO: %s", format_hex(BPTR(&work), 
BLENZ(&work), 80, &gc));

     if (!crypto_check_replay(opt, &pin, epoch, error_prefix, &gc))
     {
@@ -594,8 +594,8 @@

     /* update number of plaintext blocks decrypted. Use the (x + (n-1))/n trick
      * to round up the result to the number of blocks used. */
-    const int blocksize = AEAD_LIMIT_BLOCKSIZE;
-    opt->key_ctx_bi.decrypt.plaintext_blocks += (BLEN(&work) + (blocksize - 
1)) / blocksize;
+    const unsigned int blocksize = AEAD_LIMIT_BLOCKSIZE;
+    opt->key_ctx_bi.decrypt.plaintext_blocks += (BLENZ(&work) + (blocksize - 
1)) / blocksize;

     *buf = work;

@@ -631,7 +631,7 @@
         struct packet_id_net pin;
         bool have_pin = false;

-        dmsg(D_PACKET_CONTENT, "DECRYPT FROM: %s", format_hex(BPTR(buf), 
BLEN(buf), 80, &gc));
+        dmsg(D_PACKET_CONTENT, "DECRYPT FROM: %s", format_hex(BPTR(buf), 
BLENZ(buf), 80, &gc));

         /* Verify the HMAC */
         if (ctx->hmac)
@@ -694,7 +694,7 @@
             }

             /* Buffer overflow check (should never happen) */
-            if (!buf_safe(&work, buf->len + 
cipher_ctx_block_size(ctx->cipher)))
+            if (!buf_safe(&work, BLENZ(buf) + 
cipher_ctx_block_size(ctx->cipher)))
             {
                 CRYPT_ERROR("packet too big to decrypt");
             }
@@ -713,7 +713,7 @@
             }
             ASSERT(buf_inc_len(&work, outlen));

-            dmsg(D_PACKET_CONTENT, "DECRYPT TO: %s", format_hex(BPTR(&work), 
BLEN(&work), 80, &gc));
+            dmsg(D_PACKET_CONTENT, "DECRYPT TO: %s", format_hex(BPTR(&work), 
BLENZ(&work), 80, &gc));

             /* Get packet ID from plaintext buffer or IV, depending on cipher 
mode */
             {
@@ -855,7 +855,7 @@
 crypto_max_overhead(void)
 {
     return packet_id_size(true) + OPENVPN_MAX_IV_LENGTH + 
OPENVPN_MAX_CIPHER_BLOCK_SIZE
-           + max_int(OPENVPN_MAX_HMAC_SIZE, OPENVPN_AEAD_TAG_LENGTH);
+           + max_uint(OPENVPN_MAX_HMAC_SIZE, OPENVPN_AEAD_TAG_LENGTH);
 }

 static void
@@ -1366,7 +1366,7 @@
         size_t buf_size = strlen(file) + 1;
         ASSERT(buf_size <= INT_MAX);
         size = (int)buf_size;
-        buf_set_read(&in, (const uint8_t *)file, size);
+        buf_set_read(&in, (const uint8_t *)file, buf_size);
     }
     else /* 'file' is a filename which refers to a file containing the ascii 
key */
     {
@@ -1535,7 +1535,7 @@
     struct buffer out = alloc_buf_gc(2048, &gc);

     /* how to format the ascii file representation of key */
-    const int bytes_per_line = 16;
+    const size_t bytes_per_line = 16;

     /* write header */
     buf_printf(&out, "#\n# %d bit OpenVPN static key\n#\n", nbits);
diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h
index dbe0802..fd632be 100644
--- a/src/openvpn/crypto.h
+++ b/src/openvpn/crypto.h
@@ -760,12 +760,12 @@
  * to read.
  */
 static inline bool
-aead_usage_limit_reached(const uint64_t limit, const struct key_ctx *key_ctx, 
int64_t higest_pid)
+aead_usage_limit_reached(const uint64_t limit, const struct key_ctx *key_ctx, 
uint64_t higest_pid)
 {
     /* This is the  q + s <=  p^(1/2) * 2^(129/2) - 1 calculation where
      * q is the number of protected messages (highest_pid)
      * s Total plaintext length in all messages (in blocks) */
-    return (limit > 0 && key_ctx->plaintext_blocks + (uint64_t)higest_pid > 
limit);
+    return (limit > 0 && key_ctx->plaintext_blocks + higest_pid > limit);
 }

 #endif /* CRYPTO_H */
diff --git a/src/openvpn/crypto_epoch.c b/src/openvpn/crypto_epoch.c
index 312cf6f..243b5a2 100644
--- a/src/openvpn/crypto_epoch.c
+++ b/src/openvpn/crypto_epoch.c
@@ -98,7 +98,7 @@
     const uint8_t *label_prefix = (const uint8_t *)("ovpn ");
     uint8_t prefix_len = 5;

-    size_t hkdf_label_len = 2 + prefix_len + 1 + label_len + 1 + context_len;
+    size_t hkdf_label_len = 2u + prefix_len + 1u + label_len + 1u + 
context_len;
     struct buffer hkdf_label = alloc_buf_gc(hkdf_label_len, &gc);

     buf_write_u16(&hkdf_label, (uint16_t)out_len);
diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index 4809532..1760c90 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -2758,7 +2758,7 @@
             else
             {
                 int status;
-                int resolve_flags = GETADDR_RESOLVE | GETADDR_WARN_ON_SIGNAL | 
GETADDR_FATAL;
+                unsigned int resolve_flags = GETADDR_RESOLVE | 
GETADDR_WARN_ON_SIGNAL | GETADDR_FATAL;

                 if (!(flags & MF_CONNECT_AS_CLIENT))
                 {
@@ -4001,11 +4001,11 @@
         desc = "rsa-sign";
     }

-    buf_write(&buf_data, b64_data, (int)strlen(b64_data));
+    buf_write(&buf_data, b64_data, strlen(b64_data));
     if (man->connection.client_version >= MCV_PKSIGN_ALG)
     {
-        buf_write(&buf_data, ",", (int)strlen(","));
-        buf_write(&buf_data, algorithm, (int)strlen(algorithm));
+        buf_write(&buf_data, ",", strlen(","));
+        buf_write(&buf_data, algorithm, strlen(algorithm));
     }
     char *ret = management_query_multiline_flatten(man, (char 
*)buf_bptr(&buf_data), prompt, desc,
                                                    
&man->connection.ext_key_state,
diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c
index cbc3118..f4e142b 100644
--- a/src/openvpn/ssl_mbedtls.c
+++ b/src/openvpn/ssl_mbedtls.c
@@ -1119,7 +1119,7 @@
         return 0;
     }

-    retval = endless_buf_write(&ks->bio_ctx->in, BPTR(buf), buf->len);
+    retval = endless_buf_write(&ks->bio_ctx->in, BPTR(buf), BLENZ(buf));

     if (retval < 0)
     {

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2157?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I02f8df01f8f33cb9cd04cd844d1f1893688f51e8
Gerrit-Change-Number: 2157
Gerrit-PatchSet: 2
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

Reply via email to