Hugh McMaster : reg: Improve initial syntax checks during the 'export' operation.

Alexandre Julliard julliard at winehq.org
Thu Apr 1 16:09:27 CDT 2021


Module: wine
Branch: master
Commit: 4df5c1641e7091f42c2313b275d999f2b9d25eff
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=4df5c1641e7091f42c2313b275d999f2b9d25eff

Author: Hugh McMaster <hugh.mcmaster at outlook.com>
Date:   Thu Apr  1 23:20:48 2021 +1100

reg: Improve initial syntax checks during the 'export' operation.

Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 programs/reg/export.c | 28 +++++++++++++++++-----------
 programs/reg/reg.c    | 10 ++++++----
 programs/reg/reg.h    |  1 +
 3 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/programs/reg/export.c b/programs/reg/export.c
index 3150c075f26..79f055c691f 100644
--- a/programs/reg/export.c
+++ b/programs/reg/export.c
@@ -344,27 +344,33 @@ static HANDLE get_file_handle(WCHAR *filename, BOOL overwrite_file)
     return hFile;
 }
 
-static BOOL is_overwrite_switch(const WCHAR *s)
-{
-    return is_switch(s, 'y');
-}
-
 int reg_export(int argc, WCHAR *argvW[])
 {
     HKEY root, hkey;
     WCHAR *path, *long_key;
     BOOL overwrite_file = FALSE;
     HANDLE hFile;
-    int ret;
+    int i, ret;
 
-    if (argc == 3 || argc > 5)
-        goto error;
+    if (argc < 4) goto invalid;
 
     if (!parse_registry_key(argvW[2], &root, &path, &long_key))
         return 1;
 
-    if (argc == 5 && !(overwrite_file = is_overwrite_switch(argvW[4])))
-        goto error;
+    for (i = 4; i < argc; i++)
+    {
+        WCHAR *str;
+
+        if (argvW[i][0] != '/' && argvW[i][0] != '-')
+            goto invalid;
+
+        str = &argvW[i][1];
+
+        if (is_char(*str, 'y') && !str[1])
+            overwrite_file = TRUE;
+        else
+            goto invalid;
+    }
 
     if (RegOpenKeyExW(root, path, 0, KEY_READ, &hkey))
     {
@@ -382,7 +388,7 @@ int reg_export(int argc, WCHAR *argvW[])
 
     return ret;
 
-error:
+invalid:
     output_message(STRING_INVALID_SYNTAX);
     output_message(STRING_FUNC_HELP, wcsupr(argvW[1]));
     return 1;
diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index 10aaabf92da..6b337f5d415 100644
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -250,15 +250,17 @@ BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path, WCHAR **long
     return TRUE;
 }
 
+BOOL is_char(const WCHAR s, const WCHAR c)
+{
+    return (s == c || s == towupper(c));
+}
+
 BOOL is_switch(const WCHAR *s, const WCHAR c)
 {
     if (lstrlenW(s) > 2)
         return FALSE;
 
-    if ((s[0] == '/' || s[0] == '-') && (s[1] == c || s[1] == towupper(c)))
-        return TRUE;
-
-    return FALSE;
+    return ((s[0] == '/' || s[0] == '-') && is_char(s[1], c));
 }
 
 static BOOL is_help_switch(const WCHAR *s)
diff --git a/programs/reg/reg.h b/programs/reg/reg.h
index 3525bed75b8..c7719a6e4f0 100644
--- a/programs/reg/reg.h
+++ b/programs/reg/reg.h
@@ -40,6 +40,7 @@ BOOL ask_confirm(unsigned int msgid, WCHAR *reg_info);
 HKEY path_get_rootkey(const WCHAR *path);
 WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD subkey_len);
 BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path, WCHAR **long_key);
+BOOL is_char(const WCHAR s, const WCHAR c);
 BOOL is_switch(const WCHAR *s, const WCHAR c);
 
 /* add.c */




More information about the wine-cvs mailing list