Author: janderwald Date: Tue May 6 15:51:07 2008 New Revision: 33335
URL: http://svn.reactos.org/svn/reactos?rev=33335&view=rev Log: - fix changing time format garbles the clock output - patch by Carlo Bramix and Alwyn Tar - fix potential buffer overflows by me - bug 2437
Modified: trunk/reactos/dll/cpl/intl/date.c trunk/reactos/dll/cpl/intl/generalp.c trunk/reactos/dll/cpl/intl/misc.c trunk/reactos/dll/cpl/intl/sort.c trunk/reactos/dll/cpl/intl/time.c
Modified: trunk/reactos/dll/cpl/intl/date.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/intl/date.c?rev=333... ============================================================================== --- trunk/reactos/dll/cpl/intl/date.c [iso-8859-1] (original) +++ trunk/reactos/dll/cpl/intl/date.c [iso-8859-1] Tue May 6 15:51:07 2008 @@ -59,8 +59,8 @@ FindDateSep(const TCHAR *szSourceStr) { LPTSTR pszFoundSep; - INT nDateCompCount=0; - INT nDateSepCount=0; + UINT nDateCompCount=0; + UINT nDateSepCount=0;
pszFoundSep = (LPTSTR)malloc(MAX_SAMPLES_STR_SIZE * sizeof(TCHAR));
@@ -418,7 +418,7 @@ SetCalendarInfo(lcid, CAL_GREGORIAN, 48 , /* CAL_ITWODIGITYEARMAX */ - (LPCTSTR)&szMaxDateVal); + (LPCTSTR)szMaxDateVal); }
/* Get max date value from registry set */
Modified: trunk/reactos/dll/cpl/intl/generalp.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/intl/generalp.c?rev... ============================================================================== --- trunk/reactos/dll/cpl/intl/generalp.c [iso-8859-1] (original) +++ trunk/reactos/dll/cpl/intl/generalp.c [iso-8859-1] Tue May 6 15:51:07 2008 @@ -67,7 +67,7 @@ } else { - GetLocaleInfo(lcid, LOCALE_SLANGUAGE, lang, sizeof(lang)); + GetLocaleInfo(lcid, LOCALE_SLANGUAGE, lang, sizeof(lang)/sizeof(TCHAR)); }
if (bNoShow == FALSE) @@ -135,7 +135,7 @@
/* Select current locale */ /* or should it be System and not user? */ - GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SLANGUAGE, langSel, sizeof(langSel)); + GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SLANGUAGE, langSel, sizeof(langSel)/sizeof(TCHAR));
SendMessage(hList, CB_SELECTSTRING, @@ -160,14 +160,14 @@ TCHAR ACPPage[9]; TCHAR OEMPage[9];
- ret = GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_IDEFAULTCODEPAGE, (WORD*)OEMPage, sizeof(OEMPage)); + ret = GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_IDEFAULTCODEPAGE, OEMPage, sizeof(OEMPage)/sizeof(TCHAR)); if (ret == 0) { MessageBox(NULL, _T("Problem reading OEM code page"), _T("Big Problem"), MB_OK); return; }
- GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_IDEFAULTANSICODEPAGE, (WORD*)ACPPage, sizeof(ACPPage)); + ret = GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_IDEFAULTANSICODEPAGE, ACPPage, sizeof(ACPPage)/sizeof(TCHAR)); if (ret == 0) { MessageBox(NULL, _T("Problem reading ANSI code page"), _T("Big Problem"), MB_OK); @@ -305,7 +305,7 @@ continue; }
- if (lResult == (LCID)UnattendLCID) + if (lResult == (LRESULT)UnattendLCID) { SendMessage(hList, CB_SETCURSEL, (WPARAM)lIndex, (LPARAM)0); PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
Modified: trunk/reactos/dll/cpl/intl/misc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/intl/misc.c?rev=333... ============================================================================== --- trunk/reactos/dll/cpl/intl/misc.c [iso-8859-1] (original) +++ trunk/reactos/dll/cpl/intl/misc.c [iso-8859-1] Tue May 6 15:51:07 2008 @@ -47,7 +47,7 @@ LPTSTR pszDestStr; LPTSTR pszTempStr; TCHAR szFmtVal[255]; - INT nFmtCount = 0; + UINT nFmtCount = 0; INT nValCount = 0; INT nLastVal = 0; INT nSpaceOffset = 0; @@ -124,10 +124,10 @@ LPCTSTR szTempl) { LPTSTR szDestStr; - INT nCharCnt; - INT nSubStrCnt; - INT nDestStrCnt; - INT nFirstCharCnt; + UINT nCharCnt; + UINT nSubStrCnt; + UINT nDestStrCnt; + UINT nFirstCharCnt;
szDestStr = (LPTSTR)malloc(MAX_SAMPLES_STR_SIZE * sizeof(TCHAR));
Modified: trunk/reactos/dll/cpl/intl/sort.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/intl/sort.c?rev=333... ============================================================================== --- trunk/reactos/dll/cpl/intl/sort.c [iso-8859-1] (original) +++ trunk/reactos/dll/cpl/intl/sort.c [iso-8859-1] Tue May 6 15:51:07 2008 @@ -64,7 +64,7 @@ if ((LANGIDFROMLCID(lcid) == LANGIDFROMLCID(userLcid)) && (SORTIDFROMLCID(lcid) != SORTIDFROMLCID(userLcid))) { - GetLocaleInfo(lcid, LOCALE_SSORTNAME, lang, sizeof(lang)); + GetLocaleInfo(lcid, LOCALE_SSORTNAME, lang, sizeof(lang)/sizeof(TCHAR));
index = SendMessage(hWndSortList, CB_ADDSTRING, @@ -94,7 +94,7 @@ { /* Add traditional sorting */ GetLocaleInfo(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH), - LOCALE_SSORTNAME, lang, sizeof(lang)); + LOCALE_SSORTNAME, lang, sizeof(lang)/sizeof(TCHAR));
index = SendMessage(hwnd, CB_ADDSTRING, @@ -108,7 +108,7 @@
/* Add modern sorting */ GetLocaleInfo(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_MODERN), - LOCALE_SSORTNAME, lang, sizeof(lang)); + LOCALE_SSORTNAME, lang, sizeof(lang)/sizeof(TCHAR));
index = SendMessage(hwnd, CB_ADDSTRING, @@ -124,7 +124,7 @@ { userLcid = lcid;
- GetLocaleInfo(lcid & 0xFFFF, LOCALE_SSORTNAME, lang, sizeof(lang)); + GetLocaleInfo(lcid & 0xFFFF, LOCALE_SSORTNAME, lang, sizeof(lang)/sizeof(TCHAR));
index = SendMessage(hWndSortList, CB_ADDSTRING,
Modified: trunk/reactos/dll/cpl/intl/time.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/intl/time.c?rev=333... ============================================================================== --- trunk/reactos/dll/cpl/intl/time.c [iso-8859-1] (original) +++ trunk/reactos/dll/cpl/intl/time.c [iso-8859-1] Tue May 6 15:51:07 2008 @@ -27,6 +27,7 @@ #include <commctrl.h> #include <cpl.h> #include <tchar.h> +#include <malloc.h>
#include "intl.h" #include "resource.h" @@ -53,6 +54,36 @@ SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)szBuffer); }
+ +static VOID +GetSelectedComboEntry(HWND hwndDlg, DWORD dwIdc, TCHAR *Buffer, UINT uSize) +{ + int nIndex; + HWND hChildWnd; + + /* get handle to time format control */ + hChildWnd = GetDlgItem(hwndDlg, dwIdc); + /* Get index to selected time format */ + nIndex = SendMessage(hChildWnd, CB_GETCURSEL, 0, 0); + if (nIndex == CB_ERR) + /* no selection? get content of the edit control */ + SendMessage(hChildWnd, WM_GETTEXT, uSize, (LPARAM)Buffer); + else { + LPTSTR tmp; + UINT uReqSize; + + /* get requested size, including the null terminator; + * it shouldn't be required because the previous CB_LIMITTEXT, + * but it would be better to check it anyways */ + uReqSize = SendMessage(hChildWnd, CB_GETLBTEXTLEN, (WPARAM)nIndex, 0) + 1; + /* allocate enought space, to be more safe */ + tmp = (LPTSTR)_alloca(uReqSize*sizeof(TCHAR)); + /* get selected time format text */ + SendMessage(hChildWnd, CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)tmp); + /* finally, copy the result into the output */ + _tcsncpy(Buffer, tmp, uSize); + } +}
/* Property page dialog callback */ INT_PTR CALLBACK @@ -86,7 +117,7 @@ hwndEnum = GetDlgItem(hwndDlg, IDC_TIMEFORMAT); EnumTimeFormats(TimeFormatEnumProc, pGlobalData->lcid, 0);
- GetLocaleInfo(pGlobalData->lcid, LOCALE_STIMEFORMAT, Buffer, 80); + GetLocaleInfo(pGlobalData->lcid, LOCALE_STIMEFORMAT, Buffer, sizeof(Buffer)/sizeof(TCHAR)); SendMessage(GetDlgItem(hwndDlg, IDC_TIMEFORMAT), CB_SELECTSTRING, -1, @@ -95,7 +126,7 @@ /* Get the time separator (max. 4 characters) */ SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR), CB_LIMITTEXT, 4, 0); - GetLocaleInfo(pGlobalData->lcid, LOCALE_STIME, Buffer, 80); + GetLocaleInfo(pGlobalData->lcid, LOCALE_STIME, Buffer, sizeof(Buffer)/sizeof(TCHAR)); SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR), CB_ADDSTRING, 0, @@ -170,49 +201,30 @@ if (lpnm->code == (UINT)PSN_APPLY) { TCHAR Buffer[80]; - int nIndex; + + /* get selected/typed time format text */ + GetSelectedComboEntry(hwndDlg, IDC_TIMEFORMAT, Buffer, sizeof(Buffer)/sizeof(TCHAR));
/* Set time format */ - nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_TIMEFORMAT), - CB_GETCURSEL, 0, 0); - SendMessage(GetDlgItem(hwndDlg, IDC_TIMEFORMAT), - CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)Buffer); SetLocaleInfo(pGlobalData->lcid, LOCALE_STIMEFORMAT, Buffer);
+ /* get selected/typed time separator text */ + GetSelectedComboEntry(hwndDlg, IDC_TIMESEPARATOR, Buffer, sizeof(Buffer)/sizeof(TCHAR)); + /* Set time separator */ - nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR), - CB_GETCURSEL, 0, 0); - SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR), - CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)Buffer); SetLocaleInfo(pGlobalData->lcid, LOCALE_STIME, Buffer);
+ /* get selected/typed AM symbol text */ + GetSelectedComboEntry(hwndDlg, IDC_TIMEAMSYMBOL, Buffer, sizeof(Buffer)/sizeof(TCHAR)); + /* Set the AM symbol */ - nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_TIMEAMSYMBOL), - CB_GETCURSEL, 0, 0); - if (nIndex != CB_ERR) - { - SendMessage(GetDlgItem(hwndDlg, IDC_TIMEAMSYMBOL), - CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)Buffer); - SetLocaleInfo(pGlobalData->lcid, LOCALE_S1159, Buffer); - } - else - { - SetLocaleInfo(pGlobalData->lcid, LOCALE_S1159, _T("")); - } + SetLocaleInfo(pGlobalData->lcid, LOCALE_S1159, Buffer); + + /* get selected/typed PM symbol text */ + GetSelectedComboEntry(hwndDlg, IDC_TIMEPMSYMBOL, Buffer, sizeof(Buffer)/sizeof(TCHAR));
/* Set the PM symbol */ - nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_TIMEPMSYMBOL), - CB_GETCURSEL, 0, 0); - if (nIndex != CB_ERR) - { - SendMessage(GetDlgItem(hwndDlg, IDC_TIMEPMSYMBOL), - CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)Buffer); - SetLocaleInfo(pGlobalData->lcid, LOCALE_S2359, Buffer); - } - else - { - SetLocaleInfo(pGlobalData->lcid, LOCALE_S2359, _T("")); - } + SetLocaleInfo(pGlobalData->lcid, LOCALE_S2359, Buffer);
/* Update the time format sample */ UpdateTimeSample(GetDlgItem(hwndDlg, IDC_TIMESAMPLE), pGlobalData->lcid);