Skip to content

Commit c4f7b41

Browse files
flichtenheldcron2
authored andcommitted
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 <[email protected]> Acked-by: Gert Doering <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1269 Message-Id: <[email protected]> URL: https://sourceforge.net/p/openvpn/mailman/message/59246222/ Signed-off-by: Gert Doering <[email protected]>
1 parent f79221a commit c4f7b41

File tree

4 files changed

+20
-24
lines changed

4 files changed

+20
-24
lines changed

src/openvpn/route.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2840,7 +2840,7 @@ del_route_ipapi(const struct route_ipv4 *r, const struct tuntap *tt)
28402840

28412841
/* Returns RTA_SUCCESS on success, RTA_EEXIST if route exists, RTA_ERROR on error */
28422842
static int
2843-
do_route_service(const bool add, const route_message_t *rt, const size_t size, HANDLE pipe)
2843+
do_route_service(const bool add, const route_message_t *rt, const DWORD size, HANDLE pipe)
28442844
{
28452845
int ret = RTA_ERROR;
28462846
ack_message_t ack;

src/openvpn/win32.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,13 +1418,8 @@ win32_version_string(struct gc_arena *gc)
14181418
return (const char *)out.data;
14191419
}
14201420

1421-
#if defined(__GNUC__) || defined(__clang__)
1422-
#pragma GCC diagnostic push
1423-
#pragma GCC diagnostic ignored "-Wconversion"
1424-
#endif
1425-
14261421
bool
1427-
send_msg_iservice(HANDLE pipe, const void *data, size_t size, ack_message_t *ack,
1422+
send_msg_iservice(HANDLE pipe, const void *data, DWORD size, ack_message_t *ack,
14281423
const char *context)
14291424
{
14301425
struct gc_arena gc = gc_new();
@@ -1527,7 +1522,8 @@ win32_sleep(const int n)
15271522

15281523
while (expire >= now)
15291524
{
1530-
DWORD status = WaitForSingleObject(win32_signal.in.read, (expire - now) * 1000);
1525+
DWORD wait_ms = (DWORD)((expire - now) * 1000);
1526+
DWORD status = WaitForSingleObject(win32_signal.in.read, wait_ms);
15311527
if ((status == WAIT_OBJECT_0 && win32_signal_get(&win32_signal)) || status == WAIT_TIMEOUT)
15321528
{
15331529
return;
@@ -1539,7 +1535,7 @@ win32_sleep(const int n)
15391535
{
15401536
if (expire > now)
15411537
{
1542-
Sleep((expire - now) * 1000);
1538+
Sleep((DWORD)((expire - now) * 1000));
15431539
}
15441540
return;
15451541
}
@@ -1602,7 +1598,7 @@ plugin_in_trusted_dir(const WCHAR *plugin_path)
16021598
}
16031599

16041600
bool
1605-
protect_buffer_win32(char *buf, size_t len)
1601+
protect_buffer_win32(char *buf, DWORD len)
16061602
{
16071603
bool ret;
16081604
if (len % CRYPTPROTECTMEMORY_BLOCK_SIZE)
@@ -1620,7 +1616,7 @@ protect_buffer_win32(char *buf, size_t len)
16201616
}
16211617

16221618
bool
1623-
unprotect_buffer_win32(char *buf, size_t len)
1619+
unprotect_buffer_win32(char *buf, DWORD len)
16241620
{
16251621
bool ret;
16261622
if (len % CRYPTPROTECTMEMORY_BLOCK_SIZE)
@@ -1637,8 +1633,4 @@ unprotect_buffer_win32(char *buf, size_t len)
16371633
return ret;
16381634
}
16391635

1640-
#if defined(__GNUC__) || defined(__clang__)
1641-
#pragma GCC diagnostic pop
1642-
#endif
1643-
16441636
#endif /* ifdef _WIN32 */

src/openvpn/win32.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,14 @@ bool win_wfp_uninit(const NET_IFINDEX index, const HANDLE msg_channel);
301301
*/
302302
const char *win32_version_string(struct gc_arena *gc);
303303

304-
/*
305-
* Send the |size| bytes in buffer |data| to the interactive service |pipe|
306-
* and read the result in |ack|. Returns false on communication error.
307-
* The string in |context| is used to prefix error messages.
304+
/**
305+
* Send the \p size bytes in buffer \p data to the interactive service \p pipe
306+
* and read the result in \p ack.
307+
* The string in \p context is used to prefix error messages.
308+
*
309+
* @return true on success, false on communication error
308310
*/
309-
bool send_msg_iservice(HANDLE pipe, const void *data, size_t size, ack_message_t *ack,
311+
bool send_msg_iservice(HANDLE pipe, const void *data, DWORD size, ack_message_t *ack,
310312
const char *context);
311313

312314
/*
@@ -350,7 +352,7 @@ bool plugin_in_trusted_dir(const WCHAR *plugin_path);
350352
* - len number of bytes to encrypt -- must be a multiple of
351353
* CRYPTPROTECTMEMORY_BLOCK_SIZE = 16
352354
*/
353-
bool protect_buffer_win32(char *buf, size_t len);
355+
bool protect_buffer_win32(char *buf, DWORD len);
354356

355357
/**
356358
* Decrypt a previously encrypted region of memory using CryptUnProtectMemory()
@@ -360,7 +362,7 @@ bool protect_buffer_win32(char *buf, size_t len);
360362
* - len number of bytes to encrypt -- must be a multiple of
361363
* CRYPTPROTECTMEMORY_BLOCK_SIZE = 16
362364
*/
363-
bool unprotect_buffer_win32(char *buf, size_t len);
365+
bool unprotect_buffer_win32(char *buf, DWORD len);
364366

365367
#endif /* ifndef OPENVPN_WIN32_H */
366368
#endif /* ifdef _WIN32 */

tests/unit_tests/openvpn/test_user_pass.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,19 @@ parse_line(const char *line, char **p, const int n, const char *file, const int
7979
return 0;
8080
}
8181

82+
#ifdef _WIN32
8283
bool
83-
protect_buffer_win32(char *buf, size_t len)
84+
protect_buffer_win32(char *buf, DWORD len)
8485
{
8586
return true;
8687
}
8788

8889
bool
89-
unprotect_buffer_win32(char *buf, size_t len)
90+
unprotect_buffer_win32(char *buf, DWORD len)
9091
{
9192
return true;
9293
}
94+
#endif
9395

9496
/* tooling */
9597
static void

0 commit comments

Comments
 (0)