From 62b69d64869600e5d81c611b5450386e9fcab586 Mon Sep 17 00:00:00 2001 From: Rein Klazes Date: Thu, 8 Dec 2005 13:49:02 +0100 Subject: [PATCH] advapi32: RegCreateKeyEx fix. On Win9x,ME RegCreateKeyEx ignores the backslash character if the subkey begins with one. With a regression test. --- dlls/advapi32/registry.c | 6 +++++- dlls/advapi32/tests/registry.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c index 9399c1e7644..4cb6add12b1 100644 --- a/dlls/advapi32/registry.c +++ b/dlls/advapi32/registry.c @@ -206,7 +206,11 @@ DWORD WINAPI RegCreateKeyExA( HKEY hkey, LPCSTR name, DWORD reserved, LPSTR clas NTSTATUS status; if (reserved) return ERROR_INVALID_PARAMETER; - if (!is_version_nt()) access = KEY_ALL_ACCESS; /* Win95 ignores the access mask */ + if (!is_version_nt()) + { + access = KEY_ALL_ACCESS; /* Win95 ignores the access mask */ + if (name && *name == '\\') name++; /* win9x,ME ignores one (and only one) beginning backslash */ + } else if (!(access & KEY_ACCESS_MASK) || (access & ~KEY_ACCESS_MASK)) return ERROR_ACCESS_DENIED; if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE; diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c index 738de735261..8014e148274 100644 --- a/dlls/advapi32/tests/registry.c +++ b/dlls/advapi32/tests/registry.c @@ -476,6 +476,12 @@ static void test_reg_open_key(void) /* send in NULL hkResult */ ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL); ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %ld\n", ret); + + /* beginning backslash character */ + ret = RegOpenKeyA(HKEY_CURRENT_USER, "\\Software\\Wine\\Test", &hkResult); + ok(ret == ERROR_BAD_PATHNAME || /* NT/2k/XP */ + ret == ERROR_FILE_NOT_FOUND /* Win9x,ME */ + , "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %ld\n", ret); } static void test_reg_create_key(void) @@ -492,6 +498,15 @@ static void test_reg_create_key(void) /* clean up */ RegDeleteKey(hkey2, NULL); RegDeleteKey(hkey1, NULL); + + /* beginning backslash character */ + ret = RegCreateKeyExA(hkey_main, "\\Subkey3", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL); + if (!(GetVersion() & 0x80000000)) + ok(ret == ERROR_BAD_PATHNAME, "expected ERROR_BAD_PATHNAME, got %ld\n", ret); + else { + ok(!ret, "RegCreateKeyExA failed with error %ld\n", ret); + RegDeleteKey(hkey1, NULL); + } } static void test_reg_close_key(void)