https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6b10706205025a03c56da…
commit 6b10706205025a03c56da9d2f2997d324ed3c71a
Author: Victor Perevertkin <victor(a)perevertkin.ru>
AuthorDate: Sat Aug 17 23:04:41 2019 +0300
Commit: Victor Perevertkin <victor(a)perevertkin.ru>
CommitDate: Tue Aug 20 15:05:47 2019 +0200
[APITESTS] Use StringCbPrintfA instead of sprintf
And fix a buffer size in Test_AddFontResourceA
---
modules/rostests/apitests/advapi32/IsTextUnicode.c | 4 ++--
modules/rostests/apitests/apphelp/layerapi.c | 5 ++--
modules/rostests/apitests/gdi32/AddFontResource.c | 4 ++--
.../apitests/kernel32/GetVolumeInformation.c | 6 ++---
.../apitests/ntdll/RtlDosPathNameToNtPathName_U.c | 7 +++---
.../rostests/apitests/ntdll/RtlGenerate8dot3Name.c | 4 ++--
.../apitests/setupapi/SetupDiInstallClassExA.c | 27 +++++++++++-----------
.../SetupInstallServicesFromInfSectionEx.c | 11 +++++----
8 files changed, 36 insertions(+), 32 deletions(-)
diff --git a/modules/rostests/apitests/advapi32/IsTextUnicode.c
b/modules/rostests/apitests/advapi32/IsTextUnicode.c
index 9bd170cefb8..ba10640ec62 100644
--- a/modules/rostests/apitests/advapi32/IsTextUnicode.c
+++ b/modules/rostests/apitests/advapi32/IsTextUnicode.c
@@ -18,9 +18,9 @@ PVOID LoadCodePageData(ULONG Code)
GetSystemDirectoryA(sysdir, MAX_PATH);
if (Code != -1)
- sprintf(filename, "%s\\c_%lu.nls", sysdir, Code);
+ StringCbPrintfA(filename, sizeof(filename), "%s\\c_%lu.nls", sysdir,
Code);
else
- sprintf(filename, "%s\\l_intl.nls", sysdir);
+ StringCbPrintfA(filename, sizeof(filename), "%s\\l_intl.nls",
sysdir);
hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0,
NULL);
if (hFile != INVALID_HANDLE_VALUE)
diff --git a/modules/rostests/apitests/apphelp/layerapi.c
b/modules/rostests/apitests/apphelp/layerapi.c
index fd443989406..f06457c8c1f 100644
--- a/modules/rostests/apitests/apphelp/layerapi.c
+++ b/modules/rostests/apitests/apphelp/layerapi.c
@@ -17,6 +17,7 @@
#endif
#include <winerror.h>
#include <stdio.h>
+#include <strsafe.h>
#include "wine/test.h"
#include "apitest_iathook.h"
@@ -310,9 +311,9 @@ static void test_SdbGetPermLayerKeys(void)
skip("Skipping tests for HKLM, cannot alter the registry\n");
}
/* Fail from these paths */
- sprintf(tmp, "\\?\\%s", file);
+ StringCbPrintfA(tmp, sizeof(tmp), "\\?\\%s", file);
expect_Sdb(tmp, GPLK_USER, FALSE, 0xffffffff, "");
- sprintf(tmp, "\\??\\%s", file);
+ StringCbPrintfA(tmp, sizeof(tmp), "\\??\\%s", file);
expect_Sdb(tmp, GPLK_USER, FALSE, 0xffffffff, "");
ok(setLayerValue(FALSE, file, "!#!# RUNASADMIN RUNASADMIN !# WINXPSP3
"), "Expected setLayerValue not to fail\n");
diff --git a/modules/rostests/apitests/gdi32/AddFontResource.c
b/modules/rostests/apitests/gdi32/AddFontResource.c
index cee4079d97c..24c8433a73f 100644
--- a/modules/rostests/apitests/gdi32/AddFontResource.c
+++ b/modules/rostests/apitests/gdi32/AddFontResource.c
@@ -11,7 +11,7 @@
void Test_AddFontResourceA()
{
- CHAR szFileNameA[MAX_PATH];
+ CHAR szFileNameA[MAX_PATH*2 + 3];
CHAR szFileNameFont1A[MAX_PATH];
CHAR szFileNameFont2A[MAX_PATH];
int result;
@@ -24,7 +24,7 @@ void Test_AddFontResourceA()
memcpy(szFileNameFont2A,szFileNameA,MAX_PATH );
strcat(szFileNameFont2A, "\\bin\\testdata\\test.otf");
- RtlZeroMemory(szFileNameA,MAX_PATH);
+ RtlZeroMemory(szFileNameA, sizeof(szFileNameA));
/*
* Start testing Ansi version
diff --git a/modules/rostests/apitests/kernel32/GetVolumeInformation.c
b/modules/rostests/apitests/kernel32/GetVolumeInformation.c
index 5184f1c9c3e..8bf96d6ad5e 100644
--- a/modules/rostests/apitests/kernel32/GetVolumeInformation.c
+++ b/modules/rostests/apitests/kernel32/GetVolumeInformation.c
@@ -73,7 +73,7 @@ TestGetVolumeInformationW(VOID)
WCHAR Outbuf[MAX_PATH];
DWORD i, MCL, Flags, Len;
- memset(Outbuf, 0xAA, MAX_PATH);
+ memset(Outbuf, 0xAA, sizeof(Outbuf));
Ret = GetVolumeInformationW(L"C:\\", NULL, 0, NULL, &MCL, &Flags,
Outbuf, MAX_PATH);
ok(Ret != FALSE, "GetVolumeInformationW failed: %ld\n", GetLastError());
for (i = 0; i < MAX_PATH; ++i)
@@ -85,7 +85,7 @@ TestGetVolumeInformationW(VOID)
}
ok(i != MAX_PATH, "String was not null terminated!\n");
- memset(Outbuf, 0xAA, MAX_PATH);
+ memset(Outbuf, 0xAA, sizeof(Outbuf));
Len = i;
Ret = GetVolumeInformationW(L"C:\\", NULL, 0, NULL, &MCL, &Flags,
Outbuf, Len + 1);
ok(Ret != FALSE, "GetVolumeInformationW failed: %ld\n", GetLastError());
@@ -99,7 +99,7 @@ TestGetVolumeInformationW(VOID)
ok(i != MAX_PATH, "String was not null terminated!\n");
ok(i == Len, "String was truncated\n");
- memset(Outbuf, 0xAA, MAX_PATH);
+ memset(Outbuf, 0xAA, sizeof(Outbuf));
Len = i;
SetLastError(0xdeadbeef);
Ret = GetVolumeInformationW(L"C:\\", NULL, 0, NULL, &MCL, &Flags,
Outbuf, Len);
diff --git a/modules/rostests/apitests/ntdll/RtlDosPathNameToNtPathName_U.c
b/modules/rostests/apitests/ntdll/RtlDosPathNameToNtPathName_U.c
index 59a15523c1b..9cbeefeceb3 100644
--- a/modules/rostests/apitests/ntdll/RtlDosPathNameToNtPathName_U.c
+++ b/modules/rostests/apitests/ntdll/RtlDosPathNameToNtPathName_U.c
@@ -57,7 +57,7 @@ typedef struct UNICODE_STRING {
USHORT Length;
USHORT MaximumLength;
PWSTR Buffer;
-} UNICODE_STRING, *PUNICODE_STRING;
+} UNICODE_STRING, *PUNICODE_STRING;
typedef struct _RTLP_CURDIR_REF
{
@@ -207,7 +207,8 @@ typedef struct DirComponents
char szCD[512];
char szCDPlusSlash[512];
char* pszLastCDComponent;
- char szCurDrive[4];
+ char szCurDrive[3];
+ char reserved1;
char szCurDriveSlash[4];
char szParentDir[512];
char szParentDirPlusSlash[512];
@@ -346,7 +347,7 @@ int main()
#endif // PRINT_INFO
DirComponents cd;
- char szTmp[512];
+ char szTmp[518];
#ifndef COMPILE_AS_ROSTEST
InitFunctionPointer();
diff --git a/modules/rostests/apitests/ntdll/RtlGenerate8dot3Name.c
b/modules/rostests/apitests/ntdll/RtlGenerate8dot3Name.c
index 8ea52d0975e..9b606526c9a 100644
--- a/modules/rostests/apitests/ntdll/RtlGenerate8dot3Name.c
+++ b/modules/rostests/apitests/ntdll/RtlGenerate8dot3Name.c
@@ -76,9 +76,9 @@ PVOID LoadCodePageData(ULONG Code)
GetSystemDirectoryA(sysdir, MAX_PATH);
if (Code != -1)
- sprintf(filename, "%s\\c_%lu.nls", sysdir, Code);
+ StringCbPrintfA(filename, sizeof(filename), "%s\\c_%lu.nls", sysdir,
Code);
else
- sprintf(filename, "%s\\l_intl.nls", sysdir);
+ StringCbPrintfA(filename, sizeof(filename), "%s\\l_intl.nls", sysdir);
hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0,
NULL);
if (hFile != INVALID_HANDLE_VALUE)
diff --git a/modules/rostests/apitests/setupapi/SetupDiInstallClassExA.c
b/modules/rostests/apitests/setupapi/SetupDiInstallClassExA.c
index 34c0546ecc5..73bf2739373 100644
--- a/modules/rostests/apitests/setupapi/SetupDiInstallClassExA.c
+++ b/modules/rostests/apitests/setupapi/SetupDiInstallClassExA.c
@@ -25,6 +25,7 @@
#include <winreg.h>
#include <winsvc.h>
#include <setupapi.h>
+#include <strsafe.h>
static const char inffile[] = "test.inf";
static char CURR_DIR[MAX_PATH];
@@ -56,7 +57,7 @@ static void test_SetupDiInstallClassExA(void)
/* [Version]:Signature */
strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
create_inf_file(inffile, inf);
- sprintf(path, "%s\\%s", CURR_DIR, inffile);
+ StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
SetLastError(0xdeadbeef);
ret = SetupDiInstallClassExA(NULL, path, DI_QUIETINSTALL, NULL, NULL, NULL,NULL);
@@ -68,7 +69,7 @@ static void test_SetupDiInstallClassExA(void)
/* [Version]:Signature+Class */
strcat(inf, "Class=MySampleClass\n");
create_inf_file(inffile, inf);
- sprintf(path, "%s\\%s", CURR_DIR, inffile);
+ StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
SetLastError(0xdeadbeef);
ret = SetupDiInstallClassExA(NULL, path, DI_QUIETINSTALL, NULL, NULL, NULL,NULL);
@@ -80,7 +81,7 @@ static void test_SetupDiInstallClassExA(void)
/* [Version]:Signature+Class+ClassGUID */
strcat(inf, "ClassGuid={3b409830-5f9d-432a-abf5-7d2e4e102467}\n");
create_inf_file(inffile, inf);
- sprintf(path, "%s\\%s", CURR_DIR, inffile);
+ StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
SetLastError(0xdeadbeef);
ret = SetupDiInstallClassExA(NULL, path, DI_QUIETINSTALL, NULL, NULL, NULL,NULL);
@@ -92,7 +93,7 @@ static void test_SetupDiInstallClassExA(void)
/* [Version]Signature+Class+ClassGUID;[ClassInstall32.NT]Empty */
strcat(inf, "[ClassInstall32.NT]\n");
create_inf_file(inffile, inf);
- sprintf(path, "%s\\%s", CURR_DIR, inffile);
+ StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
SetLastError(0xdeadbeef);
ret = SetupDiInstallClassExA(NULL, path, DI_QUIETINSTALL, NULL, NULL, NULL,NULL);
@@ -104,13 +105,13 @@ static void test_SetupDiInstallClassExA(void)
{
RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM", 0, KEY_ALL_ACCESS,
&RegHandle);
del = RegDeleteKeyW(RegHandle,
L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
- ok(del == ERROR_SUCCESS, "Expected success \n");
+ ok(del == ERROR_SUCCESS, "Expected success \n");
}
/* [Version]Signature+Class+ClassGUID;[ClassInstall32.NT]AddReg */
strcat(inf, "AddReg=SampleClassAddReg\n");
create_inf_file(inffile, inf);
- sprintf(path, "%s\\%s", CURR_DIR, inffile);
+ StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
SetLastError(0xdeadbeef);
ret = SetupDiInstallClassExA(NULL, path, DI_QUIETINSTALL, NULL, NULL, NULL,NULL);
@@ -122,13 +123,13 @@ static void test_SetupDiInstallClassExA(void)
{
RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM", 0, KEY_ALL_ACCESS,
&RegHandle);
del = RegDeleteKeyW(RegHandle,
L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
- ok(del == ERROR_SUCCESS, "Expected success \n");
+ ok(del == ERROR_SUCCESS, "Expected success \n");
}
/* [Version]Signature+Class+ClassGUID;[ClassInstall32.NT]AddReg;
[SampleClassAddReg];*/
strcat(inf, "[SampleClassAddReg]\n");
create_inf_file(inffile, inf);
- sprintf(path, "%s\\%s", CURR_DIR, inffile);
+ StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
SetLastError(0xdeadbeef);
ret = SetupDiInstallClassExA(NULL, path, DI_QUIETINSTALL, NULL, NULL, NULL,NULL);
@@ -140,13 +141,13 @@ static void test_SetupDiInstallClassExA(void)
{
RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM", 0, KEY_ALL_ACCESS,
&RegHandle);
del = RegDeleteKeyW(RegHandle,
L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
- ok(del == ERROR_SUCCESS, "Expected success \n");
+ ok(del == ERROR_SUCCESS, "Expected success \n");
}
/* [Version]Signature+Class+ClassGUID;[ClassInstall32.NT]AddReg;
[SampleClassAddReg]HKR;*/
strcat(inf, "HKR,,,,\"ReactOS Test SetupDiInstallClassExA\"\n");
create_inf_file(inffile, inf);
- sprintf(path, "%s\\%s", CURR_DIR, inffile);
+ StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
SetLastError(0xdeadbeef);
ret = SetupDiInstallClassExA(NULL, path, DI_QUIETINSTALL, NULL, NULL, NULL,NULL);
@@ -158,13 +159,13 @@ static void test_SetupDiInstallClassExA(void)
{
RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM", 0, KEY_ALL_ACCESS,
&RegHandle);
del = RegDeleteKeyW(RegHandle,
L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
- ok(del == ERROR_SUCCESS, "Expected success \n");
+ ok(del == ERROR_SUCCESS, "Expected success \n");
}
/*[Version]Signature+Class+ClassGUID;[ClassInstall32.NT]AddReg;[SampleClassAddReg]HKR;[ClassInstall32.NT.Services]*/
strcat(inf, "[ClassInstall32.NT.Services]\n");
create_inf_file(inffile, inf);
- sprintf(path, "%s\\%s", CURR_DIR, inffile);
+ StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
SetLastError(0xdeadbeef);
ret = SetupDiInstallClassExA(NULL, path, DI_QUIETINSTALL, NULL, NULL, NULL,NULL);
@@ -176,7 +177,7 @@ static void test_SetupDiInstallClassExA(void)
{
RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM", 0, KEY_ALL_ACCESS,
&RegHandle);
del = RegDeleteKeyW(RegHandle,
L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
- ok(del == ERROR_SUCCESS, "Expected success\n");
+ ok(del == ERROR_SUCCESS, "Expected success\n");
}
/* Add a reference */
diff --git a/modules/rostests/apitests/setupapi/SetupInstallServicesFromInfSectionEx.c
b/modules/rostests/apitests/setupapi/SetupInstallServicesFromInfSectionEx.c
index 4e775c30281..20255faf291 100644
--- a/modules/rostests/apitests/setupapi/SetupInstallServicesFromInfSectionEx.c
+++ b/modules/rostests/apitests/setupapi/SetupInstallServicesFromInfSectionEx.c
@@ -25,6 +25,7 @@
#include <winreg.h>
#include <winsvc.h>
#include <setupapi.h>
+#include <strsafe.h>
static const char inffile[] = "test.inf";
static char CURR_DIR[MAX_PATH];
@@ -72,7 +73,7 @@ static void test_SetupInstallServicesFromInfSectionExA(void)
/* Basic inf file to satisfy SetupOpenInfFileA */
strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
create_inf_file(inffile, inf);
- sprintf(path, "%s\\%s", CURR_DIR, inffile);
+ StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
/* Nothing but the Version section */
@@ -193,7 +194,7 @@ static void test_SetupInstallServicesFromInfSectionExA(void)
strcat(inf, "[XSP.InstallPerVer]\n");
strcat(inf,
"AddReg=AspEventlogMsg.Reg,Perf.Reg,AspVersions.Reg,FreeADO.Reg,IndexServer.Reg\n");
create_inf_file(inffile, inf);
- sprintf(path, "%s\\%s", CURR_DIR, inffile);
+ StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
SetLastError(0xdeadbeef);
@@ -227,7 +228,7 @@ static void test_SetupInstallServicesFromInfSectionExW(void)
/* Basic inf file to satisfy SetupOpenInfFileA */
strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
create_inf_file(inffile, inf);
- sprintf(path, "%s\\%s", CURR_DIR, inffile);
+ StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
/* Nothing but the Version section */
@@ -348,7 +349,7 @@ static void test_SetupInstallServicesFromInfSectionExW(void)
strcat(inf, "[XSP.InstallPerVer]\n");
strcat(inf,
"AddReg=AspEventlogMsg.Reg,Perf.Reg,AspVersions.Reg,FreeADO.Reg,IndexServer.Reg\n");
create_inf_file(inffile, inf);
- sprintf(path, "%s\\%s", CURR_DIR, inffile);
+ StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
SetLastError(0xdeadbeef);
@@ -364,7 +365,7 @@ static void test_SetupInstallServicesFromInfSectionExW(void)
START_TEST(SetupInstallServicesFromInfSectionEx)
{
- char temp_path[MAX_PATH], prev_path[MAX_PATH];
+ char temp_path[MAX_PATH], prev_path[MAX_PATH];
GetCurrentDirectoryA(MAX_PATH, prev_path);
GetTempPathA(MAX_PATH, temp_path);