From: Yuxuan Shui <yshui(a)codeweavers.com> WideCharToMultiByte normally null-terminates the output if input length is -1, but it doesn't do so if the output buffer is too small. --- dlls/dsound/dsound_main.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/dlls/dsound/dsound_main.c b/dlls/dsound/dsound_main.c index bb373a4304d..19e94c1071d 100644 --- a/dlls/dsound/dsound_main.c +++ b/dlls/dsound/dsound_main.c @@ -296,12 +296,22 @@ struct morecontext static BOOL CALLBACK a_to_w_callback(LPGUID guid, LPCWSTR descW, LPCWSTR modW, LPVOID data) { struct morecontext *context = data; - char descA[MAXPNAMELEN], modA[MAXPNAMELEN]; + char *descA, *modA; + DWORD len; + BOOL ret; + + len = WideCharToMultiByte(CP_ACP, 0, descW, -1, NULL, 0, NULL, NULL); + if ((descA = malloc(len))) + WideCharToMultiByte(CP_ACP, 0, descW, -1, descA, len, NULL, NULL); + len = WideCharToMultiByte(CP_ACP, 0, modW, -1, NULL, 0, NULL, NULL); + if ((modA = malloc(len))) + WideCharToMultiByte(CP_ACP, 0, modW, -1, modA, len, NULL, NULL); - WideCharToMultiByte(CP_ACP, 0, descW, -1, descA, sizeof(descA), NULL, NULL); - WideCharToMultiByte(CP_ACP, 0, modW, -1, modA, sizeof(modA), NULL, NULL); + ret = context->callA(guid, descA, modA, context->data); - return context->callA(guid, descA, modA, context->data); + free(descA); + free(modA); + return ret; } /*************************************************************************** -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/8420