From 9413a1980f8ac94642fd263a7fea2d2d842f93d3 Mon Sep 17 00:00:00 2001 From: Carlo Bramini Date: Sat, 24 Aug 2019 20:50:24 +0200 Subject: [PATCH] hhctrl.ocx: Expand environment vars in file name. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47379 Signed-off-by: Carlo Bramini Signed-off-by: Alexandre Julliard --- dlls/hhctrl.ocx/hhctrl.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/dlls/hhctrl.ocx/hhctrl.c b/dlls/hhctrl.ocx/hhctrl.c index e75716731c3..6a98ae4f2e6 100644 --- a/dlls/hhctrl.ocx/hhctrl.c +++ b/dlls/hhctrl.ocx/hhctrl.c @@ -97,7 +97,7 @@ static const char *command_to_string(UINT command) #undef X } -static BOOL resolve_filename(const WCHAR *filename, WCHAR *fullname, DWORD buflen, WCHAR **index, WCHAR **window) +static BOOL resolve_filename(const WCHAR *env_filename, WCHAR *fullname, DWORD buflen, WCHAR **index, WCHAR **window) { const WCHAR *extra; WCHAR chm_file[MAX_PATH]; @@ -106,12 +106,25 @@ static BOOL resolve_filename(const WCHAR *filename, WCHAR *fullname, DWORD bufle static const WCHAR delimW[] = {':',':',0}; static const WCHAR delim2W[] = {'>',0}; - filename = skip_schema(filename); + DWORD env_len; + WCHAR *filename; + + env_filename = skip_schema(env_filename); /* the format is "helpFile[::/index][>window]" */ if (index) *index = NULL; if (window) *window = NULL; + env_len = ExpandEnvironmentStringsW(env_filename, NULL, 0); + if (!env_len) + return 0; + + filename = heap_alloc(env_len * sizeof(WCHAR)); + if (filename == NULL) + return 0; + + ExpandEnvironmentStringsW(env_filename, filename, env_len); + extra = wcsstr(filename, delim2W); if (extra) { @@ -140,6 +153,9 @@ static BOOL resolve_filename(const WCHAR *filename, WCHAR *fullname, DWORD bufle lstrcatW(fullname, helpW); lstrcatW(fullname, filename); } + + heap_free(filename); + return (GetFileAttributesW(fullname) != INVALID_FILE_ATTRIBUTES); }