+ /* Validate output buffer */
+ if (stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(CONSOLE_DRAW))
+ {
+ Status = STATUS_INVALID_PARAMETER;
+ break;
+ }
+ ASSERT(Irp->MdlAddress);
+ pConsoleDraw = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
+ if (pConsoleDraw == NULL)
+ {
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ break;
+ }
+ /* Capture the input info data */
+ ConsoleDraw = *pConsoleDraw;
+
+ /* Check whether we have the size for the header plus the data area */
+ if ((stk->Parameters.DeviceIoControl.OutputBufferLength - sizeof(CONSOLE_DRAW)) / 2
+ < ((ULONG)ConsoleDraw.SizeX * (ULONG)ConsoleDraw.SizeY))
+ {
+ Status = STATUS_INVALID_BUFFER_SIZE;
+ break;
+ }
+
+ // TODO: For the moment if the ConsoleDraw rectangle has borders
+ // out of the screen-buffer we just bail out. Would it be better
+ // to actually clip the rectangle within its borders instead?
+ if ( ConsoleDraw.X < 0 || ConsoleDraw.X >= DeviceExtension->Columns ||
+ ConsoleDraw.Y < 0 || ConsoleDraw.Y >= DeviceExtension->Rows )
+ {
+ Status = STATUS_SUCCESS;
+ break;
+ }
+ if ( ConsoleDraw.SizeX >= DeviceExtension->Columns - ConsoleDraw.X ||
+ ConsoleDraw.SizeY >= DeviceExtension->Rows - ConsoleDraw.Y )
+ {
+ Status = STATUS_SUCCESS;
+ break;
+ }
+