Commit 4bddbe8b authored by Vitaliy Margolen's avatar Vitaliy Margolen Committed by Alexandre Julliard

Fix buffer overflow in datetime.

parent 9e3772f6
...@@ -356,7 +356,7 @@ DATETIME_SetFormatW (HWND hwnd, WPARAM wParam, LPARAM lParam) ...@@ -356,7 +356,7 @@ DATETIME_SetFormatW (HWND hwnd, WPARAM wParam, LPARAM lParam)
static void static void
DATETIME_ReturnTxt (DATETIME_INFO *infoPtr, int count, char *result) DATETIME_ReturnTxt (DATETIME_INFO *infoPtr, int count, char *result, int resultSize)
{ {
SYSTEMTIME date = infoPtr->date; SYSTEMTIME date = infoPtr->date;
int spec; int spec;
...@@ -375,7 +375,9 @@ DATETIME_ReturnTxt (DATETIME_INFO *infoPtr, int count, char *result) ...@@ -375,7 +375,9 @@ DATETIME_ReturnTxt (DATETIME_INFO *infoPtr, int count, char *result)
if (spec & DT_STRING) { if (spec & DT_STRING) {
int txtlen=infoPtr->buflen[count]; int txtlen=infoPtr->buflen[count];
strncpy (result, infoPtr->textbuf + (spec &~ DT_STRING), txtlen); if (txtlen > resultSize)
txtlen = resultSize - 1;
memcpy (result, infoPtr->textbuf + (spec &~ DT_STRING), txtlen);
result[txtlen]=0; result[txtlen]=0;
TRACE ("arg%d=%x->[%s]\n",count,infoPtr->fieldspec[count],result); TRACE ("arg%d=%x->[%s]\n",count,infoPtr->fieldspec[count],result);
return; return;
...@@ -399,8 +401,7 @@ DATETIME_ReturnTxt (DATETIME_INFO *infoPtr, int count, char *result) ...@@ -399,8 +401,7 @@ DATETIME_ReturnTxt (DATETIME_INFO *infoPtr, int count, char *result)
break; break;
case FULLDAY: case FULLDAY:
GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SDAYNAME1+ (date.wDayOfWeek+6)%7, GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SDAYNAME1+ (date.wDayOfWeek+6)%7,
buffer,sizeof(buffer)); result, resultSize);
strcpy (result,buffer);
break; break;
case ONEDIGIT12HOUR: case ONEDIGIT12HOUR:
if (date.wHour>12) if (date.wHour>12)
...@@ -440,12 +441,12 @@ DATETIME_ReturnTxt (DATETIME_INFO *infoPtr, int count, char *result) ...@@ -440,12 +441,12 @@ DATETIME_ReturnTxt (DATETIME_INFO *infoPtr, int count, char *result)
break; break;
case THREECHARMONTH: case THREECHARMONTH:
GetLocaleInfoA( GetSystemDefaultLCID(),LOCALE_SMONTHNAME1+date.wMonth -1, GetLocaleInfoA( GetSystemDefaultLCID(),LOCALE_SMONTHNAME1+date.wMonth -1,
buffer,sizeof(buffer)); buffer,sizeof(buffer));
sprintf (result,"%.3s",buffer); sprintf (result,"%.3s",buffer);
break; break;
case FULLMONTH: case FULLMONTH:
GetLocaleInfoA( GetSystemDefaultLCID(),LOCALE_SMONTHNAME1+date.wMonth -1, GetLocaleInfoA( GetSystemDefaultLCID(),LOCALE_SMONTHNAME1+date.wMonth -1,
result,sizeof(result)); result, resultSize);
break; break;
case ONELETTERAMPM: case ONELETTERAMPM:
if (date.wHour<12) if (date.wHour<12)
...@@ -764,7 +765,7 @@ static void DATETIME_Refresh (HWND hwnd, HDC hdc) ...@@ -764,7 +765,7 @@ static void DATETIME_Refresh (HWND hwnd, HDC hdc)
HFONT oldFont; HFONT oldFont;
oldFont = SelectObject (hdc, infoPtr->hFont); oldFont = SelectObject (hdc, infoPtr->hFont);
DATETIME_ReturnTxt (infoPtr, 0, txt); DATETIME_ReturnTxt (infoPtr, 0, txt, sizeof(txt));
GetTextExtentPoint32A (hdc, txt, strlen (txt), &size); GetTextExtentPoint32A (hdc, txt, strlen (txt), &size);
rcDraw->bottom = size.cy+2; rcDraw->bottom = size.cy+2;
...@@ -773,7 +774,7 @@ static void DATETIME_Refresh (HWND hwnd, HDC hdc) ...@@ -773,7 +774,7 @@ static void DATETIME_Refresh (HWND hwnd, HDC hdc)
prevright = checkbox->right; prevright = checkbox->right;
for (i=0; i<infoPtr->nrFields; i++) { for (i=0; i<infoPtr->nrFields; i++) {
DATETIME_ReturnTxt (infoPtr, i, txt); DATETIME_ReturnTxt (infoPtr, i, txt, sizeof(txt));
GetTextExtentPoint32A (hdc, txt, strlen (txt), &size); GetTextExtentPoint32A (hdc, txt, strlen (txt), &size);
field = & infoPtr->fieldRect[i]; field = & infoPtr->fieldRect[i];
field->left = prevright; field->left = prevright;
......
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