- ObpCreateDosDevicesDirectory: Check that allocation succeeded before dereference
[reactos.git] / reactos / ntoskrnl / ob / obname.c
index 45978be..c97d4ce 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * PROJECT:         ReactOS Kernel
  * LICENSE:         GPL - See COPYING in the top level directory
- * FILE:            ntoskrnl/ob/namespce.c
+ * FILE:            ntoskrnl/ob/obname.c
  * PURPOSE:         Manages all functions related to the Object Manager name-
  *                  space, such as finding objects or querying their names.
  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
@@ -22,7 +22,7 @@ POBJECT_DIRECTORY ObpTypeDirectoryObject;
 /* DOS Device Prefix \??\ and \?? */
 ALIGNEDNAME ObpDosDevicesShortNamePrefix = {{L'\\',L'?',L'?',L'\\'}};
 ALIGNEDNAME ObpDosDevicesShortNameRoot = {{L'\\',L'?',L'?',L'\0'}};
-static UNICODE_STRING ObpDosDevicesShortName =
+UNICODE_STRING ObpDosDevicesShortName =
 {
     sizeof(ObpDosDevicesShortNamePrefix),
     sizeof(ObpDosDevicesShortNamePrefix),
@@ -100,7 +100,8 @@ ObpCreateDosDevicesDirectory(VOID)
     /* FIXME: Hack Hack! */
     ObSystemDeviceMap = ExAllocatePoolWithTag(NonPagedPool,
                                               sizeof(*ObSystemDeviceMap),
-                                              TAG('O', 'b', 'D', 'm'));
+                                              'mDbO');
+    if (!ObSystemDeviceMap) return STATUS_INSUFFICIENT_RESOURCES;
     RtlZeroMemory(ObSystemDeviceMap, sizeof(*ObSystemDeviceMap));
 
     /* Return status */
@@ -179,7 +180,7 @@ ObpDeleteNameCheck(IN PVOID Object)
 
     /* Get object structures */
     ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object);
-    ObjectNameInfo = ObpAcquireNameInformation(ObjectHeader);
+    ObjectNameInfo = ObpReferenceNameInfo(ObjectHeader);
     ObjectType = ObjectHeader->Type;
 
     /*
@@ -193,7 +194,7 @@ ObpDeleteNameCheck(IN PVOID Object)
          !(ObjectHeader->Flags & OB_FLAG_PERMANENT))
     {
         /* Setup a lookup context */
-        ObpInitializeDirectoryLookup(&Context);
+        ObpInitializeLookupContext(&Context);
 
         /* Lock the directory */
         ObpAcquireDirectoryLockExclusive(ObjectNameInfo->Directory, &Context);
@@ -206,8 +207,8 @@ ObpDeleteNameCheck(IN PVOID Object)
                                          &Context);
         if (Object)
         {
-            /* Lock the object type */
-            ObpEnterObjectTypeMutex(ObjectType);
+            /* Lock the object */
+            ObpAcquireObjectLock(ObjectHeader);
 
             /* Make sure we can still delete the object */
             if (!(ObjectHeader->HandleCount) &&
@@ -238,20 +239,20 @@ ObpDeleteNameCheck(IN PVOID Object)
             }
 
             /* Release the lock */
-            ObpLeaveObjectTypeMutex(ObjectType);
+            ObpReleaseObjectLock(ObjectHeader);
         }
 
         /* Cleanup after lookup */
-        ObpCleanupDirectoryLookup(&Context);
+        ObpReleaseLookupContext(&Context);
 
         /* Remove another query reference since we added one on top */
-        ObpReleaseNameInformation(ObjectNameInfo);
+        ObpDereferenceNameInfo(ObjectNameInfo);
 
         /* Check if we were inserted in a directory */
         if (Directory)
         {
             /* We were, so first remove the extra reference we had added */
-            ObpReleaseNameInformation(ObjectNameInfo);
+            ObpDereferenceNameInfo(ObjectNameInfo);
 
             /* Now dereference the object as well */
             ObDereferenceObject(Object);
@@ -260,7 +261,7 @@ ObpDeleteNameCheck(IN PVOID Object)
     else
     {
         /* Remove the reference we added */
-        ObpReleaseNameInformation(ObjectNameInfo);
+        ObpDereferenceNameInfo(ObjectNameInfo);
     }
 }
 
@@ -282,7 +283,6 @@ ObpLookupObjectName(IN HANDLE RootHandle OPTIONAL,
     POBJECT_HEADER ObjectHeader;
     UNICODE_STRING ComponentName, RemainingName;
     BOOLEAN Reparse = FALSE, SymLink = FALSE;
-    PDEVICE_MAP DeviceMap = NULL;
     POBJECT_DIRECTORY Directory = NULL, ParentDirectory = NULL, RootDirectory;
     POBJECT_DIRECTORY ReferencedDirectory = NULL, ReferencedParentDirectory = NULL;
     KIRQL CalloutIrql;
@@ -300,7 +300,7 @@ ObpLookupObjectName(IN HANDLE RootHandle OPTIONAL,
             InsertObject);
 
     /* Initialize starting state */
-    ObpInitializeDirectoryLookup(LookupContext);
+    ObpInitializeLookupContext(LookupContext);
     *FoundObject = NULL;
     Status = STATUS_SUCCESS;
     Object = NULL;
@@ -497,13 +497,7 @@ ObpLookupObjectName(IN HANDLE RootHandle OPTIONAL,
         else
         {
 ParseFromRoot:
-            /* Check if we have a device map */
-            if (DeviceMap)
-            {
-                /* Dereference it */
-                //ObfDereferenceDeviceMap(DeviceMap);
-                DeviceMap = NULL;
-            }
+            /* FIXME: Check if we have a device map */
 
             /* Check if this is a possible DOS name */
             if (!((ULONG_PTR)(ObjectName->Buffer) & 7))
@@ -720,7 +714,7 @@ ParseFromRoot:
                 if (ObjectNameInfo->Name.Buffer)
                 {
                     /* Free it */
-                    ExFreePool(ObjectNameInfo->Name.Buffer);
+                    ExFreePoolWithTag(ObjectNameInfo->Name.Buffer, OB_NAME_TAG );
                 }
 
                 /* Write new one */
@@ -755,7 +749,7 @@ ReparseObject:
                 InterlockedExchangeAdd(&ObjectHeader->PointerCount, 1);
 
                 /* Cleanup from the first lookup */
-                ObpCleanupDirectoryLookup(LookupContext);
+                ObpReleaseLookupContext(LookupContext);
 
                 /* Check if we have a referenced directory */
                 if (ReferencedDirectory)
@@ -931,7 +925,7 @@ ReparseObject:
     if (!NT_SUCCESS(Status))
     {
         /* Cleanup after lookup */
-        ObpCleanupDirectoryLookup(LookupContext);
+        ObpReleaseLookupContext(LookupContext);
     }
 
     /* Check if we have a device map and dereference it if so */