Synchronize with trunk.
[reactos.git] / ntoskrnl / ob / obhandle.c
index 20d1565..b4c260a 100644 (file)
@@ -753,12 +753,10 @@ ObpCloseHandleTableEntry(IN PHANDLE_TABLE HandleTable,
 
     /* Return to caller */
     OBTRACE(OB_HANDLE_DEBUG,
-            "%s - Closed handle: %lx for %p. HC PC %lx %lx\n",
+            "%s - Closed handle: %lx for %p.\n",
             __FUNCTION__,
             Handle,
-            Body,
-            ObjectHeader->HandleCount,
-            ObjectHeader->PointerCount);
+            Body);
     return STATUS_SUCCESS;
 }
 
@@ -1712,6 +1710,9 @@ ObpCloseHandle(IN HANDLE Handle,
     OBTRACE(OB_HANDLE_DEBUG,
             "%s - Closing handle: %lx\n", __FUNCTION__, Handle);
 
+    if (AccessMode == KernelMode && Handle == (HANDLE)-1)
+        return STATUS_INVALID_HANDLE;
+
     /* Check if we're dealing with a kernel handle */
     if (ObIsKernelHandle(Handle, AccessMode))
     {
@@ -1752,7 +1753,6 @@ ObpCloseHandle(IN HANDLE Handle,
 
         /* Detach and return success */
         if (AttachedToProcess) KeUnstackDetachProcess(&ApcState);
-        Status = STATUS_SUCCESS;
     }
     else
     {
@@ -2456,6 +2456,7 @@ ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes,
 
     /* Capture all the info */
     Status = ObpCaptureObjectCreateInformation(ObjectAttributes,
+                                               AccessMode,
                                                AccessMode,
                                                TRUE,
                                                &TempBuffer->ObjectCreateInfo,
@@ -2489,6 +2490,15 @@ ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes,
         PassedAccessState->SecurityDescriptor =
             TempBuffer->ObjectCreateInfo.SecurityDescriptor;
     }
+    
+    /* Validate the access mask */
+    Status = ObpValidateAccessMask(PassedAccessState);
+    if (!NT_SUCCESS(Status))
+    {
+        /* Cleanup after lookup */
+        ObpReleaseLookupContext(&TempBuffer->LookupContext);
+        goto Cleanup;
+    }
 
     /* Now do the lookup */
     Status = ObpLookupObjectName(TempBuffer->ObjectCreateInfo.RootDirectory,