From: "cron2 (Code Review)" Date: Thu, 16 Oct 2025 11:13:09 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="r7wtJ7fURVg="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: socket: Wrap winsock functions to avoid common conversion warnings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos Cc: openvpn-devel --r7wtJ7fURVg= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#3) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1277?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: socket: Wrap winsock functions to avoid common conversion w= arnings ...................................................................... socket: Wrap winsock functions to avoid common conversion warnings Before I had done those at the call site but we have several very similar issues with multiple occurrences. So handle them together. Change-Id: If91d14f31368a93182bcf23b1d82b06ea94381d8 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1277 Message-Id: <20251016101722.2979-1-gert@...1296...> URL: https://sourceforge.net/p/openvpn/mailman/message/59247452/ Signed-off-by: Gert Doering --- M src/openvpn/proxy.c M src/openvpn/socket.c M src/openvpn/socket.h M src/openvpn/socks.c 4 files changed, 51 insertions(+), 25 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/77/1277/3 diff --git a/src/openvpn/proxy.c b/src/openvpn/proxy.c index 02554ba..dfe1e59 100644 --- a/src/openvpn/proxy.c +++ b/src/openvpn/proxy.c @@ -54,11 +54,6 @@ } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - /* cached proxy username/password */ static struct user_pass static_proxy_user_pass; @@ -93,7 +88,7 @@ tv.tv_sec =3D timeout_sec; tv.tv_usec =3D 0; - status =3D select(sd + 1, &reads, NULL, NULL, &tv); + status =3D openvpn_select(sd + 1, &reads, NULL, NULL, &tv); get_signal(signal_received); if (*signal_received) @@ -192,7 +187,7 @@ static bool send_line(socket_descriptor_t sd, const char *buf) { - const ssize_t size =3D send(sd, buf, strlen(buf), MSG_NOSIGNAL); + const ssize_t size =3D openvpn_send(sd, buf, strlen(buf), MSG_NOSIGNAL= ); if (size !=3D (ssize_t)strlen(buf)) { msg(D_LINK_ERRORS | M_ERRNO, "send_line: TCP port write failed on = send()"); @@ -903,7 +898,7 @@ if (opaque) { - const int len =3D strlen(opaque) + 16; + const size_t len =3D strlen(opaque) + 16; opaque_kv =3D gc_malloc(len, false, &gc); snprintf(opaque_kv, len, ", opaque=3D\"%s\"", opaque); } @@ -1068,7 +1063,3 @@ gc_free(&gc); return ret; } - -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index f71d891..40a86fb 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -849,6 +849,10 @@ gc_free(&gc); } +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic pop +#endif + static socket_descriptor_t socket_listen_accept(socket_descriptor_t sd, struct link_socket_actual *ac= t, const char *remote_dynamic, const struct addrinfo *lo= cal, bool do_listen, @@ -873,7 +877,7 @@ tv.tv_sec =3D 0; tv.tv_usec =3D 0; - status =3D select(sd + 1, &reads, NULL, NULL, &tv); + status =3D openvpn_select(sd + 1, &reads, NULL, NULL, &tv); get_signal(signal_received); if (*signal_received) @@ -979,7 +983,7 @@ msg(M_NONFATAL | M_ERRNO, "Setting IPV6_V6ONLY=3D%d failed", v= 6only); } } - if (bind(sd, cur->ai_addr, cur->ai_addrlen)) + if (openvpn_bind(sd, cur->ai_addr, cur->ai_addrlen)) { msg(M_FATAL | M_ERRNO, "%s: Socket bind failed on local address %s= ", prefix, print_sockaddr_ex(local->ai_addr, ":", PS_SHOW_PORT, &gc)); @@ -1026,7 +1030,7 @@ tv.tv_sec =3D (connect_timeout > 0) ? 1 : 0; tv.tv_usec =3D 0; - status =3D select(sd + 1, NULL, &writes, NULL, &tv); + status =3D openvpn_select(sd + 1, NULL, &writes, NULL, &tv); #endif if (signal_received) { @@ -1183,6 +1187,11 @@ } } +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + static void resolve_bind_local(struct link_socket *sock, const sa_family_t af) { diff --git a/src/openvpn/socket.h b/src/openvpn/socket.h index 2c79a11..e986c9c 100644 --- a/src/openvpn/socket.h +++ b/src/openvpn/socket.h @@ -291,9 +291,38 @@ sh.is_handle ? SetLastError(ERROR_INVALID_FUNCTION) : WSASetLastError(= WSAEINVAL); } +/* winsock(2).h uses slightly different types so to avoid conversion + errors we wrap these functions on Windows */ + +static inline int +openvpn_select(socket_descriptor_t nfds, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds, struct timeval *timeout) +{ + (void)nfds; /* first argument ignored on Windows */ + return select(0, readfds, writefds, exceptfds, timeout); +} + +static inline ssize_t +openvpn_send(socket_descriptor_t sockfd, const void *buf, size_t len, int = flags) +{ + ASSERT(len <=3D INT_MAX); + return send(sockfd, buf, (int)len, flags); +} + +static inline int +openvpn_bind(socket_descriptor_t sockfd, const struct sockaddr *addr, size= _t addrlen) +{ + ASSERT(addrlen <=3D INT_MAX); + return bind(sockfd, addr, (int)addrlen); +} + #else /* ifdef _WIN32 */ #define openvpn_close_socket(s) close(s) +#define openvpn_select(nfds, readfds, writefds, exceptfds, timeout) \ + select(nfds, readfds, writefds, exceptfds, timeout) +#define openvpn_send(sockfd, buf, len, flags) send(sockfd, buf, len, flags) +#define openvpn_bind(sockfd, addr, addrlen) bind(sockfd, addr, addrlen) #endif /* ifdef _WIN32 */ diff --git a/src/openvpn/socks.c b/src/openvpn/socks.c index 6467baf..d383ef7 100644 --- a/src/openvpn/socks.c +++ b/src/openvpn/socks.c @@ -93,8 +93,7 @@ tv.tv_sec =3D get_server_poll_remaining_time(server_poll_timeout); tv.tv_usec =3D 0; - /* NB: first argument ignored on Windows where socket_descriptor_t != =3D int */ - const int status =3D select((int)sd + 1, &reads, NULL, NULL, &tv); + const int status =3D openvpn_select(sd + 1, &reads, NULL, NULL, &tv); get_signal(signal_received); if (*signal_received) @@ -156,10 +155,9 @@ creds.username, (int)strlen(creds.password), creds= .password); ASSERT(sret >=3D 0 && sret <=3D sizeof(to_send)); - /* NB: int because Windows APIs */ - ssize_t size =3D send(sd, to_send, (int)strlen(to_send), MSG_NOSIGNAL); + ssize_t size =3D openvpn_send(sd, to_send, strlen(to_send), MSG_NOSIGN= AL); - if (size !=3D strlen(to_send)) + if (size !=3D (ssize_t)strlen(to_send)) { msg(D_LINK_ERRORS | M_ERRNO, "socks_username_password_auth: TCP port write failed on send()= "); @@ -208,7 +206,7 @@ { method_sel[2] =3D 0x02; /* METHODS =3D [2 (plain login)] */ } - size =3D send(sd, method_sel, sizeof(method_sel), MSG_NOSIGNAL); + size =3D openvpn_send(sd, method_sel, sizeof(method_sel), MSG_NOSIGNAL= ); if (size !=3D sizeof(method_sel)) { msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port write fail= ed on send()"); @@ -415,10 +413,9 @@ buf[5 + len + 1] =3D (char)(port & 0xff); { - /* int because Windows APIs */ - int send_len =3D 5 + (int)len + 2; - const ssize_t size =3D send(sd, buf, send_len, MSG_NOSIGNAL); - if (size !=3D send_len) + size_t send_len =3D 5 + len + 2; + const ssize_t size =3D openvpn_send(sd, buf, send_len, MSG_NOSIGNA= L); + if (size !=3D (ssize_t)send_len) { msg(D_LINK_ERRORS | M_ERRNO, "establish_socks_proxy_passthru: TCP port write failed on = send()"); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1277?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: If91d14f31368a93182bcf23b1d82b06ea94381d8 Gerrit-Change-Number: 1277 Gerrit-PatchSet: 3 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --r7wtJ7fURVg= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #3 to the change originally created by flichtenhel= d.

View Change

The following approvals got outdated and were remove= d: Code-Review+2 by cron2

socket: Wrap winsock functions to a=
void common conversion warnings

Before I had done those at the call = site but we have
several very similar issues with multiple occurrences.<= br>So handle them together.

Change-Id: If91d14f31368a93182bcf23b1d82= b06ea94381d8
Signed-off-by: Frank Lichtenheld <frank@...2641...>Acked-by: Gert Doering <gert@...1296...>
Gerrit URL: https://ger= rit.openvpn.net/c/openvpn/+/1277
Message-Id: <20251016101722.2979-1-g= ert@...1296...>
URL: https://sourceforge.net/p/openvpn/mailman/messag= e/59247452/
Signed-off-by: Gert Doering <gert@...1296...>
---M src/openvpn/proxy.c
M src/openvpn/socket.c
M src/openvpn/socket.h=
M src/openvpn/socks.c
4 files changed, 51 insertions(+), 25 deletion= s(-)

git pull ssh://gerrit.openvpn.net:29418/ope=
nvpn refs/changes/77/1277/3
diff --git a/src/openvpn/proxy.c b/src/=
openvpn/proxy.c
index 02554ba..dfe1e59 100644
--- a/src/openvpn/proxy.c
+++ b/src/openvpn/proxy.c
@@ -54,11 +54,6 @@
}
<= br>
-#if defined= (__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
/* cached proxy usern= ame/password */
static struct user_pass static_proxy_user_= pass;

