From: "cron2 (Code Review)" Date: Mon, 13 Oct 2025 16:33:12 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <346bb6396f3a1c297acbe5c7a6e43a5cb8d9ec0f-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Y9d1aS/3UHg="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: win32: Change some APIs to use DWORD instead of size_t List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: plaisthos , openvpn-devel --Y9d1aS/3UHg= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/12= 69?usp=3Demail ) Change subject: win32: Change some APIs to use DWORD instead of size_t ...................................................................... win32: Change some APIs to use DWORD instead of size_t 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 Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1269 Message-Id: <20251013162221.2156-1-gert@...1296...> URL: https://sourceforge.net/p/openvpn/mailman/message/59246222/ Signed-off-by: Gert Doering --- M src/openvpn/route.c M src/openvpn/win32.c M src/openvpn/win32.h M tests/unit_tests/openvpn/test_user_pass.c 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/openvpn/route.c b/src/openvpn/route.c index ae9aaac..7d988da 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -2840,7 +2840,7 @@ /* Returns RTA_SUCCESS on success, RTA_EEXIST if route exists, RTA_ERROR o= n error */ static int -do_route_service(const bool add, const route_message_t *rt, const size_t s= ize, HANDLE pipe) +do_route_service(const bool add, const route_message_t *rt, const DWORD si= ze, HANDLE pipe) { int ret =3D RTA_ERROR; ack_message_t ack; diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c index eac2352..3c11ec3 100644 --- a/src/openvpn/win32.c +++ b/src/openvpn/win32.c @@ -1418,13 +1418,8 @@ 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 =3D gc_new(); @@ -1527,7 +1522,8 @@ while (expire >=3D now) { - DWORD status =3D WaitForSingleObject(win32_signal.in.read, (expire= - now) * 1000); + DWORD wait_ms =3D (DWORD)((expire - now) * 1000); + DWORD status =3D WaitForSingleObject(win32_signal.in.read, wait_ms= ); if ((status =3D=3D WAIT_OBJECT_0 && win32_signal_get(&win32_signal= )) || status =3D=3D WAIT_TIMEOUT) { return; @@ -1539,7 +1535,7 @@ { if (expire > now) { - Sleep((expire - now) * 1000); + Sleep((DWORD)((expire - now) * 1000)); } return; } @@ -1602,7 +1598,7 @@ } 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 @@ } 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 @@ return ret; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - #endif /* ifdef _WIN32 */ diff --git a/src/openvpn/win32.h b/src/openvpn/win32.h index ff3145a..07a58d8 100644 --- a/src/openvpn/win32.h +++ b/src/openvpn/win32.h @@ -301,12 +301,14 @@ */ 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_mes= sage_t *ack, +bool send_msg_iservice(HANDLE pipe, const void *data, DWORD size, ack_mess= age_t *ack, const char *context); /* @@ -350,7 +352,7 @@ * - len number of bytes to encrypt -- must be a multiple of * CRYPTPROTECTMEMORY_BLOCK_SIZE =3D 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 CryptUnProtectMem= ory() @@ -360,7 +362,7 @@ * - len number of bytes to encrypt -- must be a multiple of * CRYPTPROTECTMEMORY_BLOCK_SIZE =3D 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 */ diff --git a/tests/unit_tests/openvpn/test_user_pass.c b/tests/unit_tests/o= penvpn/test_user_pass.c index f5dddd6..abe223c 100644 --- a/tests/unit_tests/openvpn/test_user_pass.c +++ b/tests/unit_tests/openvpn/test_user_pass.c @@ -79,17 +79,19 @@ 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 -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1269?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: merged Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ia836e3c05a868a7e8419c2bb2f547d968260783c Gerrit-Change-Number: 1269 Gerrit-PatchSet: 2 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --Y9d1aS/3UHg= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

win32: Change some APIs to use DWORD instead of =
size_t

This is what the Win32 APIs use. Since we put static
integ= ers into this (e.g. sizeof()) this doesn't
result in new conversion = warnings at the caller sites.

Change-Id: Ia836e3c05a868a7e8419c2bb2f= 547d968260783c
Signed-off-by: Frank Lichtenheld <frank@...2641...>=
Acked-by: Gert Doering <gert@...1296...>
Gerrit URL: https://g= errit.openvpn.net/c/openvpn/+/1269
Message-Id: <20251013162221.2156-1= -gert@...1296...>
URL: https://sourceforge.net/p/openvpn/mailman/mess= age/59246222/
Signed-off-by: Gert Doering <gert@...1296...>
---=
M src/openvpn/route.c
M src/openvpn/win32.c
M src/openvpn/win32.h=
M tests/unit_tests/openvpn/test_user_pass.c
4 files changed, 20 inse= rtions(+), 24 deletions(-)

diff --git a/src/openvpn/route.c b/src/openvpn/route.c
i= ndex ae9aaac..7d988da 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -2840,7 +2840,7 @@=

