From patchwork Wed Dec 13 14:07:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "ralf_lici (Code Review)" X-Patchwork-Id: 3525 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:8d12:b0:fc:24ac:f0cb with SMTP id i18csp6527470dys; Wed, 13 Dec 2023 06:07:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMPw/Bzzb+AIUNrVzg1lzIbItenIDez7RZCVS6s4Ro82lntoaKjvj5S6auRQLGr4jeC9GC X-Received: by 2002:a17:902:8496:b0:1d0:c738:73c8 with SMTP id c22-20020a170902849600b001d0c73873c8mr16174308plo.0.1702476466703; Wed, 13 Dec 2023 06:07:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702476466; cv=none; d=google.com; s=arc-20160816; b=zd4MU2bjZ4QwQT8QF6OTgO5BBx1ApRaG64QaPCe3dVhRRytnsp9WXOFr9HMZaa/TCt V5UPSDyWxBlStv+QSlw2WgSvVHzR95fBBBAHyh+f1w0+6gXNzDtz+ZXOgnDGkKdm6VgK q6XUb4mw4P9zdxB/vEkMpAxHKhnkEZ4baT6s01BGDywHgv1vBmSYY7N8MlT7EQBJAF4W K+0S0wZhG7nea9/f0gMO34iIlHw3w/7LR6o1NY6Wjj0EZX2owUJFfICiXGMtLE3TZEgq Ua7g6HxikjP1YrkZnIUJ1Ugd0sBJOLacV5GdcWSMHPVIEKKyftL40yBDZby4rKVd0/K0 Rp3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:cc:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:user-agent :mime-version:message-id:references:auto-submitted:to:date:from :dkim-signature:dkim-signature:dkim-signature; bh=MSueFTOSZAyER3IiivPO3YkoRfVEAGp+qVcKTPT+P/U=; fh=lm0MLPW7DntlrDqRECIiC9JlE1uPxhepE0URYHIf+eE=; b=uP8Enf0XyRz/bRQ6zNhgOaws7wfhjQzW+6T1tIVzk7Cl6lNrj7iBkxY3DSSiFGpPq0 RLGzUjYmPo/MPp9PRpSX51uoU7fbO4SJw1Nz2Ld9ZTm4shE/c7FnhhlWDIO8JNkviyl2 txSs74d/q3olpvRxxv/juT9Qwp51AHn3MoF8+w4qA/C20/TLe+2K7peNsg4NE3qDTRIc K48MLu2wk099V/h3+u47tElV8o2/Qoo8b40t6YyGuLJW5PICXZXqc8o1ElhVlNgQGojv 9hmJzDTe8xX4uIBqy4YYr2l85gwkdpIOftTK3+pJbR4UWhB2TxZTHkpe0IHbsEAbWpcF 085w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=b7W0kWuS; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="FZD/jBSy"; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=aUpFRXPR; 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=openvpn.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id by12-20020a056a02058c00b005c66c2d0a5csi9936046pgb.484.2023.12.13.06.07.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Dec 2023 06:07:46 -0800 (PST) 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=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=b7W0kWuS; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="FZD/jBSy"; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=aUpFRXPR; 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=openvpn.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rDPtU-0005OS-1l; Wed, 13 Dec 2023 14:07:24 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rDPtS-0005OE-N6 for openvpn-devel@lists.sourceforge.net; Wed, 13 Dec 2023 14:07:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Content-Transfer-Encoding:MIME-Version :Message-ID:Reply-To:References:Subject:List-Unsubscribe:List-Id:Cc:To:Date: From:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help: List-Subscribe:List-Post:List-Owner:List-Archive; bh=tVLpVLF05+8dmY2d5k3BuVI/9YrOMYkpqQU78v3up+I=; b=b7W0kWuSexIjVhVoPOedPgmJjo txn59KxHyTHHNHCgSVthxEym+OhhQgRLJTiq+wlBn+7/5DZBlP04P0uUEXun7TDPhbZtzqQSlaIIP OMcaVwt0NzitnZpdGZErLmHulbhxO1xFMtbZ9ZH1VXYRQT1fUtrB6J49Pym0UUZaIKRQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Reply-To: References:Subject:List-Unsubscribe:List-Id:Cc:To:Date:From:Sender:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help:List-Subscribe:List-Post: List-Owner:List-Archive; bh=tVLpVLF05+8dmY2d5k3BuVI/9YrOMYkpqQU78v3up+I=; b=F ZD/jBSywkgF2/VILPIxP4UOl3bZAa0A7c8weABT5Bttzbc9oIwjawt45JEgy20DKM6TugNgIYDEOu 6P5yaEhdRkEbJP6xKGbHsV5foFfgHZSViF5sPwlq7r1cSOg1LjSeeLL0vJ3N067dwc2lJM2kZzb2i 9vuDkgwTK5mMov2Y=; Received: from mail-lj1-f175.google.com ([209.85.208.175]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1rDPtN-0002dO-KA for openvpn-devel@lists.sourceforge.net; Wed, 13 Dec 2023 14:07:21 +0000 Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2c9f8faf57bso89223311fa.3 for ; Wed, 13 Dec 2023 06:07:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1702476426; x=1703081226; darn=lists.sourceforge.net; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from:from:to:cc :subject:date:message-id:reply-to; bh=tVLpVLF05+8dmY2d5k3BuVI/9YrOMYkpqQU78v3up+I=; b=aUpFRXPR5Mg1mcW67fwqNlz0q+p4nEVp6KI/IVoI1UabXyc24EIoZF/niYPAH/6X1q VF2RQ63iAw59V7JbXJnPFO/20GphtQLOmkL0ZnoY57FqYrVRdeM3dV3dvD1j5qlZ7scz 7wlO5yQTDmU2IOrWqb3weK3i5fU7MSELgVNcqm6sv/lqzL1emLJa87IkHJp2HwOHu0D7 W6lt8y1lMqjHg9hDyqpU1azgInY/YAWBtR0QU/PEeVQ/Yb8c5jXKhtvEqTTTaxPO4T64 QX8ocsDGqYVUyTRF1VepQJ6ykg/K/Z2Of2ZQfapAjL/Ac+Vv2bgyKtMpnqrwABXqR21F g83w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702476426; x=1703081226; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tVLpVLF05+8dmY2d5k3BuVI/9YrOMYkpqQU78v3up+I=; b=dgV1uNqVRQRUEehxwRtdIe4wX+oGCJcH67P65eQbxVr7XG8Awi3kd8Xy4tEEy7Q6ZD xnhDVK/rWVFHavBNffimXFAWB0i0ssp7T3Bi03xCfvPnKAC7fBz7vwRlTaQgQT809CXv jI43SGm0k0y5jktWbCtUrnYaeH/6cUGCitvWkm68COB1BfRdom3SsuIn1/+VnJMLoQnp fhE0khiWJLBn93uq79Sxs63VX+YijQlBucb/DhSRchMPXKwoyOWoSSwa1vFOfFk2wuOP 8LdU4DTDRSMTGhjwsYuihw4FA6aeMdf+plt/LDhOh9hvWLrMr3duJwSH5JvekFKwOQqc nlZw== X-Gm-Message-State: AOJu0Ywli6OAkgye+U2+fSu2tgbCrZ58JEV+0uDUMxftNCN+YtnvKihT /OscRb3f3REFoQOIUccz2WM8S1GVK6OBo2LSfgc= X-Received: by 2002:a2e:859:0:b0:2cc:3e4e:8f34 with SMTP id g25-20020a2e0859000000b002cc3e4e8f34mr74872ljd.25.1702476425595; Wed, 13 Dec 2023 06:07:05 -0800 (PST) Received: from gerrit.openvpn.in (ec2-18-159-0-78.eu-central-1.compute.amazonaws.com. [18.159.0.78]) by smtp.gmail.com with ESMTPSA id e33-20020a5d5961000000b0033346fe9b9bsm13456218wri.83.2023.12.13.06.07.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 06:07:05 -0800 (PST) From: "plaisthos (Code Review)" X-Google-Original-From: "plaisthos (Code Review)" X-Gerrit-PatchSet: 1 Date: Wed, 13 Dec 2023 14:07:04 +0000 To: flichtenheld Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange X-Gerrit-Change-Id: I525ccf7872880367b248ebebb0ddc83551498042 X-Gerrit-Change-Number: 481 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: c45a2c2c79cf34f47e4a1bf7fbb903e3e38c7d41 References: Message-ID: MIME-Version: 1.0 User-Agent: Gerrit/3.8.2 X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-1.v13.lw.sourceforge.com", 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: Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.208.175 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.208.175 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 WEIRD_PORT URI: Uses non-standard port number for HTTP 0.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.0 T_KAM_HTML_FONT_INVALID Test for Invalidly Named or Formatted Colors in HTML -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1rDPtN-0002dO-KA Subject: [Openvpn-devel] [M] Change in openvpn[master]: Move get_tmp_dir to win32-util.c and error out on failure 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: , Reply-To: arne-openvpn@rfc2549.org, openvpn-devel@lists.sourceforge.net, frank@lichtenheld.com Cc: openvpn-devel Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1785175963074210867?= X-GMAIL-MSGID: =?utf-8?q?1785175963074210867?= X-getmail-filter-classifier: gerrit message type newchange Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/481?usp=email to review the following change. Change subject: Move get_tmp_dir to win32-util.c and error out on failure ...................................................................... Move get_tmp_dir to win32-util.c and error out on failure Currently we only warn in get_tmp_dir fails and set o->tmp_dir to a null pointer. This will not be caught by check_file_access_chroot either since that ignores NULL pointers but other parts of OpenVPN will assume that tmp_dir is set to a non-NULL string. Also move get_tmp_dir to ssl-utils.c to use it in unit tests. Change-Id: I525ccf7872880367b248ebebb0ddc83551498042 Signed-off-by: Arne Schwabe --- M src/openvpn/options.c M src/openvpn/win32-util.c M src/openvpn/win32-util.h M src/openvpn/win32.c 4 files changed, 34 insertions(+), 29 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/81/481/1 diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 503e832..9863261 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -885,7 +885,15 @@ #ifdef _WIN32 /* On Windows, find temp dir via environment variables */ o->tmp_dir = win_get_tempdir(); -#else + + if (!o->tmp_dir) + { + /* Warn if we can't find a valid temporary directory, which should + * be unlikely. */ + msg(M_USAGE, "Could not find a suitable temporary directory." + " (GetTempPath() failed). Consider using --tmp-dir"); + } +#else /* ifdef _WIN32 */ /* Non-windows platforms use $TMPDIR, and if not set, default to '/tmp' */ o->tmp_dir = getenv("TMPDIR"); if (!o->tmp_dir) diff --git a/src/openvpn/win32-util.c b/src/openvpn/win32-util.c index 81e504a..c5e7505 100644 --- a/src/openvpn/win32-util.c +++ b/src/openvpn/win32-util.c @@ -147,4 +147,26 @@ } return true; } + +const char * +win_get_tempdir(void) +{ + static char tmpdir[MAX_PATH]; + WCHAR wtmpdir[MAX_PATH]; + + if (!GetTempPathW(_countof(wtmpdir), wtmpdir)) + { + return NULL; + } + + if (WideCharToMultiByte(CP_UTF8, 0, wtmpdir, -1, NULL, 0, NULL, NULL) > sizeof(tmpdir)) + { + msg(M_WARN, "Could not get temporary directory. Path is too long." + " Consider using --tmp-dir"); + return NULL; + } + + WideCharToMultiByte(CP_UTF8, 0, wtmpdir, -1, tmpdir, sizeof(tmpdir), NULL, NULL); + return tmpdir; +} #endif /* _WIN32 */ diff --git a/src/openvpn/win32-util.h b/src/openvpn/win32-util.h index ac37979..98bf74b 100644 --- a/src/openvpn/win32-util.h +++ b/src/openvpn/win32-util.h @@ -40,5 +40,8 @@ /* return true if filename is safe to be used on Windows */ bool win_safe_filename(const char *fn); +/* Find temporary directory */ +const char *win_get_tempdir(void); + #endif /* OPENVPN_WIN32_UTIL_H */ #endif /* ifdef _WIN32 */ diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c index e998d90..6b7ba5e 100644 --- a/src/openvpn/win32.c +++ b/src/openvpn/win32.c @@ -1137,34 +1137,6 @@ set_win_sys_path(buf, es); } - -const char * -win_get_tempdir(void) -{ - static char tmpdir[MAX_PATH]; - WCHAR wtmpdir[MAX_PATH]; - - if (!GetTempPathW(_countof(wtmpdir), wtmpdir)) - { - /* Warn if we can't find a valid temporary directory, which should - * be unlikely. - */ - msg(M_WARN, "Could not find a suitable temporary directory." - " (GetTempPath() failed). Consider using --tmp-dir"); - return NULL; - } - - if (WideCharToMultiByte(CP_UTF8, 0, wtmpdir, -1, NULL, 0, NULL, NULL) > sizeof(tmpdir)) - { - msg(M_WARN, "Could not get temporary directory. Path is too long." - " Consider using --tmp-dir"); - return NULL; - } - - WideCharToMultiByte(CP_UTF8, 0, wtmpdir, -1, tmpdir, sizeof(tmpdir), NULL, NULL); - return tmpdir; -} - static bool win_block_dns_service(bool add, int index, const HANDLE pipe) {