[PATCH 5/5] reg: Fail if the source and destination keys are the same when copying
Hugh McMaster
hugh.mcmaster at outlook.com
Mon May 31 04:45:24 CDT 2021
Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
programs/reg/copy.c | 6 ++++++
programs/reg/reg.c | 17 +++++++----------
programs/reg/reg.rc | 2 ++
programs/reg/resource.h | 3 +++
4 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/programs/reg/copy.c b/programs/reg/copy.c
index 34abf8ade18..208adc46e00 100644
--- a/programs/reg/copy.c
+++ b/programs/reg/copy.c
@@ -163,6 +163,12 @@ int reg_copy(int argc, WCHAR *argvW[])
}
}
+ if (src.root == dest.root && !lstrcmpiW(src.subkey, dest.subkey))
+ {
+ output_message(STRING_COPY_SRC_DEST_SAME);
+ return 1;
+ }
+
return run_copy(&src, &dest, recurse, force);
invalid:
diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index 8d3bf78f0a9..617ec9df56f 100644
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -206,7 +206,7 @@ WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD
WCHAR *get_long_key(HKEY root, WCHAR *path)
{
- int i, len, path_len;
+ int i, len;
WCHAR *long_key;
for (i = 0; i < ARRAY_SIZE(root_rels); i++)
@@ -224,15 +224,7 @@ WCHAR *get_long_key(HKEY root, WCHAR *path)
return long_key;
}
- path_len = lstrlenW(path);
-
- if (path[path_len - 1] == '\\')
- {
- path[path_len - 1] = 0;
- path_len--;
- }
-
- len += path_len + 1; /* add one for the concatenating backslash */
+ len += lstrlenW(path) + 1; /* add one for the concatenating backslash */
long_key = malloc((len + 1) * sizeof(WCHAR));
swprintf(long_key, len + 1, L"%s\\%s", root_rels[i].long_name, path);
return long_key;
@@ -240,6 +232,8 @@ WCHAR *get_long_key(HKEY root, WCHAR *path)
BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path)
{
+ WCHAR *p;
+
if (!sane_path(key))
return FALSE;
@@ -263,6 +257,9 @@ BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path)
return FALSE;
}
+ p = *path + lstrlenW(*path) - 1;
+ if (*p == '\\') *p = 0;
+
return TRUE;
}
diff --git a/programs/reg/reg.rc b/programs/reg/reg.rc
index 1b451dc016b..89df2c45c4c 100644
--- a/programs/reg/reg.rc
+++ b/programs/reg/reg.rc
@@ -197,4 +197,6 @@ STRINGTABLE
\ /f\n\
\ Overwrite all registry data in <key2> without prompting for confirmation.\n\
\ This option does not modify subkeys and values that only exist in <key2>.\n\n"
+
+ STRING_COPY_SRC_DEST_SAME, "reg: The source and destination keys cannot be the same\n"
}
diff --git a/programs/reg/resource.h b/programs/reg/resource.h
index a4dcc5fc078..92d82d80a9b 100644
--- a/programs/reg/resource.h
+++ b/programs/reg/resource.h
@@ -59,6 +59,9 @@
#define STRING_OVERWRITE_VALUE 205
#define STRING_INVALID_CMDLINE 206
+/* copy.c */
+#define STRING_COPY_SRC_DEST_SAME 250
+
/* delete.c */
#define STRING_DELETE_VALUE 300
#define STRING_DELETE_VALUEALL 301
--
2.32.0.rc0
More information about the wine-devel
mailing list