Commit 884cff82 authored by Zhiyi Zhang's avatar Zhiyi Zhang Committed by Alexandre Julliard

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
parent d8cd320d
......@@ -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();
}
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment