@@ -107,6 +107,13 @@ NtCreateEvent(OUT PHANDLE EventHandle,
107107 DPRINT ("NtCreateEvent(0x%p, 0x%x, 0x%p)\n" ,
108108 EventHandle , DesiredAccess , ObjectAttributes );
109109
110+ /* Validate the event type */
111+ if ((EventType != NotificationEvent ) &&
112+ (EventType != SynchronizationEvent ))
113+ {
114+ return STATUS_INVALID_PARAMETER ;
115+ }
116+
110117 /* Check if we were called from user-mode */
111118 if (PreviousMode != KernelMode )
112119 {
@@ -134,40 +141,41 @@ NtCreateEvent(OUT PHANDLE EventHandle,
134141 0 ,
135142 0 ,
136143 (PVOID * )& Event );
144+ if (!NT_SUCCESS (Status ))
145+ {
146+ DPRINT1 ("ObCreateObject failed: 0x%X\n" , Status );
147+ return Status ;
148+ }
137149
138- /* Check for Success */
139- if (NT_SUCCESS (Status ))
150+ /* Initialize the Event */
151+ KeInitializeEvent (Event , EventType , InitialState );
152+
153+ /* Insert it */
154+ Status = ObInsertObject ((PVOID )Event ,
155+ NULL ,
156+ DesiredAccess ,
157+ 0 ,
158+ NULL ,
159+ & hEvent );
160+ if (!NT_SUCCESS (Status ))
140161 {
141- /* Initialize the Event */
142- KeInitializeEvent (Event ,
143- EventType ,
144- InitialState );
145-
146- /* Insert it */
147- Status = ObInsertObject ((PVOID )Event ,
148- NULL ,
149- DesiredAccess ,
150- 0 ,
151- NULL ,
152- & hEvent );
153-
154- /* Check for success */
155- if (NT_SUCCESS (Status ))
156- {
157- /* Enter SEH for return */
158- _SEH2_TRY
159- {
160- /* Return the handle to the caller */
161- * EventHandle = hEvent ;
162- }
163- _SEH2_EXCEPT (ExSystemExceptionFilter ())
164- {
165- /* Get the exception code */
166- Status = _SEH2_GetExceptionCode ();
167- }
168- _SEH2_END ;
169- }
162+ DPRINT1 ("ObInsertObject failed: 0x%X\n" , Status );
163+ /* Note: ObInsertObject dereferences Event on failure */
164+ return Status ;
165+ }
166+
167+ /* Enter SEH for return */
168+ _SEH2_TRY
169+ {
170+ /* Return the handle to the caller */
171+ * EventHandle = hEvent ;
172+ }
173+ _SEH2_EXCEPT (ExSystemExceptionFilter ())
174+ {
175+ /* Get the exception code */
176+ Status = _SEH2_GetExceptionCode ();
170177 }
178+ _SEH2_END ;
171179
172180 /* Return Status */
173181 return Status ;
0 commit comments