[Openvpn-devel] [M] Change in openvpn[master]: Various fixes for -Wconversion errors

2023-09-07 Thread flichtenheld (Code Review)
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=email

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 = write(fd, BPTR(buf), BLEN(buf));
+const ssize_t size = write(fd, BPTR(buf), BLEN(buf));
 if (size != BLEN(buf))
 {
 msg(M_ERRNO, "Write error on file '%s'", filename);
@@ -889,7 +889,7 @@
 {
 break;
 }
-line[n++] = c;
+line[n++] = (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++] = c;
 if (hb_index == 2)
 {
-unsigned int u;
-ASSERT(sscanf((const char *)hex_byte, "%x", &u) == 1);
+uint8_t u;
+ASSERT(sscanf((const char *)hex_byte, "%" SCNx8, &u) 
== 1);
 *out++ = u;
 hb_index = 0;
 if (++count == keylen)
@@ -1538,13 +1540,13 @@
 ASSERT(cipher_kt_key_size(kt->cipher) <= MAX_CIPHER_KEY_LENGTH
&& md_kt_size(kt->digest) <= MAX_HMAC_KEY_LENGTH);

-const uint8_t cipher_length = cipher_kt_key_size(kt->cipher);
+const uint8_t cipher_length = (uint8_t)cipher_kt_key_size(kt->cipher);
 if (!buf_write(buf, &cipher_length, 1))
 {
 return false;
 }

-uint8_t hmac_length = md_kt_size(kt->digest);
+uint8_t hmac_length = (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==htonl(1)) ? (x) : \
-   ((uint64_t)htonl((x) & 0x) << 32) | htonl((x) >> 
32))
+   ((uint64_t)htonl((uint32_t)((x) & 0x)) << 32) | 
htonl((uint32_t)((x) >> 32)))
 #endif

 #ifndef ntohll
 #define ntohll(x) ((1==ntohl(1)) ? (x) : \
-   ((uint64_t)ntohl((x) & 0x) << 32) | ntohl((x) >> 
32))
+   ((uint64_t)ntohl((uint32_t)((x) & 0x)) << 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 = hlen - sizeof(struct openvpn_tcphdr),
+for (olen = hlen - (int) sizeof(struct openvpn_tcphdr),
  opt = (uint8_t *)(tc + 1);
  olen > 1;
  olen -= optlen, opt += 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 = 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/op

[Openvpn-devel] [M] Change in openvpn[master]: Various fixes for -Wconversion errors

2023-09-07 Thread flichtenheld (Code Review)
Attention is currently required from: plaisthos.

flichtenheld has posted comments on this change. ( 
http://gerrit.openvpn.net/c/openvpn/+/267?usp=email )

Change subject: Various fixes for -Wconversion errors
..


Patch Set 3:

(1 comment)

Patchset:

PS3:
Blocks applying changes to openvpn3



--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/267?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: I6818b153bdeb1eed65870af99b0531e95807fe0f
Gerrit-Change-Number: 267
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld 
Gerrit-Reviewer: plaisthos 
Gerrit-CC: openvpn-devel 
Gerrit-Attention: plaisthos 
Gerrit-Comment-Date: Thu, 07 Sep 2023 08:45:02 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel