From 762065917f3ac47c3bdcacdb608d35b36dfb3973 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sat, 26 Mar 2022 20:03:19 +0100 Subject: Windows: Add various checks to address Coverity reported issues. --- src/Format/InPlace.c | 2 ++ src/Format/Tcformat.c | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src/Format') diff --git a/src/Format/InPlace.c b/src/Format/InPlace.c index 4a16fd4f..f6166dab 100644 --- a/src/Format/InPlace.c +++ b/src/Format/InPlace.c @@ -89,6 +89,8 @@ static __int64 NewFileSysSizeAfterShrink (HANDLE dev, const wchar_t *devicePath, } if ( (ntfsVolData.NumberSectors.QuadPart <= 0) + || (ntfsVolData.BytesPerSector == 0) + || (ntfsVolData.BytesPerSector >= (DWORD) UINT_MAX) || (ntfsVolData.NumberSectors.QuadPart > (INT64_MAX / (__int64) ntfsVolData.BytesPerSector)) // overflow test ) { diff --git a/src/Format/Tcformat.c b/src/Format/Tcformat.c index 477306ea..efd95caf 100644 --- a/src/Format/Tcformat.c +++ b/src/Format/Tcformat.c @@ -9756,11 +9756,18 @@ int AnalyzeHiddenVolumeHost (HWND hwndDlg, int *driveNo, __int64 hiddenVolHostSi // The map will be scanned to determine the size of the uninterrupted block of free // space (provided there is any) whose end is aligned with the end of the volume. // The value will then be used to determine the maximum possible size of the hidden volume. - - return ScanVolClusterBitmap (hwndDlg, - driveNo, - hiddenVolHostSize / *realClusterSize, - pnbrFreeClusters); + if (*realClusterSize > 0) + { + return ScanVolClusterBitmap (hwndDlg, + driveNo, + hiddenVolHostSize / *realClusterSize, + pnbrFreeClusters); + } + else + { + // should never happen + return -1; + } } else if (!wcsncmp (szFileSystemNameBuffer, L"NTFS", 4) || !_wcsnicmp (szFileSystemNameBuffer, L"exFAT", 5)) { -- cgit v1.2.3