[NTOS:PS]
authorDmitry Chapyshev <dmitry@reactos.org>
Thu, 1 Sep 2016 22:38:25 +0000 (22:38 +0000)
committerDmitry Chapyshev <dmitry@reactos.org>
Thu, 1 Sep 2016 22:38:25 +0000 (22:38 +0000)
- Use ProbeForRead instead ProbeForWrite (ProbeForWrite is a behavior which was in win2000)
- Set returned length after checking buffer size (ntdll_apitest NtQueryInformationProcess has tests only for ProcessTimes, but I checked other cases and always Length is set after check of the size)

* Fixes 4 tests in ntdll_apitest NtQueryInformationProcess (all NtQueryInformationProcess tests passed now)

svn path=/trunk/; revision=72532

reactos/ntoskrnl/ps/query.c

index 3341f40..2c492b6 100644 (file)
@@ -88,9 +88,9 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
         _SEH2_TRY
         {
             /* Probe the buffer */
-            ProbeForWrite(ProcessInformation,
-                          ProcessInformationLength,
-                          sizeof(ULONG));
+            ProbeForRead(ProcessInformation,
+                         ProcessInformationLength,
+                         sizeof(ULONG));
 
             /* Probe the return length if required */
             if (ReturnLength) ProbeForWriteUlong(ReturnLength);
@@ -121,15 +121,15 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
         /* Basic process information */
         case ProcessBasicInformation:
 
-            /* Set return length */
-            Length = sizeof(PROCESS_BASIC_INFORMATION);
-
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(PROCESS_BASIC_INFORMATION))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set return length */
+            Length = sizeof(PROCESS_BASIC_INFORMATION);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -167,13 +167,14 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
         /* Process quota limits */
         case ProcessQuotaLimits:
 
-            Length = sizeof(QUOTA_LIMITS);
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(QUOTA_LIMITS))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            Length = sizeof(QUOTA_LIMITS);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -230,13 +231,14 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
 
         case ProcessIoCounters:
 
-            Length = sizeof(IO_COUNTERS);
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(IO_COUNTERS))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            Length = sizeof(IO_COUNTERS);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -273,14 +275,14 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
         case ProcessTimes:
 
             /* Set the return length */
-            Length = sizeof(KERNEL_USER_TIMES);
-
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(KERNEL_USER_TIMES))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            Length = sizeof(KERNEL_USER_TIMES);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -314,15 +316,15 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
         /* Process Debug Port */
         case ProcessDebugPort:
 
-            /* Set return length */
-            Length = sizeof(HANDLE);
-
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(HANDLE))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set return length */
+            Length = sizeof(HANDLE);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -352,15 +354,15 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
 
         case ProcessHandleCount:
 
-            /* Set the return length*/
-            Length = sizeof(ULONG);
-
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(ULONG))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set the return length*/
+            Length = sizeof(ULONG);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -393,15 +395,15 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
         /* Session ID for the process */
         case ProcessSessionInformation:
 
-            /* Set the return length*/
-            Length = sizeof(PROCESS_SESSION_INFORMATION);
-
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(PROCESS_SESSION_INFORMATION))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set the return length*/
+            Length = sizeof(PROCESS_SESSION_INFORMATION);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -483,15 +485,15 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
         /* Hard Error Processing Mode */
         case ProcessDefaultHardErrorMode:
 
-            /* Set the return length*/
-            Length = sizeof(ULONG);
-
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(ULONG))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set the return length*/
+            Length = sizeof(ULONG);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -522,15 +524,15 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
         /* Priority Boosting status */
         case ProcessPriorityBoost:
 
-            /* Set the return length */
-            Length = sizeof(ULONG);
-
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(ULONG))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set the return length */
+            Length = sizeof(ULONG);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -561,10 +563,7 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
         /* DOS Device Map */
         case ProcessDeviceMap:
 
-            /* Set the return length */
-            Length = sizeof(PROCESS_DEVICEMAP_INFORMATION);
-
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(PROCESS_DEVICEMAP_INFORMATION))
             {
                 if (ProcessInformationLength == sizeof(PROCESS_DEVICEMAP_INFORMATION_EX))
                 {
@@ -578,6 +577,9 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
                 break;
             }
 
+            /* Set the return length */
+            Length = sizeof(PROCESS_DEVICEMAP_INFORMATION);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -609,15 +611,15 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
         /* Priority class */
         case ProcessPriorityClass:
 
-            /* Set the return length*/
-            Length = sizeof(PROCESS_PRIORITY_CLASS);
-
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(PROCESS_PRIORITY_CLASS))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set the return length*/
+            Length = sizeof(PROCESS_PRIORITY_CLASS);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -701,14 +703,15 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
 
         case ProcessDebugFlags:
 
-            /* Set the return length*/
-            Length = sizeof(ULONG);
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(ULONG))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set the return length*/
+            Length = sizeof(ULONG);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -737,14 +740,15 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
 
         case ProcessBreakOnTermination:
 
-            /* Set the return length*/
-            Length = sizeof(ULONG);
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(ULONG))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set the return length */
+            Length = sizeof(ULONG);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -818,15 +822,16 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
 
         case ProcessImageInformation:
 
-            /* Set the length required and validate it */
-            Length = sizeof(SECTION_IMAGE_INFORMATION);
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(SECTION_IMAGE_INFORMATION))
             {
                 /* Break out */
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set the length required and validate it */
+            Length = sizeof(SECTION_IMAGE_INFORMATION);
+
             /* Enter SEH to protect write */
             _SEH2_TRY
             {
@@ -845,14 +850,15 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
 
         case ProcessDebugObjectHandle:
 
-            /* Set the return length */
-            Length = sizeof(HANDLE);
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(HANDLE))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set the return length */
+            Length = sizeof(HANDLE);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -889,14 +895,15 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
 
         case ProcessLUIDDeviceMapsEnabled:
 
-            /* Set the return length */
-            Length = sizeof(ULONG);
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(ULONG))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set the return length */
+            Length = sizeof(ULONG);
+
             /* Indicate success */
             Status = STATUS_SUCCESS;
 
@@ -916,14 +923,15 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
 
         case ProcessWx86Information:
 
-            /* Set the return length */
-            Length = sizeof(ULONG);
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(ULONG))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set the return length */
+            Length = sizeof(ULONG);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -952,15 +960,15 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
 
         case ProcessWow64Information:
 
-            /* Set return length */
-            Length = sizeof(ULONG_PTR);
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(ULONG_PTR))
             {
-                Length = 0;
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set return length */
+            Length = sizeof(ULONG_PTR);
+
             /* Reference the process */
             Status = ObReferenceObjectByHandle(ProcessHandle,
                                                PROCESS_QUERY_INFORMATION,
@@ -1002,14 +1010,15 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
 
         case ProcessExecuteFlags:
 
-            /* Set return length */
-            Length = sizeof(ULONG);
-            if (ProcessInformationLength != Length)
+            if (ProcessInformationLength != sizeof(ULONG))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
             }
 
+            /* Set return length */
+            Length = sizeof(ULONG);
+
             if (ProcessHandle != NtCurrentProcess())
             {
                 return STATUS_INVALID_PARAMETER;