Module: wine Branch: master Commit: 7cd2821d67727b5dff985b482dd838137096c31c URL: https://gitlab.winehq.org/wine/wine/-/commit/7cd2821d67727b5dff985b482dd8381...
Author: Alexandre Julliard julliard@winehq.org Date: Tue Dec 12 11:01:14 2023 +0100
kernelbase: Don't validate calendar id for GetCalendarInfo(CAL_ITWODIGITYEARMAX).
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53845
---
dlls/kernel32/tests/time.c | 18 +++++++++++++++++- dlls/kernelbase/locale.c | 6 +++--- 2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/dlls/kernel32/tests/time.c b/dlls/kernel32/tests/time.c index bb3de483bfd..11feac72db0 100644 --- a/dlls/kernel32/tests/time.c +++ b/dlls/kernel32/tests/time.c @@ -681,7 +681,7 @@ static void test_GetCalendarInfo(void) char bufferA[20]; WCHAR bufferW[20]; DWORD val1, val2; - int ret, ret2; + int i, j, ret, ret2;
if (!pGetCalendarInfoA || !pGetCalendarInfoW) { @@ -744,6 +744,22 @@ static void test_GetCalendarInfo(void) ok( ret2, "GetCalendarInfoW failed err %lu\n", GetLastError() ); ret2 = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL ); ok( ret == ret2, "got %d, expected %d\n", ret, ret2 ); + + for (i = CAL_GREGORIAN; i <= CAL_UMALQURA; i++) + { + WCHAR name[80]; + ret = pGetCalendarInfoW( 0x0409, i, CAL_SCALNAME, name, ARRAY_SIZE(name), NULL); + for (j = CAL_ICALINTVALUE; j <= CAL_SRELATIVELONGDATE; j++) + { + ret2 = pGetCalendarInfoW( 0x0409, i, j, bufferW, ARRAY_SIZE(bufferW), NULL); + if (ret || j == CAL_ITWODIGITYEARMAX) + ok( ret2 || broken(j == CAL_SRELATIVELONGDATE), /* win7 doesn't have this */ + "calendar %u %s value %02x failed\n", i, wine_dbgstr_w(name), j ); + else + ok( !ret2, "calendar %u %s value %02x succeeded %s\n", + i, wine_dbgstr_w(name), j, wine_dbgstr_w(bufferW) ); + } + } }
static void test_GetDynamicTimeZoneInformation(void) diff --git a/dlls/kernelbase/locale.c b/dlls/kernelbase/locale.c index e8060fe9205..44af29f163d 100644 --- a/dlls/kernelbase/locale.c +++ b/dlls/kernelbase/locale.c @@ -552,8 +552,8 @@ static const NLS_LOCALE_DATA *get_locale_data( UINT idx )
static const struct calendar *get_calendar_data( const NLS_LOCALE_DATA *locale, UINT id ) { - if (id == CAL_HIJRI) id = locale->islamic_cal[0]; - else if (id == CAL_PERSIAN) id = locale->islamic_cal[1]; + if (id == CAL_HIJRI && locale->islamic_cal[0]) id = locale->islamic_cal[0]; + else if (id == CAL_PERSIAN && locale->islamic_cal[1]) id = locale->islamic_cal[1];
if (!id || id > locale_table->nb_calendars) return NULL; return (const struct calendar *)((const char *)locale_table + locale_table->calendars_offset + @@ -1617,7 +1617,7 @@ static int get_calendar_info( const NLS_LOCALE_DATA *locale, CALID id, CALTYPE t } else if (len < 0 || value) goto invalid;
- if (id != CAL_GREGORIAN) + if (id != CAL_GREGORIAN && type != CAL_ITWODIGITYEARMAX) { const USHORT *ids = locale_strings + locale->scalendartype; for (i = 0; i < ids[0]; i++) if (ids[1 + i] == id) break;