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'.
-- v2: kernelbase: Check if locale is NULL before using it in Internal_EnumDateFormats().
From: Zhiyi Zhang zzhang@codeweavers.com
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 | 20 ++++++++++++++++++++ dlls/kernelbase/locale.c | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/dlls/kernel32/tests/locale.c b/dlls/kernel32/tests/locale.c index 5c99e644f15..83824b86947 100644 --- a/dlls/kernel32/tests/locale.c +++ b/dlls/kernel32/tests/locale.c @@ -8402,6 +8402,25 @@ 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) +{ + BOOL ret; + + /* yi-Hebr is missing on versions < Win10 */ + ret = EnumDateFormatsExEx(EnumDateFormatsExEx_proc, L"yi-Hebr", DATE_SHORTDATE, 0); + ok(ret || (!ret && GetLastError() == ERROR_INVALID_PARAMETER), /* < Win10 */ + "EnumDateFormatsExEx failed, error %#lx.\n", GetLastError()); + + ret = EnumDateFormatsExEx(EnumDateFormatsExEx_proc, L"yi-Hebr", DATE_LONGDATE, 0); + ok(ret || (!ret && GetLastError() == ERROR_INVALID_PARAMETER), /* < Win10 */ + "EnumDateFormatsExEx failed, error %#lx.\n", GetLastError()); +} + START_TEST(locale) { char **argv; @@ -8421,6 +8440,7 @@ START_TEST(locale) test_EnumTimeFormatsA(); test_EnumTimeFormatsW(); test_EnumDateFormatsA(); + test_EnumDateFormatsExEx(); test_GetLocaleInfoA(); test_GetLocaleInfoW(); test_GetLocaleInfoEx(); 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:
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=134335
Your paranoid android.
=== w1064v1507 (32 bit report) ===
kernel32: locale.c:314: Test failed: got 25 with 'Unknown Locale (yi-Hebr)' (expected 24 with 'English (United States)') locale.c:2994: Test failed: got L"yi-Hebr" / L"en-US" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w1064v1809 (32 bit report) ===
kernel32: locale.c:314: Test failed: got 25 with 'Unknown Locale (yi-Hebr)' (expected 24 with 'English (United States)') locale.c:2994: Test failed: got L"yi-Hebr" / L"en-US" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w1064_tsign (32 bit report) ===
kernel32: locale.c:314: Test failed: got 25 with 'Unknown Locale (yi-Hebr)' (expected 24 with 'English (United States)') locale.c:2994: Test failed: got L"yi-Hebr" / L"en-US" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w10pro64 (32 bit report) ===
kernel32: locale.c:314: Test failed: got 25 with 'Unknown Locale (yi-Hebr)' (expected 24 with 'English (United States)') locale.c:2994: Test failed: got L"yi-Hebr" / L"en-US" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w11pro64 (32 bit report) ===
kernel32: locale.c:314: Test failed: got 25 with 'Unknown Locale (yi-Hebr)' (expected 24 with 'English (United States)') locale.c:2994: Test failed: got L"yi-Hebr" / L"en-US" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w1064v1507 (64 bit report) ===
kernel32: locale.c:314: Test failed: got 25 with 'Unknown Locale (yi-Hebr)' (expected 24 with 'English (United States)') locale.c:2994: Test failed: got L"yi-Hebr" / L"en-US" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w1064v1809 (64 bit report) ===
kernel32: locale.c:314: Test failed: got 25 with 'Unknown Locale (yi-Hebr)' (expected 24 with 'English (United States)') locale.c:2994: Test failed: got L"yi-Hebr" / L"en-US" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w1064_2qxl (64 bit report) ===
kernel32: locale.c:314: Test failed: got 25 with 'Unknown Locale (yi-Hebr)' (expected 24 with 'English (United States)') locale.c:2994: Test failed: got L"yi-Hebr" / L"en-US" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w1064_adm (64 bit report) ===
kernel32: locale.c:314: Test failed: got 25 with 'Unknown Locale (yi-Hebr)' (expected 24 with 'English (United States)') locale.c:2994: Test failed: got L"yi-Hebr" / L"en-US" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w1064_tsign (64 bit report) ===
kernel32: locale.c:314: Test failed: got 25 with 'Unknown Locale (yi-Hebr)' (expected 24 with 'English (United States)') locale.c:2994: Test failed: got L"yi-Hebr" / L"en-US" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w10pro64 (64 bit report) ===
kernel32: locale.c:314: Test failed: got 25 with 'Unknown Locale (yi-Hebr)' (expected 24 with 'English (United States)') locale.c:2994: Test failed: got L"yi-Hebr" / L"en-US" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w10pro64_en_AE_u8 (64 bit report) ===
kernel32: locale.c:314: Test failed: got 25 with 'Unknown Locale (yi-Hebr)' (expected 31 with 'English (United Arab Emirates)') locale.c:2994: Test failed: got L"yi-Hebr" / L"en-AE" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w10pro64_ar (64 bit report) ===
kernel32: locale.c:314: Test failed: got 37 with '��������� ����� ��� ������ (yi-Hebr)' (expected 15 with '������� (���)�') locale.c:2994: Test failed: got L"yi-Hebr" / L"ar-EG" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w10pro64_ja (64 bit report) ===
kernel32: locale.c:314: Test failed: got 25 with '�s�������P�[�� (yi-Hebr)' (expected 14 with '���{�� (���{)') locale.c:2994: Test failed: got L"yi-Hebr" / L"ja-JP" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w10pro64_zh_CN (64 bit report) ===
kernel32: locale.c:314: Test failed: got 23 with '������������ (yi-Hebr)' (expected 17 with '����(����������)') locale.c:2994: Test failed: got L"yi-Hebr" / L"zh-CN" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
=== w11pro64_amd (64 bit report) ===
kernel32: locale.c:314: Test failed: got 25 with 'Unknown Locale (yi-Hebr)' (expected 24 with 'English (United States)') locale.c:2994: Test failed: got L"yi-Hebr" / L"en-US" locale.c:3326: Test failed: wrong lcid 0c00 locale.c:4404: Test failed: wrong lcid 0c00
On Fri Jun 30 03:47:57 2023 +0000, Nikolay Sivov wrote:
Could you add a test for how this is called by Excel? Specifically, is it called with actually invalid locale, or is it a valid one that we don't recognize.
It's calling EnumDateFormatsExEx() with the 'yi-Hebr' locale, which is added in Win10. How do I add the locale?