@@ -93,7 +88,7 @@
= tv.tv_sec =3D timeout_sec;
tv.tv_usec =3D = 0;

- = status =3D select(sd + 1, &reads, NULL, NULL, &tv);+ status =3D openvpn_s= elect(sd + 1, &reads, NULL, NULL, &tv);
get_signal(signal_received);
if (*= signal_received)
@@ -192,7 +187,7 @@
stati= c bool
send_line(socket_descriptor_t sd, const char *buf)<= /span>
{
- = const ssize_t size =3D send(sd, buf, strlen(buf), MSG_NOSIGNAL);+ const ssize_t size =3D op= envpn_send(sd, buf, strlen(buf), MSG_NOSIGNAL);
if (si= ze !=3D (ssize_t)strlen(buf))
{
= msg(D_LINK_ERRORS | M_ERRNO, "send_line: TCP port write failed on s= end()");
@@ -903,7 +898,7 @@
<= br> if (opaque)
{
- cons= t int len =3D strlen(opaque) + 16;
+ const size_t len =3D strlen(opaque) + 16= ;
opaque_kv =3D gc_malloc(len, false, = &gc);
snprintf(opaque_kv, len, &qu= ot;, opaque=3D\"%s\"", opaque);
= }
@@ -1068,7 +1063,3 @@
gc_free(&= amp;gc);
return ret;
}
-

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
diff --= git a/src/openvpn/socket.c b/src/openvpn/socket.c
index f71= d891..40a86fb 100644
--- a/src/openvpn/socket.c
<= span>+++ b/src/openvpn/socket.c

@@ -849,6 +849,10 @@=
gc_free(&gc);
}

+#if defined(__GNUC__) || = defined(__clang__)
+#= pragma GCC diagnostic pop
+#endif
+=
static socket_descriptor_t
socket_listen_accept= (socket_descriptor_t sd, struct link_socket_actual *act,
= const char *remote_dynamic, const struct addrinfo *loca= l, bool do_listen,
@@ -873,7 +877,7 @@
= tv.tv_sec =3D 0;
tv.tv_usec =3D 0;
=
- status= =3D select(sd + 1, &reads, NULL, NULL, &tv);
+ status =3D openvpn_select(sd + 1,= &reads, NULL, NULL, &tv);

= get_signal(signal_received);
if (*signal_receiv= ed)
@@ -979,7 +983,7 @@
msg(M_= NONFATAL | M_ERRNO, "Setting IPV6_V6ONLY=3D%d failed", v6only);
}
}
- if (bind(sd, cur->ai_addr, cur->ai_add= rlen))
+ if (openv= pn_bind(sd, cur->ai_addr, cur->ai_addrlen))
{
msg(M_FATAL | M_ERRNO, "%s: Socket bind failed = on local address %s", prefix,
print_socka= ddr_ex(local->ai_addr, ":", PS_SHOW_PORT, &gc));@@ -1026,7 +1030,7 @@
tv.tv_sec =3D (co= nnect_timeout > 0) ? 1 : 0;
tv.tv_usec =3D = 0;

- = status =3D select(sd + 1, NULL, &writes, NULL, &tv);

+ status =3D = openvpn_select(sd + 1, NULL, &writes, NULL, &tv);
= #endif
if (signal_received)
= {
@@ -1183,6 +1187,11 @@
}<= /span>
}

+#if defined(__GNUC__) || defined(__clang__)
+#pragma GCC diagnostic push
=
+#pragma GCC diagnostic ign= ored "-Wconversion"
+#endif
+
static void
resolve_bind_local(struct link_= socket *sock, const sa_family_t af)
{
diff= --git a/src/openvpn/socket.h b/src/openvpn/socket.h
index = 2c79a11..e986c9c 100644
--- a/src/openvpn/socket.h+++ b/src/openvpn/socket.h
@@ -291,9 +291,38 @@
sh.is_handle ? SetLastError(ERROR_INVALID_FUNCTION) : WSA= SetLastError(WSAEINVAL);
}

