diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2015-02-08 23:46:04 +0100 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2015-02-09 11:01:21 +0100 |
commit | d5f34ad49d345803767d4a1166d764f9f8485541 (patch) | |
tree | a101ab51e55dffdbcdef4c15596fd9418df421cd /src/Format/InPlace.c | |
parent | 608e86c7bc962f369003d9d05d4402f9da273f0c (diff) | |
download | VeraCrypt-d5f34ad49d345803767d4a1166d764f9f8485541.tar.gz VeraCrypt-d5f34ad49d345803767d4a1166d764f9f8485541.zip |
Static Code Analysis: Avoid over-flaw in arithmetic operations by adding more checks. Add extra checks. Solve various issues.
Diffstat (limited to 'src/Format/InPlace.c')
-rw-r--r-- | src/Format/InPlace.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Format/InPlace.c b/src/Format/InPlace.c index 4c5491e3..3998c2a5 100644 --- a/src/Format/InPlace.c +++ b/src/Format/InPlace.c @@ -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;
|