mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 19:08:26 -06:00
Static Code Analysis : Use Safe string functions inside VeraCrypt Device Driver to avoid potential security issues. Add many checks for NULL pointers to handle low memory use cases.
This commit is contained in:
@@ -30,6 +30,8 @@
|
||||
|
||||
#pragma warning( disable : 4127 )
|
||||
|
||||
#include <Ntstrsafe.h>
|
||||
|
||||
volatile BOOL ProbingHostDeviceForWrite = FALSE;
|
||||
|
||||
|
||||
@@ -380,8 +382,8 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
|
||||
OBJECT_ATTRIBUTES oaParentFileAttributes;
|
||||
LARGE_INTEGER parentKeyDataOffset;
|
||||
|
||||
_snwprintf (parentDrivePath,
|
||||
sizeof (parentDrivePath) / sizeof (WCHAR) - 1,
|
||||
RtlStringCbPrintfW (parentDrivePath,
|
||||
sizeof (parentDrivePath),
|
||||
WIDE ("\\Device\\Harddisk%d\\Partition0"),
|
||||
mount->nPartitionInInactiveSysEncScopeDriveNo);
|
||||
|
||||
@@ -478,6 +480,14 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
|
||||
{
|
||||
/* Volume header successfully decrypted */
|
||||
|
||||
if (!Extension->cryptoInfo)
|
||||
{
|
||||
/* should never happen */
|
||||
mount->nReturnCode = ERR_OUTOFMEMORY;
|
||||
ntStatus = STATUS_SUCCESS;
|
||||
goto error;
|
||||
}
|
||||
|
||||
Dump ("Volume header decrypted\n");
|
||||
Dump ("Required program version = %x\n", (int) Extension->cryptoInfo->RequiredProgramVersion);
|
||||
Dump ("Legacy volume = %d\n", (int) Extension->cryptoInfo->LegacyVolume);
|
||||
@@ -645,14 +655,14 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
|
||||
if (wcsstr (pwszMountVolume, WIDE ("\\??\\UNC\\")) == pwszMountVolume)
|
||||
{
|
||||
/* UNC path */
|
||||
_snwprintf (Extension->wszVolume,
|
||||
sizeof (Extension->wszVolume) / sizeof (WCHAR) - 1,
|
||||
RtlStringCbPrintfW (Extension->wszVolume,
|
||||
sizeof (Extension->wszVolume),
|
||||
WIDE ("\\??\\\\%s"),
|
||||
pwszMountVolume + 7);
|
||||
}
|
||||
else
|
||||
{
|
||||
wcsncpy (Extension->wszVolume, pwszMountVolume, sizeof (Extension->wszVolume) / sizeof (WCHAR) - 1);
|
||||
RtlStringCbCopyW (Extension->wszVolume, sizeof(Extension->wszVolume),pwszMountVolume);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user