From: Fabian Maurer Subject: [PATCH] ntdll: Expand environment variables when querying them Message-Id: <20190325212840.32251-1-dark.shadow4@web.de> Date: Mon, 25 Mar 2019 22:28:40 +0100 For a test program see the bug report. A test is hard to include since environment variables won't update without a reboot. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46901 Signed-off-by: Fabian Maurer --- dlls/ntdll/env.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dlls/ntdll/env.c b/dlls/ntdll/env.c index 367d083211..e186e3b917 100644 --- a/dlls/ntdll/env.c +++ b/dlls/ntdll/env.c @@ -164,11 +164,16 @@ NTSTATUS WINAPI RtlQueryEnvironmentVariable_U(PWSTR env, var = ENV_FindVariable(var, name->Buffer, namelen); if (var != NULL) { - value->Length = strlenW(var) * sizeof(WCHAR); + WCHAR buffer[UNICODE_STRING_MAX_CHARS]; + SIZE_T len; + RtlExpandEnvironmentStrings(env, (WCHAR *)var, strlenW(var), buffer, ARRAY_SIZE(buffer), &len); + + value->Length = (len - 1) * sizeof(WCHAR); /* Length without '\0' terminator */ if (value->Length <= value->MaximumLength) { - memmove(value->Buffer, var, min(value->Length + sizeof(WCHAR), value->MaximumLength)); + memmove(value->Buffer, buffer, min(value->Length + sizeof(WCHAR), value->MaximumLength)); + nts = STATUS_SUCCESS; } else nts = STATUS_BUFFER_TOO_SMALL; -- 2.21.0