From: "cron2 (Code Review)" Date: Mon, 8 Jan 2024 21:33:58 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <5577028ce88ce51ea5d91b6310b65884f6049c65-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Y8wYoang4vo="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Move get_tmp_dir to win32-util.c and error out on failure List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --Y8wYoang4vo= 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= plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/481?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+1 by cron2, Code-Review+2 by flichtenheld 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 win32-util.c to use it in unit tests. Change-Id: I525ccf7872880367b248ebebb0ddc83551498042 Signed-off-by: Arne Schwabe Acked-by: Frank Lichtenheld Message-Id: <20240108171349.15871-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg27= 964.html Signed-off-by: Gert Doering --- M src/openvpn/options.c M src/openvpn/win32-util.c M src/openvpn/win32-util.h M src/openvpn/win32.c M src/openvpn/win32.h 5 files changed, 34 insertions(+), 32 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/81/481/3 diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 1b28a19..f54f276 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 =3D win_get_tempdir(); -#else + + if (!o->tmp_dir) + { + /* Error out if we can't find a valid temporary directory, which s= hould + * be very 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 =3D 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), N= ULL, 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), N= ULL, NULL); - return tmpdir; -} - static bool win_block_dns_service(bool add, int index, const HANDLE pipe) { diff --git a/src/openvpn/win32.h b/src/openvpn/win32.h index 3605966..aa8513b 100644 --- a/src/openvpn/win32.h +++ b/src/openvpn/win32.h @@ -286,9 +286,6 @@ /* call self in a subprocess */ void fork_to_self(const char *cmdline); -/* Find temporary directory */ -const char *win_get_tempdir(void); - bool win_wfp_block_dns(const NET_IFINDEX index, const HANDLE msg_channel); bool win_wfp_uninit(const NET_IFINDEX index, const HANDLE msg_channel); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/481?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I525ccf7872880367b248ebebb0ddc83551498042 Gerrit-Change-Number: 481 Gerrit-PatchSet: 3 Gerrit-Owner: plaisthos Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --Y8wYoang4vo= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #3 to the change originally cr= eated by plaisthos.

View Change

The following approvals got outdated= and were removed: Code-Review+1 by cron2, Code-Review+2 by flichtenheld

Move get_tmp_dir to w=
in32-util.c and error out on failure

Currently we only warn in get_t= mp_dir fails and set o->tmp_dir to
a null pointer. This will not be c= aught by check_file_access_chroot
either since that ignores NULL pointer= s but other parts of OpenVPN
will assume that tmp_dir is set to a non-NU= LL string.

Also move get_tmp_dir to win32-util.c to use it in unit t= ests.

Change-Id: I525ccf7872880367b248ebebb0ddc83551498042
Signed= -off-by: Arne Schwabe <arne@...1227...>
Acked-by: Frank Lichtenhel= d <frank@...2641...>
Message-Id: <20240108171349.15871-1-gert@...220...= ..1296...>
URL: https://www.mail-archive.com/openvpn-devel@...1439...= ceforge.net/msg27964.html
Signed-off-by: Gert Doering <gert@...2132...= .>
---
M src/openvpn/options.c
M src/openvpn/win32-util.c
M = src/openvpn/win32-util.h
M src/openvpn/win32.c
M src/openvpn/win32.h<= br>5 files changed, 34 insertions(+), 32 deletions(-)

git pull ss=
h://gerrit.openvpn.net:29418/openvpn refs/changes/81/481/3
diff --=
git a/src/openvpn/options.c b/src/openvpn/options.c
index 1= b28a19..f54f276 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 =3D win= _get_tempdir();
-#else<= /span>
+
+ if (!o->tmp_dir)
+ {

+ /* Error out if we can't find a valid= temporary directory, which should
+ * be very unlikely. */
+ msg(M_USAGE, "Could not find a suit= able temporary directory."
+ " (GetTempPath() failed). Consider using --tm= p-dir");
+ }<= /span>
+#else /* ifdef _WIN= 32 */
/* Non-windows platforms use $TMPDIR, and if not= set, default to '/tmp' */
o->tmp_dir =3D g= etenv("TMPDIR");
if (!o->tmp_dir)<= br>diff --git a/src/openvpn/win32-util.c b/src/openvpn/win32-util.c
index 81e504a..c5e7505 100644
--- a/src/open= vpn/win32-util.c
+++ b/src/openvpn/win32-util.c
<= span>@@ -147,4 +147,26 @@

}
retur= n true;
}
+
+const char *=
+win_get_tempdir(voi= d)
+{
+ static char tmpdir[MAX_PATH];
+ WCHAR wtmpdir[MAX= _PATH];
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (!GetTempPathW(_countof(= wtmpdir), wtmpdir))

+= {
+ return= NULL;
+ }<= br>+
+ if (WideCharToMultiByte(CP_UTF8, 0, wtmpdi= r, -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(tmpdi= r), NULL, NULL);
+ = return tmpdir;
+}
#endif /* _WIN32 */
diff --git a/src/openvpn= /win32-util.h b/src/openvpn/win32-util.h
index ac37979..98b= f74b 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_g= et_tempdir(void);
+
#endif /* OPENVPN_WIN32_UTIL_H */
#endif /= * ifdef _WIN32 */
diff --git a/src/openvpn/win32.c b/src/op= envpn/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_t= empdir(void)
-{<= br>- static char tmpdir[MAX_PA= TH];
- 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, wtm= pdir, -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 tmp= dir;
-}
-

static bool<= br> win_block_dns_service(bool add, int index, const HANDLE pipe)
{
diff --git a/src/openvpn/win32.h b/src/open= vpn/win32.h
index 3605966..aa8513b 100644
-= -- a/src/openvpn/win32.h
+++ b/src/openvpn/win32.h@@ -286,9 +286,6 @@
/* call self in a subprocess *= /
void fork_to_self(const char *cmdline);
=
-/* Find temporary di= rectory */
-const char = *win_get_tempdir(void);
-
bool win_wfp_block_dns(const NET_IFINDEX index, const H= ANDLE msg_channel);

bool win_wfp_uninit(= const NET_IFINDEX index, const HANDLE msg_channel);
=

To view, visit change 481. To unsubscribe, or for help writing mail= filters, visit settings= .

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I525ccf7872880367b248ebebb0d= dc83551498042
Gerrit-Change-Number: 481
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--Y8wYoang4vo=--