]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Support non-ASCII characters in Windows tmp path
authorHeiko Hund <heiko.hund@sophos.com>
Tue, 19 Nov 2013 17:36:14 +0000 (18:36 +0100)
committerGert Doering <gert@greenie.muc.de>
Thu, 5 Dec 2013 18:48:37 +0000 (19:48 +0100)
Get the temporary path from the system as UCS-2 and convert it to
UTF-8 and return that for internal use.

Fix trac#278.

Signed-off-by: Heiko Hund <heiko.hund@sophos.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1384882574-28242-1-git-send-email-heiko.hund@sophos.com>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8002
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/win32.c

index 022eec5c90c140c87e93977ba2f839623dd25bc3..f35c96be377636b460e815f23034f2a8090b8cdc 100644 (file)
@@ -996,19 +996,27 @@ set_win_sys_path_via_env (struct env_set *es)
 const char *
 win_get_tempdir()
 {
-  static char buf[MAX_PATH];
-  char *tmpdir = buf;
-
-  CLEAR(buf);
-
-  if (!GetTempPath(sizeof(buf),buf)) {
-    /* 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 to use --tmp-dir");
-    tmpdir = NULL;
-  }
+  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;
 }
 #endif