From a4250afadc0299b41f1cd99b34a2e13cdfe156a9 Mon Sep 17 00:00:00 2001 From: Markus Kuhn Date: Tue, 23 May 2017 20:04:23 +0100 Subject: [PATCH] strip drive letter from %HOMEPATH% (#103) Many programs access the user's home directory as %HOMEDRIVE%%HOMEPATH%. Without removing the drive letter from %HOMEPATH%, the result of this concatenation is something like "C:C:\Users\mgkuhn" and results in applications not finding the home directory. After this change, OpenSSH will set %HOMEPATH% without a drive letter, like Windows does, as documented at https://support.microsoft.com/en-us/help/101507/how-windows-nt-determines-a-user-s-home-directory I also added a safety check to test that pw_dir_w is not empty. --- session.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/session.c b/session.c index 371f6147e..0e830ef24 100644 --- a/session.c +++ b/session.c @@ -322,14 +322,16 @@ static void setup_session_vars(Session* s) { UTF8_TO_UTF16_FATAL(tmp, s->display); SetEnvironmentVariableW(L"DISPLAY", tmp); } - SetEnvironmentVariableW(L"HOMEPATH", pw_dir_w); SetEnvironmentVariableW(L"USERPROFILE", pw_dir_w); - if (pw_dir_w[1] == L':') { + if (pw_dir_w[0] && pw_dir_w[1] == L':') { + SetEnvironmentVariableW(L"HOMEPATH", pw_dir_w + 2); wchar_t wc = pw_dir_w[2]; pw_dir_w[2] = L'\0'; SetEnvironmentVariableW(L"HOMEDRIVE", pw_dir_w); pw_dir_w[2] = wc; + } else { + SetEnvironmentVariableW(L"HOMEPATH", pw_dir_w); } snprintf(buf, sizeof buf, "%.50s %d %d",