VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2017-07-29 15:49:30 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2017-07-29 15:54:28 +0200
commit7158e2b0970c38ed0e13ce59219a30ced541770d (patch)
tree9b517b868440233c19d4cab1af87df5cd6e4e0df
parent8288fecc0ad74624f489bbdf3fb71cb1a1fbf286 (diff)
downloadVeraCrypt-7158e2b0970c38ed0e13ce59219a30ced541770d.tar.gz
VeraCrypt-7158e2b0970c38ed0e13ce59219a30ced541770d.zip
Windows Driver: avoid allocating memory for some IOCTL_STORAGE_QUERY_PROPERTY calls that always return fixed size structures.
-rw-r--r--src/Driver/Ntvol.c53
1 files changed, 16 insertions, 37 deletions
diff --git a/src/Driver/Ntvol.c b/src/Driver/Ntvol.c
index 99e06bdf..81549ba1 100644
--- a/src/Driver/Ntvol.c
+++ b/src/Driver/Ntvol.c
@@ -89,7 +89,6 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
LARGE_INTEGER diskLengthInfo;
DISK_GEOMETRY_EX dg;
STORAGE_PROPERTY_QUERY storagePropertyQuery = {0};
- STORAGE_DESCRIPTOR_HEADER storageHeader = {0};
byte* dgBuffer;
ntStatus = IoGetDeviceObjectPointer (&FullFileName,
@@ -127,6 +126,7 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
NTSTATUS lStatus;
storage.Version = sizeof (STORAGE_READ_CAPACITY);
+ storage.Size = sizeof (STORAGE_READ_CAPACITY);
lStatus = TCSendHostDeviceIoControlRequest (DeviceObject, Extension,
IOCTL_STORAGE_READ_CAPACITY,
(char*) &storage, sizeof (STORAGE_READ_CAPACITY));
@@ -150,54 +150,33 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
/* IOCTL_STORAGE_QUERY_PROPERTY supported only on Vista and above */
if (OsMajorVersion >= 6)
{
+ STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR alignmentDesc = {0};
+ STORAGE_ADAPTER_DESCRIPTOR adapterDesc = {0};
+
storagePropertyQuery.PropertyId = StorageAccessAlignmentProperty;
storagePropertyQuery.QueryType = PropertyStandardQuery;
+ alignmentDesc.Version = sizeof (STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR);
+ alignmentDesc.Size = sizeof (STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR);
+
if (NT_SUCCESS (TCSendHostDeviceIoControlRequestEx (DeviceObject, Extension, IOCTL_STORAGE_QUERY_PROPERTY,
(char*) &storagePropertyQuery, sizeof(storagePropertyQuery),
- (char *) &storageHeader, sizeof (storageHeader))))
+ (char *) &alignmentDesc, sizeof (alignmentDesc))))
{
- byte* outputBuffer = TCalloc (storageHeader.Size);
- if (!outputBuffer)
- {
- ntStatus = STATUS_INSUFFICIENT_RESOURCES;
- goto error;
- }
-
- if (NT_SUCCESS (TCSendHostDeviceIoControlRequestEx (DeviceObject, Extension, IOCTL_STORAGE_QUERY_PROPERTY,
- (char*) &storagePropertyQuery, sizeof(storagePropertyQuery),
- outputBuffer, storageHeader.Size)))
- {
- PSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR pStorageDescriptor = (PSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR) outputBuffer;
- Extension->HostBytesPerPhysicalSector = pStorageDescriptor->BytesPerPhysicalSector;
- }
-
- TCfree (outputBuffer);
+ Extension->HostBytesPerPhysicalSector = alignmentDesc.BytesPerPhysicalSector;
}
storagePropertyQuery.PropertyId = StorageAdapterProperty;
+ adapterDesc.Version = sizeof (STORAGE_ADAPTER_DESCRIPTOR);
+ adapterDesc.Size = sizeof (STORAGE_ADAPTER_DESCRIPTOR);
+
if (NT_SUCCESS (TCSendHostDeviceIoControlRequestEx (DeviceObject, Extension, IOCTL_STORAGE_QUERY_PROPERTY,
(char*) &storagePropertyQuery, sizeof(storagePropertyQuery),
- (char *) &storageHeader, sizeof (storageHeader))))
+ (char *) &adapterDesc, sizeof (adapterDesc))))
{
- byte* outputBuffer = TCalloc (storageHeader.Size);
- if (!outputBuffer)
- {
- ntStatus = STATUS_INSUFFICIENT_RESOURCES;
- goto error;
- }
-
- if (NT_SUCCESS (TCSendHostDeviceIoControlRequestEx (DeviceObject, Extension, IOCTL_STORAGE_QUERY_PROPERTY,
- (char*) &storagePropertyQuery, sizeof(storagePropertyQuery),
- outputBuffer, storageHeader.Size)))
- {
- PSTORAGE_ADAPTER_DESCRIPTOR pStorageDescriptor = (PSTORAGE_ADAPTER_DESCRIPTOR) outputBuffer;
- Extension->HostMaximumTransferLength = pStorageDescriptor->MaximumTransferLength;
- Extension->HostMaximumPhysicalPages = pStorageDescriptor->MaximumPhysicalPages;
- Extension->HostAlignmentMask = pStorageDescriptor->AlignmentMask;
- }
-
- TCfree (outputBuffer);
+ Extension->HostMaximumTransferLength = adapterDesc.MaximumTransferLength;
+ Extension->HostMaximumPhysicalPages = adapterDesc.MaximumPhysicalPages;
+ Extension->HostAlignmentMask = adapterDesc.AlignmentMask;
}
}