From patchwork Tue Sep 23 15:10:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4441 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:c08a:b0:72f:f16c:e055 with SMTP id jr10csp932819mab; Tue, 23 Sep 2025 08:11:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXzqxCRkuLTiJPRnFhm4rrn4SrlqtuCyCudW46zwnlVToqBNnnKu7pzjqVNiTwGktQuNG3L3p182QU=@openvpn.net X-Google-Smtp-Source: AGHT+IF25VouixjOxImsXO+J1gFyD0nF+sDOw97PPJKV457y2j4tVUzz+wcDk88unlsvd3Q6YRU7 X-Received: by 2002:a05:6820:1504:b0:61f:f932:8d68 with SMTP id 006d021491bc7-63303ebff96mr1388739eaf.1.1758640270221; Tue, 23 Sep 2025 08:11:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1758640270; cv=none; d=google.com; s=arc-20240605; b=F2s7UA8yQ7D5mCoL/yV8zabGQ7eXSt0to6mB0NN/WTj730+8v4tY46YLq4HYP9h7Ms GMz5NsxXuTikfe9VyNml7yBI2UQFZ3WsOTi67jghXkcZd73RrjM8KNysF67K6dFv669a J4m+4J73iUS4K997iYyZben+L+dJ+twMkJEWXkcHZDn7rno2FqXfnyN+lQ3ZFj/lOJXx YyMe8zVMEV1hLVhsISgfypH1wCpiXrcozVyeXiKFFspgBVMtUNnEpJ2RyuJQqJvyL2J2 bph6r90SSB5KoLobTdLDQxSttLV1u/nT9x7AFvQd4UCNm3IsVcuMd9VlYn1NZSVdtJQZ Dfsw== 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=P9QHWV7nNXGQvIBtaTNqetcyCn/p4Sa+eDk7kH+Dubs=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=lxZ+1adXvsGADGxQqfm6oSy2EB7KZre5jjiawbEj+IkNxtiG7D17wKzEf1qXc1VQlh MLDDhXly9v5FnL6bEDzRG3QRmjHHVMJSZ0gOxRDenJniLo1VbNexk0seWBHPrJl261nx JNhmAN9jFhnXtkA3xCyf9X93tk0XaA9WlrCPV1lZmdSne8aSwuFW9pa88vi1Cjx4cBv3 Typ9kleCG0gPcZAkcml8Vhc+ZprAZcmG0PKcXMm28KcOW7esrUnkHEelZxJbKbBE3H1O iheN6dBS56g9IZDDqgGHyTgecpmq9xZo6r4pbapk8xCSrXy3hdwUXeZQudr2O8ustzYA BQRA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=OU5N50he; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=DI3woRds; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=O2bf7+jI; 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 006d021491bc7-631a32e23besi830622eaf.27.2025.09.23.08.11.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Sep 2025 08:11:10 -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=OU5N50he; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=DI3woRds; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=O2bf7+jI; 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=P9QHWV7nNXGQvIBtaTNqetcyCn/p4Sa+eDk7kH+Dubs=; b=OU5N50hevTvCLVfVQlj1mxLcRx ucYKN4peTLSOgSqeEZrbASWb/N2fJt3zpOYD+Zld3MP/8QqxF36BGzOP8bVYoCLzQMt10NmFXdVBU Ttr0dyJHuL/nZty+eDqVOd3MW/IZ7xb2xm2DPg9tfD6SKAQIDfKiv9AGW2TWvp8B2OD8=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1v14fa-0007VI-TS; Tue, 23 Sep 2025 15:11:06 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1v14fZ-0007V9-9W for openvpn-devel@lists.sourceforge.net; Tue, 23 Sep 2025 15:11:05 +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=u4ze9Py/JeWZnLnGl89UWJLiG8PlbmZuMNKB5udUdxA=; b=DI3woRdshtD4nGX3Ftle94NyCC Dehru424EDd3prw1s3OhjVea0VOJMug9y2ek8m53Hxq71o7OXsWWsWMs684kuh3k2Bl7dfxB+TIFQ b439aZ7ZiskdADhRgUfEtgYqVmH5iIJBWpB02Jkjfvv8R433+xhuWdZDKf0xGlHf/5Eg=; 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=u4ze9Py/JeWZnLnGl89UWJLiG8PlbmZuMNKB5udUdxA=; b=O2bf7+jITFLgZMowonvya3DYwG +hAYVwpaTutJ+tGc/8kVhLIFUVRPxY1aHmJUT9HnTlZfjkjbVQR5f+2qZvW4sd0F1HP2FwqebLyub NxCeTfruOQQSg/Aw8P7RXkHCVTIBun237kq0+jSxodGO+/LD8aCjk4vn69UVAg4oe+sI=; 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 1v14fW-0006Li-Es for openvpn-devel@lists.sourceforge.net; Tue, 23 Sep 2025 15:11:05 +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 58NFAoWm027354 for ; Tue, 23 Sep 2025 17:10:50 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 58NFAoNk027353 for openvpn-devel@lists.sourceforge.net; Tue, 23 Sep 2025 17:10:50 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Tue, 23 Sep 2025 17:10:44 +0200 Message-ID: <20250923151050.27336-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 This is basically identical code duplicated three times. Change-Id: I6e848df8104b6e3a6e2c3245ece91a20e473fb40 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: 1v14fW-0006Li-Es Subject: [Openvpn-devel] [PATCH v2] socks: factor out socks_proxy_recv_char() 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?1844067979990965191?= X-GMAIL-MSGID: =?utf-8?q?1844067979990965191?= From: Frank Lichtenheld This is basically identical code duplicated three times. Change-Id: I6e848df8104b6e3a6e2c3245ece91a20e473fb40 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1165 --- 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/+/1165 This mail reflects revision 2 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/src/openvpn/socks.c b/src/openvpn/socks.c index 481d3fb..1102421 100644 --- a/src/openvpn/socks.c +++ b/src/openvpn/socks.c @@ -81,6 +81,54 @@ } static bool +socks_proxy_recv_char(char *c, const char *name, socket_descriptor_t sd, + struct event_timeout *server_poll_timeout, + volatile int *signal_received) +{ + fd_set reads; + FD_ZERO(&reads); + openvpn_fd_set(sd, &reads); + + struct timeval tv; + tv.tv_sec = get_server_poll_remaining_time(server_poll_timeout); + tv.tv_usec = 0; + + const int status = select(sd + 1, &reads, NULL, NULL, &tv); + + get_signal(signal_received); + if (*signal_received) + { + return false; + } + + /* timeout? */ + if (status == 0) + { + msg(D_LINK_ERRORS | M_ERRNO, "%s: TCP port read timeout expired", name); + return false; + } + + /* error */ + if (status < 0) + { + msg(D_LINK_ERRORS | M_ERRNO, "%s: TCP port read failed on select()", name); + return false; + } + + /* read single char */ + const ssize_t size = recv(sd, c, 1, MSG_NOSIGNAL); + + /* error? */ + if (size != 1) + { + msg(D_LINK_ERRORS | M_ERRNO, "%s: TCP port read failed on recv()", name); + return false; + } + + return true; +} + +static bool socks_username_password_auth(struct socks_proxy_info *p, socket_descriptor_t sd, struct event_timeout *server_poll_timeout, volatile int *signal_received) @@ -121,52 +169,12 @@ while (len < 2) { - int status; - ssize_t size; - fd_set reads; - struct timeval tv; char c; - FD_ZERO(&reads); - openvpn_fd_set(sd, &reads); - tv.tv_sec = get_server_poll_remaining_time(server_poll_timeout); - tv.tv_usec = 0; - - status = select(sd + 1, &reads, NULL, NULL, &tv); - - get_signal(signal_received); - if (*signal_received) + if (!socks_proxy_recv_char(&c, __func__, sd, server_poll_timeout, signal_received)) { goto cleanup; } - - /* timeout? */ - if (status == 0) - { - msg(D_LINK_ERRORS | M_ERRNO, - "socks_username_password_auth: TCP port read timeout expired"); - goto cleanup; - } - - /* error */ - if (status < 0) - { - msg(D_LINK_ERRORS | M_ERRNO, - "socks_username_password_auth: TCP port read failed on select()"); - goto cleanup; - } - - /* read single char */ - size = recv(sd, &c, 1, MSG_NOSIGNAL); - - /* error? */ - if (size != 1) - { - msg(D_LINK_ERRORS | M_ERRNO, - "socks_username_password_auth: TCP port read failed on recv()"); - goto cleanup; - } - /* store char in buffer */ buf[len++] = c; } @@ -208,49 +216,12 @@ while (len < 2) { - int status; - ssize_t size; - fd_set reads; - struct timeval tv; char c; - FD_ZERO(&reads); - openvpn_fd_set(sd, &reads); - tv.tv_sec = get_server_poll_remaining_time(server_poll_timeout); - tv.tv_usec = 0; - - status = select(sd + 1, &reads, NULL, NULL, &tv); - - get_signal(signal_received); - if (*signal_received) + if (!socks_proxy_recv_char(&c, __func__, sd, server_poll_timeout, signal_received)) { return false; } - - /* timeout? */ - if (status == 0) - { - msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port read timeout expired"); - return false; - } - - /* error */ - if (status < 0) - { - msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port read failed on select()"); - return false; - } - - /* read single char */ - size = recv(sd, &c, 1, MSG_NOSIGNAL); - - /* error? */ - if (size != 1) - { - msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port read failed on recv()"); - return false; - } - /* store char in buffer */ buf[len++] = c; } @@ -317,54 +288,13 @@ while (len < 4 + alen + 2) { - int status; - ssize_t size; - fd_set reads; - struct timeval tv; char c; - FD_ZERO(&reads); - openvpn_fd_set(sd, &reads); - tv.tv_sec = get_server_poll_remaining_time(server_poll_timeout); - tv.tv_usec = 0; - - status = select(sd + 1, &reads, NULL, NULL, &tv); - - get_signal(signal_received); - if (*signal_received) + if (!socks_proxy_recv_char(&c, __func__, sd, server_poll_timeout, signal_received)) { return false; } - /* timeout? */ - if (status == 0) - { - msg(D_LINK_ERRORS | M_ERRNO, "recv_socks_reply: TCP port read timeout expired"); - return false; - } - - /* error */ - if (status < 0) - { - msg(D_LINK_ERRORS | M_ERRNO, "recv_socks_reply: TCP port read failed on select()"); - return false; - } - - /* read single char */ - size = recv(sd, &c, 1, MSG_NOSIGNAL); - - /* error? */ - if (size < 0) - { - msg(D_LINK_ERRORS | M_ERRNO, "recv_socks_reply: TCP port read failed on recv()"); - return false; - } - else if (size == 0) - { - msg(D_LINK_ERRORS, "ERROR: recv_socks_reply: empty response from socks server"); - return false; - } - if (len == 3) { atyp = c;