From patchwork Thu Oct 16 10:17:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4509 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:750e:b0:72f:89c5:165f with SMTP id r14csp6441325mai; Thu, 16 Oct 2025 03:17:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUVThQHe5RP7Zfi0Rk8+kS/f6vftjR2yadhwK+YC03369n1y0M38BHXY2sa5v4coi2W6HaUHO+lKlE=@openvpn.net X-Google-Smtp-Source: AGHT+IGB9fwwd3eTDL8EdaREglRfkcbhxudwEGrpW4+YpBJinVl3iQ5pWecu2HAPgMmQ+uQcblzg X-Received: by 2002:a05:6808:13c2:b0:441:8f74:e73 with SMTP id 5614622812f47-441fb9bbbbcmr1727534b6e.27.1760609866300; Thu, 16 Oct 2025 03:17:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1760609866; cv=none; d=google.com; s=arc-20240605; b=OFb5MQDTVVi1HMvunSyi485wuzRYIgNpIc8r4/nZnXqZ3j279yaY48Koukc3o58gyr wegaqNncVNlMgVOTj4B/p0eZD2OOGB3DzFMi5kTWqZ3TRbtmho7H0oTChu+qnGQmVmpJ wC6MIgqth5ULuihXhcxRq0YVv4Aun+zgZN4+rdpxwbn6u5S0KBoaEwTE3Ivc6xhBFbfc LgbiGRcOVt6mdwh6+OJiU7Om5t5rb26t/xL4XztgTmwW617ysrcrX25uzhhfDwP/OBun 2vVwhzJIY6RR8tK295vdBhyNFfWX9mWLK27MqYytL1PXNmpFm6BQwcQe/d1KYuFkkeb7 SX0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=evoJMwYYv24fw2Aks5lUXfyP99VHoByl700JK898oGo=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=eE3h/NdfpHBne3l7lkljMztWyUF8qiQX/tmtJArFC2Zcw3zTFKiLsnqd7SK1I2s+mv dig1vKluNDqS3lHiuIUhAuSo9epxqQ+3IITEQMsqz+neCl+cpBArpFljLR3soRfgIXW1 xfXKhBxb+UaOu0+PWWI+vITaCtM6jcMcLheWnaAKA6W/uQW5lQJsebn6tYfhURXJsd56 2kYXmUv+mJn2LWyUVDGNbpd38KPxGS/yN1L/QlMBxlQ0pmKHZfAfrUIJK1WEetU5TRvq 3r5Q3qHC76S0mfnoPduk15XGsavvbcMqWr1Ql9azK/SbzWvZo/9QsuhmTGQjXpLfA6yc EH5g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=O+BQcH3E; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=d2ZNHfer; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="Z3t/BLWb"; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 586e51a60fabf-3c8c8fa947esi5392021fac.144.2025.10.16.03.17.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Oct 2025 03:17:46 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=O+BQcH3E; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=d2ZNHfer; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="Z3t/BLWb"; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=evoJMwYYv24fw2Aks5lUXfyP99VHoByl700JK898oGo=; b=O+BQcH3ErcayffBoXp/dUfckHy KgS+n3rv46b93Kd2nI3gU5Zmcp5sbRwhPYkA9bbPysxWkI8u7t/m+Rq57jAPa2bfOohpvIml0noBA ojwJgUcPCH5sqE+ydqBS1xUZlowyli27A+ZjKi7Gau66IQcEOCoOs6OIwQG4VEYpT4ew=; Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1v9L3A-0004iK-IV; Thu, 16 Oct 2025 10:17:36 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1v9L39-0004iD-Po for openvpn-devel@lists.sourceforge.net; Thu, 16 Oct 2025 10:17:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=E1XNBPAKD5+bzdScaKIIgR85w6uRccLfasrgPTXsTJ8=; b=d2ZNHferYeaiyo5rDcVDpNH7W4 ac+LORCr1aVbb/5aSRtdp1IG5o7cyeOd+Ki9pCz6voxd4bdSrrv6tydmg2risaA78CAXzOP0+meXo u3kMb38IGRnZe/wte5+kxqIVHMI6cB1bWPFhJOc1vbejiQfwe+RSLp7ZwyAGQWojSKus=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=E1XNBPAKD5+bzdScaKIIgR85w6uRccLfasrgPTXsTJ8=; b=Z3t/BLWb5IX6R3rymFMgo1c8kM N/S+ryDgmBU4BGFMEshlhFw4JL9S09MN4O9lkjLiIKbU7ZuRz3nLG3TrtjgSWCf1fEEiy6e/kc68l YCMCaruLLXtctZ6mSHdhQbD6VnP4uuulpJZG229Dok29L0/zXtu4ntkmso9WDL9r2cCk=; Received: from [193.149.48.134] (helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1v9L38-0006J4-MW for openvpn-devel@lists.sourceforge.net; Thu, 16 Oct 2025 10:17:35 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 59GAHMdL003002 for ; Thu, 16 Oct 2025 12:17:22 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 59GAHM2a003001 for openvpn-devel@lists.sourceforge.net; Thu, 16 Oct 2025 12:17:22 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Thu, 16 Oct 2025 12:17:16 +0200 Message-ID: <20251016101722.2979-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.49.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Frank Lichtenheld 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/open [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1v9L38-0006J4-MW Subject: [Openvpn-devel] [PATCH v2] socket: Wrap winsock functions to avoid common conversion warnings X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1846133251551800806?= X-GMAIL-MSGID: =?utf-8?q?1846133251551800806?= From: Frank Lichtenheld 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 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1277 This mail reflects revision 2 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering 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 = timeout_sec; tv.tv_usec = 0; - status = select(sd + 1, &reads, NULL, NULL, &tv); + status = 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 = send(sd, buf, strlen(buf), MSG_NOSIGNAL); + const ssize_t size = openvpn_send(sd, buf, strlen(buf), MSG_NOSIGNAL); if (size != (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 = strlen(opaque) + 16; + const size_t len = strlen(opaque) + 16; opaque_kv = gc_malloc(len, false, &gc); snprintf(opaque_kv, len, ", opaque=\"%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 *act, const char *remote_dynamic, const struct addrinfo *local, bool do_listen, @@ -873,7 +877,7 @@ tv.tv_sec = 0; tv.tv_usec = 0; - status = select(sd + 1, &reads, NULL, NULL, &tv); + status = 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=%d failed", v6only); } } - 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 = (connect_timeout > 0) ? 1 : 0; tv.tv_usec = 0; - status = select(sd + 1, NULL, &writes, NULL, &tv); + status = 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 <= 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 <= 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 = get_server_poll_remaining_time(server_poll_timeout); tv.tv_usec = 0; - /* NB: first argument ignored on Windows where socket_descriptor_t != int */ - const int status = select((int)sd + 1, &reads, NULL, NULL, &tv); + const int status = 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 >= 0 && sret <= sizeof(to_send)); - /* NB: int because Windows APIs */ - ssize_t size = send(sd, to_send, (int)strlen(to_send), MSG_NOSIGNAL); + ssize_t size = openvpn_send(sd, to_send, strlen(to_send), MSG_NOSIGNAL); - if (size != strlen(to_send)) + if (size != (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] = 0x02; /* METHODS = [2 (plain login)] */ } - size = send(sd, method_sel, sizeof(method_sel), MSG_NOSIGNAL); + size = openvpn_send(sd, method_sel, sizeof(method_sel), MSG_NOSIGNAL); if (size != sizeof(method_sel)) { msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port write failed on send()"); @@ -415,10 +413,9 @@ buf[5 + len + 1] = (char)(port & 0xff); { - /* int because Windows APIs */ - int send_len = 5 + (int)len + 2; - const ssize_t size = send(sd, buf, send_len, MSG_NOSIGNAL); - if (size != send_len) + size_t send_len = 5 + len + 2; + const ssize_t size = openvpn_send(sd, buf, send_len, MSG_NOSIGNAL); + if (size != (ssize_t)send_len) { msg(D_LINK_ERRORS | M_ERRNO, "establish_socks_proxy_passthru: TCP port write failed on send()");