From patchwork Wed Sep 9 02:07:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 1431 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director7.mail.ord1d.rsapps.net ([172.27.255.57]) by backend30.mail.ord1d.rsapps.net with LMTP id aBTFGLLFWF8SVQAAIUCqbw (envelope-from ) for ; Wed, 09 Sep 2020 08:08:18 -0400 Received: from proxy20.mail.iad3a.rsapps.net ([172.27.255.57]) by director7.mail.ord1d.rsapps.net with LMTP id +O2IGLLFWF97KQAAovjBpQ (envelope-from ) for ; Wed, 09 Sep 2020 08:08:18 -0400 Received: from smtp19.gate.iad3a ([172.27.255.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy20.mail.iad3a.rsapps.net with LMTPS id 6OqmErLFWF/regAAtfLT2w (envelope-from ) for ; Wed, 09 Sep 2020 08:08:18 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp19.gate.iad3a.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=greenie.muc.de X-Suspicious-Flag: YES X-Classification-ID: 23a53bfa-f295-11ea-aee6-5254005d39f2-1-1 Received: from [216.105.38.7] ([216.105.38.7:34736] helo=lists.sourceforge.net) by smtp19.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id C0/D6-25246-FA5C85F5; Wed, 09 Sep 2020 08:08:15 -0400 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.90_1) (envelope-from ) id 1kFysp-0007yx-Ep; Wed, 09 Sep 2020 12:07:27 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFysn-0007yH-SI for openvpn-devel@lists.sourceforge.net; Wed, 09 Sep 2020 12:07:25 +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=u3kaL+x64adTx9YRqXk42xkDDFtdUsVz4PIUJZxCBz8=; b=bJc853fc0LW7kcOcRAKOPOONYb UcBT1SY5xui3OuVKpRVggq9xD1XReiDuBX5THEWfva+OGdkWegw42Q7aalUlhmM5aGtTg/WKN+71p n6upUSmc/kaZf06e7ob8NgTZQ+0oBCqjrdLunVmmlQHvCSOrrCRzZdTYrBVBLkknarec=; 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=u3kaL+x64adTx9YRqXk42xkDDFtdUsVz4PIUJZxCBz8=; b=B61slqrO2cHw/fKu6piOTW04Au yxuRrl16TFaS6D9IIOCSgwbpAPFzUC17hiLx+cQ/DV49wkupF9lokv0Lqz9VFpEpw3qtfcEc9YaaR l9ZDc6Zb3fC8naeE/RSdbTENOjcpILlq05cx4j64l47asLxK2VKUl12jE8zTFRwQgpvw=; Received: from dhcp-174.greenie.muc.de ([193.149.48.174] helo=blue.greenie.muc.de) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1kFysk-000WB0-Ch for openvpn-devel@lists.sourceforge.net; Wed, 09 Sep 2020 12:07:25 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.14.9/8.14.9) with ESMTP id 089C78Zw008712 for ; Wed, 9 Sep 2020 14:07:08 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.15.2/8.14.9/Submit) id 089C78VY008711 for openvpn-devel@lists.sourceforge.net; Wed, 9 Sep 2020 14:07:08 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Wed, 9 Sep 2020 14:07:07 +0200 Message-Id: <20200909120707.8663-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200909120319.8464-1-gert@greenie.muc.de> References: <20200909120319.8464-1-gert@greenie.muc.de> MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: muc.de] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1kFysk-000WB0-Ch Subject: [Openvpn-devel] [PATCH v2] socks.c: fix alen for DOMAIN type addresses 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 When a SOCKS5 server sends back a reply, it encodes an "address", which can be IPv4 (4 bytes), IPv6 (16 bytes) or "a domain name", which has a lenght (1 byte) and "a string of length " - so when copying bytes, we need to hande "length +1" bytes. Our code totally doesn't use this variant of addresses, but since this has been pointed out by "tpw_rules" in Trac, fix it, so if/when someone works on this again, the foundation is correct. v2: increase buf[] len to be large enough to actually copy a domain name Reported-By: tpw_rules in Trac Trac: #848 Signed-off-by: Gert Doering --- src/openvpn/socks.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/openvpn/socks.c b/src/openvpn/socks.c index 57f0cee2..f1bdf4d4 100644 --- a/src/openvpn/socks.c +++ b/src/openvpn/socks.c @@ -312,7 +312,7 @@ recv_socks_reply(socket_descriptor_t sd, char atyp = '\0'; int alen = 0; int len = 0; - char buf[22]; + char buf[270]; /* 4 + alen(max 256) + 2 */ const int timeout_sec = 5; if (addr != NULL) @@ -381,7 +381,10 @@ recv_socks_reply(socket_descriptor_t sd, break; case '\x03': /* DOMAINNAME */ - alen = (unsigned char) c; + /* RFC 1928, section 5: 1 byte length, bytes name, + * so the total "address length" is (length+1) + */ + alen = (unsigned char) c +1; break; case '\x04': /* IP V6 */