Skip to contentSkip to conversation

Use proper print format/casting when converting msg_channel handle

PATCH In review Arne Schwabe 3 participants 3 messages Feb 14, 2023 – Mar 1, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use proper print format/casting when converting msg_channel handle

The current casting triggers a warning on 32bit:

init.c:1842:66: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]

Use the proper printf format specifier for printing a pointer avoiding the cast alltogether.

In options.c use a cast to intptr_t before converting to a handle to avoid having to ifdef atoll/atol for 32/64 bit.

---
 src/openvpn/init.c    | 3 ++-
 src/openvpn/options.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
src/openvpn/init.c +2 -1
index 0ad2c7e09..0d50d9189 100644
@@ -1839,7 +1839,8 @@ do_open_tun(struct context *c, int *error_flags)
 #ifdef _WIN32
         /* store (hide) interactive service handle in tuntap_options */
         c->c1.tuntap->options.msg_channel = c->options.msg_channel;
-        msg(D_ROUTE, "interactive service msg_channel=%" PRIu64, (unsigned long long) c->options.msg_channel);
+        msg(D_ROUTE, "interactive service msg_channel=%" PRIuPTR,
+            (intptr_t) c->options.msg_channel);
 #endif
 
         /* allocate route list structure */
src/openvpn/options.c +1 -1
index c1ddb0262..679528187 100644
@@ -7882,7 +7882,7 @@ add_option(struct options *options,
 #ifdef _WIN32
         VERIFY_PERMISSION(OPT_P_GENERAL);
         HANDLE process = GetCurrentProcess();
-        HANDLE handle = (HANDLE) atoll(p[1]);
+        HANDLE handle = (HANDLE) ((intptr_t) atoll(p[1]));
         if (!DuplicateHandle(process, handle, process, &options->msg_channel, 0,
                              FALSE, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS))
         {
Signature · 1 line
2.37.1 (Apple Git-137.1)
Acked-by on v1 1/1
#1 lore raw

Hi,

Sadly MSVC doesn't show those warnings even on L4.

Change looks good. I couldn't (yet) test on x86 since I (hopefully not for long) lost access to the x86 machine, but arm64 works just fine.

ti 14. helmik. 2023 klo 15.44 Arne Schwabe ([email protected]...) kirjoitti:

Quoted 53 lines

The current casting triggers a warning on 32bit:

init.c:1842:66: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]

Use the proper printf format specifier for printing a pointer avoiding the cast alltogether.

In options.c use a cast to intptr_t before converting to a handle to avoid having to ifdef atoll/atol for 32/64 bit.

---
 src/openvpn/init.c    | 3 ++-
 src/openvpn/options.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
src/openvpn/init.c +2 -1
index 0ad2c7e09..0d50d9189 100644
@@ -1839,7 +1839,8 @@ do_open_tun(struct context *c, int *error_flags)
 #ifdef _WIN32
         /* store (hide) interactive service handle in tuntap_options */
         c->c1.tuntap->options.msg_channel = c->options.msg_channel;
-        msg(D_ROUTE, "interactive service msg_channel=%" PRIu64, (unsigned long long) c->options.msg_channel);
+        msg(D_ROUTE, "interactive service msg_channel=%" PRIuPTR,
+            (intptr_t) c->options.msg_channel);
 #endif
 
         /* allocate route list structure */
src/openvpn/options.c +1 -2
index c1ddb0262..679528187 100644
@@ -7882,7 +7882,7 @@ add_option(struct options *options,
 #ifdef _WIN32
         VERIFY_PERMISSION(OPT_P_GENERAL);
         HANDLE process = GetCurrentProcess();
-        HANDLE handle = (HANDLE) atoll(p[1]);
+        HANDLE handle = (HANDLE) ((intptr_t) atoll(p[1]));
         if (!DuplicateHandle(process, handle, process, &options->msg_channel, 0,
                              FALSE, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS))
         {
--

2.37.1 (Apple Git-137.1)

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
-Lev
#2 lore raw
In reply to Arne Schwabe

I have not tested this beyond "compile on mingw", which didn't warn before the patch either. But it looks innocent enough, and if Lev confirms it actually works, good enough.

Your patch has been applied to the master and release/2.6 branch.

commit 9c52e0c610ef1229561c2d038ca41fe2cbefe8da (master) commit 27dac5061cfeff75470dca11e07dadb1fb0ad180 (release/2.6)

Author: Arne Schwabe
Date:   Tue Feb 14 14:43:23 2023 +0100
     Use proper print format/casting when converting msg_channel handle

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Lev Stipakov <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26255.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering