Commit bc2b9e3f authored by Vitaliy Margolen's avatar Vitaliy Margolen Committed by Alexandre Julliard

comctl32: Fix invalid date/time check in MCM_SETRANGE: ignore time and fail on bad date.

parent 8aee2f29
...@@ -160,14 +160,10 @@ int MONTHCAL_MonthLength(int month, int year) ...@@ -160,14 +160,10 @@ int MONTHCAL_MonthLength(int month, int year)
/* make sure that time is valid */ /* make sure that time is valid */
static int MONTHCAL_ValidateTime(SYSTEMTIME time) static int MONTHCAL_ValidateTime(SYSTEMTIME time)
{ {
if(time.wMonth > 12) return FALSE; if(time.wMonth < 1 || time.wMonth > 12 ) return FALSE;
if(time.wDayOfWeek > 6) return FALSE; if(time.wDayOfWeek > 6) return FALSE;
if(time.wDay > MONTHCAL_MonthLength(time.wMonth, time.wYear)) if(time.wDay > MONTHCAL_MonthLength(time.wMonth, time.wYear))
return FALSE; return FALSE;
if(time.wHour > 23) return FALSE;
if(time.wMinute > 59) return FALSE;
if(time.wSecond > 59) return FALSE;
if(time.wMilliseconds > 999) return FALSE;
return TRUE; return TRUE;
} }
...@@ -943,29 +939,25 @@ MONTHCAL_GetMaxTodayWidth(MONTHCAL_INFO *infoPtr) ...@@ -943,29 +939,25 @@ MONTHCAL_GetMaxTodayWidth(MONTHCAL_INFO *infoPtr)
static LRESULT static LRESULT
MONTHCAL_SetRange(MONTHCAL_INFO *infoPtr, WPARAM wParam, LPARAM lParam) MONTHCAL_SetRange(MONTHCAL_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{ {
SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *)lParam; SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *)lParam;
int prev; int prev;
TRACE("%x %lx\n", wParam, lParam); TRACE("%x %lx\n", wParam, lParam);
if ((wParam & GDTR_MIN && !MONTHCAL_ValidateTime(lprgSysTimeArray[0])) ||
(wParam & GDTR_MAX && !MONTHCAL_ValidateTime(lprgSysTimeArray[1])))
return FALSE;
if(wParam & GDTR_MAX) { if (wParam & GDTR_MIN)
if(MONTHCAL_ValidateTime(lprgSysTimeArray[1])){ {
MONTHCAL_CopyTime(&lprgSysTimeArray[1], &infoPtr->maxDate); MONTHCAL_CopyTime(&lprgSysTimeArray[0], &infoPtr->minDate);
infoPtr->rangeValid|=GDTR_MAX; infoPtr->rangeValid |= GDTR_MIN;
} else {
GetSystemTime(&infoPtr->todaysDate);
MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
} }
} if (wParam & GDTR_MAX)
if(wParam & GDTR_MIN) { {
if(MONTHCAL_ValidateTime(lprgSysTimeArray[0])) { MONTHCAL_CopyTime(&lprgSysTimeArray[1], &infoPtr->maxDate);
MONTHCAL_CopyTime(&lprgSysTimeArray[0], &infoPtr->minDate); infoPtr->rangeValid |= GDTR_MAX;
infoPtr->rangeValid|=GDTR_MIN;
} else {
GetSystemTime(&infoPtr->todaysDate);
MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->minDate);
} }
}
prev = infoPtr->monthRange; prev = infoPtr->monthRange;
infoPtr->monthRange = infoPtr->maxDate.wMonth - infoPtr->minDate.wMonth; infoPtr->monthRange = infoPtr->maxDate.wMonth - infoPtr->minDate.wMonth;
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
void test_monthcal(void) void test_monthcal(void)
{ {
HWND hwnd; HWND hwnd;
SYSTEMTIME st[2]; SYSTEMTIME st[2], st1[2];
INITCOMMONCONTROLSEX ic = {sizeof(INITCOMMONCONTROLSEX), ICC_DATE_CLASSES}; INITCOMMONCONTROLSEX ic = {sizeof(INITCOMMONCONTROLSEX), ICC_DATE_CLASSES};
InitCommonControlsEx(&ic); InitCommonControlsEx(&ic);
...@@ -39,6 +39,25 @@ void test_monthcal(void) ...@@ -39,6 +39,25 @@ void test_monthcal(void)
0, 300, 300, 0, 0, NULL, NULL); 0, 300, 300, 0, 0, NULL, NULL);
ok(hwnd != NULL, "Failed to create MonthCal\n"); ok(hwnd != NULL, "Failed to create MonthCal\n");
GetSystemTime(&st[0]); GetSystemTime(&st[0]);
st[1] = st[0];
/* Invalid date/time */
st[0].wYear = 2000;
/* Time should not matter */
st[1].wHour = st[1].wMinute = st[1].wSecond = 70;
ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
ok(st1[0].wYear != 2000, "Lover limit changed\n");
st[1].wMonth = 0;
ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Should have failed to set limits\n");
ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
ok(st1[0].wYear != 2000, "Lover limit changed\n");
ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Should have failed to set MAX limit\n");
ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
ok(st1[0].wYear != 2000, "Lover limit changed\n");
GetSystemTime(&st[0]);
st[0].wMonth = 5; st[0].wMonth = 5;
st[1] = st[0]; st[1] = st[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