Skip to content

Commit a4250af

Browse files
mgkuhnmanojampalam
authored andcommitted
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.
1 parent e296463 commit a4250af

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

session.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,16 @@ static void setup_session_vars(Session* s) {
322322
UTF8_TO_UTF16_FATAL(tmp, s->display);
323323
SetEnvironmentVariableW(L"DISPLAY", tmp);
324324
}
325-
SetEnvironmentVariableW(L"HOMEPATH", pw_dir_w);
326325
SetEnvironmentVariableW(L"USERPROFILE", pw_dir_w);
327326

328-
if (pw_dir_w[1] == L':') {
327+
if (pw_dir_w[0] && pw_dir_w[1] == L':') {
328+
SetEnvironmentVariableW(L"HOMEPATH", pw_dir_w + 2);
329329
wchar_t wc = pw_dir_w[2];
330330
pw_dir_w[2] = L'\0';
331331
SetEnvironmentVariableW(L"HOMEDRIVE", pw_dir_w);
332332
pw_dir_w[2] = wc;
333+
} else {
334+
SetEnvironmentVariableW(L"HOMEPATH", pw_dir_w);
333335
}
334336

335337
snprintf(buf, sizeof buf, "%.50s %d %d",

0 commit comments

Comments
 (0)