]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
win32: Change some APIs to use DWORD instead of size_t
authorFrank Lichtenheld <frank@lichtenheld.com>
Mon, 13 Oct 2025 16:22:15 +0000 (18:22 +0200)
committerGert Doering <gert@greenie.muc.de>
Mon, 13 Oct 2025 16:30:07 +0000 (18:30 +0200)
This is what the Win32 APIs use. Since we put static
integers into this (e.g. sizeof()) this doesn't
result in new conversion warnings at the caller sites.

Change-Id: Ia836e3c05a868a7e8419c2bb2f547d968260783c
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1269
Message-Id: <20251013162221.2156-1-gert@greenie.muc.de>
URL: https://sourceforge.net/p/openvpn/mailman/message/59246222/
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/route.c
src/openvpn/win32.c
src/openvpn/win32.h
tests/unit_tests/openvpn/test_user_pass.c

index ae9aaacb26888b75dd93a6249a91c595520d8c75..7d988da14f7ba683b4cd075b051713913d2e61b8 100644 (file)
@@ -2840,7 +2840,7 @@ del_route_ipapi(const struct route_ipv4 *r, const struct tuntap *tt)
 
 /* Returns RTA_SUCCESS on success, RTA_EEXIST if route exists, RTA_ERROR on error */
 static int
-do_route_service(const bool add, const route_message_t *rt, const size_t size, HANDLE pipe)
+do_route_service(const bool add, const route_message_t *rt, const DWORD size, HANDLE pipe)
 {
     int ret = RTA_ERROR;
     ack_message_t ack;
index eac2352a4c4d9418f045104dd35b04ca993945e9..3c11ec3ae6e295bc2e16ab334c0a18cc7337cd9c 100644 (file)
@@ -1418,13 +1418,8 @@ win32_version_string(struct gc_arena *gc)
     return (const char *)out.data;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 bool
-send_msg_iservice(HANDLE pipe, const void *data, size_t size, ack_message_t *ack,
+send_msg_iservice(HANDLE pipe, const void *data, DWORD size, ack_message_t *ack,
                   const char *context)
 {
     struct gc_arena gc = gc_new();
@@ -1527,7 +1522,8 @@ win32_sleep(const int n)
 
     while (expire >= now)
     {
-        DWORD status = WaitForSingleObject(win32_signal.in.read, (expire - now) * 1000);
+        DWORD wait_ms = (DWORD)((expire - now) * 1000);
+        DWORD status = WaitForSingleObject(win32_signal.in.read, wait_ms);
         if ((status == WAIT_OBJECT_0 && win32_signal_get(&win32_signal)) || status == WAIT_TIMEOUT)
         {
             return;
@@ -1539,7 +1535,7 @@ win32_sleep(const int n)
         {
             if (expire > now)
             {
-                Sleep((expire - now) * 1000);
+                Sleep((DWORD)((expire - now) * 1000));
             }
             return;
         }
@@ -1602,7 +1598,7 @@ plugin_in_trusted_dir(const WCHAR *plugin_path)
 }
 
 bool
-protect_buffer_win32(char *buf, size_t len)
+protect_buffer_win32(char *buf, DWORD len)
 {
     bool ret;
     if (len % CRYPTPROTECTMEMORY_BLOCK_SIZE)
@@ -1620,7 +1616,7 @@ protect_buffer_win32(char *buf, size_t len)
 }
 
 bool
-unprotect_buffer_win32(char *buf, size_t len)
+unprotect_buffer_win32(char *buf, DWORD len)
 {
     bool ret;
     if (len % CRYPTPROTECTMEMORY_BLOCK_SIZE)
@@ -1637,8 +1633,4 @@ unprotect_buffer_win32(char *buf, size_t len)
     return ret;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #endif /* ifdef _WIN32 */
index ff3145ae67c7d2b33f52f4173f406a9ff8e91cce..07a58d8f55e425e97432ff81a6350e18b7bcea50 100644 (file)
@@ -301,12 +301,14 @@ bool win_wfp_uninit(const NET_IFINDEX index, const HANDLE msg_channel);
  */
 const char *win32_version_string(struct gc_arena *gc);
 
-/*
- * Send the |size| bytes in buffer |data| to the interactive service |pipe|
- * and read the result in |ack|. Returns false on communication error.
- * The string in |context| is used to prefix error messages.
+/**
+ * Send the \p size bytes in buffer \p data to the interactive service \p pipe
+ * and read the result in \p ack.
+ * The string in \p context is used to prefix error messages.
+ *
+ * @return true on success, false on communication error
  */
-bool send_msg_iservice(HANDLE pipe, const void *data, size_t size, ack_message_t *ack,
+bool send_msg_iservice(HANDLE pipe, const void *data, DWORD size, ack_message_t *ack,
                        const char *context);
 
 /*
@@ -350,7 +352,7 @@ bool plugin_in_trusted_dir(const WCHAR *plugin_path);
  * - len   number of bytes to encrypt -- must be a multiple of
  *         CRYPTPROTECTMEMORY_BLOCK_SIZE = 16
  */
-bool protect_buffer_win32(char *buf, size_t len);
+bool protect_buffer_win32(char *buf, DWORD len);
 
 /**
  * Decrypt a previously encrypted region of memory using CryptUnProtectMemory()
@@ -360,7 +362,7 @@ bool protect_buffer_win32(char *buf, size_t len);
  * - len   number of bytes to encrypt -- must be a multiple of
  *         CRYPTPROTECTMEMORY_BLOCK_SIZE = 16
  */
-bool unprotect_buffer_win32(char *buf, size_t len);
+bool unprotect_buffer_win32(char *buf, DWORD len);
 
 #endif /* ifndef OPENVPN_WIN32_H */
 #endif /* ifdef _WIN32 */
index f5dddd6545137d684fce68f587b52bccce949752..abe223c94d41d76b553f69adadcfa68d8bd408f1 100644 (file)
@@ -79,17 +79,19 @@ parse_line(const char *line, char **p, const int n, const char *file, const int
     return 0;
 }
 
+#ifdef _WIN32
 bool
-protect_buffer_win32(char *buf, size_t len)
+protect_buffer_win32(char *buf, DWORD len)
 {
     return true;
 }
 
 bool
-unprotect_buffer_win32(char *buf, size_t len)
+unprotect_buffer_win32(char *buf, DWORD len)
 {
     return true;
 }
+#endif
 
 /* tooling */
 static void