Author: tfaber
Date: Sat Jan 18 12:35:18 2014
New Revision: 61671
URL:
http://svn.reactos.org/svn/reactos?rev=61671&view=rev
Log:
[RAPPS]
- Use strsafe functions. Welcome to the 21st century...
Modified:
trunk/reactos/base/applications/rapps/available.c
trunk/reactos/base/applications/rapps/installed.c
trunk/reactos/base/applications/rapps/loaddlg.c
trunk/reactos/base/applications/rapps/misc.c
trunk/reactos/base/applications/rapps/parser.c
trunk/reactos/base/applications/rapps/settingsdlg.c
trunk/reactos/base/applications/rapps/winmain.c
Modified: trunk/reactos/base/applications/rapps/available.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/av…
==============================================================================
--- trunk/reactos/base/applications/rapps/available.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/available.c [iso-8859-1] Sat Jan 18 12:35:18
2014
@@ -46,11 +46,16 @@
WCHAR szSearchPath[MAX_PATH];
WCHAR szPath[MAX_PATH];
WCHAR szTmp[MAX_PATH];
+ HRESULT hr;
if (!GetStorageDirectory(szPath, sizeof(szPath) / sizeof(szPath[0])))
return FALSE;
- swprintf(szCabPath, L"%s\\rappmgr.cab", szPath);
+ hr = StringCbPrintfW(szCabPath, sizeof(szCabPath),
+ L"%ls\\rappmgr.cab",
+ szPath);
+ if (FAILED(hr))
+ return FALSE;
if (GetFileAttributesW(szCabPath) != INVALID_FILE_ATTRIBUTES)
{
@@ -58,8 +63,15 @@
return FALSE;
}
- wcscat(szPath, L"\\rapps\\");
- swprintf(szSearchPath, L"%s*.txt", szPath);
+ hr = StringCbCatW(szPath, sizeof(szPath), L"\\rapps\\");
+ if (FAILED(hr))
+ return FALSE;
+
+ hr = StringCbPrintfW(szSearchPath, sizeof(szSearchPath),
+ L"%ls*.txt",
+ szPath);
+ if (FAILED(hr))
+ return FALSE;
hFind = FindFirstFileW(szSearchPath, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
@@ -67,8 +79,10 @@
do
{
- swprintf(szTmp, L"%s%s", szPath, FindFileData.cFileName);
- if (!DeleteFileW(szTmp))
+ hr = StringCbPrintfW(szTmp, sizeof(szTmp),
+ L"%ls%ls",
+ szPath, FindFileData.cFileName);
+ if (FAILED(hr) || !DeleteFileW(szTmp))
{
FindClose(hFind);
return FALSE;
@@ -97,10 +111,19 @@
if (!GetStorageDirectory(szPath, sizeof(szPath) / sizeof(szPath[0])))
return FALSE;
- swprintf(szCabPath, L"%s\\rappmgr.cab", szPath);
-
- wcscat(szPath, L"\\rapps\\");
- wcscpy(szAppsPath, szPath);
+ if (FAILED(StringCbPrintfW(szCabPath, sizeof(szCabPath),
+ L"%ls\\rappmgr.cab",
+ szPath)))
+ {
+ return FALSE;
+ }
+
+ if (FAILED(StringCbPrintfW(szAppsPath, sizeof(szAppsPath),
+ L"%ls\\rapps\\",
+ szPath)))
+ {
+ return FALSE;
+ }
ExtractFilesFromCab(szCabPath, szAppsPath);
@@ -119,16 +142,25 @@
WCHAR szCabPath[MAX_PATH];
WCHAR szLocale[4 + 1];
APPLICATION_INFO Info;
+ HRESULT hr;
if (!GetStorageDirectory(szPath, sizeof(szPath) / sizeof(szPath[0])))
{
return FALSE;
}
- swprintf(szCabPath, L"%s\\rappmgr.cab", szPath);
-
- wcscat(szPath, L"\\rapps\\");
- wcscpy(szAppsPath, szPath);
+ hr = StringCbPrintfW(szCabPath, sizeof(szCabPath),
+ L"%ls\\rappmgr.cab",
+ szPath);
+ if (FAILED(hr))
+ return FALSE;
+
+ hr = StringCbCatW(szPath, sizeof(szPath), L"\\rapps\\");
+ if (FAILED(hr))
+ return FALSE;
+ hr = StringCbCopyW(szAppsPath, sizeof(szAppsPath), szPath);
+ if (FAILED(hr))
+ return FALSE;
if (!CreateDirectory(szPath, NULL) &&
GetLastError() != ERROR_ALREADY_EXISTS)
@@ -137,9 +169,13 @@
}
GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_ILANGUAGE, szLocale, sizeof(szLocale) /
sizeof(WCHAR));
- wcscat(szSectionLocale, szLocale);
-
- wcscat(szPath, L"*.txt");
+ hr = StringCbCatW(szSectionLocale, sizeof(szSectionLocale), szLocale);
+ if (FAILED(hr))
+ return FALSE;
+
+ hr = StringCbCatW(szPath, sizeof(szPath), L"*.txt");
+ if (FAILED(hr))
+ return FALSE;
hFind = FindFirstFileW(szPath, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
Modified: trunk/reactos/base/applications/rapps/installed.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/in…
==============================================================================
--- trunk/reactos/base/applications/rapps/installed.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/installed.c [iso-8859-1] Sat Jan 18 12:35:18
2014
@@ -23,7 +23,7 @@
return TRUE;
}
- wcscpy(lpString, L"---");
+ (VOID)StringCchCopyW(lpString, MAX_PATH, L"---");
return FALSE;
}
Modified: trunk/reactos/base/applications/rapps/loaddlg.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/lo…
==============================================================================
--- trunk/reactos/base/applications/rapps/loaddlg.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/loaddlg.c [iso-8859-1] Sat Jan 18 12:35:18 2014
@@ -232,7 +232,11 @@
}
else
{
- wcscpy(path, SettingsInfo.szDownloadDir);
+ if (FAILED(StringCbCopyW(path, sizeof(path),
+ SettingsInfo.szDownloadDir)))
+ {
+ goto end;
+ }
}
}
else goto end;
@@ -243,8 +247,10 @@
goto end;
}
- wcscat(path, L"\\");
- wcscat(path, p + 1);
+ if (FAILED(StringCbCatW(path, sizeof(path), L"\\")))
+ goto end;
+ if (FAILED(StringCbCatW(path, sizeof(path), p + 1)))
+ goto end;
/* download it */
bTempfile = TRUE;
@@ -353,7 +359,12 @@
APPLICATION_INFO IntInfo;
ZeroMemory(&IntInfo, sizeof(APPLICATION_INFO));
- wcscpy(IntInfo.szUrlDownload, lpUrl);
+ if (FAILED(StringCbCopyW(IntInfo.szUrlDownload,
+ sizeof(IntInfo.szUrlDownload),
+ lpUrl)))
+ {
+ return;
+ }
AppInfo = &IntInfo;
Modified: trunk/reactos/base/applications/rapps/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/mi…
==============================================================================
--- trunk/reactos/base/applications/rapps/misc.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/misc.c [iso-8859-1] Sat Jan 18 12:35:18 2014
@@ -111,18 +111,23 @@
VOID
CopyTextToClipboard(LPCWSTR lpszText)
{
+ HRESULT hr;
+
if(OpenClipboard(NULL))
{
HGLOBAL ClipBuffer;
WCHAR *Buffer;
+ DWORD cchBuffer;
EmptyClipboard();
- ClipBuffer = GlobalAlloc(GMEM_DDESHARE, (wcslen(lpszText) + 1) * sizeof(TCHAR));
+ cchBuffer = wcslen(lpszText) + 1;
+ ClipBuffer = GlobalAlloc(GMEM_DDESHARE, cchBuffer * sizeof(WCHAR));
Buffer = (WCHAR*)GlobalLock(ClipBuffer);
- wcscpy(Buffer, lpszText);
+ hr = StringCchCopyW(Buffer, cchBuffer, lpszText);
GlobalUnlock(ClipBuffer);
- SetClipboardData(CF_UNICODETEXT, ClipBuffer);
+ if (SUCCEEDED(hr))
+ SetClipboardData(CF_UNICODETEXT, ClipBuffer);
CloseClipboard();
}
Modified: trunk/reactos/base/applications/rapps/parser.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/pa…
==============================================================================
--- trunk/reactos/base/applications/rapps/parser.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/parser.c [iso-8859-1] Sat Jan 18 12:35:18 2014
@@ -176,7 +176,8 @@
for ( ; section; section = section->next)
{
- int len = 0;
+ size_t len = 0;
+ size_t remaining;
if (section->name[0]) len += wcslen(section->name) + 4;
@@ -190,28 +191,28 @@
if (!buffer) return;
p = buffer;
+ remaining = len;
if (section->name[0])
{
- *p++ = '[';
- wcscpy(p, section->name);
- p += wcslen(p);
- *p++ = ']';
- *p++ = '\r';
- *p++ = '\n';
+ StringCchPrintfExW(p, remaining, &p, &remaining, 0,
+ L"[%ls]\r\n",
+ section->name);
}
for (key = section->key; key; key = key->next)
{
- wcscpy(p, key->name);
- p += wcslen(p);
if (key->value)
{
- *p++ = '=';
- wcscpy(p, key->value);
- p += wcslen(p);
- }
- *p++ = '\r';
- *p++ = '\n';
+ StringCchPrintfExW(p, remaining, &p, &remaining, 0,
+ L"%ls=%ls\r\n",
+ key->name, key->value);
+ }
+ else
+ {
+ StringCchPrintfExW(p, remaining, &p, &remaining, 0,
+ L"%ls\r\n",
+ key->name);
+ }
}
ParserWriteLine(hFile, buffer, len, encoding);
HeapFree(GetProcessHeap(), 0, buffer);
@@ -434,6 +435,7 @@
*ParserFind(SECTION **section, LPCWSTR section_name, LPCWSTR key_name, BOOL create, BOOL
create_always)
{
LPCWSTR p;
+ DWORD cch;
int seclen, keylen;
while (ParserIsSpace(*section_name)) section_name++;
@@ -474,9 +476,10 @@
}
if (!create)
return NULL;
- if (!(*key = HeapAlloc(GetProcessHeap(), 0, sizeof(SECTIONKEY) +
wcslen(key_name) * sizeof(WCHAR))))
+ cch = wcslen(key_name) + 1;
+ if (!(*key = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(SECTIONKEY, name) +
cch * sizeof(WCHAR))))
return NULL;
- wcscpy((*key)->name, key_name);
+ StringCchCopyW((*key)->name, cch, key_name);
(*key)->value = NULL;
(*key)->next = NULL;
return *key;
@@ -484,17 +487,19 @@
section = &(*section)->next;
}
if (!create) return NULL;
- *section = HeapAlloc(GetProcessHeap(), 0, sizeof(SECTION) + wcslen(section_name) *
sizeof(WCHAR));
+ cch = wcslen(section_name) + 1;
+ *section = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(SECTION, name) + cch *
sizeof(WCHAR));
if(*section == NULL) return NULL;
- wcscpy((*section)->name, section_name);
+ StringCchCopyW((*section)->name, cch, section_name);
(*section)->next = NULL;
+ cch = wcslen(key_name) + 1;
if (!((*section)->key = HeapAlloc(GetProcessHeap(), 0,
- sizeof(SECTIONKEY) + wcslen(key_name) *
sizeof(WCHAR))))
+ FIELD_OFFSET(SECTIONKEY, name) + cch *
sizeof(WCHAR))))
{
HeapFree(GetProcessHeap(), 0, *section);
return NULL;
}
- wcscpy((*section)->key->name, key_name);
+ StringCchCopyW((*section)->key->name, cch, key_name);
(*section)->key->value = NULL;
(*section)->key->next = NULL;
return (*section)->key;
@@ -541,10 +546,10 @@
{
WCHAR szDir[MAX_PATH];
WCHAR buffer[MAX_PATH];
+ DWORD cch;
HANDLE hFile = INVALID_HANDLE_VALUE;
int i, j;
ITEMS *tempProfile;
- static const WCHAR wszSeparator[] = L"\\rapps\\";
if (!CurProfile)
for (i = 0; i < N_CACHED_ITEMS; i++)
@@ -559,9 +564,9 @@
GetStorageDirectory(szDir, sizeof(szDir) / sizeof(szDir[0]));
- wcscpy(buffer, szDir);
- wcscat(buffer, wszSeparator);
- wcscat(buffer, filename);
+ StringCbPrintfW(buffer, sizeof(buffer),
+ L"%ls\\rapps\\%ls",
+ szDir, filename);
hFile = CreateFileW(buffer, GENERIC_READ | (write_access ? GENERIC_WRITE : 0),
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
@@ -605,11 +610,12 @@
if (CurProfile->filename) ParserReleaseFile();
- CurProfile->filename = HeapAlloc(GetProcessHeap(), 0, (wcslen(buffer) + 1) *
sizeof(WCHAR));
+ cch = wcslen(buffer) + 1;
+ CurProfile->filename = HeapAlloc(GetProcessHeap(), 0, cch * sizeof(WCHAR));
if (CurProfile->filename == NULL)
return FALSE;
- wcscpy(CurProfile->filename, buffer);
+ StringCchCopyW(CurProfile->filename, cch, buffer);
if (hFile != INVALID_HANDLE_VALUE)
{
Modified: trunk/reactos/base/applications/rapps/settingsdlg.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/se…
==============================================================================
--- trunk/reactos/base/applications/rapps/settingsdlg.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/settingsdlg.c [iso-8859-1] Sat Jan 18 12:35:18
2014
@@ -113,7 +113,9 @@
if (dwAttr != INVALID_FILE_ATTRIBUTES &&
(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
{
- wcscpy(NewSettingsInfo.szDownloadDir, szDir);
+ StringCbCopyW(NewSettingsInfo.szDownloadDir,
+ sizeof(NewSettingsInfo.szDownloadDir),
+ szDir);
}
else
{
Modified: trunk/reactos/base/applications/rapps/winmain.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/wi…
==============================================================================
--- trunk/reactos/base/applications/rapps/winmain.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/winmain.c [iso-8859-1] Sat Jan 18 12:35:18 2014
@@ -22,7 +22,9 @@
pSettingsInfo->bSaveWndPos = TRUE;
pSettingsInfo->bUpdateAtStart = FALSE;
pSettingsInfo->bLogEnabled = TRUE;
- wcscpy(pSettingsInfo->szDownloadDir, L"C:\\Downloads");
+ StringCbCopyW(pSettingsInfo->szDownloadDir,
+ sizeof(pSettingsInfo->szDownloadDir),
+ L"C:\\Downloads");
pSettingsInfo->bDelInstaller = FALSE;
pSettingsInfo->Maximized = FALSE;
@@ -217,7 +219,9 @@
SelectedEnumType = EnumType;
LoadStringW(hInst, IDS_APPS_COUNT, szBuffer2, sizeof(szBuffer2) / sizeof(WCHAR));
- swprintf(szBuffer1, szBuffer2, ListView_GetItemCount(hListView));
+ StringCbPrintfW(szBuffer1, sizeof(szBuffer1),
+ szBuffer2,
+ ListView_GetItemCount(hListView));
SetStatusBarText(szBuffer1);
SetWelcomeText();
@@ -330,7 +334,9 @@
InitCategoriesList();
LoadStringW(hInst, IDS_APPS_COUNT, szBuffer2, sizeof(szBuffer2) /
sizeof(WCHAR));
- swprintf(szBuffer1, szBuffer2, ListView_GetItemCount(hListView));
+ StringCbPrintfW(szBuffer1, sizeof(szBuffer1),
+ szBuffer2,
+ ListView_GetItemCount(hListView));
SetStatusBarText(szBuffer1);
return TRUE;
}