Module: wine Branch: master Commit: 884cff821481b4819f9bdba455217bd5a3f97744 URL: https://gitlab.winehq.org/wine/wine/-/commit/884cff821481b4819f9bdba455217bd...
Author: Zhiyi Zhang zzhang@codeweavers.com Date: Thu Jun 29 10:31:34 2023 +0800
kernelbase: Check if locale is NULL before using it in Internal_EnumDateFormats().
Initialize the calendars variable after checking if locale is NULL before using it to avoid NULL pointer references. Fix a Excel 2016 crash when formatting dates with the custom format 'ddd'. It calls EnumDateFormatsExEx() with the 'yi-Hebr' locale, which is added in Win10.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=55099
---
dlls/kernel32/tests/locale.c | 33 +++++++++++++++++++++++++++++++++ dlls/kernelbase/locale.c | 4 +++- 2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/dlls/kernel32/tests/locale.c b/dlls/kernel32/tests/locale.c index 5c99e644f15..bebd857dfa4 100644 --- a/dlls/kernel32/tests/locale.c +++ b/dlls/kernel32/tests/locale.c @@ -8402,6 +8402,36 @@ static void dump_sortkeys( char *argv[] ) fclose( f ); }
+static BOOL CALLBACK EnumDateFormatsExEx_proc(LPWSTR date_format_string, CALID calendar_id, LPARAM lp) +{ + return TRUE; +} + +static void test_EnumDateFormatsExEx(void) +{ + DWORD error; + BOOL ret; + + /* Invalid locale name */ + ret = EnumDateFormatsExEx(EnumDateFormatsExEx_proc, L"deadbeef", DATE_SHORTDATE, 0); + error = GetLastError(); + ok(!ret, "EnumDateFormatsExEx succeeded.\n"); + ok(error == ERROR_INVALID_PARAMETER, "Got unexpected error %#lx.\n", error); + + /* yi-Hebr is missing on versions < Win10 */ + /* Running the following tests will cause other tests that use LOCALE_CUSTOM_UNSPECIFIED to + * report yi-Hebr instead the default locale on Windows 10. So run them at the end */ + ret = EnumDateFormatsExEx(EnumDateFormatsExEx_proc, L"yi-Hebr", DATE_SHORTDATE, 0); + error = GetLastError(); + ok(ret || (!ret && error == ERROR_INVALID_PARAMETER), /* < Win10 */ + "EnumDateFormatsExEx failed, error %#lx.\n", error); + + ret = EnumDateFormatsExEx(EnumDateFormatsExEx_proc, L"yi-Hebr", DATE_LONGDATE, 0); + error = GetLastError(); + ok(ret || (!ret && error == ERROR_INVALID_PARAMETER), /* < Win10 */ + "EnumDateFormatsExEx failed, error %#lx.\n", error); +} + START_TEST(locale) { char **argv; @@ -8473,4 +8503,7 @@ START_TEST(locale) test_EnumCalendarInfoW(); test_EnumCalendarInfoExA(); test_EnumCalendarInfoExW(); + + /* Run this test at the end */ + test_EnumDateFormatsExEx(); } diff --git a/dlls/kernelbase/locale.c b/dlls/kernelbase/locale.c index 45180f4bb8a..e8060fe9205 100644 --- a/dlls/kernelbase/locale.c +++ b/dlls/kernelbase/locale.c @@ -4390,7 +4390,7 @@ BOOL WINAPI DECLSPEC_HOTPATCH Internal_EnumDateFormats( DATEFMT_ENUMPROCW proc, INT i, j, ret; DWORD pos; const struct calendar *cal; - const USHORT *calendars = locale_strings + locale->scalendartype; + const USHORT *calendars; const DWORD *array;
if (!proc || !locale) @@ -4399,6 +4399,8 @@ BOOL WINAPI DECLSPEC_HOTPATCH Internal_EnumDateFormats( DATEFMT_ENUMPROCW proc, return FALSE; }
+ calendars = locale_strings + locale->scalendartype; + switch (flags & ~LOCALE_USE_CP_ACP) { case 0: