[Openvpn-devel,4/4] Use correct types for OpenSSL and Windows APIs

Message ID 20210324222330.455-4-arne@rfc2549.org
State Accepted
Headers show
Series [Openvpn-devel,1/4] Make buffer related function conversion explicit when narrowing | expand

Commit Message

Arne Schwabe March 24, 2021, 11:23 a.m. UTC
The error code of OpenSSL is a long. On most Unics systems
(mac, Linux...) this happens to be the same as size_t. But on Windows
as LP64, long is a 32 bit type and size_t is a 64 bit type. So use the
same type as OpenSSL.

When calling the Windows API use DWORD for the functions that want a
DWORD.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
---
 src/openvpn/crypto_openssl.c | 2 +-
 src/openvpn/cryptoapi.c      | 2 +-
 src/openvpn/route.c          | 9 +++------
 3 files changed, 5 insertions(+), 8 deletions(-)

Comments

Gert Doering March 25, 2021, 12:43 a.m. UTC | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

"Because it makes sense".  The DWORD changes for the loop variables
confused me a bit, because these are not "passed to a windows API" - but 
they are *compared* to "i < rt->dwNumEntries", and since *that* is a
DWORD, I can see why it might warn.

Again, compile tested on MinGW, lightly client side tested on Linux
and FreeBSD.

Your patch has been applied to the master branch.

commit 467b16dc65df711c0f1b3a8640b1fadc09c56803
Author: Arne Schwabe
Date:   Wed Mar 24 23:23:30 2021 +0100

     Use correct types for OpenSSL and Windows APIs

     Signed-off-by: Arne Schwabe <arne@rfc2549.org>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20210324222330.455-4-arne@rfc2549.org>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg21803.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c
index 4486d246..573beaed 100644
--- a/src/openvpn/crypto_openssl.c
+++ b/src/openvpn/crypto_openssl.c
@@ -199,7 +199,7 @@  crypto_clear_error(void)
 void
 crypto_print_openssl_errors(const unsigned int flags)
 {
-    size_t err = 0;
+    unsigned long err = 0;
 
     while ((err = ERR_get_error()))
     {
diff --git a/src/openvpn/cryptoapi.c b/src/openvpn/cryptoapi.c
index a992441b..ded8c914 100644
--- a/src/openvpn/cryptoapi.c
+++ b/src/openvpn/cryptoapi.c
@@ -997,7 +997,7 @@  pkey_rsa_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
     }
 
     msg(D_LOW, "cryptoapicert: calling priv_enc_CNG with alg = %ls", alg);
-    *siglen = priv_enc_CNG(cd, alg, tbs, (int)tbslen, sig, *siglen,
+    *siglen = priv_enc_CNG(cd, alg, tbs, (int)tbslen, sig, (int)*siglen,
                            cng_padding_type(padding), (DWORD)saltlen);
 
     return (*siglen == 0) ? 0 : 1;
diff --git a/src/openvpn/route.c b/src/openvpn/route.c
index 5e1dca67..c6b3dc58 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -2701,12 +2701,11 @@  get_default_gateway_row(const MIB_IPFORWARDTABLE *routes)
     struct gc_arena gc = gc_new();
     DWORD lowest_metric = MAXDWORD;
     const MIB_IPFORWARDROW *ret = NULL;
-    int i;
     int best = -1;
 
     if (routes)
     {
-        for (i = 0; i < routes->dwNumEntries; ++i)
+        for (DWORD i = 0; i < routes->dwNumEntries; ++i)
         {
             const MIB_IPFORWARDROW *row = &routes->table[i];
             const in_addr_t net = ntohl(row->dwForwardDest);
@@ -3167,14 +3166,13 @@  void
 show_routes(int msglev)
 {
     struct gc_arena gc = gc_new();
-    int i;
 
     const MIB_IPFORWARDTABLE *rt = get_windows_routing_table(&gc);
 
     msg(msglev, "SYSTEM ROUTING TABLE");
     if (rt)
     {
-        for (i = 0; i < rt->dwNumEntries; ++i)
+        for (DWORD i = 0; i < rt->dwNumEntries; ++i)
         {
             msg(msglev, "%s", format_route_entry(&rt->table[i], &gc));
         }
@@ -4023,8 +4021,7 @@  test_local_addr(const in_addr_t addr, const struct route_gateway_info *rgi)
     const MIB_IPFORWARDTABLE *rt = get_windows_routing_table(&gc);
     if (rt)
     {
-        int i;
-        for (i = 0; i < rt->dwNumEntries; ++i)
+        for (DWORD i = 0; i < rt->dwNumEntries; ++i)
         {
             const MIB_IPFORWARDROW *row = &rt->table[i];
             const in_addr_t net = ntohl(row->dwForwardDest);