[PATCH 0/2] MR606: msvcp90: Call 'setlocale' before 'mbstowcs_s'
Otherwise 'mbstowcs_s' will make a wrong path if the parameter 'name' contains non-ASCII words in non-ASCII environments. Signed-off-by: YeshunYe <yeyeshun(a)uniontech.com> -- https://gitlab.winehq.org/wine/wine/-/merge_requests/606
From: YeshunYe <yeyeshun(a)uniontech.com> Otherwise 'mbstowcs_s' will make a wrong path if the parameter 'name' contains non-ASCII words in non-ASCII environments. Signed-off-by: YeshunYe <yeyeshun(a)uniontech.com> --- dlls/msvcp90/ios.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dlls/msvcp90/ios.c b/dlls/msvcp90/ios.c index ef2c122f17f..37f23980c4c 100644 --- a/dlls/msvcp90/ios.c +++ b/dlls/msvcp90/ios.c @@ -25,6 +25,7 @@ #include "windef.h" #include "winbase.h" #include "winnls.h" +#include "locale.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(msvcp); @@ -3261,7 +3262,7 @@ FILE* __cdecl _Fiopen(const char *name, int mode, int prot) wchar_t nameW[FILENAME_MAX]; TRACE("(%s %d %d)\n", name, mode, prot); - + setlocale(LC_ALL, ""); if(mbstowcs_s(NULL, nameW, FILENAME_MAX, name, FILENAME_MAX-1) != 0) return NULL; return _Fiopen_wchar(nameW, mode, prot); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/606
From: YeshunYe <yeyeshun(a)uniontech.com> Otherwise 'mbstowcs_s' will make a wrong path if the parameter 'name' contains non-ASCII words in non-ASCII environments. Signed-off-by: YeshunYe <yeyeshun(a)uniontech.com> --- dlls/msvcp60/ios.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dlls/msvcp60/ios.c b/dlls/msvcp60/ios.c index 1fef80f8a43..96e74defe95 100644 --- a/dlls/msvcp60/ios.c +++ b/dlls/msvcp60/ios.c @@ -2127,7 +2127,7 @@ FILE* __cdecl ___Fiopen(const char *name, int mode) wchar_t nameW[FILENAME_MAX]; TRACE("(%p %d)\n", name, mode); - + setlocale(LC_ALL, ""); if(mbstowcs_s(NULL, nameW, FILENAME_MAX, name, FILENAME_MAX-1) != 0) return NULL; return _Fiopen_wchar(nameW, mode, _SH_DENYNO); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/606
I have a demo:[test_ifstream.cpp](/uploads/4a4359d6f70adaa0955c0f8916033d02/test_ifstream.cpp) I built it by 'Visual Studio 2013' on Windows 7. It printed 'read: ok' on Windows 7 but printed 'open file failed!' on wine. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/606#note_5885
Piotr Caban (@piotr) commented about dlls/msvcp60/ios.c:
wchar_t nameW[FILENAME_MAX];
TRACE("(%p %d)\n", name, mode); - + setlocale(LC_ALL, "");
You can't change locale here. It also still fails the test I have attached in last merge request. I was thinking about something like: [0001-msvcp60-Use-MultiByteToWideChar-in-__Fiopen-implementa.txt](/uploads/a8f47e1d09f086e57eeca564029d0a6d/0001-msvcp60-Use-MultiByteToWideChar-in-__Fiopen-implementa.txt) [0002-msvcp90-Use-MultiByteToWideChar-in-_Fiopen-implementat.txt](/uploads/f741c97ea3060a2bef80eea70de6f315/0002-msvcp90-Use-MultiByteToWideChar-in-_Fiopen-implementat.txt) -- https://gitlab.winehq.org/wine/wine/-/merge_requests/606#note_5936
OK, maybe I should set the locale back after call 'mbstowcs_s', but I think it's not thread-safe. You are right, 'MultiByteToWideChar' is a better choice. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/606#note_5994
This merge request was closed by Yeshun Ye. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/606
On Tue Aug 9 17:33:17 2022 +0000, Piotr Caban wrote:
You can't change locale here. It also still fails the test I have attached in last merge request. I was thinking about something like: [0001-msvcp60-Use-MultiByteToWideChar-in-__Fiopen-implementa.txt](/uploads/a8f47e1d09f086e57eeca564029d0a6d/0001-msvcp60-Use-MultiByteToWideChar-in-__Fiopen-implementa.txt) [0002-msvcp90-Use-MultiByteToWideChar-in-_Fiopen-implementat.txt](/uploads/f741c97ea3060a2bef80eea70de6f315/0002-msvcp90-Use-MultiByteToWideChar-in-_Fiopen-implementat.txt) The code: `#if _MSVCP_VER >= 71 && _MSVCP_VER <= 90` Why "_MSVCP_VER >= 71" not "_MSVCP_VER >= 70"?
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/606#note_5995
On Wed Aug 10 02:03:15 2022 +0000, Yeshun Ye wrote:
The code: `#if _MSVCP_VER >= 71 && _MSVCP_VER <= 90` Why "_MSVCP_VER >= 71" not "_MSVCP_VER >= 70"? And why "_MSVCP_VER <= 90" not "_MSVCP_VER <= 140"? The __Fiopen function is a stub in msvcp70. So there's no difference between setting it to `_MSVCP_VER >= 70` or `_MSVCP_VER >= 71` (I didn't test what's the expected behavior with msvcp70 since it's not available on my machine). The `_MSVCP_VER <= 90` check comes from the test I have attached to your last merge request (I had to add more dll versions to the test to validate how each version works).
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/606#note_6017
There's no need to close the MR if patches needs updating. You can force-push updated version. This way all the comments will be preserved. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/606#note_6019
participants (3)
-
Piotr Caban (@piotr) -
Yeshun Ye (@yeyeshun) -
YeshunYe