ReactOS  0.4.15-dev-3453-gff89651
NtSetInformationProcess.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API tests
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: Tests for the NtSetInformationProcess API
5  * COPYRIGHT: Copyright 2020 George BiČ™oc <george.bisoc@reactos.org>
6  */
7 
8 #include "precomp.h"
9 #include <internal/ps_i.h>
10 
11 static
12 void
14 {
16 
17  /*
18  * Assign a priority of HIGH_PRIORITY (see pstypes.h).
19  * The function will fail with a status of STATUS_PRIVILEGE_NOT_HELD
20  * as the process who executed the caller doesn't have the requested
21  * privileges to perform the operation.
22  */
23  KPRIORITY BasePriority = HIGH_PRIORITY;
24 
25  /* Everything is NULL */
28  NULL,
29  0);
31 
32  /* Set the base priority to an invalid process handle */
35  &BasePriority,
36  sizeof(KPRIORITY));
38 
39  /* Don't input anything to the caller but the length information is valid */
42  NULL,
43  sizeof(KPRIORITY));
45 
46  /* Give the base priority input to the caller but length is invalid */
49  &BasePriority,
50  0);
52 
53  /* The input buffer is misaligned and length information invalid */
56  (PVOID)1,
57  0);
59 
60  /* The input buffer is misaligned */
63  (PVOID)1,
64  sizeof(KPRIORITY));
66 
67  /* The input buffer is misaligned (try with an alignment of 2) */
70  (PVOID)2,
71  sizeof(KPRIORITY));
73 
74  /* Set the base priority but we have lack privileges to do so */
77  &BasePriority,
78  sizeof(KPRIORITY));
80 
81  /*
82  * Assign a random priority value this time and
83  * set the base priority to the current process.
84  */
85  BasePriority = 8;
88  &BasePriority,
89  sizeof(KPRIORITY));
91 }
92 
93 static
94 void
96 {
98 
99  /* Raise the priority as much as possible */
100  ULONG RaisePriority = MAXIMUM_PRIORITY;
101 
102  /* Everything is NULL */
105  NULL,
106  0);
108 
109  /* A invalid handle to process is given */
112  &RaisePriority,
113  sizeof(ULONG));
115 
116  /* The input buffer is misaligned and length information invalid */
119  (PVOID)1,
120  0);
122 
123  /* A NULL buffer has been accessed */
126  NULL,
127  sizeof(ULONG));
129 
130  /* The input buffer is misaligned */
133  (PVOID)1,
134  sizeof(ULONG));
136 
137  /* The input buffer is misaligned -- try with an alignment size of 2 */
140  (PVOID)2,
141  sizeof(ULONG));
143 
144  /* Raise the priority of the given current process */
147  &RaisePriority,
148  sizeof(ULONG));
150 }
151 
152 static
153 void
155 {
157  PPROCESS_FOREGROUND_BACKGROUND ProcForeground;
158 
160  if (ProcForeground == NULL)
161  {
162  skip("Failed to allocate memory block from heap for PROCESS_FOREGROUND_BACKGROUND!\n");
163  return;
164  }
165 
166  /* As a test, set the foreground of the retrieved current process to FALSE */
167  ProcForeground->Foreground = FALSE;
168 
169  /* Set everything NULL for the caller */
172  NULL,
173  0);
175 
176  /* Give an invalid process handle (but the input buffer and length are correct) */
179  ProcForeground,
182 
183  /* Give a buffer data to the argument input as NULL */
186  NULL,
189 
190  /* Set the information process foreground with an incorrect buffer alignment and zero buffer length */
193  (PVOID)1,
194  0);
196 
197  /*
198  * Set the information process foreground with an incorrect buffer alignment but correct size length.
199  * The function will return STATUS_ACCESS_VIOLATION as the alignment probe requirement is not performed
200  * in this class.
201  */
204  (PVOID)1,
207 
208  /* Set the foreground information to the current given process, we must expect the function should succeed */
211  ProcForeground,
214 
215  /* Clear all the stuff */
216  HeapFree(GetProcessHeap(), 0, ProcForeground);
217 }
218 
219 static
220 void
222 {
224  ULONG VdmPower = 1;
225 
226  /* Everything is NULL */
229  NULL,
230  0);
232 
233  /* Don't set anything to the process */
236  NULL,
237  sizeof(VdmPower));
239 
240  /* The buffer is misaligned and information length is wrong */
243  (PVOID)1,
244  0);
246 
247  /* The buffer is misaligned */
250  (PVOID)1,
251  sizeof(VdmPower));
253 
254  /* The buffer is misaligned -- try with an alignment size of 2 */
257  (PVOID)2,
258  sizeof(VdmPower));
260 
261  /* We do not have privileges to set the VDM power */
264  &VdmPower,
265  sizeof(VdmPower));
267 }
268 
269 static
270 void
272 {
273  ULONG InfoClass;
274 
275  /* Iterate over the process info classes and begin the tests */
276  for (InfoClass = 0; InfoClass < _countof(PsProcessInfoClass); InfoClass++)
277  {
278  /* The buffer is misaligned */
280  InfoClass,
281  (PVOID)(ULONG_PTR)1,
282  PsProcessInfoClass[InfoClass].RequiredSizeSET,
284 
285  /* We set an invalid buffer address */
287  InfoClass,
288  (PVOID)(ULONG_PTR)PsProcessInfoClass[InfoClass].AlignmentSET,
289  PsProcessInfoClass[InfoClass].RequiredSizeSET,
291 
292  /* The information length is wrong */
294  InfoClass,
295  (PVOID)(ULONG_PTR)PsProcessInfoClass[InfoClass].AlignmentSET,
296  PsProcessInfoClass[InfoClass].RequiredSizeSET - 1,
298  }
299 }
300 
302 {
308 }
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define SET(field, seg, reg)
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
LONG NTSTATUS
Definition: precomp.h:26
#define ok_hex(expression, result)
Definition: atltest.h:94
LONG KPRIORITY
Definition: compat.h:662
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
static void Test_ProcSetAlignmentProbe(void)
static void Test_ProcForegroundBackgroundClass(void)
#define HIGH_PRIORITY
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define MAXIMUM_PRIORITY
Status
Definition: gdiplustypes.h:24
VOID QuerySetProcessValidator(_In_ ALIGNMENT_PROBE_MODE ValidationMode, _In_ ULONG InfoClassIndex, _In_ PVOID InfoPointer, _In_ ULONG InfoLength, _In_ NTSTATUS ExpectedStatus)
Definition: probelib.c:12
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define _countof(array)
Definition: sndvol32.h:68
static void Test_ProcRaisePriorityClass(void)
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1105
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define skip(...)
Definition: atltest.h:64
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:183
unsigned int ULONG
Definition: retypes.h:1
static void Test_ProcessWx86InformationClass(void)
#define STATUS_SUCCESS
Definition: shellext.h:65
START_TEST(NtSetInformationProcess)
#define HeapFree(x, y, z)
Definition: compat.h:594
static const INFORMATION_CLASS_INFO PsProcessInfoClass[]
Definition: ps_i.h:15
static void Test_ProcBasePriorityClass(void)