[NTOSKRNL] Use captured variable to check parameters in NtRead/WriteFile
[reactos.git] / ntoskrnl / io / iomgr / iofunc.c
index c344b42..01a9565 100644 (file)
@@ -2621,11 +2621,19 @@ NtReadFile(IN HANDLE FileHandle,
                     return STATUS_INVALID_PARAMETER;
                 }
 
+                /* Fail if buffer doesn't match alignment requirements */
+                if (((ULONG_PTR)Buffer & DeviceObject->AlignmentRequirement) != 0)
+                {
+                    /* Release the file object and and fail */
+                    ObDereferenceObject(FileObject);
+                    return STATUS_INVALID_PARAMETER;
+                }
+
                 if (ByteOffset)
                 {
                     /* Fail if ByteOffset is not sector size aligned */
                     if ((DeviceObject->SectorSize != 0) &&
-                        (ByteOffset->QuadPart % DeviceObject->SectorSize != 0))
+                        (CapturedByteOffset.QuadPart % DeviceObject->SectorSize != 0))
                     {
                         /* Release the file object and and fail */
                         ObDereferenceObject(FileObject);
@@ -3650,15 +3658,29 @@ NtWriteFile(IN HANDLE FileHandle,
                     return STATUS_INVALID_PARAMETER;
                 }
 
+                /* Fail if buffer doesn't match alignment requirements */
+                if (((ULONG_PTR)Buffer & DeviceObject->AlignmentRequirement) != 0)
+                {
+                    /* Release the file object and and fail */
+                    ObDereferenceObject(FileObject);
+                    return STATUS_INVALID_PARAMETER;
+                }
+
                 if (ByteOffset)
                 {
                     /* Fail if ByteOffset is not sector size aligned */
                     if ((DeviceObject->SectorSize != 0) &&
-                        (ByteOffset->QuadPart % DeviceObject->SectorSize != 0))
+                        (CapturedByteOffset.QuadPart % DeviceObject->SectorSize != 0))
                     {
-                        /* Release the file object and and fail */
-                        ObDereferenceObject(FileObject);
-                        return STATUS_INVALID_PARAMETER;
+                        /* Only if that's not specific values for synchronous IO */
+                        if ((CapturedByteOffset.QuadPart != FILE_WRITE_TO_END_OF_FILE) &&
+                            (CapturedByteOffset.QuadPart != FILE_USE_FILE_POINTER_POSITION ||
+                             !BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO)))
+                        {
+                            /* Release the file object and and fail */
+                            ObDereferenceObject(FileObject);
+                            return STATUS_INVALID_PARAMETER;
+                        }
                     }
                 }
             }