From c220db01281564bf5b50575ee7e24b38e45f5050 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Mon, 14 Jul 2014 17:41:09 +0200 Subject: Static Code Analysis : Generalize the use of Safe String functions. Add some NULL pointer checks. Avoid false-positive detection in AppendMenu (MF_SEPARATOR) calls by setting the last parameter to "" instead of NULL. --- src/Common/Format.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/Common/Format.c') diff --git a/src/Common/Format.c b/src/Common/Format.c index 25f20acd..ad6be026 100644 --- a/src/Common/Format.c +++ b/src/Common/Format.c @@ -29,6 +29,8 @@ #include "Format/FormatCom.h" #include "Format/Tcformat.h" +#include + int FormatWriteBufferSize = 1024 * 1024; static uint32 FormatSectorSize = 0; @@ -129,8 +131,8 @@ int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams) if (volParams->bDevice) { - strcpy ((char *)deviceName, volParams->volumePath); - ToUNICODE ((char *)deviceName); + StringCbCopyA ((char *)deviceName, sizeof(deviceName), volParams->volumePath); + ToUNICODE ((char *)deviceName, sizeof(deviceName)); driveLetter = GetDiskDeviceDriveLetter (deviceName); } @@ -170,7 +172,7 @@ begin_format: DWORD dwResult; int nPass; - if (FakeDosNameForDevice (volParams->volumePath, dosDev, devName, FALSE) != 0) + if (FakeDosNameForDevice (volParams->volumePath, dosDev, sizeof(dosDev), devName, sizeof(devName), FALSE) != 0) return ERR_OS_ERROR; if (IsDeviceMounted (devName)) @@ -803,10 +805,10 @@ BOOL FormatNtfs (int driveNo, int clusterSize) if (GetSystemDirectory (dllPath, MAX_PATH)) { - strcat(dllPath, "\\fmifs.dll"); + StringCbCatA(dllPath, sizeof(dllPath), "\\fmifs.dll"); } else - strcpy(dllPath, "C:\\Windows\\System32\\fmifs.dll"); + StringCbCopyA(dllPath, sizeof(dllPath), "C:\\Windows\\System32\\fmifs.dll"); hModule = LoadLibrary (dllPath); @@ -819,7 +821,7 @@ BOOL FormatNtfs (int driveNo, int clusterSize) return FALSE; } - wcscat (dir, L":\\"); + StringCbCatW (dir, sizeof(dir), L":\\"); FormatExResult = FALSE; -- cgit v1.2.3