• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-cqtcocoa誰得pythonphprubygameguibathyscaphec翻訳計画中(planning stage)omegatframeworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

XKeymacs for 64bit Windows


Commit MetaInfo

Révision4f9498bc998fb84bf0a9da862e4828ae6bd1f668 (tree)
l'heure2011-05-28 16:58:03
AuteurKazuhiro Fujieda <fujieda@user...>
CommiterKazuhiro Fujieda

Message de Log

Use secure versions of library functions.

Change Summary

Modification

--- a/xkeymacs/dotxkeymacs.cpp
+++ b/xkeymacs/dotxkeymacs.cpp
@@ -64,24 +64,25 @@ void CDotXkeymacs::LoadMainData(LPCTSTR lpszFileName)
6464 TCHAR szDir[_MAX_DIR] = {'\0'};
6565
6666 if (GetModuleFileName(NULL, szModuleFileName, sizeof(szModuleFileName))) {
67- _tsplitpath(szModuleFileName, szDrive, szDir, NULL, NULL);
67+ _tsplitpath_s(szModuleFileName, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, NULL, 0, NULL, 0);
6868 }
6969
7070 TCHAR szOldPath[MAX_PATH] = {'\0'}; // This path is used by XKeymacs 3.22 and earlier
71- _tmakepath(szOldPath, szDrive, szDir, lpszFileName, m_szExt);
71+ _tmakepath_s(szOldPath, szDrive, szDir, lpszFileName, m_szExt);
7272
7373 PathAppend(szDir, _T("etc"));
7474 TCHAR szEtc[MAX_PATH] = {'\0'};
75- _tmakepath(szEtc, szDrive, szDir, NULL, NULL);
75+ _tmakepath_s(szEtc, szDrive, szDir, NULL, NULL);
7676 (void)_tmkdir(szEtc); // make etc directory if needed
7777
7878 TCHAR szPath[MAX_PATH] = {'\0'};
79- _tmakepath(szPath, szDrive, szDir, lpszFileName, m_szExt);
79+ _tmakepath_s(szPath, szDrive, szDir, lpszFileName, m_szExt);
8080
8181 if (_trename(szOldPath, szPath)) { // try to move old file as backup when rename returns an error because files exist in both directorys
8282 TCHAR szBackupPath[MAX_PATH] = {'\0'};
8383 TCHAR szBackupFlag[_MAX_FNAME] = _T("~");
84- _tmakepath(szBackupPath, szDrive, szDir, _tcscat(szBackupFlag, lpszFileName), m_szExt);
84+ _tcscat_s(szBackupFlag, lpszFileName);
85+ _tmakepath_s(szBackupPath, szDrive, szDir, szBackupFlag, m_szExt);
8586 (void)_trename(szOldPath, szBackupPath); // do nothing when a backup file has existed already
8687 }
8788
@@ -92,7 +93,7 @@ void CDotXkeymacs::LoadUserData(LPCTSTR lpszFileName)
9293 {
9394 TCHAR szPath[MAX_PATH] = {'\0'};
9495 if (SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, TRUE)) {
95- _tmakepath(szPath, NULL, szPath, lpszFileName, m_szExt);
96+ _tmakepath_s(szPath, NULL, szPath, lpszFileName, m_szExt);
9697 Load(szPath);
9798 }
9899 }
@@ -268,7 +269,10 @@ LPCTSTR CDotXkeymacs::GetLanguage()
268269 LPCTSTR szLanguage = _T("unknown");
269270
270271 TCHAR lptstrFilename[MAX_PATH] = {'\0'};
271- _tmakepath(lptstrFilename, NULL, _tgetenv(_T("windir")), _T("explorer"), _T("exe"));
272+ TCHAR windir[MAX_PATH] = "";
273+ size_t len;
274+ _tgetenv_s(&len, windir, _T("windir"));
275+ _tmakepath_s(lptstrFilename, NULL, windir, _T("explorer"), _T("exe"));
272276 DWORD dwLen = GetFileVersionInfoSize(lptstrFilename, NULL);
273277
274278 if (dwLen) {
--- a/xkeymacs/mainfrm.cpp
+++ b/xkeymacs/mainfrm.cpp
@@ -589,14 +589,14 @@ void CMainFrame::OnHelpFinder()
589589 {
590590 TCHAR szPath[MAX_PATH] = {'\0'};
591591 const TCHAR szExt[] = _T("txt");
592- _tmakepath(szPath, NULL, NULL, CString(MAKEINTRESOURCE(IDS_README)), szExt);
592+ _tmakepath_s(szPath, NULL, NULL, CString(MAKEINTRESOURCE(IDS_README)), szExt);
593593
594594 TCHAR szModuleFileName[MAX_PATH] = {'\0'};
595595 if (GetModuleFileName(NULL, szModuleFileName, sizeof(szModuleFileName))) {
596596 TCHAR szDrive[_MAX_DRIVE] = {'\0'};
597597 TCHAR szDir[_MAX_DIR] = {'\0'};
598- _tsplitpath(szModuleFileName, szDrive, szDir, NULL, NULL);
599- _tmakepath(szPath, szDrive, szDir, CString(MAKEINTRESOURCE(IDS_README)), szExt);
598+ _tsplitpath_s(szModuleFileName, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, NULL, 0, NULL, 0);
599+ _tmakepath_s(szPath, szDrive, szDir, CString(MAKEINTRESOURCE(IDS_README)), szExt);
600600 }
601601
602602 ShellExecute(NULL, NULL, szPath, NULL, NULL, SW_SHOWNORMAL);
--- a/xkeymacs/profile.cpp
+++ b/xkeymacs/profile.cpp
@@ -408,7 +408,7 @@ BOOL CALLBACK CProfile::EnumWindowsProc(const HWND hWnd, const LPARAM lParam)
408408 CComboBox *pApplication = (CComboBox*)lParam;
409409 PTASK_LIST pTask = CProfile::m_TaskList;
410410
411- TCHAR szWindowName[WINDOW_NAME_LENGTH];
411+ TCHAR szWindowName[WINDOW_TEXT_LENGTH];
412412 TCHAR szClassName[CLASS_NAME_LENGTH];
413413 WINDOWPLACEMENT wpl;
414414
--- a/xkeymacsdll/Commands.cpp
+++ b/xkeymacsdll/Commands.cpp
@@ -1787,9 +1787,10 @@ int CCommands::YankPop()
17871787 // M-!: cmd.exe/command.com
17881788 int CCommands::ShellCommand()
17891789 {
1790- if (!CUtils::Run(_tgetenv(_T("XKEYMACS_SHELL")))) {
1791- CUtils::Run(_tgetenv(_T("COMSPEC")));
1792- }
1790+ TCHAR szShell[MAX_PATH];
1791+ size_t len;
1792+ !_tgetenv_s(&len, szShell, _T("XKEYMACS_SHELL")) && len != 0 && CUtils::Run(szShell) ||
1793+ !_tgetenv_s(&len, szShell, _T("COMSPEC")) && len != 0 && CUtils::Run(szShell);
17931794 return Reset(GOTO_HOOK);
17941795 }
17951796
--- a/xkeymacsdll/Utils.cpp
+++ b/xkeymacsdll/Utils.cpp
@@ -205,20 +205,20 @@ void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, LPTSTR szWindo
205205 }
206206
207207 if (*szWindowText == '"' && _tcschr(szWindowText+1, _T('"'))) { // "foo bar" -> foo bar
208- int nApplicationName = _tcschr(szWindowText+1, _T('"')) - szWindowText - 1; // length of "foo bar"
209- _tcsncpy(szWindowText, szWindowText + 1, nApplicationName);
210- memset(szWindowText + nApplicationName, 0, WINDOW_TEXT_LENGTH - nApplicationName);
208+ int len = _tcschr(szWindowText+1, _T('"')) - szWindowText - 1; // length of "foo bar"
209+ memmove(szWindowText, szWindowText + 1, len);
210+ memset(szWindowText + len, 0, WINDOW_TEXT_LENGTH - len);
211211 } else if (_tcschr(szWindowText, _T(' '))) { // foo bar -> foo
212- LPTSTR pFirstSpace = _tcschr(szWindowText, _T(' '));
213- memset(pFirstSpace, 0, WINDOW_TEXT_LENGTH - (pFirstSpace - szWindowText));
212+ LPTSTR p = _tcschr(szWindowText, _T(' '));
213+ memset(p, 0, WINDOW_TEXT_LENGTH - (p - szWindowText));
214214 }
215215
216216 memset(szApplicationName, 0, MAX_PATH);
217- _stprintf(szApplicationName, _T("%s"), szWindowText);
217+ _stprintf_s(szApplicationName, MAX_PATH, _T("%s"), szWindowText);
218218
219219 static LPCTSTR const szExe = _T(".exe");
220220 if (_tcsnicmp(szApplicationName + _tcslen(szApplicationName) - _tcslen(szExe), szExe, _tcslen(szExe))) {
221- _tcscat(szApplicationName, szExe);
221+ _tcscat_s(szApplicationName, MAX_PATH, szExe);
222222 }
223223 }
224224
@@ -240,26 +240,26 @@ void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindow
240240 }
241241
242242 TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};
243- _stprintf(sz, _T("%s%s"), szPromptName[i], szSeparator);
243+ _stprintf_s(sz, _T("%s%s"), szPromptName[i], szSeparator);
244244
245245 if (!_tcsnicmp(szWindowText, sz, _tcslen(sz))) { // "Command Promp - foo"
246- _tcscpy(szWindowText, szWindowText + _tcslen(sz));
246+ _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, szWindowText + _tcslen(sz));
247247 FairConsoleApplicationName(szApplicationName, szWindowText);
248248 return;
249249 }
250250 }
251251
252252 for (i = 0; i < sizeof(szPromptPath) / sizeof(szPromptPath[0]); ++i) {
253- TCHAR szWindowTextLower[WINDOW_TEXT_LENGTH] = {'\0'};
254- _tcscpy(szWindowTextLower, szWindowText);
255- _tcslwr(szWindowTextLower);
253+ TCHAR lower[WINDOW_TEXT_LENGTH] = {'\0'};
254+ _tcscpy_s(lower, szWindowText);
255+ _tcslwr_s(lower);
256256
257- if (_tcsstr(szWindowTextLower, szPromptPath[i])) {
257+ if (_tcsstr(lower, szPromptPath[i])) {
258258 TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};
259- _stprintf(sz, _T("%s%s"), szPromptPath[i], szSeparator);
259+ _stprintf_s(sz, _T("%s%s"), szPromptPath[i], szSeparator);
260260
261- if (_tcsstr(szWindowTextLower, sz)) { // "X:\WINNT\system32\cmd.exe - foo"
262- _tcscpy(szWindowText, _tcsstr(szWindowTextLower, sz) + _tcslen(sz));
261+ if (_tcsstr(lower, sz)) { // "X:\WINNT\system32\cmd.exe - foo"
262+ _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, _tcsstr(lower, sz) + _tcslen(sz));
263263 FairConsoleApplicationName(szApplicationName, szWindowText);
264264 return;
265265 } else { // "X:\WINNT\system32\cmd.exe"
@@ -269,7 +269,7 @@ void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindow
269269 }
270270
271271 LPTSTR newName = NULL, newText = NULL;
272- if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))
272+ if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))
273273 || (*szWindowText == _T('~'))
274274 || (*szWindowText == _T('/'))) { // Bash
275275 newName = _T("bash.exe");
@@ -302,9 +302,9 @@ void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindow
302302 }
303303 if (newName) {
304304 memset(szApplicationName, 0, MAX_PATH);
305- _stprintf(szApplicationName, newName);
305+ _tcscpy_s(szApplicationName, MAX_PATH, newName);
306306 memset(szWindowText, 0, WINDOW_TEXT_LENGTH);
307- _stprintf(szWindowText, newText);
307+ _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, newText);
308308 }
309309 } else if (IsJavaW(szApplicationName)) {
310310 LPTSTR newName = NULL;
@@ -319,7 +319,7 @@ void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindow
319319 }
320320 if (newName) {
321321 memset(szApplicationName, 0, MAX_PATH);
322- _stprintf(szApplicationName, newName);
322+ _tcscpy_s(szApplicationName, MAX_PATH, newName);
323323 }
324324 }
325325 return;
@@ -335,7 +335,7 @@ void CUtils::SetApplicationName(BOOL bImeComposition)
335335 HKL hKL = GetKeyboardLayout(0);
336336 if (ImmIsIME(hKL)) {
337337 if (!ImmGetIMEFileName(hKL, m_szIMEName, sizeof(m_szIMEName))) {
338- _tcsncpy(m_szIMEName, _T("IME"), sizeof(m_szIMEName)); // IDS_IME_FILE_NAME
338+ _tcsncpy_s(m_szIMEName, _T("IME"), _TRUNCATE); // IDS_IME_FILE_NAME
339339 }
340340 // CUtils::Log(_T("SetApplicationName: m_szIMEName == %s"), m_szIMEName);
341341 }
@@ -347,13 +347,13 @@ void CUtils::SetApplicationName(BOOL bImeComposition)
347347 HKL hKL = GetKeyboardLayout(0);
348348 if (ImmIsIME(hKL)) {
349349 if (!ImmGetIMEFileName(hKL, m_szApplicationName, sizeof(m_szApplicationName))) {
350- _tcsncpy(m_szApplicationName, m_szIMEName, sizeof(m_szApplicationName));
350+ _tcsncpy_s(m_szApplicationName, m_szIMEName, _TRUNCATE);
351351 }
352- _tcsncpy(m_szIMEName, m_szApplicationName, sizeof(m_szIMEName));
352+ _tcsncpy_s(m_szIMEName, m_szApplicationName, sizeof(m_szIMEName));
353353 } else {
354354 // ImmIsIME return 0 on Word2002, Excel2002, etc. with IME2002, so...
355355 // _tcsncpy(m_szApplicationName, _T("imjp81.ime"), sizeof(m_szApplicationName));
356- _tcsncpy(m_szApplicationName, m_szIMEName, sizeof(m_szApplicationName));
356+ _tcsncpy_s(m_szApplicationName, m_szIMEName, _TRUNCATE);
357357 }
358358 } else {
359359 // CUtils::Log(_T("SetApplicationName: appication (%s)"), m_szApplicationName);
@@ -362,7 +362,7 @@ void CUtils::SetApplicationName(BOOL bImeComposition)
362362 CString szFn(m_szApplicationName);
363363 szFn.Delete(0, szFn.ReverseFind(_T('\\')) + 1);
364364 ZeroMemory(m_szApplicationName, sizeof(m_szApplicationName));
365- _tcsncpy(m_szApplicationName, szFn, szFn.GetLength());
365+ _tcscpy_s(m_szApplicationName, szFn);
366366
367367 // CUtils::Log(_T("SetApplicationName: appication [%s]"), m_szApplicationName);
368368
@@ -370,7 +370,7 @@ void CUtils::SetApplicationName(BOOL bImeComposition)
370370 // CUtils::Log(_T("SetApplicationName: console"));
371371
372372 memset(m_szApplicationName, 0, sizeof(m_szApplicationName));
373- _tcscpy(m_szApplicationName, _T("CMD.exe"));
373+ _tcscpy_s(m_szApplicationName, _T("CMD.exe"));
374374 TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
375375 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
376376 SetCorrectApplicationName(m_szApplicationName, szWindowText);
@@ -383,7 +383,7 @@ void CUtils::SetApplicationName(BOOL bImeComposition)
383383 // CUtils::Log(_T("SetApplicationName: cygwin"));
384384
385385 memset(m_szApplicationName, 0, sizeof(m_szApplicationName));
386- _tcscpy(m_szApplicationName, _T("bash.exe"));
386+ _tcscpy_s(m_szApplicationName, _T("bash.exe"));
387387 }
388388 // CUtils::Log(_T("name: %s"), m_szApplicationName);
389389 }
@@ -641,13 +641,13 @@ BOOL CUtils::IsConsole()
641641
642642 BOOL CUtils::IsConsole(LPCTSTR szApplicationName)
643643 {
644- return !_tcsnicmp(szApplicationName, _T("WINOA386.MOD"), MAX_PATH)
645- || !_tcsnicmp(szApplicationName, _T("CMD.exe"), MAX_PATH);
644+ return !_tcsicmp(szApplicationName, _T("WINOA386.MOD"))
645+ || !_tcsicmp(szApplicationName, _T("CMD.exe"));
646646 }
647647
648648 BOOL CUtils::IsJavaW(LPCTSTR szApplicationName)
649649 {
650- return !_tcsnicmp(szApplicationName, _T("javaw.exe"), MAX_PATH);
650+ return !_tcsicmp(szApplicationName, _T("javaw.exe"));
651651 }
652652
653653 BOOL CUtils::IsSleipnir()
@@ -671,11 +671,12 @@ void CUtils::Log(LPTSTR fmt, ...)
671671
672672 for (unsigned int nIndex = 0; nIndex < _tcslen(fmt); ) {
673673 LPTSTR pNextString = fmt + nIndex;
674- LPTSTR pLogEnd = szLog + _tcslen(szLog);
674+ int len = _tcslen(szLog);
675+ LPTSTR pLogEnd = szLog + len;
675676
676677 if (*pNextString == _T('%')) {
677678 TCHAR szFormatTag[LOG_MAX] = {'0'};
678- _tcscpy(szFormatTag, pNextString);
679+ _tcscpy_s(szFormatTag, pNextString);
679680
680681 switch (GetFormatTag(szFormatTag)) {
681682 case _T('d'):
@@ -685,36 +686,37 @@ void CUtils::Log(LPTSTR fmt, ...)
685686 case _T('X'):
686687 case _T('u'):
687688 case _T('c'):
688- _stprintf(pLogEnd, szFormatTag, va_arg(ap, int));
689+ _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, int));
689690 break;
690691 case _T('s'):
691- _stprintf(pLogEnd, szFormatTag, va_arg(ap, LPTSTR));
692+ _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, LPTSTR));
692693 break;
693694 case _T('f'):
694695 case _T('e'):
695696 case _T('E'):
696697 case _T('g'):
697698 case _T('G'):
698- _stprintf(pLogEnd, szFormatTag, va_arg(ap, double));
699+ _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, double));
699700 break;
700701 case _T('p'):
701- _stprintf(pLogEnd, szFormatTag, va_arg(ap, void *));
702+ _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, void *));
702703 break;
703704 case _T('n'):
704- _stprintf(pLogEnd, szFormatTag, va_arg(ap, int *));
705+ _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, int *));
705706 break;
706707 case _T('%'):
707708 default:
708- _stprintf(pLogEnd, _T("%s"), szFormatTag);
709+ _stprintf_s(pLogEnd, LOG_MAX - len, _T("%s"), szFormatTag);
709710 break;
710711 }
711712
712713 nIndex += _tcslen(szFormatTag);
713714 } else {
714715 TCHAR szString[LOG_MAX] = {'0'};
715- _tcscpy(szString, pNextString);
716- LPTSTR pString = _tcstok(szString, _T("%"));
717- _stprintf(pLogEnd, _T("%s"), pString);
716+ _tcscpy_s(szString, pNextString);
717+ LPTSTR c;
718+ LPTSTR pString = _tcstok_s(szString, _T("%"), &c);
719+ _stprintf_s(pLogEnd, LOG_MAX - len, _T("%s"), pString);
718720
719721 nIndex += _tcslen(pString);
720722 }
@@ -726,14 +728,15 @@ void CUtils::Log(LPTSTR fmt, ...)
726728 TCHAR szPath[MAX_PATH] = {'\0'};
727729 if (GetTempPath(MAX_PATH, szPath)) {
728730 #ifndef _WIN64
729- _tmakepath(szPath, NULL, szPath, _T("xkeylog"), _T("txt"));
731+ _tmakepath_s(szPath, NULL, szPath, _T("xkeylog"), _T("txt"));
730732 #else
731- _tmakepath(szPath, NULL, szPath, _T("xkeylog64"), _T("txt"));
733+ _tmakepath_s(szPath, NULL, szPath, _T("xkeylog64"), _T("txt"));
732734 #endif
733735 } else {
734- _tcscpy(szPath, _T("c:\\xkeylog.txt"));
736+ _tcscpy_s(szPath, _T("c:\\xkeylog.txt"));
735737 }
736- FILE *fp = _tfopen(szPath, _T("a"));
738+ FILE *fp;
739+ _tfopen_s(&fp, szPath, _T("a"));
737740 _ftprintf(fp, _T("%8d: %s %s\n"), n++, m_szApplicationName, szLog);
738741 fflush(fp);
739742 fclose(fp);
--- a/xkeymacsdll/xkeymacsdll.cpp
+++ b/xkeymacsdll/xkeymacsdll.cpp
@@ -1238,14 +1238,14 @@ void CXkeymacsDll::SetModifierIcons()
12381238
12391239 void CXkeymacsDll::SetApplicationName(int nApplicationID, CString szApplicationName)
12401240 {
1241- ZeroMemory(m_Config.szSpecialApp[nApplicationID], sizeof(m_Config.szSpecialApp[nApplicationID]));
1242- _tcsncpy(m_Config.szSpecialApp[nApplicationID], szApplicationName, sizeof(m_Config.szSpecialApp[nApplicationID]));
1241+ ZeroMemory(m_Config.szSpecialApp[nApplicationID], CLASS_NAME_LENGTH);
1242+ _tcsncpy_s(m_Config.szSpecialApp[nApplicationID], szApplicationName, _TRUNCATE);
12431243 }
12441244
12451245 void CXkeymacsDll::SetWindowText(int nApplicationID, CString szWindowText)
12461246 {
1247- ZeroMemory(m_Config.szWindowText[nApplicationID], sizeof(m_Config.szWindowText[nApplicationID]));
1248- _tcsncpy(m_Config.szWindowText[nApplicationID], szWindowText, sizeof(m_Config.szWindowText[nApplicationID]));
1247+ ZeroMemory(m_Config.szWindowText[nApplicationID], WINDOW_TEXT_LENGTH);
1248+ _tcsncpy_s(m_Config.szWindowText[nApplicationID], szWindowText, _TRUNCATE);
12491249 }
12501250
12511251 void CXkeymacsDll::SetCommandID(int nApplicationID, int nCommandType, int nKey, int nCommandID)
@@ -1694,7 +1694,7 @@ void CXkeymacsDll::SetFunctionDefinition(int nFunctionID, CString szDefinition)
16941694 }
16951695
16961696 memset(m_Config.szFunctionDefinition[nFunctionID], 0, sizeof(m_Config.szFunctionDefinition[nFunctionID]));
1697- _stprintf(m_Config.szFunctionDefinition[nFunctionID], _T("%s"), szDefinition);
1697+ _stprintf_s(m_Config.szFunctionDefinition[nFunctionID], _T("%s"), szDefinition);
16981698
16991699 return;
17001700