static NTSTATUS QueryFileInfo( _In_ HANDLE FileHandle, _Out_ PVOID *Info, _Inout_ PSIZE_T Length, _In_ FILE_INFORMATION_CLASS FileInformationClass) { NTSTATUS Status; IO_STATUS_BLOCK IoStatus; PVOID Buffer; *Info = NULL; if (*Length) { Buffer = KmtAllocateGuarded(*Length); if (skip(Buffer != NULL, "Failed to allocate %Iu bytes\n", *Length)) return STATUS_INSUFFICIENT_RESOURCES; } else { Buffer = NULL; } RtlFillMemory(Buffer, *Length, 0xDD); RtlFillMemory(&IoStatus, sizeof(IoStatus), 0x55); _SEH2_TRY { Status = ZwQueryInformationFile(FileHandle, &IoStatus, Buffer, *Length, FileInformationClass); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { Status = _SEH2_GetExceptionCode(); ok(0, "Exception %lx querying class %d with length %Iu\n", Status, FileInformationClass, *Length); } _SEH2_END; if (Status == STATUS_PENDING) { Status = ZwWaitForSingleObject(FileHandle, FALSE, NULL); ok_eq_hex(Status, STATUS_SUCCESS); Status = IoStatus.Status; } *Length = IoStatus.Information; *Info = Buffer; return Status; }
static VOID Test_IoSetDeviceInterface(VOID) { NTSTATUS Status; UNICODE_STRING SymbolicLinkName; PWCHAR Buffer; ULONG BufferSize; /* Invalid prefix or GUID */ KmtStartSeh() Status = IoSetDeviceInterfaceState(NULL, TRUE); KmtEndSeh(STATUS_SUCCESS) ok_eq_hex(Status, STATUS_INVALID_PARAMETER); RtlInitEmptyUnicodeString(&SymbolicLinkName, NULL, 0); KmtStartSeh() Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE); KmtEndSeh(STATUS_SUCCESS) ok_eq_hex(Status, STATUS_INVALID_PARAMETER); RtlInitUnicodeString(&SymbolicLinkName, L"\\??"); KmtStartSeh() Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE); KmtEndSeh(STATUS_SUCCESS) ok_eq_hex(Status, STATUS_INVALID_PARAMETER); RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\"); KmtStartSeh() Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE); KmtEndSeh(STATUS_SUCCESS) ok_eq_hex(Status, STATUS_INVALID_PARAMETER); RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\\\"); KmtStartSeh() Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE); KmtEndSeh(STATUS_SUCCESS) ok_eq_hex(Status, STATUS_INVALID_PARAMETER); RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}"); KmtStartSeh() Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE); KmtEndSeh(STATUS_SUCCESS) ok_eq_hex(Status, STATUS_INVALID_PARAMETER); /* Valid prefix & GUID, invalid device node */ RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\X{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}"); KmtStartSeh() Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE); KmtEndSeh(STATUS_SUCCESS) ok_eq_hex(Status, STATUS_OBJECT_NAME_NOT_FOUND); RtlInitUnicodeString(&SymbolicLinkName, L"\\\\?\\X{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}"); KmtStartSeh() Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE); KmtEndSeh(STATUS_SUCCESS) ok_eq_hex(Status, STATUS_OBJECT_NAME_NOT_FOUND); RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\X{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}\\"); KmtStartSeh() Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE); KmtEndSeh(STATUS_SUCCESS) ok_eq_hex(Status, STATUS_OBJECT_NAME_NOT_FOUND); RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\#{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}"); KmtStartSeh() Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE); KmtEndSeh(STATUS_SUCCESS) ok_eq_hex(Status, STATUS_OBJECT_NAME_NOT_FOUND); /* Must not read past the buffer */ RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\#{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}"); BufferSize = SymbolicLinkName.Length; Buffer = KmtAllocateGuarded(BufferSize); if (!skip(Buffer != NULL, "Failed to allocate %lu bytes\n", BufferSize)) { RtlCopyMemory(Buffer, SymbolicLinkName.Buffer, BufferSize); SymbolicLinkName.Buffer = Buffer; SymbolicLinkName.MaximumLength = BufferSize; KmtStartSeh() Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE); KmtEndSeh(STATUS_SUCCESS) ok_eq_hex(Status, STATUS_OBJECT_NAME_NOT_FOUND); KmtFreeGuarded(Buffer); } RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\#aaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}"); BufferSize = SymbolicLinkName.Length; Buffer = KmtAllocateGuarded(BufferSize); if (!skip(Buffer != NULL, "Failed to allocate %lu bytes\n", BufferSize)) { RtlCopyMemory(Buffer, SymbolicLinkName.Buffer, BufferSize); SymbolicLinkName.Buffer = Buffer; SymbolicLinkName.MaximumLength = BufferSize; KmtStartSeh() Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE); KmtEndSeh(STATUS_SUCCESS) ok_eq_hex(Status, STATUS_INVALID_PARAMETER); KmtFreeGuarded(Buffer); } }