msvcrt: Add support for quoted paths in _searchenv.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2020-01-28 18:26:12 +01:00 committed by Alexandre Julliard
parent f17a228d45
commit 1d0cca465a
2 changed files with 32 additions and 3 deletions

View File

@ -1683,12 +1683,27 @@ void CDECL MSVCRT__searchenv(const char* file, const char* env, char *buf)
for(; *penv; penv = (*end ? end + 1 : end))
{
end = penv;
while(*end && *end != ';') end++; /* Find end of next path */
path_len = end - penv;
path_len = 0;
while(*end && *end != ';' && path_len < MAX_PATH)
{
if (*end == '"')
{
end++;
while(*end && *end != '"' && path_len < MAX_PATH)
{
path[path_len++] = *end;
end++;
}
if (*end == '"') end++;
continue;
}
path[path_len++] = *end;
end++;
}
if (!path_len || path_len >= MAX_PATH)
continue;
memcpy(path, penv, path_len);
if (path[path_len - 1] != '/' && path[path_len - 1] != '\\')
path[path_len++] = '\\';
if (path_len + fname_len >= MAX_PATH)

View File

@ -597,6 +597,20 @@ static void test_searchenv(void)
ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
}
strcpy(env1, "TEST_PATH=");
strcat(env1, tmppath);
strcat(env1, "\"\\search_env_test\\\"d\"i\"r\"1");
putenv(env1);
strcpy(exp, tmppath);
strcat(exp, files[0]);
_searchenv("1.dat", "TEST_PATH", result);
ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
strcat(env1, ";");
putenv(env1);
_searchenv("1.dat", "TEST_PATH", result);
ok(!result[0], "got %s, expected ''\n", result);
putenv("TEST_PATH=");
for (i=ARRAY_SIZE(files)-1; i>=0; i--) {