/* 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 boo= l add, const route_message_t *rt, const DWORD size, HANDLE pipe)
= {
int ret =3D RTA_ERROR;
a= ck_message_t ack;
diff --git a/src/openvpn/win32.c b/src/op= envpn/win32.c
index eac2352..3c11ec3 100644
--- a/src/openvpn/win32.c

+++ b/src/openvpn/win32.c=
@@ -1418,13 +1418,8 @@
return (const char *)= out.data;
}

-#if defined(__GNUC__) || defined(__clang__)=
-#pragma GCC diagnostic push<= /span>
-#pragma GCC diagnostic= ignored "-Wconversion"
-#endif
-
bool
-se= nd_msg_iservice(HANDLE pipe, const void *data, size_t size, ack_message_t *= ack,
+send_msg_iservi= ce(HANDLE pipe, const void *data, DWORD size, ack_message_t *ack, const char *context)
{ struct gc_arena gc =3D gc_new();
@@ -1527,7 +15= 22,8 @@

while (expire >=3D now)
{
-= DWORD status =3D WaitForSingleObject(win32_signal.in.read, (expire = - now) * 1000);
+ = DWORD wait_ms =3D (DWORD)((expire - now) * 1000);
+ DWORD status =3D WaitForSingleObj= ect(win32_signal.in.read, wait_ms);
if ((status = =3D=3D WAIT_OBJECT_0 && win32_signal_get(&win32_signal)) || sta= tus =3D=3D WAIT_TIMEOUT)
{
= return;
@@ -1539,7 +1535,7 @@
= {
if (expire > now)
= {
- = Sleep((expire - now) * 1000);
+ Sleep((DWORD)((expire - now) * 1000));=
}
return;
}

@@ -1602,7 +1598,7 @@
}

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 @@
}

bool
= -unprotect_buffer_win32(char *buf= , size_t len)
+unprot= ect_buffer_win32(char *buf, DWORD len)
{
= bool ret;
if (len % CRYPTPROTECTMEMORY_BLOCK_SIZE)=
@@ -1637,8 +1633,4 @@
return ret;

}

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
#endif /* ifdef _WIN32 */<= br>diff --git a/src/openvpn/win32.h b/src/openvpn/win32.h
<= span>index ff3145a..07a58d8 100644
--- a/src/openvpn/win32.= h
+++ b/src/openvpn/win32.h
@@ -301,12 +301= ,14 @@
*/
const char *win32_version_stri= ng(struct gc_arena *gc);

-/*
- * Send the |size| bytes in buffer |data| to the interactive service |pip= e|
- * and read the res= ult in |ack|. Returns false on communication error.
- * The string in |context| is used to prefi= x error messages.
+/*= *
+ * Send the \p siz= e bytes in buffer \p data to the interactive service \p pipe
+ * and read the result in \p ack.<= /span>
+ * 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,
<= span> const char *context);

=
/*
@@ -350,7 +352,7 @@
* - len= number of bytes to encrypt -- must be a multiple of
* = CRYPTPROTECTMEMORY_BLOCK_SIZE =3D 16
*/-bool protect_buffer_win32(char = *buf, size_t len);
+b= ool protect_buffer_win32(char *buf, DWORD len);
/**
* Decrypt a previously encrypted region of me= mory using CryptUnProtectMemory()
@@ -360,7 +362,7 @@
* - len number of bytes to encrypt -- must be a multiple of<= /span>
* CRYPTPROTECTMEMORY_BLOCK_SIZE =3D 16
= */
-bool unprot= ect_buffer_win32(char *buf, size_t len);
+bool unprotect_buffer_win32(char *buf, DWORD len);


#endif /* ifndef OPENVPN_WIN32_H */<= br> #endif /* ifdef _WIN32 */
diff --git a/tests/unit= _tests/openvpn/test_user_pass.c b/tests/unit_tests/openvpn/test_user_pass.c=
index f5dddd6..abe223c 100644
--- a/tests/= unit_tests/openvpn/test_user_pass.c
+++ b/tests/unit_tests/= openvpn/test_user_pass.c
@@ -79,17 +79,19 @@
return 0;
}

+#ifdef _WIN32
bool
-protect_buffer_win32(char *= buf, size_t len)
+pro= tect_buffer_win32(char *buf, DWORD len)
{
= return true;
}

boo= l
-unprotect_buffer_win= 32(char *buf, size_t len)
+unprotect_buffer_win32(char *buf, DWORD len)
{
return true;
}
+#endif

/* to= oling */
static void

T= o view, visit change 1269. To unsubscribe, or for help writing mail filters, vi= sit settings= .

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia836e3c05a868a7e8419c2bb2f5= 47d968260783c
Gerrit-Change-Number: 1269
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --Y9d1aS/3UHg=--