Skip to content

Commit

Permalink
Merge pull request #2725 from native-api/homedir_seclogons
Browse files Browse the repository at this point in the history
Ignore Vista+ HOMEDRIVE/HOMEPATH default for non-shell logons
  • Loading branch information
dscho committed Jan 25, 2021
2 parents 164123f + 4bf58e0 commit 7c75618
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,18 @@ static size_t append_system_bin_dirs(char *path, size_t size)
}
#endif

static int is_system32_path(const char *path)
{
WCHAR system32[MAX_LONG_PATH], wpath[MAX_LONG_PATH];

if (xutftowcs_long_path(wpath, path) < 0 ||
!GetSystemDirectoryW(system32, ARRAY_SIZE(system32)) ||
_wcsicmp(system32, wpath))
return 0;

return 1;
}

static void setup_windows_environment(void)
{
char *tmp = getenv("TMPDIR");
Expand Down Expand Up @@ -2856,7 +2868,8 @@ static void setup_windows_environment(void)
strbuf_addstr(&buf, tmp);
if ((tmp = getenv("HOMEPATH"))) {
strbuf_addstr(&buf, tmp);
if (is_directory(buf.buf))
if (!is_system32_path(buf.buf) &&
is_directory(buf.buf))
setenv("HOME", buf.buf, 1);
else
tmp = NULL; /* use $USERPROFILE */
Expand Down

0 comments on commit 7c75618

Please sign in to comment.