[PATCH 0/3] MR3396: msvcrt: Further locale cleanups.
Fixes a memory leak and cleans up some other parts of MR !3050. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/3396
From: Victor Chiletto <vchiletto(a)codeweavers.com> --- dlls/msvcrt/locale.c | 1 - 1 file changed, 1 deletion(-) diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index 153c4fb1c7d..b14aa73af05 100644 --- a/dlls/msvcrt/locale.c +++ b/dlls/msvcrt/locale.c @@ -244,7 +244,6 @@ typedef struct { WCHAR search_language[MAX_ELEM_LEN]; WCHAR search_country[MAX_ELEM_LEN]; WCHAR found_lang_sname[LOCALE_NAME_MAX_LENGTH]; - DWORD found_codepage; unsigned int match_flags; BOOL allow_sname; } locale_search_t; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/3396
From: Victor Chiletto <vchiletto(a)codeweavers.com> --- dlls/msvcrt/locale.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index b14aa73af05..a24c0c16a48 100644 --- a/dlls/msvcrt/locale.c +++ b/dlls/msvcrt/locale.c @@ -1959,6 +1959,9 @@ static pthreadlocinfo create_locinfo(int category, InterlockedIncrement(&locinfo->lc_time_curr->refcount); } + for (i = 0; i < LC_MAX; i++) + free(locale_sname[i]); + return locinfo; fail: -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/3396
From: Victor Chiletto <vchiletto(a)codeweavers.com> --- dlls/msvcrt/locale.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index a24c0c16a48..1d2edd74704 100644 --- a/dlls/msvcrt/locale.c +++ b/dlls/msvcrt/locale.c @@ -338,11 +338,14 @@ BOOL locale_to_sname(const char *locale, unsigned short *codepage, BOOL *sname_m DWORD locale_cp; if (!strcmp(locale, data->cached_locale)) { + if (sname_size < wcslen(data->cached_sname) + 1) + return FALSE; + if (codepage) *codepage = data->cached_cp; if (sname_match) *sname_match = data->cached_sname_match; - wcsncpy(sname, data->cached_sname, sname_size); + wcscpy(sname, data->cached_sname); return TRUE; } @@ -388,7 +391,10 @@ BOOL locale_to_sname(const char *locale, unsigned short *codepage, BOOL *sname_m if (search.allow_sname && IsValidLocaleName(search.search_language)) { search.match_flags = FOUND_SNAME; - wcsncpy(sname, search.search_language, sname_size); + + if (sname_size < wcslen(search.search_language) + 1) + return FALSE; + wcscpy(sname, search.search_language); } else { @@ -404,7 +410,9 @@ BOOL locale_to_sname(const char *locale, unsigned short *codepage, BOOL *sname_m if (search.search_country[0] && !(search.match_flags & FOUND_COUNTRY)) return FALSE; - wcsncpy(sname, search.found_lang_sname, sname_size); + if (sname_size < wcslen(search.found_lang_sname) + 1) + return FALSE; + wcscpy(sname, search.found_lang_sname); } is_sname = !remapped && (search.match_flags & FOUND_SNAME) != 0; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/3396
Piotr Caban (@piotr) commented about dlls/msvcrt/locale.c:
if (search.allow_sname && IsValidLocaleName(search.search_language)) { search.match_flags = FOUND_SNAME; - wcsncpy(sname, search.search_language, sname_size); + + if (sname_size < wcslen(search.search_language) + 1) + return FALSE; + wcscpy(sname, search.search_language);
Isn't it better to remove sname_size parameter and assume that passed buffer length is LOCALE_NAME_MAX_LENGTH? The size checks should not be needed since locale name always fits into LOCALE_NAME_MAX_LENGTH buffer. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/3396#note_40125
participants (3)
-
Piotr Caban (@piotr) -
Victor Chiletto -
Victor Hermann Chiletto (@vitorhnn)