+/* winsock(2).h uses slightly dif= ferent types so to avoid conversion

+ errors we wrap these functions on Windows */
<= span style=3D"color: hsl(120, 100%, 40%);">+

+static inline int
+openvpn_select(socket_descriptor_t nfds, fd_set *rea= dfds, fd_set *writefds,
+ fd_set *exceptfds, struct timeval *timeout)
+{
+ (void)nfds; /* first argument ignored on Windo= ws */
+ return sel= ect(0, readfds, writefds, exceptfds, timeout);
+}
+
+static inl= ine ssize_t
+openvpn_= send(socket_descriptor_t sockfd, const void *buf, size_t len, int flags)

+{
+ ASSERT(len <=3D INT_MAX);<= br>+ return send(sockfd, buf= , (int)len, flags);
+= }
+
+static inline int
+openvpn_bind(socket_descriptor_t sockfd= , const struct sockaddr *addr, size_t addrlen)
+{
+ ASSERT(addrlen <=3D INT_MAX);
+ return bind(sockfd, addr, (int)addrlen);
+}
+
#else /* ifdef _WIN32 *= /

#define openvpn_close_socket(s) close(= s)
+#define openvpn_s= elect(nfds, readfds, writefds, exceptfds, timeout) \
+ select(nfds, readfds, writefds, excep= tfds, timeout)
+#defi= ne openvpn_send(sockfd, buf, len, flags) send(sockfd, buf, len, flags)
+#define openvpn_bind(soc= kfd, addr, addrlen) bind(sockfd, addr, addrlen)
<= br> #endif /* ifdef _WIN32 */

diff = --git a/src/openvpn/socks.c b/src/openvpn/socks.c
index 646= 7baf..d383ef7 100644
--- a/src/openvpn/socks.c
+++ b/src/openvpn/socks.c

@@ -93,8 +93,7 @@
<= span> tv.tv_sec =3D get_server_poll_remaining_time(server_poll_timeout)= ;

tv.tv_usec =3D 0;

- /* NB: first argument ignored on W= indows where socket_descriptor_t !=3D int */
- const int status =3D select((int)sd + 1, &re= ads, NULL, NULL, &tv);
+ const int status =3D openvpn_select(sd + 1, &reads, NULL, NU= LL, &tv);

get_signal(signal_rece= ived);
if (*signal_received)
@@ -156,1= 0 +155,9 @@
creds.username, (int)s= trlen(creds.password), creds.password);
ASSERT(sret &g= t;=3D 0 && sret <=3D sizeof(to_send));
<= br>- /* NB: int because Window= s APIs */
- ssize_t = size =3D send(sd, to_send, (int)strlen(to_send), MSG_NOSIGNAL);
<= span style=3D"color: hsl(120, 100%, 40%);">+ ssize_t size =3D openvpn_se= nd(sd, to_send, strlen(to_send), MSG_NOSIGNAL);
- if (size !=3D strlen(to_sen= d))
+ if (size != =3D (ssize_t)strlen(to_send))
{
= msg(D_LINK_ERRORS | M_ERRNO,
"socks_us= ername_password_auth: TCP port write failed on send()");
@@ -208,7 +206,7 @@
{
meth= od_sel[2] =3D 0x02; /* METHODS =3D [2 (plain login)] */
= }
- size =3D send(= sd, method_sel, sizeof(method_sel), MSG_NOSIGNAL);
+ size =3D openvpn_send(sd, method_sel, si= zeof(method_sel), MSG_NOSIGNAL);
if (size !=3D sizeof(= method_sel))
{
msg(D_LINK_ERR= ORS | M_ERRNO, "socks_handshake: TCP port write failed on send()"= );
@@ -415,10 +413,9 @@
buf[5 + len + = 1] =3D (char)(port & 0xff);

{
- /* int because W= indows APIs */
- = int send_len =3D 5 + (int)len + 2;
- const ssize_t size =3D send(sd, buf, send_len, MSG_NO= SIGNAL);
- if (s= ize !=3D send_len)
+ = size_t send_len =3D 5 + len + 2;
+ const ssize_t size =3D openvpn_send(sd, buf, se= nd_len, MSG_NOSIGNAL);
change 1277= . To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If91d14f31368a93182bcf23b1d8= 2b06ea94381d8
Gerrit-Change-Number: 1277
Gerrit-PatchSet: 3
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>
= --r7wtJ7fURVg=--