advapi32-RegCopyTree: Update patchset.

This commit is contained in:
Sebastian Lackner 2016-02-28 03:37:04 +01:00
parent c7e3487afa
commit b5dbf4d86c
6 changed files with 161 additions and 154 deletions

View File

@ -1,14 +1,15 @@
From 33d8e5aac7dfedd9230ef340eeef57398282147c Mon Sep 17 00:00:00 2001
From a467ec1afb9e82ac62292f86b9dd53cf7eff2a83 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Mon, 15 Feb 2016 03:38:48 +0100
Date: Fri, 26 Feb 2016 16:58:23 +0100
Subject: advapi32/tests: Improve RegDeleteTree tests.
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
---
dlls/advapi32/tests/registry.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
dlls/advapi32/tests/registry.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index ef5d989..183e538 100644
index ef5d989..76a2928 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -41,7 +41,7 @@ static const char * sTestpath2 = "%FOO%\\subdir1";
@ -39,7 +40,7 @@ index ef5d989..183e538 100644
ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
ret = pRegDeleteTreeA(subkey, NULL);
ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
@@ -2143,8 +2146,8 @@ static void test_reg_delete_tree(void)
@@ -2143,9 +2146,23 @@ static void test_reg_delete_tree(void)
ok(ret == ERROR_SUCCESS,
"Default value of subkey is not present\n");
ok(!buffer[0], "Expected length 0 got length %u(%s)\n", lstrlenA(buffer), buffer);
@ -48,8 +49,23 @@ index ef5d989..183e538 100644
+ dwsize = MAX_PATH;
+ ok(RegQueryValueExA(subkey, "value", NULL, &type, (BYTE *)buffer, &dwsize),
"Value is still present\n");
+ ret = RegCloseKey(subkey);
+ ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
+
+ ret = RegOpenKeyA(hkey_main, "subkey", &subkey);
+ ok(ret == ERROR_SUCCESS, "subkey was deleted\n");
+ ret = pRegDeleteTreeA(subkey, "");
+ ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
+ ret = RegCloseKey(subkey);
+ ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
+
+ ret = RegOpenKeyA(hkey_main, "subkey", &subkey);
+ todo_wine ok(ret == ERROR_SUCCESS, "subkey was deleted\n");
+ ret = RegCloseKey(subkey);
+ todo_wine ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
ret = pRegDeleteTreeA(hkey_main, "not-here");
ok(ret == ERROR_FILE_NOT_FOUND,
--
2.7.1

View File

@ -1,14 +1,15 @@
From b41aaf3ea73161ee1680dd3dad34544484eaf05c Mon Sep 17 00:00:00 2001
From 662fc2e86a67494a394b6f9e98d2aac3e8705042 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Mon, 15 Feb 2016 03:40:36 +0100
Date: Fri, 26 Feb 2016 16:59:06 +0100
Subject: advapi32/tests: Add tests for RegCopyTree.
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
---
dlls/advapi32/tests/registry.c | 98 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index 183e538..d29e131 100644
index 76a2928..7664362 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -41,6 +41,7 @@ static const char * sTestpath2 = "%FOO%\\subdir1";
@ -129,7 +130,7 @@ index 183e538..d29e131 100644
static void test_reg_delete_tree(void)
{
CHAR buffer[MAX_PATH];
@@ -3320,6 +3417,7 @@ START_TEST(registry)
@@ -3334,6 +3431,7 @@ START_TEST(registry)
test_reg_save_key();
test_reg_load_key();
test_reg_unload_key();

View File

@ -1,18 +1,23 @@
From 8303376b344d5525f7124016fef073da747c6acd Mon Sep 17 00:00:00 2001
From d58022657d2eda1e50cabde52e96a6c8864b2123 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Mon, 15 Feb 2016 06:27:10 +0100
Date: Fri, 26 Feb 2016 17:00:05 +0100
Subject: advapi32: Implement RegCopyTreeA/W.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Michael Müller <michael@fds-team.de>
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
---
dlls/advapi32/advapi32.spec | 4 +-
dlls/advapi32/registry.c | 114 +++++++++++++++++++++
dlls/advapi32/tests/registry.c | 2 +-
.../api-ms-win-core-registry-l1-1-0.spec | 2 +-
.../api-ms-win-downlevel-advapi32-l1-1-0.spec | 2 +-
5 files changed, 119 insertions(+), 5 deletions(-)
dlls/advapi32/advapi32.spec | 4 +-
dlls/advapi32/registry.c | 95 ++++++++++++++++++++++
dlls/advapi32/tests/registry.c | 2 +-
.../api-ms-win-core-registry-l1-1-0.spec | 2 +-
.../api-ms-win-downlevel-advapi32-l1-1-0.spec | 2 +-
5 files changed, 100 insertions(+), 5 deletions(-)
diff --git a/dlls/advapi32/advapi32.spec b/dlls/advapi32/advapi32.spec
index 36f176b..e3c7c4b 100644
index 88f7fee..08f799d 100644
--- a/dlls/advapi32/advapi32.spec
+++ b/dlls/advapi32/advapi32.spec
@@ -575,8 +575,8 @@
@ -27,44 +32,13 @@ index 36f176b..e3c7c4b 100644
@ stdcall RegCreateKeyExA(long str long ptr long long ptr ptr ptr)
@ stdcall RegCreateKeyExW(long wstr long ptr long long ptr ptr ptr)
diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c
index 3508407..faca66c 100644
index 3508407..1e7639c 100644
--- a/dlls/advapi32/registry.c
+++ b/dlls/advapi32/registry.c
@@ -3104,6 +3104,120 @@ LSTATUS WINAPI RegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey)
@@ -3104,6 +3104,101 @@ LSTATUS WINAPI RegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey)
return ret;
}
+
+static LONG reg_get_buffers( HKEY hkey, WCHAR **name_buf, DWORD *name_size,
+ BYTE **value_buf, DWORD *value_size )
+{
+ DWORD ret, max_subkey, max_name, max_value;
+
+ ret = RegQueryInfoKeyW( hkey, NULL, NULL, NULL, NULL, &max_subkey,
+ NULL, NULL, &max_name, &max_value, NULL, NULL );
+ if (ret)
+ return ret;
+
+ /* allocate buffer for subkeys / names */
+ max_name = max( max_subkey, max_name ) + 1;
+ if (max_name > *name_size)
+ {
+ if (!(*name_buf = heap_alloc( max_name * sizeof(WCHAR) )))
+ return ERROR_NOT_ENOUGH_MEMORY;
+ *name_size = max_name;
+ }
+
+ /* allocate buffer for values */
+ if (max_value > *value_size)
+ {
+ if (!(*value_buf = heap_alloc( max_value )))
+ return ERROR_NOT_ENOUGH_MEMORY;
+ *value_size = max_value;
+ }
+
+ return ERROR_SUCCESS;
+}
+
+
+/******************************************************************************
+ * RegCopyTreeW [ADVAPI32.@]
@ -72,11 +46,11 @@ index 3508407..faca66c 100644
+ */
+LONG WINAPI RegCopyTreeW( HKEY hsrc, const WCHAR *subkey, HKEY hdst )
+{
+ WCHAR buf1[MAX_PATH], *name_buf = buf1;
+ BYTE buf2[MAX_PATH], *value_buf = buf2;
+ DWORD name_size, max_name = sizeof(buf1) / sizeof(WCHAR);
+ DWORD value_size, max_value = sizeof(buf2);
+ DWORD i, type;
+ DWORD name_size, max_name;
+ DWORD value_size, max_value;
+ DWORD max_subkey, i, type;
+ WCHAR *name_buf = NULL;
+ BYTE *value_buf = NULL;
+ HKEY hkey;
+ LONG ret;
+
@ -88,11 +62,25 @@ index 3508407..faca66c 100644
+ if (ret) return ret;
+ }
+
+ /* Allocate required buffers */
+ ret = reg_get_buffers( hsrc, &name_buf, &max_name, &value_buf, &max_value );
+ if (ret) goto cleanup;
+ ret = RegQueryInfoKeyW( hsrc, NULL, NULL, NULL, NULL, &max_subkey,
+ NULL, NULL, &max_name, &max_value, NULL, NULL );
+ if (ret)
+ goto cleanup;
+
+ /* Copy all the values */
+ max_name = max( max_subkey, max_name ) + 1;
+ if (!(name_buf = heap_alloc( max_name * sizeof(WCHAR) )))
+ {
+ ret = ERROR_NOT_ENOUGH_MEMORY;
+ goto cleanup;
+ }
+
+ if (!(value_buf = heap_alloc( max_value )))
+ {
+ ret = ERROR_NOT_ENOUGH_MEMORY;
+ goto cleanup;
+ }
+
+ /* Copy values */
+ for (i = 0;; i++)
+ {
+ name_size = max_name;
@ -104,7 +92,7 @@ index 3508407..faca66c 100644
+ if (ret) goto cleanup;
+ }
+
+ /* Recursively copy all the subkeys */
+ /* Recursively copy subkeys */
+ for (i = 0;; i++)
+ {
+ name_size = max_name;
@ -121,10 +109,8 @@ index 3508407..faca66c 100644
+ ret = ERROR_SUCCESS;
+
+cleanup:
+ if (name_buf != buf1)
+ heap_free( name_buf );
+ if (value_buf != buf2)
+ heap_free( value_buf );
+ heap_free( name_buf );
+ heap_free( value_buf );
+ if (subkey)
+ RegCloseKey( hsrc );
+ return ret;
@ -152,7 +138,7 @@ index 3508407..faca66c 100644
* RegDisableReflectionKey [ADVAPI32.@]
*
diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index d29e131..658b356 100644
index 7664362..483df47 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -2090,7 +2090,7 @@ static void test_reg_copy_tree(void)

View File

@ -1,51 +1,21 @@
From f9c5910f851677d6a8e7051043d254fb1538c0c3 Mon Sep 17 00:00:00 2001
From 7f360564594bf9bdc33e1c2d675a62045a1f41db Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Mon, 15 Feb 2016 06:40:17 +0100
Subject: advapi32: Clean up RegDeleteTree implementation.
Date: Fri, 26 Feb 2016 17:02:25 +0100
Subject: advapi32: Simplify and clean up RegDeleteTree implementation.
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
---
dlls/advapi32/registry.c | 156 ++++++++++++++++++++++-------------------------
1 file changed, 74 insertions(+), 82 deletions(-)
dlls/advapi32/registry.c | 101 +++++++++++++++++++++++------------------------
1 file changed, 50 insertions(+), 51 deletions(-)
diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c
index faca66c..eb23eb1 100644
index 1e7639c..172423b 100644
--- a/dlls/advapi32/registry.c
+++ b/dlls/advapi32/registry.c
@@ -3016,126 +3016,118 @@ LSTATUS WINAPI RegDisablePredefinedCache(void)
@@ -3016,91 +3016,90 @@ LSTATUS WINAPI RegDisablePredefinedCache(void)
return ERROR_SUCCESS;
}
+
+static LONG reg_get_buffers( HKEY hkey, WCHAR **name_buf, DWORD *name_size,
+ BYTE **value_buf, DWORD *value_size )
+{
+ DWORD ret, max_subkey, max_name, max_value;
+
+ ret = RegQueryInfoKeyW( hkey, NULL, NULL, NULL, NULL, &max_subkey,
+ NULL, NULL, &max_name, &max_value, NULL, NULL );
+ if (ret)
+ return ret;
+
+ /* allocate buffer for subkeys / names */
+ max_name = max( max_subkey, max_name ) + 1;
+ if (max_name > *name_size)
+ {
+ if (!(*name_buf = heap_alloc( max_name * sizeof(WCHAR) )))
+ return ERROR_NOT_ENOUGH_MEMORY;
+ *name_size = max_name;
+ }
+
+ /* allocate buffer for values */
+ if (value_buf && max_value > *value_size)
+ {
+ if (!(*value_buf = heap_alloc( max_value )))
+ return ERROR_NOT_ENOUGH_MEMORY;
+ *value_size = max_value;
+ }
+
+ return ERROR_SUCCESS;
+}
+
+
/******************************************************************************
* RegDeleteTreeW [ADVAPI32.@]
@ -55,8 +25,8 @@ index faca66c..eb23eb1 100644
+LSTATUS WINAPI RegDeleteTreeW( HKEY hkey, const WCHAR *subkey )
{
+ static const WCHAR emptyW[] = {0};
+ WCHAR buf1[MAX_PATH], *name_buf = buf1;
+ DWORD name_size, max_name = sizeof(buf1) / sizeof(WCHAR);
+ DWORD name_size, max_name, max_subkey;
+ WCHAR *name_buf = NULL;
LONG ret;
- DWORD dwMaxSubkeyLen, dwMaxValueLen;
- DWORD dwMaxLen, dwSize;
@ -77,16 +47,18 @@ index faca66c..eb23eb1 100644
- /* Get highest length for keys, values */
- ret = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
- &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
+ /* Allocate required buffers */
+ ret = reg_get_buffers( hkey, &name_buf, &max_name, NULL, NULL );
if (ret) goto cleanup;
- if (ret) goto cleanup;
+ ret = RegQueryInfoKeyW( hkey, NULL, NULL, NULL, NULL, &max_subkey,
+ NULL, NULL, &max_name, NULL, NULL, NULL );
+ if (ret)
+ goto cleanup;
- dwMaxSubkeyLen++;
- dwMaxValueLen++;
- dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
- if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
+ /* Recursively delete all the subkeys */
+ for (;;)
+ max_name = max( max_subkey, max_name ) + 1;
+ if (!(name_buf = heap_alloc( max_name * sizeof(WCHAR) )))
{
- /* Name too big: alloc a buffer for it */
- if (!(lpszName = heap_alloc( dwMaxLen*sizeof(WCHAR))))
@ -94,15 +66,21 @@ index faca66c..eb23eb1 100644
- ret = ERROR_NOT_ENOUGH_MEMORY;
- goto cleanup;
- }
+ ret = ERROR_NOT_ENOUGH_MEMORY;
+ goto cleanup;
}
+ /* Recursively delete subkeys */
+ for (;;)
+ {
+ name_size = max_name;
+ ret = RegEnumKeyExW( hkey, 0, name_buf, &name_size, NULL, NULL, NULL, NULL );
+ if (ret == ERROR_NO_MORE_ITEMS) break;
+ if (ret) goto cleanup;
+ ret = RegDeleteTreeW( hkey, name_buf );
+ if (ret) goto cleanup;
}
+ }
-
- /* Recursively delete all the subkeys */
- while (TRUE)
+ /* Delete the key itself */
@ -116,7 +94,7 @@ index faca66c..eb23eb1 100644
+ }
- ret = RegDeleteTreeW(hSubKey, lpszName);
+ /* Delete the values */
+ /* Delete values */
+ for (;;)
+ {
+ name_size = max_name;
@ -147,8 +125,7 @@ index faca66c..eb23eb1 100644
- heap_free( lpszName);
- if(lpszSubKey)
- RegCloseKey(hSubKey);
+ if (name_buf != buf1)
+ heap_free( name_buf );
+ heap_free( name_buf );
+ if (subkey)
+ RegCloseKey( hkey );
return ret;
@ -177,41 +154,6 @@ index faca66c..eb23eb1 100644
return ret;
}
-static LONG reg_get_buffers( HKEY hkey, WCHAR **name_buf, DWORD *name_size,
- BYTE **value_buf, DWORD *value_size )
-{
- DWORD ret, max_subkey, max_name, max_value;
-
- ret = RegQueryInfoKeyW( hkey, NULL, NULL, NULL, NULL, &max_subkey,
- NULL, NULL, &max_name, &max_value, NULL, NULL );
- if (ret)
- return ret;
-
- /* allocate buffer for subkeys / names */
- max_name = max( max_subkey, max_name ) + 1;
- if (max_name > *name_size)
- {
- if (!(*name_buf = heap_alloc( max_name * sizeof(WCHAR) )))
- return ERROR_NOT_ENOUGH_MEMORY;
- *name_size = max_name;
- }
-
- /* allocate buffer for values */
- if (max_value > *value_size)
- {
- if (!(*value_buf = heap_alloc( max_value )))
- return ERROR_NOT_ENOUGH_MEMORY;
- *value_size = max_value;
- }
-
- return ERROR_SUCCESS;
-}
-
-
/******************************************************************************
* RegCopyTreeW [ADVAPI32.@]
*
--
2.7.1

View File

@ -0,0 +1,60 @@
From a46f711251567a2846eb5b0f40a0d8c0b66661ac Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sun, 28 Feb 2016 03:33:09 +0100
Subject: advapi32: Fix RegDeleteTreeW when empty string is passed.
---
dlls/advapi32/registry.c | 6 +++---
dlls/advapi32/tests/registry.c | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c
index 172423b..aa451b1 100644
--- a/dlls/advapi32/registry.c
+++ b/dlls/advapi32/registry.c
@@ -3030,7 +3030,7 @@ LSTATUS WINAPI RegDeleteTreeW( HKEY hkey, const WCHAR *subkey )
TRACE( "(%p, %s)\n", hkey, debugstr_w(subkey) );
- if (subkey)
+ if (subkey && *subkey)
{
ret = RegOpenKeyExW( hkey, subkey, 0, KEY_READ, &hkey );
if (ret) return ret;
@@ -3060,7 +3060,7 @@ LSTATUS WINAPI RegDeleteTreeW( HKEY hkey, const WCHAR *subkey )
}
/* Delete the key itself */
- if (subkey)
+ if (subkey && *subkey)
{
ret = RegDeleteKeyW( hkey, emptyW );
goto cleanup;
@@ -3081,7 +3081,7 @@ LSTATUS WINAPI RegDeleteTreeW( HKEY hkey, const WCHAR *subkey )
cleanup:
heap_free( name_buf );
- if (subkey)
+ if (subkey && *subkey)
RegCloseKey( hkey );
return ret;
}
diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index 483df47..6010123 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -2257,9 +2257,9 @@ static void test_reg_delete_tree(void)
ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
ret = RegOpenKeyA(hkey_main, "subkey", &subkey);
- todo_wine ok(ret == ERROR_SUCCESS, "subkey was deleted\n");
+ ok(ret == ERROR_SUCCESS, "subkey was deleted\n");
ret = RegCloseKey(subkey);
- todo_wine ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
+ ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
ret = pRegDeleteTreeA(hkey_main, "not-here");
ok(ret == ERROR_FILE_NOT_FOUND,
--
2.7.1

View File

@ -2508,12 +2508,14 @@ if test "$enable_advapi32_RegCopyTree" -eq 1; then
patch_apply advapi32-RegCopyTree/0001-advapi32-tests-Improve-RegDeleteTree-tests.patch
patch_apply advapi32-RegCopyTree/0002-advapi32-tests-Add-tests-for-RegCopyTree.patch
patch_apply advapi32-RegCopyTree/0003-advapi32-Implement-RegCopyTreeA-W.patch
patch_apply advapi32-RegCopyTree/0004-advapi32-Clean-up-RegDeleteTree-implementation.patch
patch_apply advapi32-RegCopyTree/0004-advapi32-Simplify-and-clean-up-RegDeleteTree-impleme.patch
patch_apply advapi32-RegCopyTree/0005-advapi32-Fix-RegDeleteTreeW-when-empty-string-is-pas.patch
(
echo '+ { "Sebastian Lackner", "advapi32/tests: Improve RegDeleteTree tests.", 1 },';
echo '+ { "Sebastian Lackner", "advapi32/tests: Add tests for RegCopyTree.", 1 },';
echo '+ { "Michael Müller", "advapi32: Implement RegCopyTreeA/W.", 1 },';
echo '+ { "Sebastian Lackner", "advapi32: Clean up RegDeleteTree implementation.", 1 },';
echo '+ { "Sebastian Lackner", "advapi32: Simplify and clean up RegDeleteTree implementation.", 1 },';
echo '+ { "Sebastian Lackner", "advapi32: Fix RegDeleteTreeW when empty string is passed.", 1 },';
) >> "$patchlist"
fi