diff --git a/src/driver/fortdrv.c b/src/driver/fortdrv.c index e2f75a87..0a4d6011 100644 --- a/src/driver/fortdrv.c +++ b/src/driver/fortdrv.c @@ -40,8 +40,10 @@ static NTSTATUS fort_driver_load(PDRIVER_OBJECT driver, PUNICODE_STRING reg_path ExInitializeDriverRuntime(DrvRtPoolNxOptIn); status = fort_system32_path_init(driver, reg_path); - if (!NT_SUCCESS(status)) + if (!NT_SUCCESS(status)) { + LOG("Driver Path Init: Error: %x\n", status); return status; + } UNICODE_STRING device_name; RtlInitUnicodeString(&device_name, FORT_NT_DEVICE_NAME); @@ -50,13 +52,16 @@ static NTSTATUS fort_driver_load(PDRIVER_OBJECT driver, PUNICODE_STRING reg_path PDEVICE_OBJECT device_obj; status = IoCreateDevice(driver, sizeof(FORT_DEVICE), &device_name, FORT_DEVICE_TYPE, 0, /*exclusive=*/TRUE, &device_obj); - if (!NT_SUCCESS(status)) + if (!NT_SUCCESS(status)) { + LOG("Create Device: Error: %x\n", status); return status; + } device_obj->Flags |= DO_BUFFERED_IO; status = IoRegisterShutdownNotification(device_obj); if (!NT_SUCCESS(status)) { + LOG("Register Shutdown: Error: %x\n", status); fort_driver_delete_device(driver); return status; } @@ -65,8 +70,10 @@ static NTSTATUS fort_driver_load(PDRIVER_OBJECT driver, PUNICODE_STRING reg_path RtlInitUnicodeString(&device_link, FORT_DOS_DEVICE_NAME); status = IoCreateSymbolicLink(&device_link, &device_name); - if (!NT_SUCCESS(status)) + if (!NT_SUCCESS(status)) { + LOG("Create Link: Error: %x\n", status); return status; + } driver->DriverUnload = &fort_driver_unload; driver->MajorFunction[IRP_MJ_CREATE] = &fort_device_create; diff --git a/src/driver/fortutl.c b/src/driver/fortutl.c index 2d607964..f86775b7 100644 --- a/src/driver/fortutl.c +++ b/src/driver/fortutl.c @@ -7,7 +7,7 @@ #define FORT_MAX_FILE_SIZE (4 * 1024 * 1024) #define FORT_KEY_INFO_PATH_SIZE \ - (2 + (MAX_PATH * sizeof(WCHAR)) / sizeof(KEY_VALUE_FULL_INFORMATION)) + (2 * sizeof(KEY_VALUE_FULL_INFORMATION) + (MAX_PATH * sizeof(WCHAR))) static WCHAR g_system32PathBuffer[64]; static UNICODE_STRING g_system32Path; @@ -33,11 +33,15 @@ static NTSTATUS fort_reg_value(HANDLE regKey, PUNICODE_STRING valueName, PUNICOD { NTSTATUS status; - KEY_VALUE_FULL_INFORMATION keyInfo[FORT_KEY_INFO_PATH_SIZE]; - ULONG keyInfoSize; + PKEY_VALUE_FULL_INFORMATION keyInfo = + fort_mem_alloc(FORT_KEY_INFO_PATH_SIZE, FORT_UTL_POOL_TAG); + if (keyInfo == NULL) + return STATUS_INSUFFICIENT_RESOURCES; - status = ZwQueryValueKey( - regKey, valueName, KeyValueFullInformation, keyInfo, sizeof(keyInfo), &keyInfoSize); + ULONG keyInfoSize = 0; + + status = ZwQueryValueKey(regKey, valueName, KeyValueFullInformation, keyInfo, + FORT_KEY_INFO_PATH_SIZE, &keyInfoSize); if (NT_SUCCESS(status)) { const PUCHAR src = ((const PUCHAR) keyInfo + keyInfo->DataOffset); @@ -46,6 +50,8 @@ static NTSTATUS fort_reg_value(HANDLE regKey, PUNICODE_STRING valueName, PUNICOD status = fort_string_new(len, (PCWSTR) src, outData); } + fort_mem_free(keyInfo, FORT_UTL_POOL_TAG); + return status; }