diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2017-06-11 14:38:30 +0200 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2017-06-11 17:28:21 +0200 |
commit | 70d083bfb2c5dfb5537c5803aef5c8627c8cb551 (patch) | |
tree | ad6111c01d1583bedcc69b5d6a08c9d259f20583 /src | |
parent | 1662abb707ea1f7e3e8d165a49faf32d4d2d2e39 (diff) | |
download | VeraCrypt-70d083bfb2c5dfb5537c5803aef5c8627c8cb551.tar.gz VeraCrypt-70d083bfb2c5dfb5537c5803aef5c8627c8cb551.zip |
Windows: Add checks on IOCTL_DISK_GET_DRIVE_LAYOUT_EX response to make Coverity happy.
Diffstat (limited to 'src')
-rw-r--r-- | src/Common/Dlgcode.c | 92 |
1 files changed, 48 insertions, 44 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index fbeb5675..af3bec0b 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -11995,62 +11995,66 @@ void UpdateMountableHostDeviceList () (LPVOID) buffer.data(), (DWORD) buffer.size(), (LPDWORD) &bytesReturned, - NULL)) + NULL) && (bytesReturned >= sizeof (DRIVE_LAYOUT_INFORMATION_EX))) { PDRIVE_LAYOUT_INFORMATION_EX layout = (PDRIVE_LAYOUT_INFORMATION_EX) buffer.data(); - for (DWORD i = 0; i < layout->PartitionCount; i++) + // sanity checks + if (layout->PartitionCount <= 256) { - if (layout->PartitionEntry[i].PartitionStyle == PARTITION_STYLE_MBR) + for (DWORD i = 0; i < layout->PartitionCount; i++) { - if (layout->PartitionEntry[i].Mbr.PartitionType == 0) - continue; + if (layout->PartitionEntry[i].PartitionStyle == PARTITION_STYLE_MBR) + { + if (layout->PartitionEntry[i].Mbr.PartitionType == 0) + continue; - bHasPartition = true; + bHasPartition = true; - /* skip dynamic volume */ - if (layout->PartitionEntry[i].Mbr.PartitionType == PARTITION_LDM) - { - bIsDynamic = true; - /* remove any partition that may have been added */ - while (!mountableDevices.empty() && (mountableDevices.back().SystemNumber == It->SystemNumber)) - mountableDevices.pop_back (); - break; + /* skip dynamic volume */ + if (layout->PartitionEntry[i].Mbr.PartitionType == PARTITION_LDM) + { + bIsDynamic = true; + /* remove any partition that may have been added */ + while (!mountableDevices.empty() && (mountableDevices.back().SystemNumber == It->SystemNumber)) + mountableDevices.pop_back (); + break; + } } - } - if (layout->PartitionEntry[i].PartitionStyle == PARTITION_STYLE_GPT) - { - if (IsEqualGUID(layout->PartitionEntry[i].Gpt.PartitionType, PARTITION_ENTRY_UNUSED_GUID)) - continue; + if (layout->PartitionEntry[i].PartitionStyle == PARTITION_STYLE_GPT) + { + if (IsEqualGUID(layout->PartitionEntry[i].Gpt.PartitionType, PARTITION_ENTRY_UNUSED_GUID)) + continue; - bHasPartition = true; + bHasPartition = true; - /* skip dynamic volume */ - if ( IsEqualGUID(layout->PartitionEntry[i].Gpt.PartitionType, PARTITION_LDM_METADATA_GUID) - || IsEqualGUID(layout->PartitionEntry[i].Gpt.PartitionType, PARTITION_LDM_DATA_GUID) - ) - { - bIsDynamic = true; - /* remove any partition that may have been added */ - while (!mountableDevices.empty() && (mountableDevices.back().SystemNumber == It->SystemNumber)) - mountableDevices.pop_back (); - break; + /* skip dynamic volume */ + if ( IsEqualGUID(layout->PartitionEntry[i].Gpt.PartitionType, PARTITION_LDM_METADATA_GUID) + || IsEqualGUID(layout->PartitionEntry[i].Gpt.PartitionType, PARTITION_LDM_DATA_GUID) + ) + { + bIsDynamic = true; + /* remove any partition that may have been added */ + while (!mountableDevices.empty() && (mountableDevices.back().SystemNumber == It->SystemNumber)) + mountableDevices.pop_back (); + break; + } } - } - WCHAR path[MAX_PATH]; - StringCbPrintfW (path, sizeof(path), L"\\\\?\\GLOBALROOT\\Device\\Harddisk%d\\Partition%d", It->SystemNumber, layout->PartitionEntry[i].PartitionNumber); - HANDLE handle = CreateFile( path, - 0, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - 0, - NULL ); - if (handle != INVALID_HANDLE_VALUE) - { - AddDeviceToList (mountableDevices, It->SystemNumber, layout->PartitionEntry[i].PartitionNumber); - CloseHandle (handle); + WCHAR path[MAX_PATH]; + StringCbPrintfW (path, sizeof(path), L"\\\\?\\GLOBALROOT\\Device\\Harddisk%d\\Partition%d", It->SystemNumber, layout->PartitionEntry[i].PartitionNumber); + HANDLE handle = CreateFile( path, + 0, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + 0, + NULL ); + if (handle != INVALID_HANDLE_VALUE) + { + AddDeviceToList (mountableDevices, It->SystemNumber, layout->PartitionEntry[i].PartitionNumber); + CloseHandle (handle); + } } } } |