[PATCH] advapi32: Only allow opening HKEY_CLASSES_ROOT subkeys with backslash prefix on W2K+. (try 2)

Lei Zhang thestig at google.com
Tue Nov 25 14:05:29 CST 2008


Hi,

Commit aacb511da1540fa015c5e853c90fd054b9442701 assumed NT+ behaved
the same way, but running the tests turns out it's actually W2K+.

This is the correct copy of the patch.
-------------- next part --------------
From 98a35b2279d6ce04af848ab3bb44dd7d01e08426 Mon Sep 17 00:00:00 2001
From: Lei Zhang <thestig at google.com>
Date: Tue, 25 Nov 2008 12:04:11 -0800
Subject: [PATCH] advapi32: Only allow opening HKEY_CLASSES_ROOT subkeys with backslash prefix on W2K+.

---
 dlls/advapi32/registry.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c
index 6615bc0..473c8a3 100644
--- a/dlls/advapi32/registry.c
+++ b/dlls/advapi32/registry.c
@@ -91,6 +91,14 @@ static inline int is_version_nt(void)
     return !(GetVersion() & 0x80000000);
 }
 
+/* check if current version is W2K or greater */
+static inline int is_version_2kplus(void)
+{
+    DWORD ver = GetVersion();
+    if (ver & 0x80000000) return 0;
+    return (ver & 0x000000ff) >= 5;
+}
+
 /* create one of the HKEY_* special root keys */
 static HKEY create_special_root_hkey( HANDLE hkey, DWORD access )
 {
@@ -306,8 +314,9 @@ LSTATUS WINAPI RegOpenKeyExW( HKEY hkey, LPCWSTR name, DWORD reserved, REGSAM ac
     OBJECT_ATTRIBUTES attr;
     UNICODE_STRING nameW;
 
-    /* NT+ allows beginning backslash for HKEY_CLASSES_ROOT */
-    if (hkey == HKEY_CLASSES_ROOT && name && *name == '\\') name++;
+    /* W2K+ allows beginning backslash for HKEY_CLASSES_ROOT */
+    if (hkey == HKEY_CLASSES_ROOT && is_version_2kplus() &&
+        name && *name == '\\') name++;
 
     if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
 
@@ -351,8 +360,9 @@ LSTATUS WINAPI RegOpenKeyExA( HKEY hkey, LPCSTR name, DWORD reserved, REGSAM acc
     if (!is_version_nt()) access = KEY_ALL_ACCESS;  /* Win95 ignores the access mask */
     else
     {
-        /* NT+ allows beginning backslash for HKEY_CLASSES_ROOT */
-        if (hkey == HKEY_CLASSES_ROOT && name && *name == '\\') name++;
+        /* W2K+ allows beginning backslash for HKEY_CLASSES_ROOT */
+        if (hkey == HKEY_CLASSES_ROOT && name && is_version_2kplus() &&
+            *name == '\\') name++;
     }
 
     if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
-- 
1.5.4.5


More information about the wine-patches mailing list