[ros-diffs] [akhaldi] 54982: [PORTCLS] * Fix a bug which closed an already invalid handle. * Allow only general registry keys to be deleted. * Do not close a key twice in the error case.

akhaldi at svn.reactos.org akhaldi at svn.reactos.org
Sun Jan 15 20:27:17 UTC 2012


Author: akhaldi
Date: Sun Jan 15 20:27:15 2012
New Revision: 54982

URL: http://svn.reactos.org/svn/reactos?rev=54982&view=rev
Log:
[PORTCLS]
* Fix a bug which closed an already invalid handle.
* Allow only general registry keys to be deleted.
* Do not close a key twice in the error case.

Modified:
    trunk/reactos/drivers/wdm/audio/backpln/portcls/registry.cpp

Modified: trunk/reactos/drivers/wdm/audio/backpln/portcls/registry.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/portcls/registry.cpp?rev=54982&r1=54981&r2=54982&view=diff
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/registry.cpp [iso-8859-1] (original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/registry.cpp [iso-8859-1] Sun Jan 15 20:27:15 2012
@@ -31,20 +31,24 @@
     }
 
     IMP_IRegistryKey;
-    CRegistryKey(IUnknown * OuterUnknown, HANDLE hKey) : m_hKey(hKey){}
+    CRegistryKey(IUnknown * OuterUnknown, HANDLE hKey, BOOL CanDelete) : m_hKey(hKey), m_Deleted(FALSE), m_CanDelete(CanDelete), m_Ref(0){}
     virtual ~CRegistryKey();
 
 protected:
 
     HANDLE m_hKey;
     BOOL m_Deleted;
+    BOOL m_CanDelete;
     LONG m_Ref;
 };
 
 CRegistryKey::~CRegistryKey()
 {
-    if (m_hKey)
+    if (!m_Deleted)
+    {
+         // close key only when has not been deleted yet
          ZwClose(m_hKey);
+    }
 }
 
 
@@ -83,13 +87,22 @@
 
     if (m_Deleted)
     {
-        return STATUS_INVALID_HANDLE;
-    }
-
+        // key already deleted
+        return STATUS_INVALID_HANDLE;
+    }
+
+    if (!m_CanDelete)
+    {
+        // only general keys can be deleted
+        return STATUS_ACCESS_DENIED;
+    }
+
+    // delete key
     Status = ZwDeleteKey(m_hKey);
     if (NT_SUCCESS(Status))
     {
         m_Deleted = TRUE;
+        m_hKey = NULL;
     }
     return Status;
 }
@@ -164,7 +177,7 @@
         return Status;
     }
 
-    RegistryKey = new(NonPagedPool, TAG_PORTCLASS)CRegistryKey(OuterUnknown, hKey);
+    RegistryKey = new(NonPagedPool, TAG_PORTCLASS)CRegistryKey(OuterUnknown, hKey, TRUE);
     if (!RegistryKey)
         return STATUS_INSUFFICIENT_RESOURCES;
 
@@ -172,7 +185,6 @@
 
     if (!NT_SUCCESS(Status))
     {
-        ZwClose(hKey);
         delete RegistryKey;
         return Status;
     }
@@ -278,6 +290,7 @@
     PSUBDEVICE_DESCRIPTOR SubDeviceDescriptor;
     ISubdevice * Device;
     PSYMBOLICLINK_ENTRY SymEntry;
+    BOOL CanDelete = FALSE;
 
     DPRINT("PcNewRegistryKey entered\n");
 
@@ -304,6 +317,9 @@
         }
         // try to create the key
         Status = ZwCreateKey(&hHandle, DesiredAccess, ObjectAttributes, 0, NULL, CreateOptions, Disposition);
+
+        // key can be deleted
+        CanDelete = TRUE;
     }
     else if (RegistryKeyType == DeviceRegistryKey ||
              RegistryKeyType == DriverRegistryKey ||
@@ -374,7 +390,7 @@
     }
 
     // allocate new registry key object
-    RegistryKey = new(NonPagedPool, TAG_PORTCLASS)CRegistryKey(OuterUnknown, hHandle);
+    RegistryKey = new(NonPagedPool, TAG_PORTCLASS)CRegistryKey(OuterUnknown, hHandle, CanDelete);
     if (!RegistryKey)
     {
         // not enough memory
@@ -394,4 +410,3 @@
     DPRINT("PcNewRegistryKey result %p\n", *OutRegistryKey);
     return STATUS_SUCCESS;
 }
-




More information about the Ros-diffs mailing list