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

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

wine commit id 4df5c1641e7091f42c2313b275d999f2b9d25eff by Hugh McMaster <hugh.mcmaster@outlook.com>

manual adjustment needed
This commit is contained in:
winesync 2022-01-16 20:56:12 +01:00 committed by Thomas Csovcsity
parent ec55298764
commit 9b424b0080
4 changed files with 25 additions and 16 deletions

View file

@ -344,27 +344,33 @@ static HANDLE get_file_handle(WCHAR *filename, BOOL overwrite_file)
return hFile; return hFile;
} }
static BOOL is_overwrite_switch(const WCHAR *s)
{
return is_switch(s, 'y');
}
int reg_export(int argc, WCHAR *argvW[]) int reg_export(int argc, WCHAR *argvW[])
{ {
HKEY root, hkey; HKEY root, hkey;
WCHAR *path, *long_key; WCHAR *path, *long_key;
BOOL overwrite_file = FALSE; BOOL overwrite_file = FALSE;
HANDLE hFile; HANDLE hFile;
int ret; int i, ret;
if (argc == 3 || argc > 5) if (argc < 4) goto invalid;
goto error;
if (!parse_registry_key(argvW[2], &root, &path, &long_key)) if (!parse_registry_key(argvW[2], &root, &path, &long_key))
return 1; return 1;
if (argc == 5 && !(overwrite_file = is_overwrite_switch(argvW[4]))) for (i = 4; i < argc; i++)
goto error; {
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)) if (RegOpenKeyExW(root, path, 0, KEY_READ, &hkey))
{ {
@ -382,7 +388,7 @@ int reg_export(int argc, WCHAR *argvW[])
return ret; return ret;
error: invalid:
output_message(STRING_INVALID_SYNTAX); output_message(STRING_INVALID_SYNTAX);
output_message(STRING_FUNC_HELP, _wcsupr(argvW[1])); output_message(STRING_FUNC_HELP, _wcsupr(argvW[1]));
return 1; return 1;

View file

@ -250,15 +250,17 @@ BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path, WCHAR **long
return TRUE; 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) BOOL is_switch(const WCHAR *s, const WCHAR c)
{ {
if (lstrlenW(s) > 2) if (lstrlenW(s) > 2)
return FALSE; return FALSE;
if ((s[0] == '/' || s[0] == '-') && (s[1] == c || s[1] == towupper(c))) return ((s[0] == '/' || s[0] == '-') && is_char(s[1], c));
return TRUE;
return FALSE;
} }
static BOOL is_help_switch(const WCHAR *s) static BOOL is_help_switch(const WCHAR *s)

View file

@ -40,6 +40,7 @@ BOOL ask_confirm(unsigned int msgid, WCHAR *reg_info);
HKEY path_get_rootkey(const WCHAR *path); HKEY path_get_rootkey(const WCHAR *path);
WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD subkey_len); 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 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); BOOL is_switch(const WCHAR *s, const WCHAR c);
/* add.c */ /* add.c */

View file

@ -4,4 +4,4 @@ directories:
files: files:
programs/reg/resource.h: base/applications/cmdutils/reg/resource.h programs/reg/resource.h: base/applications/cmdutils/reg/resource.h
tags: tags:
wine: 1b746c1e1c4da4a07a1293fe9e60429867c86697 wine: 4df5c1641e7091f42c2313b275d999f2b9d25eff