1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 19:08:26 -06:00

Static Code Analysis: Avoid over-flaw in arithmetic operations by adding more checks. Add extra checks. Solve various issues.

This commit is contained in:
Mounir IDRASSI
2015-02-08 23:46:04 +01:00
parent 608e86c7bc
commit d5f34ad49d
6 changed files with 172 additions and 58 deletions

View File

@@ -21,6 +21,7 @@ IMPORTANT: Due to this issue, functions in this file must not directly interact
#include <stdlib.h>
#include <string.h>
#include <string>
#include <intsafe.h>
#include "Tcdefs.h"
#include "Platform/Finally.h"
@@ -71,6 +72,17 @@ static __int64 NewFileSysSizeAfterShrink (HANDLE dev, const char *devicePath, in
return -1;
}
if ( (ntfsVolData.NumberSectors.QuadPart <= 0)
|| (ntfsVolData.NumberSectors.QuadPart > (INT64_MAX / (__int64) ntfsVolData.BytesPerSector)) // overflow test
)
{
SetLastError (ERROR_INTERNAL_ERROR);
if (!silent)
handleWin32Error (MainDlg);
return -1;
}
fileSysSize = ntfsVolData.NumberSectors.QuadPart * ntfsVolData.BytesPerSector;
desiredNbrSectors = (fileSysSize - TC_TOTAL_VOLUME_HEADERS_SIZE) / ntfsVolData.BytesPerSector;